Cafu Engine
Vector3T< T > Class Template Reference

This class represents a polymorphic 3-dimensional vector. More...

#include "Vector3.hpp"

Inheritance diagram for Vector3T< T >:

Public Member Functions

 Vector3T ()
 The default constructor. It initializes all components to zero. More...
 
 Vector3T (T x_, T y_, T z_)
 This constructor initializes the components from x_, y_ and z_ respectively. More...
 
template<class C >
 Vector3T (const C Values[])
 This constructor initializes the components from an array of (at least) three Ts. More...
 
bool IsValid () const
 Returns true if the vector is valid, that is, all components are non-NANs. More...
 
T & operator[] (unsigned int Index)
 Component access by index number (0 to 2) rather than by name. More...
 
const T & operator[] (unsigned int Index) const
 Component access by index number (0 to 2) rather than by name. More...
 
Vector3T< float > AsVectorOfFloat () const
 Gets this Vector3T<T> as a Vector3T<float>, so that the cast is explicitly visible in user code. More...
 
Vector3T< double > AsVectorOfDouble () const
 Gets this Vector3T<T> as a Vector3T<double>, so that the cast is explicitly visible in user code. More...
 
Vector3T< int > AsVectorOfInt () const
 Gets this Vector3T<T> as a Vector3T<int>, so that the cast is explicitly visible in user code. More...
 
Group of const inspector methods. They are all const and thus do not modify this object.
GetLengthSqr () const
 Returns the square of the length of this vector. More...
 
bool IsEqual (const Vector3T< T > &B, const T Epsilon) const
 Returns whether this vector is equal to B within tolerance Epsilon, that is, whether it is geometrically closer to B than Epsilon. More...
 
Vector3T< T > GetScaled (const T s) const
 Returns a copy of this vector scaled by s, that is, the scalar product (Skalarmultiplikation) of this vector and s. More...
 
Vector3T< T > GetScaled (const Vector3T< T > &S) const
 Returns a copy of this vector non-uniformely scaled by S. More...
 
Vector3T< T > GetRotX (const T Angle) const
 Returns a copy of this vector rotated around the x-axis by Angle degrees. More...
 
Vector3T< T > GetRotY (const T Angle) const
 Returns a copy of this vector rotated around the y-axis by Angle degrees. More...
 
Vector3T< T > GetRotZ (const T Angle) const
 Returns a copy of this vector rotated around the z-axis by Angle degrees. More...
 
void CreateOrthoVectors (Vector3T< T > &Left, Vector3T< T > &Down) const
 Returns two vectors that are orthogonal to this vector and to each other. More...
 
Group of (constructive) binary operators that do not modify their operands.
bool operator== (const Vector3T< T > &B) const
 Returns whether this vector and B are truly (bit-wise) identical. More...
 
bool operator!= (const Vector3T< T > &B) const
 Returns whether this vector and B are not equal (bit-wise). More...
 
Vector3T< T > operator+ (const Vector3T< T > &B) const
 Returns the sum of this Vector3T<T> and B. More...
 
Vector3T< T > operator- (const Vector3T< T > &B) const
 Returns the difference between this Vector3T<T> and B. More...
 
Vector3T< T > operator- () const
 The unary minus operator. B=-A is quasi identical with B=A.GetScaled(-1). More...
 
Vector3T< T > operator* (const T s) const
 Returns a copy of this vector scaled by s, that is, the scalar product (Skalarmultiplikation) of this vector and s. More...
 
Vector3T< T > operator/ (const T s) const
 Returns a copy of this vector divided by s, that is, the scalar product (Skalarmultiplikation) of this vector and 1/s. More...
 
dot (const Vector3T< T > &B) const
 Returns the dot product (Skalarprodukt) of this vector and B. More...
 
Vector3T< T > cross (const Vector3T< T > &B) const
 Returns the cross product (Vektorprodukt) of this vector and B. More...
 
Group of operators that modify this vector.
Vector3T< T > & operator+= (const Vector3T< T > &B)
 Adds B to this vector. More...
 
Vector3T< T > & operator-= (const Vector3T< T > &B)
 Subtracts B from this vector. More...
 
Vector3T< T > & operator*= (const T s)
 Scales this vector by s. More...
 
Vector3T< T > & operator/= (const T s)
 Divides this vector by s. Assumes that s is not 0. More...
 

Public Attributes

x
 The x-component of this vector. More...
 
y
 The y-component of this vector. More...
 
z
 The z-component of this vector. More...
 

Detailed Description

template<class T>
class Vector3T< T >

This class represents a polymorphic 3-dimensional vector.

In order to clearly distinguish between methods that modify their "this" Vector3T<T> and those that don't, the general idea is that all const, non-modifying methods start with "Get", e.g. GetLength(). However the dot() and cross() methods are exceptions for increased readability of user code. Semantically and intuitively, we prefer to treat them as special binary infix operators as we do in hand-written math – its just the C++ language that doesn't provide us with appropriate symbols.

For operators, it is intuitively clear whether they modify the this object or not. E.g. the += operator modifies the this object, the + operator does not. Note that there is no need to define "constructive", binary infix operators (like the + operator) outside (that is, not as members) of this class, because promotion of the left-hand argument as described in the C++ FAQs does not occur in and thus is not relevant for this class (we have no constructor to promote a built-in type to a Vector3T<T>). See http://www.parashift.com/c++-faq-lite/operator-overloading.html#faq-13.9 items 5 to 7 (especially 7) and http://www.parashift.com/c++-faq-lite/friends.html#faq-14.5 for details about this.

Constructor & Destructor Documentation

template<class T>
Vector3T< T >::Vector3T ( )
inline

The default constructor. It initializes all components to zero.

template<class T>
Vector3T< T >::Vector3T ( x_,
y_,
z_ 
)
inline

This constructor initializes the components from x_, y_ and z_ respectively.

template<class T>
template<class C >
Vector3T< T >::Vector3T ( const C  Values[])
inlineexplicit

This constructor initializes the components from an array of (at least) three Ts.

Member Function Documentation

template<class T>
Vector3T<double> Vector3T< T >::AsVectorOfDouble ( ) const
inline

Gets this Vector3T<T> as a Vector3T<double>, so that the cast is explicitly visible in user code.

template<class T>
Vector3T<float> Vector3T< T >::AsVectorOfFloat ( ) const
inline

Gets this Vector3T<T> as a Vector3T<float>, so that the cast is explicitly visible in user code.

template<class T>
Vector3T<int> Vector3T< T >::AsVectorOfInt ( ) const
inline

Gets this Vector3T<T> as a Vector3T<int>, so that the cast is explicitly visible in user code.

template<class T>
void Vector3T< T >::CreateOrthoVectors ( Vector3T< T > &  Left,
Vector3T< T > &  Down 
) const
inline

Returns two vectors that are orthogonal to this vector and to each other.

template<class T>
Vector3T<T> Vector3T< T >::cross ( const Vector3T< T > &  B) const
inline

Returns the cross product (Vektorprodukt) of this vector and B.

template<class T>
T Vector3T< T >::dot ( const Vector3T< T > &  B) const
inline

Returns the dot product (Skalarprodukt) of this vector and B.

template<class T>
T Vector3T< T >::GetLengthSqr ( ) const
inline

Returns the square of the length of this vector.

template<class T>
Vector3T<T> Vector3T< T >::GetRotX ( const T  Angle) const
inline

Returns a copy of this vector rotated around the x-axis by Angle degrees.

template<class T>
Vector3T<T> Vector3T< T >::GetRotY ( const T  Angle) const
inline

Returns a copy of this vector rotated around the y-axis by Angle degrees.

template<class T>
Vector3T<T> Vector3T< T >::GetRotZ ( const T  Angle) const
inline

Returns a copy of this vector rotated around the z-axis by Angle degrees.

template<class T>
Vector3T<T> Vector3T< T >::GetScaled ( const T  s) const
inline

Returns a copy of this vector scaled by s, that is, the scalar product (Skalarmultiplikation) of this vector and s.

Parameters
sScale factor to scale this vector by.
See Also
Also see the operator *, which does exactly the same.
template<class T>
Vector3T<T> Vector3T< T >::GetScaled ( const Vector3T< T > &  S) const
inline

Returns a copy of this vector non-uniformely scaled by S.

template<class T>
bool Vector3T< T >::IsEqual ( const Vector3T< T > &  B,
const T  Epsilon 
) const
inline

Returns whether this vector is equal to B within tolerance Epsilon, that is, whether it is geometrically closer to B than Epsilon.

Parameters
BVector to compare to.
EpsilonTolerance value.
See Also
operator ==
template<class T>
bool Vector3T< T >::IsValid ( ) const
inline

Returns true if the vector is valid, that is, all components are non-NANs.

template<class T>
bool Vector3T< T >::operator!= ( const Vector3T< T > &  B) const
inline

Returns whether this vector and B are not equal (bit-wise).

Use this operator with care, as it comes without any epsilon threshold for taking rounding errors into account.

Parameters
BVector to compare to.
See Also
IsEqual()
template<class T>
Vector3T<T> Vector3T< T >::operator* ( const T  s) const
inline

Returns a copy of this vector scaled by s, that is, the scalar product (Skalarmultiplikation) of this vector and s.

Parameters
sFactor to multiply this vector with.
See Also
GetScaled(), which does exactly the same.
template<class T>
Vector3T<T>& Vector3T< T >::operator*= ( const T  s)
inline

Scales this vector by s.

template<class T>
Vector3T<T> Vector3T< T >::operator+ ( const Vector3T< T > &  B) const
inline

Returns the sum of this Vector3T<T> and B.

template<class T>
Vector3T<T>& Vector3T< T >::operator+= ( const Vector3T< T > &  B)
inline

Adds B to this vector.

template<class T>
Vector3T<T> Vector3T< T >::operator- ( const Vector3T< T > &  B) const
inline

Returns the difference between this Vector3T<T> and B.

template<class T>
Vector3T<T> Vector3T< T >::operator- ( ) const
inline

The unary minus operator. B=-A is quasi identical with B=A.GetScaled(-1).

template<class T>
Vector3T<T>& Vector3T< T >::operator-= ( const Vector3T< T > &  B)
inline

Subtracts B from this vector.

template<class T>
Vector3T<T> Vector3T< T >::operator/ ( const T  s) const
inline

Returns a copy of this vector divided by s, that is, the scalar product (Skalarmultiplikation) of this vector and 1/s.

template<class T>
Vector3T<T>& Vector3T< T >::operator/= ( const T  s)
inline

Divides this vector by s. Assumes that s is not 0.

template<class T>
bool Vector3T< T >::operator== ( const Vector3T< T > &  B) const
inline

Returns whether this vector and B are truly (bit-wise) identical.

Use this operator with care, as it comes without any epsilon threshold for taking rounding errors into account.

Parameters
BVector to compare to.
See Also
IsEqual()
template<class T>
T& Vector3T< T >::operator[] ( unsigned int  Index)
inline

Component access by index number (0 to 2) rather than by name.

Parameters
IndexIndex of the component to access. Can only be 0, 1 or 2 (for x, y, z).
Exceptions
InvalidOperationEif Index is not 0, 1 or 2.
template<class T>
const T& Vector3T< T >::operator[] ( unsigned int  Index) const
inline

Component access by index number (0 to 2) rather than by name.

Parameters
IndexIndex of the component to access. Can only be 0, 1 or 2 (for x, y, z).
Exceptions
InvalidOperationEif Index is not 0, 1 or 2.

Member Data Documentation

template<class T>
T Vector3T< T >::x

The x-component of this vector.

template<class T>
T Vector3T< T >::y

The y-component of this vector.

template<class T>
T Vector3T< T >::z

The z-component of this vector.


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