vmath  vmath-0.12
Vector4< T > Class Template Reference

Class for four dimensional vector. More...

#include <vmath.h>

+ Collaboration diagram for Vector4< T >:

Public Member Functions

 Vector4 ()
 Creates and sets to (0,0,0,0) More...
 
 Vector4 (T nx, T ny, T nz, T nw)
 Creates and sets to (x,y,z,z) More...
 
 Vector4 (const Vector4< T > &src)
 Copy constructor. More...
 
template<class FromT >
 Vector4 (const Vector4< FromT > &src)
 Copy casting constructor. More...
 
 Vector4 (const Vector3< T > &src, T w)
 
template<typename FromT >
 Vector4 (const Vector3< FromT > &src, FromT w)
 
Vector4< T > operator= (const Vector4< T > &rhs)
 Copy operator. More...
 
template<class FromT >
Vector4< T > operator= (const Vector4< FromT > &rhs)
 Copy casting operator. More...
 
T & operator[] (int n)
 Array access operator. More...
 
const T & operator[] (int n) const
 Array access operator. More...
 
Vector4< T > operator+ (const Vector4< T > &rhs) const
 Addition operator. More...
 
Vector4< T > operator- (const Vector4< T > &rhs) const
 Subtraction operator. More...
 
Vector4< T > operator* (const Vector4< T > rhs) const
 Multiplication operator. More...
 
Vector4< T > operator/ (const Vector4< T > &rhs) const
 Division operator. More...
 
Vector4< T > & operator+= (const Vector4< T > &rhs)
 Addition operator. More...
 
Vector4< T > & operator-= (const Vector4< T > &rhs)
 Subtraction operator. More...
 
Vector4< T > & operator*= (const Vector4< T > &rhs)
 Multiplication operator. More...
 
Vector4< T > & operator/= (const Vector4< T > &rhs)
 Division operator. More...
 
bool operator== (const Vector4< T > &rhs) const
 Equality test operator. More...
 
bool operator!= (const Vector4< T > &rhs) const
 Inequality test operator. More...
 
Vector4< T > operator- () const
 Unary negate operator. More...
 
Vector4< T > operator+ (T rhs) const
 Addition operator. More...
 
Vector4< T > operator- (T rhs) const
 Subtraction operator. More...
 
Vector4< T > operator* (T rhs) const
 Multiplication operator. More...
 
Vector4< T > operator/ (T rhs) const
 Division operator. More...
 
Vector4< T > & operator+= (T rhs)
 Addition operator. More...
 
Vector4< T > & operator-= (T rhs)
 Subtraction operator. More...
 
Vector4< T > & operator*= (T rhs)
 Multiplication operator. More...
 
Vector4< T > & operator/= (T rhs)
 Division operator. More...
 
length () const
 Get length of vector. More...
 
void normalize ()
 Normalize vector. More...
 
lengthSq () const
 Return square of length. More...
 
Vector4< T > lerp (T fact, const Vector4< T > &r) const
 Linear interpolation of two vectors. More...
 
 operator T * ()
 Conversion to pointer operator. More...
 
 operator const T * () const
 Conversion to pointer operator. More...
 
Vector3< T > xyz () const
 Gets 3D vector. More...
 
std::string toString () const
 Gets string representation. More...
 

Public Attributes

union {
   T   r
 First element of vector, alias for R-coordinate. More...
 
   T   x
 
}; 
 
union {
   T   g
 Second element of vector, alias for G-coordinate. More...
 
   T   y
 Second element of vector, alias for Y-coordinate. More...
 
}; 
 
union {
   T   b
 Third element of vector, alias for B-coordinate. More...
 
   T   z
 Third element of vector, alias for Z-coordinate. More...
 
}; 
 
union {
   T   a
 Fourth element of vector, alias for A-coordinate. More...
 
   T   w
 First element of vector, alias for W-coordinate. More...
 
}; 
 

Friends

std::ostream & operator<< (std::ostream &lhs, const Vector4< T > &rhs)
 Output to stream operator. More...
 

Detailed Description

template<class T>
class Vector4< T >

Class for four dimensional vector.

There are four ways of accessing vector components. Let's have Vector4f v, you can either:

  • access as position in projective space (x,y,z,w) — v.x = v.y = v.z = v.w = 1;
  • access as texture coordinate (s,t,u,v) — v.s = v.t = v.u = v.v = 1;
  • access as color (r,g,b,a) — v.r = v.g = v.b = v.a = 1;
  • access via operator[] — v[0] = v[1] = v[2] = v[3] = 1;

Constructor & Destructor Documentation

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

Creates and sets to (0,0,0,0)

template<class T>
Vector4< T >::Vector4 ( nx,
ny,
nz,
nw 
)
inline

Creates and sets to (x,y,z,z)

Parameters
nxinitial x-coordinate value (R)
nyinitial y-coordinate value (G)
nzinitial z-coordinate value (B)
nwinitial w-coordinate value (Alpha)
template<class T>
Vector4< T >::Vector4 ( const Vector4< T > &  src)
inline

Copy constructor.

Parameters
srcSource of data for new created Vector4 instance.
template<class T>
template<class FromT >
Vector4< T >::Vector4 ( const Vector4< FromT > &  src)
inline

Copy casting constructor.

Parameters
srcSource of data for new created Vector4 instance.
template<class T>
Vector4< T >::Vector4 ( const Vector3< T > &  src,
w 
)
inline
template<class T>
template<typename FromT >
Vector4< T >::Vector4 ( const Vector3< FromT > &  src,
FromT  w 
)
inline

Member Function Documentation

template<class T>
T Vector4< T >::length ( ) const
inline

Get length of vector.

Returns
lenght of vector
template<class T>
T Vector4< T >::lengthSq ( ) const
inline

Return square of length.

Returns
length ^ 2
Note
This method is faster then length(). For comparison of length of two vector can be used just this value, instead of more expensive length() method.
template<class T>
Vector4<T> Vector4< T >::lerp ( fact,
const Vector4< T > &  r 
) const
inline

Linear interpolation of two vectors.

Parameters
factFactor of interpolation. For translation from position of this vector to vector r, values of factor goes from 0.0 to 1.0.
rSecond Vector for interpolation
Note
However values of fact parameter are reasonable only in interval [0.0 , 1.0], you can pass also values outside of this interval and you can get result (extrapolation?)
template<class T>
void Vector4< T >::normalize ( )
inline

Normalize vector.

template<class T>
Vector4< T >::operator const T * ( ) const
inline

Conversion to pointer operator.

Returns
Constant Pointer to internally stored (in management of class Vector4<T>) used for passing Vector4<T> values to gl*4[fd] functions.
template<class T>
Vector4< T >::operator T * ( )
inline

Conversion to pointer operator.

Returns
Pointer to internally stored (in management of class Vector4<T>) used for passing Vector4<T> values to gl*4[fd] functions.
template<class T>
bool Vector4< T >::operator!= ( const Vector4< T > &  rhs) const
inline

Inequality test operator.

Parameters
rhsRight hand side argument of binary operator.
Returns
not (lhs == rhs) :-P
template<class T>
Vector4<T> Vector4< T >::operator* ( const Vector4< T >  rhs) const
inline

Multiplication operator.

Parameters
rhsRight hand side argument of binary operator.
template<class T>
Vector4<T> Vector4< T >::operator* ( rhs) const
inline

Multiplication operator.

Parameters
rhsRight hand side argument of binary operator.
template<class T>
Vector4<T>& Vector4< T >::operator*= ( const Vector4< T > &  rhs)
inline

Multiplication operator.

Parameters
rhsRight hand side argument of binary operator.
template<class T>
Vector4<T>& Vector4< T >::operator*= ( rhs)
inline

Multiplication operator.

Parameters
rhsRight hand side argument of binary operator.
template<class T>
Vector4<T> Vector4< T >::operator+ ( const Vector4< T > &  rhs) const
inline

Addition operator.

Parameters
rhsRight hand side argument of binary operator.
template<class T>
Vector4<T> Vector4< T >::operator+ ( rhs) const
inline

Addition operator.

Parameters
rhsRight hand side argument of binary operator.
template<class T>
Vector4<T>& Vector4< T >::operator+= ( const Vector4< T > &  rhs)
inline

Addition operator.

Parameters
rhsRight hand side argument of binary operator.
template<class T>
Vector4<T>& Vector4< T >::operator+= ( rhs)
inline

Addition operator.

Parameters
rhsRight hand side argument of binary operator.
template<class T>
Vector4<T> Vector4< T >::operator- ( const Vector4< T > &  rhs) const
inline

Subtraction operator.

Parameters
rhsRight hand side argument of binary operator.
template<class T>
Vector4<T> Vector4< T >::operator- ( ) const
inline

Unary negate operator.

Returns
negated vector
template<class T>
Vector4<T> Vector4< T >::operator- ( rhs) const
inline

Subtraction operator.

Parameters
rhsRight hand side argument of binary operator.
template<class T>
Vector4<T>& Vector4< T >::operator-= ( const Vector4< T > &  rhs)
inline

Subtraction operator.

Parameters
rhsRight hand side argument of binary operator.
template<class T>
Vector4<T>& Vector4< T >::operator-= ( rhs)
inline

Subtraction operator.

Parameters
rhsRight hand side argument of binary operator.
template<class T>
Vector4<T> Vector4< T >::operator/ ( const Vector4< T > &  rhs) const
inline

Division operator.

Parameters
rhsRight hand side argument of binary operator.
template<class T>
Vector4<T> Vector4< T >::operator/ ( rhs) const
inline

Division operator.

Parameters
rhsRight hand side argument of binary operator.
template<class T>
Vector4<T>& Vector4< T >::operator/= ( const Vector4< T > &  rhs)
inline

Division operator.

Parameters
rhsRight hand side argument of binary operator.
template<class T>
Vector4<T>& Vector4< T >::operator/= ( rhs)
inline

Division operator.

Parameters
rhsRight hand side argument of binary operator.
template<class T>
Vector4<T> Vector4< T >::operator= ( const Vector4< T > &  rhs)
inline

Copy operator.

Parameters
rhsRight hand side argument of binary operator.
template<class T>
template<class FromT >
Vector4<T> Vector4< T >::operator= ( const Vector4< FromT > &  rhs)
inline

Copy casting operator.

Parameters
rhsRight hand side argument of binary operator.
template<class T>
bool Vector4< T >::operator== ( const Vector4< T > &  rhs) const
inline

Equality test operator.

Parameters
rhsRight hand side argument of binary operator.
Note
Test of equality is based of threshold EPSILON value. To be two values equal, must satisfy this condition | lhs.x - rhs.y | < EPSILON, same for y-coordinate, z-coordinate, and w-coordinate.
template<class T>
T& Vector4< T >::operator[] ( int  n)
inline

Array access operator.

Parameters
nArray index
Returns
For n = 0, reference to x coordinate, n = 1 reference to y coordinate, n = 2 reference to z, else reference to w coordinate.
template<class T>
const T& Vector4< T >::operator[] ( int  n) const
inline

Array access operator.

Parameters
nArray index
Returns
For n = 0, reference to x coordinate, n = 1 reference to y coordinate, n = 2 reference to z, else reference to w coordinate.
template<class T>
std::string Vector4< T >::toString ( ) const
inline

Gets string representation.

template<class T>
Vector3<T> Vector4< T >::xyz ( ) const
inline

Gets 3D vector.

Note that the output is divided by w coordinate to apply projection transform. If the w coordinate is equal to zero, the result is not divided.

Returns
(x/w, y/w, z/w) iff w != 0 otherwise (x,y,z)

Friends And Related Function Documentation

template<class T>
std::ostream& operator<< ( std::ostream &  lhs,
const Vector4< T > &  rhs 
)
friend

Output to stream operator.

Parameters
lhsLeft hand side argument of operator (commonly ostream instance).
rhsRight hand side argument of operator.
Returns
Left hand side argument - the ostream object passed to operator.

Member Data Documentation

union { ... }
union { ... }
union { ... }
union { ... }
template<class T>
T Vector4< T >::a

Fourth element of vector, alias for A-coordinate.

For color notation. This represnt aplha chanell

template<class T>
T Vector4< T >::b

Third element of vector, alias for B-coordinate.

For color notation.

template<class T>
T Vector4< T >::g

Second element of vector, alias for G-coordinate.

For color notation.

template<class T>
T Vector4< T >::r

First element of vector, alias for R-coordinate.

For color notation. First element of vector, alias for X-coordinate.

template<class T>
T Vector4< T >::w

First element of vector, alias for W-coordinate.

Note
For vectors (such as normals) should be set to 0.0 For vertices should be set to 1.0
template<class T>
T Vector4< T >::x
template<class T>
T Vector4< T >::y

Second element of vector, alias for Y-coordinate.

template<class T>
T Vector4< T >::z

Third element of vector, alias for Z-coordinate.


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