Vector

A lightweight 1x3 vector class.  Vector allows game objects to be represented in three dimensional world space.  It provides basic arithmetic and vector functions for manipulating position data.

Project

ModelCore

Include

Vector.h

Summary
A lightweight 1x3 vector class.
The default Vector constructor.
The Vector constructor.
Compares the vector to another vector.
Compares the vector to another vector.
Subtracts another vector from the vector.
Adds another vector to the vector.
Multiples the vector by a scalar.
Divides the vector by a scalar.
Calculates and returns the length of the vector.
Normalizes the vector in place.
Normalizes the vector into the given Vector.

Constructors

Vector

Vector() : x(0.0f), y(0.0f), z(0.0f)

The default Vector constructor.  Initializes all values to zero.

Vector

Vector(float a,
float b,
float c) : x(a), y(b), z(c)

The Vector constructor.  Initializes all values to the given values.

Parameters

aThe x value.
bThe y value.
cThe z value.

Operators

operator==

bool operator==(const Vector &rhs)

Compares the vector to another vector.

Parameters

rhsThe vector to compare.

Returns

A bool that is true if the Vectors are equal and false if not.

operator!=

bool operator!=(const Vector &rhs)

Compares the vector to another vector.

Parameters

rhsThe vector to compare.

Returns

A bool that is false if the Vectors are equal and true if not.

operator-=

Vector &operator-=(const Vector &rhs)

Subtracts another vector from the vector.

Parameters

rhsThe vector to subtract.

operator+=

Vector &operator+=(const Vector &rhs)

Adds another vector to the vector.

Parameters

rhsThe vector to add.

operator*=

Vector &operator*=(const float rhs)

Multiples the vector by a scalar.

Parameters

rhsThe scalar to multiply by.

operator/=

Vector &operator/=(const float rhs)

Divides the vector by a scalar.

Parameters

rhsThe scalar to divide by.

Functions

Length

float Length() const

Calculates and returns the length of the vector.

Returns

The length of the vector.

Normalize

void Normalize()

Normalizes the vector in place.

Normalize

void Normalize(Vector &dest)

Normalizes the vector into the given Vector.

Parameters

destThe destination Vector.
Vector() : x(0.0f), y(0.0f), z(0.0f)
The default Vector constructor.
bool operator==(const Vector &rhs)
Compares the vector to another vector.
bool operator!=(const Vector &rhs)
Compares the vector to another vector.
Vector &operator-=(const Vector &rhs)
Subtracts another vector from the vector.
Vector &operator+=(const Vector &rhs)
Adds another vector to the vector.
Vector &operator*=(const float rhs)
Multiples the vector by a scalar.
Vector &operator/=(const float rhs)
Divides the vector by a scalar.
float Length() const
Calculates and returns the length of the vector.
void Normalize()
Normalizes the vector in place.
ModelCore provides all of the data classes and associated helper classes and functions required to represent a complete game.