Ocular Engine
Ocular::Math::Vector3< T > Class Template Reference

Public Member Functions

 Vector3 (T const *values)
 
 Vector3 (Quaternion const &quat)
 
 Vector3 (Euler const &euler)
 
 Vector3 (Vector2< T > const &vec)
 
 Vector3 (T const x, T const y, T const z)
 
T & operator[] (unsigned const &index)
 
operator[] (unsigned const &index) const
 
Vector3< T > operator- ()
 
Vector3< T > & operator= (Vector3< T > const &rhs)
 
Vector3< T > & operator+= (Vector3< T > const &rhs)
 
Vector3< T > & operator+= (T const rhs)
 
Vector3< T > & operator-= (Vector3< T > const &rhs)
 
Vector3< T > & operator-= (T const rhs)
 
Vector3< T > & operator*= (Vector3< T > const &rhs)
 
Vector3< T > & operator*= (T const rhs)
 
Vector3< T > & operator/= (Vector3< T > const &rhs)
 
Vector3< T > & operator/= (T const rhs)
 
Vector2< T > xy () const
 
getMagnitude () const
 
getLength () const
 
void normalize ()
 
Vector3< T > getNormalized () const
 
Vector3< T > cross (Vector3< T > const &rhs) const
 
dot (Vector3< T > const &rhs) const
 
double angleBetween (Vector3< T > const &rhs) const
 
distanceTo (Vector3< T > const &rhs) const
 

Static Public Member Functions

static Vector3< T > Lerp (Vector3< T > const from, Vector3< T > const to, T fraction)
 
static Vector3< T > Slerp (Vector3< T > const &from, Vector3< T > const &to, double fraction)
 
static Vector3< T > Midpoint (Vector3< T > const &a, Vector3< T > const &b)
 
static Vector3< T > Identity ()
 
static Vector3< T > Up ()
 
static Vector3< T > Down ()
 
static Vector3< T > Left ()
 
static Vector3< T > Right ()
 
static Vector3< T > Forward ()
 
static Vector3< T > Backward ()
 

Public Attributes

union {
   T   x
 
   T   r
 
   T   u
 
   T   s
 
}; 
 
union {
   T   y
 
   T   g
 
   T   v
 
   T   t
 
}; 
 
union {
   T   z
 
   T   b
 
   T   w
 
}; 
 

Static Public Attributes

static bool OCULAR_INTERNAL_Force
 

Member Function Documentation

template<typename T>
double Ocular::Math::Vector3< T >::angleBetween ( Vector3< T > const &  rhs) const
inline

This is equivalent to taking the acos of the dot product.
The returned angle is the acute angle, i.e the smallest of the two angles.

Parameters
[in]rhsThe second vector to calculate the angle with
Returns
The angle, in radians, between the vectors
template<typename T>
Vector3<T> Ocular::Math::Vector3< T >::cross ( Vector3< T > const &  rhs) const
inline

The cross product is a third vector that is perpendicular to the two original vectors.

Note
Order is important for cross product
Parameters
[in]rhsThe second vector to cross multiply with
Returns
The cross product of the two vectors
template<typename T>
T Ocular::Math::Vector3< T >::distanceTo ( Vector3< T > const &  rhs) const
inline
Parameters
[in]rhsThe second vector to calculate the distance with
Returns
The distance between the two vectors
template<typename T>
T Ocular::Math::Vector3< T >::dot ( Vector3< T > const &  rhs) const
inline

The dot product is a value equal to the magnitudes of the two vectors multiplied together and then multiplied by the cosine of the angle between them.

Parameters
[in]rhsThe second vector dot multiply with
Returns
The dot product of the two vectors (in radians)
template<typename T>
T Ocular::Math::Vector3< T >::getLength ( ) const
inline
Returns
The length of the vector.
template<typename T>
T Ocular::Math::Vector3< T >::getMagnitude ( ) const
inline
Returns
The magnitude (length) of the vector.
template<typename T>
Vector3<T> Ocular::Math::Vector3< T >::getNormalized ( ) const
inline

Returns the normalized form of this vector

template<typename T>
static Vector3<T> Ocular::Math::Vector3< T >::Lerp ( Vector3< T > const  from,
Vector3< T > const  to,
fraction 
)
inlinestatic

Linearly interpolates the two vectors using the specified fraction.

When fraction == 0, the return is equal to from. When fraction == 1, the return is equal to to.

Parameters
[in]fromThe 'start' vector.
[in]toThe 'end' vector.
[in]fractionThe fraction to interpolate by.
Returns
The resultant interpolated vector.
template<typename T>
static Vector3<T> Ocular::Math::Vector3< T >::Midpoint ( Vector3< T > const &  a,
Vector3< T > const &  b 
)
inlinestatic

Calculates the midpoint of the two provided points.

Parameters
[in]a
[in]b
Returns
The midpoint vector
template<typename T>
void Ocular::Math::Vector3< T >::normalize ( )
inline

Normalizes the vector.
When normalized, a vector maintains its direction but its magnitude is set to 1.0.

Note
This method modifies the internal data stored in the vector. See getNormalized if this is not desired.
template<typename T>
static Vector3<T> Ocular::Math::Vector3< T >::Slerp ( Vector3< T > const &  from,
Vector3< T > const &  to,
double  fraction 
)
inlinestatic

Spherically interpolates the two vectors using the specified fraction.

When slerping, the vectors are treated as directions as opposed to points in space (as in lerp). The resultant direction is interpolated by the angle between the vectors, and the magnitude is interpolated by those of the two input vectors.

Parameters
[in]fromThe 'start' vector.
[in]toThe 'end' vector.
[in]fractionThe fraction to interpolate by.
Returns
The resultant interpolated vector.

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