v0.1.8
 All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Pages
CGUL::Vector3T< Type > Struct Template Reference

A three dimensional 32 bit floating point vector. More...

#include <Vector3.hpp>

Public Member Functions

 Vector3T ()
 Initializes to (0, 0, 0).
 
 Vector3T (const Vector3T &copy)
 Copies a vector into this vector. More...
 
 Vector3T (const Vector2T< Type > &copy)
 Copies a vector2 into this vector3's first two components and Initializes z to 0. More...
 
 Vector3T (const Vector2T< Type > &copy, Type z)
 Copies a vector2 into this vector3's first two components and Initializes z with the individual component value. More...
 
 Vector3T (Type value)
 Initializes all components to a given value. More...
 
 Vector3T (Type x, Type y, Type z)
 Initializes the vector with individual component values. More...
 
Vector3Toperator= (const Vector3T &operand)
 Assigns another vector into this vector. More...
 
Type & operator[] (UInt32 index)
 Accesses an individual component in this vector. More...
 
Type operator[] (UInt32 index) const
 Accesses an individual (constant) component in this vector. More...
 
Vector3T operator- () const
 Gets the inverse of the vector. More...
 
bool operator== (const Vector3T &operand) const
 Checks if two vectors are exactly equal. More...
 
bool operator!= (const Vector3T &operand) const
 Checks if two vectors are not exactly equal. More...
 
Vector3T operator+ (const Vector3T &operand) const
 Performs component-based addition on two vectors. More...
 
Vector3Toperator+= (const Vector3T &operand)
 Adds the individual components of another vector to this vector's components. More...
 
Vector3Toperator+= (const Vector2T< Type > &operand)
 Adds the individual components of a vector2 to this vector3's first two components. More...
 
Vector3T operator- (const Vector3T &operand) const
 Performs component-based subtraction on two vectors. More...
 
Vector3Toperator-= (const Vector3T &operand)
 Subtracts the individual components of another vector from this vector's components. More...
 
Vector3Toperator-= (const Vector2T< Type > &operand)
 Subtracts the individual components of a vector2 to this vector3's first two components. More...
 
Vector3T operator* (Type operand) const
 Performs component-based multiplication on two vectors. More...
 
Vector3T operator* (const MatrixT< Type > &operand) const
 
Vector3Toperator*= (Type operand)
 Multiplies the individual components of another vector onto this vector's components. More...
 
Vector3Toperator*= (const MatrixT< Type > &operand)
 
Vector3T operator/ (Type operand) const
 Performs component-based division on two vectors. More...
 
Vector3Toperator/= (Type operand)
 Divides the individual components of another vector onto this vector's components. More...
 
template<typename OtherType >
 operator Vector3T< OtherType > ()
 
Type & At (UInt32 index)
 Accesses an individual component in this vector. More...
 
Type At (UInt32 index) const
 Accesses an individual (constant) component in this vector. More...
 
void Set (Type value)
 Sets all components to a given value. More...
 
void Set (Type x, Type y, Type z)
 Sets all components to the given values. More...
 
void Clear ()
 Clears the vector to (0, 0, 0).
 
Vector2T< Type > Swizzle (UInt32 x, UInt32 y) const
 Performs a two dimensional swizzle. More...
 
Vector3T< Type > Swizzle (UInt32 x, UInt32 y, UInt32 z) const
 Performs a three dimensional swizzle. More...
 
Vector4T< Type > Swizzle (UInt32 x, UInt32 y, UInt32 z, UInt32 w) const
 Performs a four dimensional swizzle. More...
 
void Normalize ()
 Normalizes the vector resulting in a length of 1. More...
 
Boolean IsNormalized (Type epsilon=0.00001f) const
 Checks if the vector is normalizes within a given epsilon. More...
 
Type GetMagnitude () const
 Gets the magnitude of the vector. More...
 
Type GetSquaredMagnitude () const
 Gets the squared magnitude of the vector. More...
 
Type GetManhattanMagnitude () const
 Gets the manhattan magnitude of the vector. More...
 
Type GetDistance (const Vector3T &other) const
 Gets the distance between two vectors. More...
 
Type GetSquaredDistance (const Vector3T &other) const
 Gets the squared distance between two vectors. More...
 
Type GetManhattanDistance (const Vector3T &other) const
 Gets the manhattan distance between two vectors. More...
 
void Floor ()
 Rounds down each component to the nearest whole number.
 
void Round ()
 Rounds each component to the nearest whole number.
 
void Ceil ()
 Rounds up each component to the nearest whole number.
 
Vector3T Floored () const
 Returns a vector with each component rounded down. More...
 
Vector3T Rounded () const
 Returns a vector with each component rounded. More...
 
Vector3T Ceiled () const
 Returns a vector with each component rounded up. More...
 
Type SumComponents () const
 Gets the sum of the elements. More...
 
Type MultiplyComponents () const
 Gets the product of the elements. More...
 
void MakeOrthonormalBasis (Vector3T< Type > *vectorB, Vector3T< Type > *vectorC)
 
Type IsNaN () const
 

Static Public Member Functions

static Type DotProduct (const Vector3T &valueA, const Vector3T &valueB)
 
static Vector3T CrossProduct (const Vector3T &valueA, const Vector3T &valueB)
 
static Vector3T Normalized (const Vector3T &value)
 
static Type Distance (const Vector3T &vectorA, const Vector3T &vectorB)
 
static Type DistanceSquared (const Vector3T &valueA, const Vector3T &vectorB)
 
static Type DistanceManhattan (const Vector3T &valueA, const Vector3T &vectorB)
 
static Vector3T Lerp (const Vector3T &from, const Vector3T &to, Type t)
 Performs linear interpolation on a vector3.
 

Public Attributes

Type x
 The x component.
 
Type y
 The y component.
 
Type z
 The z component.
 

Static Public Attributes

static const Vector3T zero
 Zero vector, defined as (0, 0, 0).
 
static const Vector3T one
 One vector, defined as (1, 1, 1).
 
static const Vector3T unitX
 Unit X vector, defined as (1, 0, 0).
 
static const Vector3T unitY
 Unit Y vector, defined as (0, 1, 0).
 
static const Vector3T unitZ
 Unit Y vector, defined as (0, 0, 1).
 
static const Vector3T nan
 NaN vector, defined as (NaN, NaN, NaN).
 

Friends

std::ostream & operator<< (std::ostream &stream, const Vector3T< Type > &vector)
 An operator to output this vector on an output stream.
 

Detailed Description

template<typename Type>
struct CGUL::Vector3T< Type >

A three dimensional 32 bit floating point vector.

Todo:
Template this to allow 64 bit floating point or integer as well?

Constructor & Destructor Documentation

template<typename Type >
CGUL::Vector3T< Type >::Vector3T ( const Vector3T< Type > &  copy)
inline

Copies a vector into this vector.

Parameters
copyThe vector to copy.
template<typename Type >
CGUL::Vector3T< Type >::Vector3T ( const Vector2T< Type > &  copy)
inline

Copies a vector2 into this vector3's first two components and Initializes z to 0.

Parameters
copyThe vector to copy.
template<typename Type >
CGUL::Vector3T< Type >::Vector3T ( const Vector2T< Type > &  copy,
Type  value 
)
inline

Copies a vector2 into this vector3's first two components and Initializes z with the individual component value.

Parameters
copyThe vector to copy.
zThe z component.
template<typename Type >
CGUL::Vector3T< Type >::Vector3T ( Type  value)
inline

Initializes all components to a given value.

Parameters
valueThe value for each component.
template<typename Type >
CGUL::Vector3T< Type >::Vector3T ( Type  x,
Type  y,
Type  z 
)
inline

Initializes the vector with individual component values.

Parameters
xThe x component.
yThe y component.
zThe z component.

Member Function Documentation

template<typename Type >
Type & CGUL::Vector3T< Type >::At ( UInt32  index)
inline

Accesses an individual component in this vector.

Parameters
indexThe component index, so 0 for x, 1 for y, and 2 for z.
Returns
The value at that index.
template<typename Type >
Type CGUL::Vector3T< Type >::At ( UInt32  index) const
inline

Accesses an individual (constant) component in this vector.

Parameters
indexThe component index, so 0 for x, 1 for y, and 2 for z.
Returns
The value at that index.
template<typename Type >
CGUL::Vector3T< Type > CGUL::Vector3T< Type >::Ceiled ( ) const
inline

Returns a vector with each component rounded up.

Returns
The resulting vector.
template<typename Type >
CGUL::Vector3T< Type > CGUL::Vector3T< Type >::Floored ( ) const
inline

Returns a vector with each component rounded down.

Returns
The resulting vector.
template<typename Type >
Type CGUL::Vector3T< Type >::GetDistance ( const Vector3T< Type > &  other) const
inline

Gets the distance between two vectors.

The distance between two vectors is defined as the magnitude of one vector subtracted by another. In other words: GetMagnitude(Vec1 - Vec2). Because of this the same notes in GetMagnitude apply to this method.

Warning
This method uses sqrt() which can be slow!
Parameters
otherThe other vector.
Returns
The distance between the two vectors.
See Also
GetMagnitude
GetSquaredDistance
GetManhattanDistance
template<typename Type >
Type CGUL::Vector3T< Type >::GetMagnitude ( ) const
inline

Gets the magnitude of the vector.

Faster implementations of this method exist but are less accurate. For more information, see GetSquaredMagnitude and GetManhattanMagnitude.

Warning
This method uses sqrt() which can be slow!
Returns
The magnitude.
See Also
GetSquaredMagnitude
GetManhattanMagnitude
template<typename Type >
Type CGUL::Vector3T< Type >::GetManhattanDistance ( const Vector3T< Type > &  other) const
inline

Gets the manhattan distance between two vectors.

Parameters
otherThe other vector.
Returns
The manhattan distance between the two vectors.
See Also
GetDistance
Todo:
Check the implementation because this is actually slower than the squared distance.
template<typename Type >
Type CGUL::Vector3T< Type >::GetManhattanMagnitude ( ) const
inline

Gets the manhattan magnitude of the vector.

The Manhattan magnitude is even faster than the GetMagnitudeSquared alternative, but far less accurate. The squared magnitude cannot be used to determine if one magnitude is larger than another, nor can it be used to compare magnitudes. The purpose of the Manhattan magnitude is mostly used as a guess to speed up algorithms that may use it as a heuristic.

Note
The name Manhattan is a reference to the city Manhattan and how all the streets are laid out in blocks. To walk one block you would have to walk the length of the block, then the width. The result of this function is just that, the sum of the x and y components. A call to make the values absolute is also necessary to ensure an always positive result.
Returns
The manhattan magnitude.
template<typename Type >
Type CGUL::Vector3T< Type >::GetSquaredDistance ( const Vector3T< Type > &  other) const
inline

Gets the squared distance between two vectors.

Parameters
otherThe other vector.
Returns
The squared distance between the two vectors.
See Also
GetDistance
template<typename Type >
Type CGUL::Vector3T< Type >::GetSquaredMagnitude ( ) const
inline

Gets the squared magnitude of the vector.

The squared magnitude is a less accurate, but more quickly calculated alternative to the GetMagnitude method. A squared magnitude can be used to measure if one magnitude is larger than another, but cannot be used to accurately determine differences between magnitudes.

Returns
The squared magnitude.
template<typename Type >
Type CGUL::Vector3T< Type >::IsNaN ( ) const
inline
Returns
True if the vector contains NaN values, false otherwise.
template<typename Type >
CGUL::Boolean CGUL::Vector3T< Type >::IsNormalized ( Type  epsilon = 0.00001f) const
inline

Checks if the vector is normalizes within a given epsilon.

Warning
This method uses sqrt() which can be slow!
template<typename Type >
Type CGUL::Vector3T< Type >::MultiplyComponents ( ) const
inline

Gets the product of the elements.

Returns
x * y * z
template<typename Type >
void CGUL::Vector3T< Type >::Normalize ( )
inline

Normalizes the vector resulting in a length of 1.

Warning
This method uses sqrt() which can be slow!
template<typename Type >
bool CGUL::Vector3T< Type >::operator!= ( const Vector3T< Type > &  operand) const
inline

Checks if two vectors are not exactly equal.

Due to floating point imprecision, vectors are rarely ever exactly equal. Use with care.

Parameters
operandThe other vector.
Returns
True if they are not equal, false otherwise.
template<typename Type >
CGUL::Vector3T< Type > CGUL::Vector3T< Type >::operator* ( Type  operand) const
inline

Performs component-based multiplication on two vectors.

Parameters
operandA scalar value.
Returns
The resulting vector.
template<typename Type >
CGUL::Vector3T< Type > & CGUL::Vector3T< Type >::operator*= ( Type  operand)
inline

Multiplies the individual components of another vector onto this vector's components.

Parameters
operandA scalar value.
Returns
A reference to the current object.
template<typename Type >
CGUL::Vector3T< Type > CGUL::Vector3T< Type >::operator+ ( const Vector3T< Type > &  operand) const
inline

Performs component-based addition on two vectors.

Parameters
operandThe other vector.
Returns
The resulting vector.
template<typename Type >
CGUL::Vector3T< Type > & CGUL::Vector3T< Type >::operator+= ( const Vector3T< Type > &  operand)
inline

Adds the individual components of another vector to this vector's components.

Parameters
operandThe other operand.
Returns
A reference to the current object.
template<typename Type >
CGUL::Vector3T< Type > & CGUL::Vector3T< Type >::operator+= ( const Vector2T< Type > &  operand)
inline

Adds the individual components of a vector2 to this vector3's first two components.

Parameters
operandThe other operand.
Returns
A reference to the current object.
template<typename Type >
CGUL::Vector3T< Type > CGUL::Vector3T< Type >::operator- ( ) const
inline

Gets the inverse of the vector.

The inverse is defined as (-x, -y, -z) of the original vector.

Returns
The inverse vector.
template<typename Type >
CGUL::Vector3T< Type > CGUL::Vector3T< Type >::operator- ( const Vector3T< Type > &  operand) const
inline

Performs component-based subtraction on two vectors.

Parameters
operandThe other vector.
Returns
The resulting vector.
template<typename Type >
CGUL::Vector3T< Type > & CGUL::Vector3T< Type >::operator-= ( const Vector3T< Type > &  operand)
inline

Subtracts the individual components of another vector from this vector's components.

Parameters
operandThe other operand.
Returns
A reference to the current object.
template<typename Type >
CGUL::Vector3T< Type > & CGUL::Vector3T< Type >::operator-= ( const Vector2T< Type > &  operand)
inline

Subtracts the individual components of a vector2 to this vector3's first two components.

Parameters
operandThe other operand.
Returns
A reference to the current object.
template<typename Type >
CGUL::Vector3T< Type > CGUL::Vector3T< Type >::operator/ ( Type  operand) const
inline

Performs component-based division on two vectors.

Parameters
operandThe other vector.
Returns
The resulting vector.
template<typename Type >
CGUL::Vector3T< Type > & CGUL::Vector3T< Type >::operator/= ( Type  operand)
inline

Divides the individual components of another vector onto this vector's components.

Parameters
operandThe other operand.
Returns
A reference to the current object.
template<typename Type >
CGUL::Vector3T< Type > & CGUL::Vector3T< Type >::operator= ( const Vector3T< Type > &  operand)
inline

Assigns another vector into this vector.

Parameters
operandThe other vector.
Returns
A reference to the current object.
template<typename Type >
bool CGUL::Vector3T< Type >::operator== ( const Vector3T< Type > &  operand) const
inline

Checks if two vectors are exactly equal.

Due to floating point imprecision, vectors are rarely ever exactly equal. Use with care.

Parameters
operandThe other vector.
Returns
True if they are equal, false otherwise.
template<typename Type >
Type & CGUL::Vector3T< Type >::operator[] ( UInt32  index)
inline

Accesses an individual component in this vector.

Warning
This method does not bounds check, must be 0, 1, or 2!
Parameters
indexThe component index (0 for x, 1 for y, 2 for z).
Returns
The value at that index.
template<typename Type >
Type CGUL::Vector3T< Type >::operator[] ( UInt32  index) const
inline

Accesses an individual (constant) component in this vector.

Unlike the other operator[], this one works on constant vectors and returns a value that cannot be modified to alter the original vector.

Warning
This method does not bounds check, must be 0, 1, or 2!
Parameters
indexThe component index (0 for x, 1 for y, 2 for z).
Returns
The value at that index.
template<typename Type >
CGUL::Vector3T< Type > CGUL::Vector3T< Type >::Rounded ( ) const
inline

Returns a vector with each component rounded.

Returns
The resulting vector.
template<typename Type >
void CGUL::Vector3T< Type >::Set ( Type  value)
inline

Sets all components to a given value.

Parameters
valueThe value to set all components to.
template<typename Type >
void CGUL::Vector3T< Type >::Set ( Type  x,
Type  y,
Type  z 
)
inline

Sets all components to the given values.

Parameters
xThe x component.
yThe y component.
zThe z component.
template<typename Type >
Type CGUL::Vector3T< Type >::SumComponents ( ) const
inline

Gets the sum of the elements.

Returns
x + y + z
template<typename Type >
CGUL::Vector2T< Type > CGUL::Vector3T< Type >::Swizzle ( UInt32  x,
UInt32  y 
) const
inline

Performs a two dimensional swizzle.

Swizzles the vector allowing the components to be re-arranged into a new vector.

Parameters
xThe x component (0 for x, 1 for y, 2 for z).
yThe y component (0 for x, 1 for y, 2 for z).
Returns
The resulting vector.
Todo:
Better documentation on swizzle (for now just look it up!)
template<typename Type >
CGUL::Vector3T< Type > CGUL::Vector3T< Type >::Swizzle ( UInt32  x,
UInt32  y,
UInt32  z 
) const
inline

Performs a three dimensional swizzle.

Swizzles the vector allowing the components to be re-arranged into a new vector.

Parameters
xThe x component (0 for x, 1 for y, 2 for z).
yThe y component (0 for x, 1 for y, 2 for z).
zThe z component (0 for x, 1 for y, 2 for z).
Returns
The resulting vector.
Todo:
Better documentation on swizzle (for now just look it up!)
template<typename Type >
CGUL::Vector4T< Type > CGUL::Vector3T< Type >::Swizzle ( UInt32  x,
UInt32  y,
UInt32  z,
UInt32  w 
) const
inline

Performs a four dimensional swizzle.

Swizzles the vector allowing the components to be re-arranged into a new vector.

Parameters
xThe x component (0 for x, 1 for y, 2 for z).
yThe y component (0 for x, 1 for y, 2 for z).
zThe z component (0 for x, 1 for y, 2 for z).
wThe w component (0 for x, 1 for y, 2 for z).
Returns
The resulting vector.
Todo:
Better documentation on swizzle (for now just look it up!)

The documentation for this struct was generated from the following files: