TurtleBrains  0.3.1
High quality, portable, C++ framework for rapid 2D game development.
TurtleBrains::Math::Vector4 Class Reference

#include <tb_vector.h>

Public Member Functions

 Vector4 (const SkipInitialization &fastAndStupid)
 
 Vector4 (void)
 
 Vector4 (const float valueX, const float valueY, const float valueZ, const float valueW)
 
 Vector4 (const Vector2 &other, const float valueZ, const float valueW)
 
 Vector4 (const Vector3 &other, const float valueW)
 
 Vector4 (const Vector4 &other)
 
 ~Vector4 (void)
 
Vector4operator= (const Vector4 &other)
 
bool operator== (const Vector4 &other) const
 
bool operator!= (const Vector4 &other) const
 
 operator const float * (void) const
 
 operator float * (void)
 
const float & operator[] (const size_t index) const
 
float & operator[] (const size_t index)
 
Vector4 operator+ (const Vector4 &rightSide) const
 
Vector4operator+= (const Vector4 &rightSide)
 
Vector4 operator- (const Vector4 &rightSide) const
 
Vector4operator-= (const Vector4 &rightSide)
 
Vector4 operator* (float scalar) const
 
Vector4operator*= (float scalar)
 
Vector4 operator/ (float scalar) const
 
Vector4operator/= (float scalar)
 
Vector4 operator- (void) const
 
float operator* (const Vector4 &rightSide) const
 
float Magnitude (void) const
 
float MagnitudeSquared (void) const
 
Vector4 GetNormalized (void) const
 
float Normalize (void)
 
void Scale (float scalar)
 
void SetLength (float length)
 

Static Public Member Functions

static Vector4 Zero (void)
 

Public Attributes

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

Friends

Vector4 operator* (float scalar, const Vector4 &rightSide)
 

Detailed Description

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

Constructor & Destructor Documentation

TurtleBrains::Math::Vector4::Vector4 ( const SkipInitialization fastAndStupid)
inlineexplicit

Constructs a Vector4 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.
TurtleBrains::Math::Vector4::Vector4 ( void  )
inline

Constructs a default Vector4 object with all components set to 0.0f.

TurtleBrains::Math::Vector4::Vector4 ( const float  valueX,
const float  valueY,
const float  valueZ,
const float  valueW 
)
inline

Constructs a Vector4 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.
TurtleBrains::Math::Vector4::Vector4 ( const Vector2 other,
const float  valueZ,
const float  valueW 
)
inlineexplicit

Constructs a Vector4 object by copying a Vector2 object and providing a value for the z and w components.

Parameters
otherThe Vector2 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.
TurtleBrains::Math::Vector4::Vector4 ( const Vector3 other,
const float  valueW 
)
inlineexplicit

Constructs a Vector4 object by copying a Vector3 object and providing a value for the w component.

Parameters
otherThe Vector3 object to initialize the x, y and z component values to.
valueWThe value to initialize the w component as.
TurtleBrains::Math::Vector4::Vector4 ( const Vector4 other)
inline

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

Parameters
otherThe Vector4 object to initialize component values to.
TurtleBrains::Math::Vector4::~Vector4 ( void  )
inline

Nothing needs to happen to destroy a Vector4 object.

Member Function Documentation

Vector4 TurtleBrains::Math::Vector4::GetNormalized ( void  ) const
inline

Computes the magnitude and returns a unit length vector in the same direction. Since this could result in a divide-by-zero, if the magnitude is zero, the zero vector is returned.

float TurtleBrains::Math::Vector4::Magnitude ( void  ) const
inline

Computes the length / magnitude of the Vector object which involves a square root, then returns the resulting scalar value.

float TurtleBrains::Math::Vector4::MagnitudeSquared ( void  ) const
inline

Computes the length / magnitude of the Vector object left squared so the square root is not taken, then returns the resulting scalar value.

float TurtleBrains::Math::Vector4::Normalize ( void  )
inline

Computes the magnitude of the Vector object and modifies it to represent the unit length vector in the same direction. If the magnitude is zero, the vector remains unmodified... After modifying the object the old magnitude is returned.

TurtleBrains::Math::Vector4::operator const float * ( void  ) const
inline

Returns a float array of the Vector4 components.

TurtleBrains::Math::Vector4::operator float * ( void  )
inline

Returns a float array of the Vector4 components. If modified the internal components will also be modified as well.

bool TurtleBrains::Math::Vector4::operator!= ( const Vector4 other) const
inline

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

Vector4 TurtleBrains::Math::Vector4::operator* ( float  scalar) const
inline

Performs a scalar multiplication on the Vector4 object, returning the resulting Vector4.

float TurtleBrains::Math::Vector4::operator* ( const Vector4 rightSide) const
inline

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

Vector4& TurtleBrains::Math::Vector4::operator*= ( float  scalar)
inline

Performs a scalar multiplication on the Vector4 object modifying the object and returning it as the resulting Vector4.

Vector4 TurtleBrains::Math::Vector4::operator+ ( const Vector4 rightSide) const
inline

Adds two vectors together and returns a Vector4 object, by value, with the result.

Vector4& TurtleBrains::Math::Vector4::operator+= ( const Vector4 rightSide)
inline

Adds each component of a Vector4 object to the component values of the left side object modifying it and returning the result.

Vector4 TurtleBrains::Math::Vector4::operator- ( const Vector4 rightSide) const
inline

Subtracts two vectors (this - rightSide) and returns a Vector4 object, by value, with the result.

Vector4 TurtleBrains::Math::Vector4::operator- ( void  ) const
inline

Returns a Vector4 object with each component being the negative of the object used.

Vector4& TurtleBrains::Math::Vector4::operator-= ( const Vector4 rightSide)
inline

Subtracts two Vector2 objects (this -= rightSide) and modifies this object and returns the result.

Vector4 TurtleBrains::Math::Vector4::operator/ ( float  scalar) const
inline

Performs a scalar division operation on each component of the Vector4 object returning the result.

Vector4& TurtleBrains::Math::Vector4::operator/= ( float  scalar)
inline

Performs a scalar division operation on each component of the Vector4 object modifying the components of the Vector4 and returning the object as the result.

Vector4& TurtleBrains::Math::Vector4::operator= ( const Vector4 other)
inline

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

Parameters
otherThe Vector4 object to set the components to.
bool TurtleBrains::Math::Vector4::operator== ( const Vector4 other) const
inline

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

Parameters
otherThe Vector4 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.
const float& TurtleBrains::Math::Vector4::operator[] ( const size_t  index) const
inline

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

float& TurtleBrains::Math::Vector4::operator[] ( const size_t  index)
inline

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

void TurtleBrains::Math::Vector4::Scale ( float  scalar)
inline

Performs scalar multiplication on the Vector object, exactly the same as *= with a scalar.

void TurtleBrains::Math::Vector4::SetLength ( float  length)
inline

This is a convenience function that will normalize then scale the Vector object, setting the length as desired.

Parameters
lengthThe desired length of the vector in the same direction. 1.0 is the unit vector and has the same vector as if you had just normalized.
static Vector4 TurtleBrains::Math::Vector4::Zero ( void  )
inlinestatic

Creates and returns a Vector4 object representing 0.0f, 0.0f, 0.0f, 0.0f.

Friends And Related Function Documentation

Vector4 operator* ( float  scalar,
const Vector4 rightSide 
)
friend

Performs a scalar multiplication on the Vector4 object with the scalar on the left-hand side for simple usage. Returns the resulting Vector4.