TurtleBrains  0.3.5
High quality, portable, C++ framework for rapid 2D game development.
TurtleBrains::Math::TypedVector3< Type > Class Template Reference

#include <tb_vector.hpp>

Public Member Functions

 TypedVector3 (const SkipInitialization &fastAndStupid)
 
 TypedVector3 (void)
 
 TypedVector3 (const Type valueX, const Type valueY, const Type valueZ)
 
 TypedVector3 (const TypedVector2< Type > &other, const Type valueZ)
 
 TypedVector3 (const Type *componentArray)
 
 TypedVector3 (const TypedVector3< Type > &other)
 
template<typename FromType >
 TypedVector3 (const TypedVector3< FromType > &other)
 
 ~TypedVector3 (void)
 
TypedVector3operator= (const TypedVector3 &other)
 
bool operator== (const TypedVector3 &other) const
 
bool operator!= (const TypedVector3 &other) const
 
 operator const Type * (void) const
 
 operator Type * (void)
 
template<typename ToType >
 operator TypedVector3< ToType > (void) const
 
const Type & operator[] (const int index) const
 
const Type & operator[] (const std::size_t &index) const
 
Type & operator[] (const int index)
 
Type & operator[] (const std::size_t &index)
 

Static Public Member Functions

static TypedVector3 Zero (void)
 
static TypedVector3 One (void)
 
static TypedVector3 Right (void)
 
static TypedVector3 Left (void)
 
static TypedVector3 Up (void)
 
static TypedVector3 Down (void)
 
static TypedVector3 Forward (void)
 
static TypedVector3 Backward (void)
 
static Type Dot (const TypedVector3< Type > &leftSide, const TypedVector3< Type > &rightSide)
 
static TypedVector3 Cross (const TypedVector3< Type > &leftSide, const TypedVector3< Type > &rightSide)
 
static TypedVector3 Normalize (const TypedVector3< Type > &value)
 
static TypedVector3 Normalize (const TypedVector3< Type > &value, Type &magnitude)
 

Public Attributes

union {
   Type   mComponents [3]
 
   struct {
      Type   x
 
      Type   y
 
      Type   z
 
   } 
 
}; 
 

Detailed Description

template<typename Type>
class TurtleBrains::Math::TypedVector3< Type >

The TypedVector3 object is a three component mathematical vector of Types packed together with some functionality to perform basic vector math.

Constructor & Destructor Documentation

◆ TypedVector3() [1/6]

template<typename Type >
TurtleBrains::Math::TypedVector3< Type >::TypedVector3 ( const SkipInitialization fastAndStupid)
inlineexplicit

Constructs a TypedVector3 object leaving the members uninitialized and must be initialized manually before the object is used.

Note
Should be used only if the consequences are understood, and even then only sparingly.

◆ TypedVector3() [2/6]

template<typename Type >
TurtleBrains::Math::TypedVector3< Type >::TypedVector3 ( void  )
inline

Constructs a default TypedVector3 object with all components set to Type(0).

◆ TypedVector3() [3/6]

template<typename Type >
TurtleBrains::Math::TypedVector3< Type >::TypedVector3 ( const Type  valueX,
const Type  valueY,
const Type  valueZ 
)
inline

Constructs a TypedVector3 object with each component initialized with the values provided.

Parameters
valueXThe value to initialize the x component as.
valueYThe value to initialize the y component as.
valueZThe value to initialize the z component as.

◆ TypedVector3() [4/6]

template<typename Type >
TurtleBrains::Math::TypedVector3< Type >::TypedVector3 ( const TypedVector2< Type > &  other,
const Type  valueZ 
)
inlineexplicit

Constructs a TypedVector3 object by copying a TypedVector2 object and providing a value for the Z component.

Parameters
otherThe TypedVector2 object to initialize the x and y component values to.
valueZThe value to initialize the z component as.

◆ TypedVector3() [5/6]

template<typename Type >
TurtleBrains::Math::TypedVector3< Type >::TypedVector3 ( const Type *  componentArray)
inlineexplicit

Constructs a TypedVector3 object with the supplied Type array, which must contain at least 3 Types.

Parameters
componentArrayMust have at least 3 Types, one for each component in the TypedVector3.

◆ TypedVector3() [6/6]

template<typename Type >
TurtleBrains::Math::TypedVector3< Type >::TypedVector3 ( const TypedVector3< Type > &  other)
inline

Constructs a TypedVector3 object by copying another TypedVector3 object, each component will be initialized to the value of the other components.

Parameters
otherThe TypedVector3 object to initialize component values to.

◆ ~TypedVector3()

template<typename Type >
TurtleBrains::Math::TypedVector3< Type >::~TypedVector3 ( void  )
inline

Nothing needs to happen to destroy a TypedVector3 object.

Member Function Documentation

◆ Cross()

template<typename Type >
static TypedVector3 TurtleBrains::Math::TypedVector3< Type >::Cross ( const TypedVector3< Type > &  leftSide,
const TypedVector3< Type > &  rightSide 
)
inlinestatic

Perform a cross product on two TypedVector3 objects, returning the TypedVector3 result that is perpendicular two the two given vectors.

◆ Dot()

template<typename Type >
static Type TurtleBrains::Math::TypedVector3< Type >::Dot ( const TypedVector3< Type > &  leftSide,
const TypedVector3< Type > &  rightSide 
)
inlinestatic

Perform a dot product on two TypedVector3 objects, returning the scalar result.

◆ Normalize() [1/2]

template<typename Type >
static TypedVector3 TurtleBrains::Math::TypedVector3< Type >::Normalize ( const TypedVector3< Type > &  value)
inlinestatic

Take a Vector3 and returns a unit length vector in the same direction.

◆ Normalize() [2/2]

template<typename Type >
static TypedVector3 TurtleBrains::Math::TypedVector3< Type >::Normalize ( const TypedVector3< Type > &  value,
Type &  magnitude 
)
inlinestatic

Take a Vector3 and returns a unit length vector in the same direction while also returning the original magnitude.

◆ One()

template<typename Type >
static TypedVector3 TurtleBrains::Math::TypedVector3< Type >::One ( void  )
inlinestatic

Creates and returns a TypedVector3 object representing 1, 1, 1

◆ operator const Type *()

template<typename Type >
TurtleBrains::Math::TypedVector3< Type >::operator const Type * ( void  ) const
inlineexplicit

Returns a Type array of the TypedVector3 components.

◆ operator Type *()

template<typename Type >
TurtleBrains::Math::TypedVector3< Type >::operator Type * ( void  )
inlineexplicit

Returns a Type array of the TypedVector3 components. If modified the internal components will also be modified as well.

◆ operator TypedVector3< ToType >()

template<typename Type >
template<typename ToType >
TurtleBrains::Math::TypedVector3< Type >::operator TypedVector3< ToType > ( void  ) const
inline

Casts a Vector to Vector to move from float to double or such.

◆ operator!=()

template<typename Type >
bool TurtleBrains::Math::TypedVector3< Type >::operator!= ( const TypedVector3< Type > &  other) const
inline

Inequality operator, returns the opposite of the equality operator, which compares each value in one TypedVector3 object to another using IsEqual to compare the floating point component values.

◆ operator=()

template<typename Type >
TypedVector3& TurtleBrains::Math::TypedVector3< Type >::operator= ( const TypedVector3< Type > &  other)
inline

Assignment operator, sets each component of the TypedVector3 object to the values of the other object.

Parameters
otherThe TypedVector3 object to set the components to.

◆ operator==()

template<typename Type >
bool TurtleBrains::Math::TypedVector3< Type >::operator== ( const TypedVector3< Type > &  other) const
inline

Equality operator, compares each component of the TypedVector3 object to the values of another TypedVector3 returning true if all components are equal, or false if any of the components are not equal.

Parameters
otherThe TypedVector3 object to compare against.
Note
Because the components are floating point values tbMath::IsEqual is used to compare the components for equality using the default tolerance: kTolerance.

◆ operator[]() [1/2]

template<typename Type >
Type& TurtleBrains::Math::TypedVector3< Type >::operator[] ( const int  index)
inline

Returns a reference to one of the TypedVector3 components by an index provided by the VectorComponent enum. If the reference returned is modified, the internal components will also be modified as well.

◆ operator[]() [2/2]

template<typename Type >
const Type& TurtleBrains::Math::TypedVector3< Type >::operator[] ( const int  index) const
inline

Returns a reference to one of the TypedVector3 components by an index provided by the VectorComponent enum.

◆ Zero()

template<typename Type >
static TypedVector3 TurtleBrains::Math::TypedVector3< Type >::Zero ( void  )
inlinestatic

Creates and returns a TypedVector3 object representing Type(0), Type(0), Type(0).