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

#include <tb_vector.hpp>

Public Member Functions

 TypedVector4 (const SkipInitialization &fastAndStupid)
 
 TypedVector4 (void)
 
 TypedVector4 (const Type valueX, const Type valueY, const Type valueZ, const Type valueW)
 
 TypedVector4 (const TypedVector2< Type > &other, const Type valueZ, const Type valueW)
 
 TypedVector4 (const TypedVector3< Type > &other, const Type valueW)
 
 TypedVector4 (const Type *componentArray)
 
 TypedVector4 (const TypedVector4 &other)
 
template<typename FromType >
 TypedVector4 (const TypedVector4< FromType > &other)
 
 ~TypedVector4 (void)
 
TypedVector4operator= (const TypedVector4 &other)
 
bool operator== (const TypedVector4 &other) const
 
bool operator!= (const TypedVector4 &other) const
 
 operator const Type * (void) const
 
 operator Type * (void)
 
template<typename ToType >
 operator TypedVector4< 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 TypedVector4 Zero (void)
 
static TypedVector4 One (void)
 
static Type Dot (const TypedVector4< Type > &leftSide, const TypedVector4< Type > &rightSide)
 
static TypedVector4 Cross (const TypedVector4< Type > &leftSide, const TypedVector4< Type > &rightSide)
 
static TypedVector4 Normalize (const TypedVector4< Type > &value)
 
static TypedVector4 Normalize (const TypedVector4< Type > &value, Type &magnitude)
 

Public Attributes

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

Detailed Description

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

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

Constructor & Destructor Documentation

◆ TypedVector4() [1/7]

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

Constructs a TypedVector4 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.

◆ TypedVector4() [2/7]

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

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

◆ TypedVector4() [3/7]

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

Constructs a TypedVector4 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.
valueWThe value to initialize the w component as.

◆ TypedVector4() [4/7]

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

Constructs a TypedVector4 object by copying a TypedVector2 object and providing a value for the z and w components.

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

◆ TypedVector4() [5/7]

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

Constructs a TypedVector4 object by copying a TypedVector3 object and providing a value for the w component.

Parameters
otherThe TypedVector3 object to initialize the x, y and z component values to.
valueWThe value to initialize the w component as.

◆ TypedVector4() [6/7]

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

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

Parameters
componentArrayMust have at least 4 Types, one for each component in the TypedVector4.

◆ TypedVector4() [7/7]

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

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

Parameters
otherThe TypedVector4 object to initialize component values to.

◆ ~TypedVector4()

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

Nothing needs to happen to destroy a TypedVector4 object.

Member Function Documentation

◆ Cross()

template<typename Type >
static TypedVector4 TurtleBrains::Math::TypedVector4< Type >::Cross ( const TypedVector4< Type > &  leftSide,
const TypedVector4< 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::TypedVector4< Type >::Dot ( const TypedVector4< Type > &  leftSide,
const TypedVector4< Type > &  rightSide 
)
inlinestatic

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

◆ Normalize() [1/2]

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

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

◆ Normalize() [2/2]

template<typename Type >
static TypedVector4 TurtleBrains::Math::TypedVector4< Type >::Normalize ( const TypedVector4< 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 TypedVector4 TurtleBrains::Math::TypedVector4< Type >::One ( void  )
inlinestatic

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

◆ operator const Type *()

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

Returns a Type array of the TypedVector4 components.

◆ operator Type *()

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

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

◆ operator TypedVector4< ToType >()

template<typename Type >
template<typename ToType >
TurtleBrains::Math::TypedVector4< Type >::operator TypedVector4< ToType > ( void  ) const
inlineexplicit

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

◆ operator!=()

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

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

◆ operator=()

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

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

Parameters
otherThe TypedVector4 object to set the components to.

◆ operator==()

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

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

Parameters
otherThe TypedVector4 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::TypedVector4< Type >::operator[] ( const int  index)
inline

Returns a reference to one of the TypedVector4 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::TypedVector4< Type >::operator[] ( const int  index) const
inline

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

◆ Zero()

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

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