VMTK
VMATH_NAMESPACE::Vector4< T > Class Template Reference

#include <vmath.h>

Public Member Functions

 Vector4 ()
 
 Vector4 (T nx, T ny, T nz, T nw)
 
 Vector4 (T nx, T ny, T nz)
 
 Vector4 (const Vector3< T > &v, T nw)
 
 Vector4 (const Vector3< T > &v)
 
 Vector4 (const Vector4< T > &src)
 
template<class FromT >
 Vector4 (const Vector4< FromT > &src)
 
template<typename FromT >
 Vector4 (const Vector3< FromT > &src, FromT w)
 
Vector4< T > operator= (const Vector4< T > &rhs)
 
template<class FromT >
Vector4< T > operator= (const Vector4< FromT > &rhs)
 
T & operator[] (int n)
 
const T & operator[] (int n) const
 
Vector4< T > operator+ (const Vector4< T > &rhs) const
 
Vector4< T > operator- (const Vector4< T > &rhs) const
 
Vector4< T > operator* (const Vector4< T > rhs) const
 
Vector4< T > operator/ (const Vector4< T > &rhs) const
 
Vector4< T > & operator+= (const Vector4< T > &rhs)
 
Vector4< T > & operator-= (const Vector4< T > &rhs)
 
Vector4< T > & operator*= (const Vector4< T > &rhs)
 
Vector4< T > & operator/= (const Vector4< T > &rhs)
 
bool operator== (const Vector4< T > &rhs) const
 
bool operator!= (const Vector4< T > &rhs) const
 
Vector4< T > operator- () const
 
Vector4< T > operator+ (T rhs) const
 
Vector4< T > operator- (T rhs) const
 
Vector4< T > operator* (T rhs) const
 
Vector4< T > operator/ (T rhs) const
 
Vector4< T > & operator+= (T rhs)
 
Vector4< T > & operator-= (T rhs)
 
Vector4< T > & operator*= (T rhs)
 
Vector4< T > & operator/= (T rhs)
 
length () const
 
void normalize ()
 
lengthSq () const
 
Vector4< T > lerp (T fact, const Vector4< T > &r) const
 
 operator T* ()
 
 operator const T * () const
 
Vector3< T > xyz () const
 
std::string toString () const
 
void print ()
 

Public Attributes

union {
   T   r
 
   T   x
 
}; 
 
union {
   T   g
 
   T   y
 
}; 
 
union {
   T   b
 
   T   z
 
}; 
 
union {
   T   a
 
   T   w
 
}; 
 

Friends

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

Detailed Description

template<class T>
class VMATH_NAMESPACE::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;

Definition at line 1214 of file vmath.h.

Constructor & Destructor Documentation

◆ Vector4() [1/5]

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

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

Definition at line 1276 of file vmath.h.

◆ Vector4() [2/5]

template<class T>
VMATH_NAMESPACE::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)

Definition at line 1288 of file vmath.h.

◆ Vector4() [3/5]

template<class T>
VMATH_NAMESPACE::Vector4< T >::Vector4 ( nx,
ny,
nz 
)
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 = 1.0)

Definition at line 1300 of file vmath.h.

◆ Vector4() [4/5]

template<class T>
VMATH_NAMESPACE::Vector4< T >::Vector4 ( const Vector4< T > &  src)
inline

Copy constructor.

Parameters
srcSource of data for new created Vector4 instance.

Definition at line 1319 of file vmath.h.

◆ Vector4() [5/5]

template<class T>
template<class FromT >
VMATH_NAMESPACE::Vector4< T >::Vector4 ( const Vector4< FromT > &  src)
inline

Copy casting constructor.

Parameters
srcSource of data for new created Vector4 instance.

Definition at line 1329 of file vmath.h.

Member Function Documentation

◆ length()

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

Get length of vector.

Returns
lenght of vector

Definition at line 1625 of file vmath.h.

◆ lengthSq()

template<class T>
T VMATH_NAMESPACE::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.

Definition at line 1649 of file vmath.h.

◆ lerp()

template<class T>
Vector4<T> VMATH_NAMESPACE::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?)

Definition at line 1664 of file vmath.h.

◆ normalize()

template<class T>
void VMATH_NAMESPACE::Vector4< T >::normalize ( )
inline

Normalize vector

Definition at line 1633 of file vmath.h.

Here is the call graph for this function:

◆ operator const T *()

template<class T>
VMATH_NAMESPACE::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.

Definition at line 1686 of file vmath.h.

◆ operator T*()

template<class T>
VMATH_NAMESPACE::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.

Definition at line 1676 of file vmath.h.

◆ operator!=()

template<class T>
bool VMATH_NAMESPACE::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

Definition at line 1515 of file vmath.h.

◆ operator*() [1/2]

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

Multiplication operator

Parameters
rhsRight hand side argument of binary operator.

Definition at line 1430 of file vmath.h.

◆ operator*() [2/2]

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

Multiplication operator

Parameters
rhsRight hand side argument of binary operator.

Definition at line 1554 of file vmath.h.

◆ operator*=() [1/2]

template<class T>
Vector4<T>& VMATH_NAMESPACE::Vector4< T >::operator*= ( const Vector4< T > &  rhs)
inline

Multiplication operator

Parameters
rhsRight hand side argument of binary operator.

Definition at line 1474 of file vmath.h.

◆ operator*=() [2/2]

template<class T>
Vector4<T>& VMATH_NAMESPACE::Vector4< T >::operator*= ( rhs)
inline

Multiplication operator

Parameters
rhsRight hand side argument of binary operator.

Definition at line 1598 of file vmath.h.

◆ operator+() [1/2]

template<class T>
Vector4<T> VMATH_NAMESPACE::Vector4< T >::operator+ ( const Vector4< T > &  rhs) const
inline

Addition operator

Parameters
rhsRight hand side argument of binary operator.

Definition at line 1412 of file vmath.h.

◆ operator+() [2/2]

template<class T>
Vector4<T> VMATH_NAMESPACE::Vector4< T >::operator+ ( rhs) const
inline

Addition operator

Parameters
rhsRight hand side argument of binary operator.

Definition at line 1536 of file vmath.h.

◆ operator+=() [1/2]

template<class T>
Vector4<T>& VMATH_NAMESPACE::Vector4< T >::operator+= ( const Vector4< T > &  rhs)
inline

Addition operator

Parameters
rhsRight hand side argument of binary operator.

Definition at line 1448 of file vmath.h.

◆ operator+=() [2/2]

template<class T>
Vector4<T>& VMATH_NAMESPACE::Vector4< T >::operator+= ( rhs)
inline

Addition operator

Parameters
rhsRight hand side argument of binary operator.

Definition at line 1572 of file vmath.h.

◆ operator-() [1/3]

template<class T>
Vector4<T> VMATH_NAMESPACE::Vector4< T >::operator- ( const Vector4< T > &  rhs) const
inline

Subtraction operator

Parameters
rhsRight hand side argument of binary operator.

Definition at line 1421 of file vmath.h.

◆ operator-() [2/3]

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

Unary negate operator

Returns
negated vector

Definition at line 1525 of file vmath.h.

◆ operator-() [3/3]

template<class T>
Vector4<T> VMATH_NAMESPACE::Vector4< T >::operator- ( rhs) const
inline

Subtraction operator

Parameters
rhsRight hand side argument of binary operator.

Definition at line 1545 of file vmath.h.

◆ operator-=() [1/2]

template<class T>
Vector4<T>& VMATH_NAMESPACE::Vector4< T >::operator-= ( const Vector4< T > &  rhs)
inline

Subtraction operator

Parameters
rhsRight hand side argument of binary operator.

Definition at line 1461 of file vmath.h.

◆ operator-=() [2/2]

template<class T>
Vector4<T>& VMATH_NAMESPACE::Vector4< T >::operator-= ( rhs)
inline

Subtraction operator

Parameters
rhsRight hand side argument of binary operator.

Definition at line 1585 of file vmath.h.

◆ operator/() [1/2]

template<class T>
Vector4<T> VMATH_NAMESPACE::Vector4< T >::operator/ ( const Vector4< T > &  rhs) const
inline

Division operator

Parameters
rhsRight hand side argument of binary operator.

Definition at line 1439 of file vmath.h.

◆ operator/() [2/2]

template<class T>
Vector4<T> VMATH_NAMESPACE::Vector4< T >::operator/ ( rhs) const
inline

Division operator

Parameters
rhsRight hand side argument of binary operator.

Definition at line 1563 of file vmath.h.

◆ operator/=() [1/2]

template<class T>
Vector4<T>& VMATH_NAMESPACE::Vector4< T >::operator/= ( const Vector4< T > &  rhs)
inline

Division operator

Parameters
rhsRight hand side argument of binary operator.

Definition at line 1487 of file vmath.h.

◆ operator/=() [2/2]

template<class T>
Vector4<T>& VMATH_NAMESPACE::Vector4< T >::operator/= ( rhs)
inline

Division operator

Parameters
rhsRight hand side argument of binary operator.

Definition at line 1611 of file vmath.h.

◆ operator=() [1/2]

template<class T>
Vector4<T> VMATH_NAMESPACE::Vector4< T >::operator= ( const Vector4< T > &  rhs)
inline

Copy operator

Parameters
rhsRight hand side argument of binary operator.

Definition at line 1344 of file vmath.h.

◆ operator=() [2/2]

template<class T>
template<class FromT >
Vector4<T> VMATH_NAMESPACE::Vector4< T >::operator= ( const Vector4< FromT > &  rhs)
inline

Copy casting operator

Parameters
rhsRight hand side argument of binary operator.

Definition at line 1358 of file vmath.h.

◆ operator==()

template<class T>
bool VMATH_NAMESPACE::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.

Definition at line 1504 of file vmath.h.

◆ operator[]() [1/2]

template<class T>
T& VMATH_NAMESPACE::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.

Definition at line 1374 of file vmath.h.

◆ operator[]() [2/2]

template<class T>
const T& VMATH_NAMESPACE::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.

Definition at line 1394 of file vmath.h.

◆ print()

template<class T>
void VMATH_NAMESPACE::Vector4< T >::print ( )
inline

Show the print of string representation.

Definition at line 1731 of file vmath.h.

Here is the call graph for this function:

◆ toString()

template<class T>
std::string VMATH_NAMESPACE::Vector4< T >::toString ( ) const
inline

Gets string representation.

Definition at line 1721 of file vmath.h.

◆ xyz()

template<class T>
Vector3<T> VMATH_NAMESPACE::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)

Definition at line 1696 of file vmath.h.

Friends And Related Function Documentation

◆ operator<<

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.

Definition at line 1712 of file vmath.h.

Member Data Documentation

◆ a

template<class T>
T VMATH_NAMESPACE::Vector4< T >::a

Fourth element of vector, alias for A-coordinate. For color notation. This represnt aplha chanell

Definition at line 1263 of file vmath.h.

◆ b

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

Third element of vector, alias for B-coordinate. For color notation.

Definition at line 1250 of file vmath.h.

◆ g

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

Second element of vector, alias for G-coordinate. For color notation.

Definition at line 1237 of file vmath.h.

◆ r

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

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

Definition at line 1227 of file vmath.h.

◆ w

template<class T>
T VMATH_NAMESPACE::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

Definition at line 1269 of file vmath.h.

◆ y

template<class T>
T VMATH_NAMESPACE::Vector4< T >::y

Second element of vector, alias for Y-coordinate.

Definition at line 1241 of file vmath.h.

◆ z

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

Third element of vector, alias for Z-coordinate.

Definition at line 1254 of file vmath.h.


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