VMTK
VMATH_NAMESPACE::Vector3< T > Class Template Reference

#include <vmath.h>

Public Member Functions

 Vector3 ()
 
 Vector3 (T nx, T ny, T nz)
 
 Vector3 (const Vector2< T > &v, T nz)
 
 Vector3 (const Vector3< T > &src)
 
 Vector3 (const T v[3])
 
template<class FromT >
 Vector3 (const Vector3< FromT > &src)
 
Vector3< T > operator= (const Vector3< T > &rhs)
 
template<class FromT >
Vector3< T > operator= (const Vector3< FromT > &rhs)
 
T & operator[] (int n)
 
const T & operator[] (int n) const
 
Vector3< T > operator+ (const Vector3< T > &rhs) const
 
Vector3< T > operator- (const Vector3< T > &rhs) const
 
Vector3< T > operator* (const Vector3< T > &rhs) const
 
Vector3< T > operator/ (const Vector3< T > &rhs) const
 
Vector3< T > & operator+= (const Vector3< T > &rhs)
 
Vector3< T > & operator-= (const Vector3< T > &rhs)
 
Vector3< T > & operator*= (const Vector3< T > &rhs)
 
Vector3< T > & operator/= (const Vector3< T > &rhs)
 
dotProduct (const Vector3< T > &rhs) const
 
Vector3< T > crossProduct (const Vector3< T > &rhs) const
 
Vector3< T > vectorNormal (const Vector3< T > v) const
 
Vector3< T > vectorNormalFromThreePoints (const Vector3< T > v1, const Vector3< T > v2, const Vector3< T > v3) const
 
Vector3< T > mean (const Vector3< T > v1, const Vector3< T > v2) const
 
Vector3< T > mean (const Vector3< T > v1, const Vector3< T > v2, const Vector3< T > v3) const
 
distance (const Vector3< T > v) const
 
Vector3< T > operator+ (T rhs) const
 
Vector3< T > operator- (T rhs) const
 
Vector3< T > operator* (T rhs) const
 
Vector3< T > operator/ (T rhs) const
 
Vector3< T > & operator+= (T rhs)
 
Vector3< T > & operator-= (T rhs)
 
Vector3< T > & operator*= (T rhs)
 
Vector3< T > & operator/= (T rhs)
 
bool operator== (const Vector3< T > &rhs) const
 
bool operator!= (const Vector3< T > &rhs) const
 
Vector3< T > operator- () const
 
length () const
 
lengthSq () const
 
void normalize ()
 
void rotate (T ax, T ay, T az)
 
Vector3< T > lerp (T fact, const Vector3< T > &r) const
 
 operator T* ()
 
 operator const T * () const
 
std::string toString () const
 
void print ()
 

Static Public Member Functions

static Vector3< T > crossProduct (Vector3< T > v1, Vector3< T > v2)
 
static Vector3< T > vectorNormal (Vector3< T > v1, Vector3< T > v2)
 
static T distance (Vector3< T > v1, Vector3< T > v2)
 

Public Attributes

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

Friends

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

Detailed Description

template<class T>
class VMATH_NAMESPACE::Vector3< T >

Class for three dimensional vector. There are four ways of accessing vector components. Let's have Vector3f v, you can either:

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

Definition at line 627 of file vmath.h.

Constructor & Destructor Documentation

◆ Vector3() [1/5]

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

Creates and sets to (0,0,0)

Definition at line 692 of file vmath.h.

◆ Vector3() [2/5]

template<class T>
VMATH_NAMESPACE::Vector3< T >::Vector3 ( nx,
ny,
nz 
)
inline

Creates and sets to (x,y,z)

Parameters
nxinitial x-coordinate value
nyinitial y-coordinate value
nzinitial z-coordinate value

Definition at line 703 of file vmath.h.

◆ Vector3() [3/5]

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

Copy constructor.

Parameters
srcSource of data for new created Vector3 instance.

Definition at line 718 of file vmath.h.

◆ Vector3() [4/5]

template<class T>
VMATH_NAMESPACE::Vector3< T >::Vector3 ( const T  v[3])
inline

Creates and sets to (x,y,z)

Parameters
v[3]vector of data, where x=v[0], y=v[1] and z=v[2].

Definition at line 727 of file vmath.h.

◆ Vector3() [5/5]

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

Copy casting constructor.

Parameters
srcSource of data for new created Vector3 instance.

Definition at line 737 of file vmath.h.

Member Function Documentation

◆ crossProduct()

template<class T>
Vector3<T> VMATH_NAMESPACE::Vector3< T >::crossProduct ( const Vector3< T > &  rhs) const
inline

Cross product operator

Parameters
rhsRight hand side argument of binary operator.

Definition at line 902 of file vmath.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ dotProduct()

template<class T>
T VMATH_NAMESPACE::Vector3< T >::dotProduct ( const Vector3< T > &  rhs) const
inline

Dot product of two vectors.

Parameters
rhsRight hand side argument of binary operator.

Definition at line 893 of file vmath.h.

◆ length()

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

Get length of vector.

Returns
lenght of vector

Definition at line 1078 of file vmath.h.

Here is the caller graph for this function:

◆ lengthSq()

template<class T>
T VMATH_NAMESPACE::Vector3< 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 1090 of file vmath.h.

Here is the caller graph for this function:

◆ lerp()

template<class T>
Vector3<T> VMATH_NAMESPACE::Vector3< T >::lerp ( fact,
const Vector3< T > &  r 
) const
inline

Linear interpolation of two vectors

Parameters
factFactor of interpolation. For translation from positon 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 1139 of file vmath.h.

Here is the caller graph for this function:

◆ normalize()

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

Normalize vector

Definition at line 1098 of file vmath.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ operator const T *()

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

Conversion to pointer operator

Returns
Constant Pointer to internally stored (in management of class Vector3<T>) used for passing Vector3<T> values to gl*3[fd] functions.

Definition at line 1161 of file vmath.h.

◆ operator T*()

template<class T>
VMATH_NAMESPACE::Vector3< T >::operator T* ( )
inline

Conversion to pointer operator

Returns
Pointer to internally stored (in management of class Vector3<T>) used for passing Vector3<T> values to gl*3[fd] functions.

Definition at line 1151 of file vmath.h.

◆ operator!=()

template<class T>
bool VMATH_NAMESPACE::Vector3< T >::operator!= ( const Vector3< T > &  rhs) const
inline

Inequality test operator

Parameters
rhsRight hand side argument of binary operator.
Returns
not (lhs == rhs) :-P

Definition at line 1058 of file vmath.h.

◆ operator*() [1/2]

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

Multiplication operator

Parameters
rhsRight hand side argument of binary operator.

Definition at line 827 of file vmath.h.

◆ operator*() [2/2]

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

Multiplication operator

Parameters
rhsRight hand side argument of binary operator.

Definition at line 978 of file vmath.h.

◆ operator*=() [1/2]

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

Multiplication operator

Parameters
rhsRight hand side argument of binary operator.

Definition at line 869 of file vmath.h.

◆ operator*=() [2/2]

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

Multiplication operator

Parameters
rhsRight hand side argument of binary operator.

Definition at line 1020 of file vmath.h.

◆ operator+() [1/2]

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

Addition operator

Parameters
rhsRight hand side argument of binary operator.

Definition at line 809 of file vmath.h.

◆ operator+() [2/2]

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

Addition operator

Parameters
rhsRight hand side argument of binary operator.

Definition at line 960 of file vmath.h.

◆ operator+=() [1/2]

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

Addition operator

Parameters
rhsRight hand side argument of binary operator.

Definition at line 845 of file vmath.h.

◆ operator+=() [2/2]

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

Addition operator

Parameters
rhsRight hand side argument of binary operator.

Definition at line 996 of file vmath.h.

◆ operator-() [1/3]

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

Subtraction operator

Parameters
rhsRight hand side argument of binary operator.

Definition at line 818 of file vmath.h.

◆ operator-() [2/3]

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

Subtraction operator

Parameters
rhsRight hand side argument of binary operator.

Definition at line 969 of file vmath.h.

◆ operator-() [3/3]

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

Unary negate operator

Returns
negated vector

Definition at line 1068 of file vmath.h.

◆ operator-=() [1/2]

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

Subtraction operator

Parameters
rhsRight hand side argument of binary operator.

Definition at line 857 of file vmath.h.

◆ operator-=() [2/2]

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

Subtraction operator

Parameters
rhsRight hand side argument of binary operator.

Definition at line 1008 of file vmath.h.

◆ operator/() [1/2]

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

Division operator

Parameters
rhsRight hand side argument of binary operator.

Definition at line 836 of file vmath.h.

◆ operator/() [2/2]

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

Division operator

Parameters
rhsRight hand side argument of binary operator.

Definition at line 987 of file vmath.h.

◆ operator/=() [1/2]

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

Division operator

Parameters
rhsRight hand side argument of binary operator.

Definition at line 881 of file vmath.h.

◆ operator/=() [2/2]

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

Division operator

Parameters
rhsRight hand side argument of binary operator.

Definition at line 1032 of file vmath.h.

◆ operator=() [1/2]

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

Copy operator

Parameters
rhsRight hand side argument of binary operator.

Definition at line 747 of file vmath.h.

◆ operator=() [2/2]

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

Copy casting operator.

Parameters
rhsRight hand side argument of binary operator.

Definition at line 760 of file vmath.h.

◆ operator==()

template<class T>
bool VMATH_NAMESPACE::Vector3< T >::operator== ( const Vector3< 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, and z-coordinate.

Definition at line 1048 of file vmath.h.

◆ operator[]() [1/2]

template<class T>
T& VMATH_NAMESPACE::Vector3< T >::operator[] ( int  n)
inline

Array access operator

Parameters
nArray index
Returns
For n = 0, reference to x coordinate, n = 1 reference to y, else reference to z y coordinate.

Definition at line 775 of file vmath.h.

◆ operator[]() [2/2]

template<class T>
const T& VMATH_NAMESPACE::Vector3< T >::operator[] ( int  n) const
inline

Constant array access operator

Parameters
nArray index
Returns
For n = 0, reference to x coordinate, n = 1 reference to y, else reference to z y coordinate.

Definition at line 793 of file vmath.h.

◆ print()

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

Show the print of string representation.

Definition at line 1192 of file vmath.h.

Here is the call graph for this function:

◆ rotate()

template<class T>
void VMATH_NAMESPACE::Vector3< T >::rotate ( ax,
ay,
az 
)
inline

Rotate vector around three axis.

Parameters
axAngle (in degrees) to be rotated around X-axis.
ayAngle (in degrees) to be rotated around Y-axis.
azAngle (in degrees) to be rotated around Z-axis.

Definition at line 1113 of file vmath.h.

◆ toString()

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

Gets string representation.

Definition at line 1182 of file vmath.h.

Friends And Related Function Documentation

◆ operator<<

template<class T>
std::ostream& operator<< ( std::ostream &  lhs,
const Vector3< 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 1173 of file vmath.h.

Member Data Documentation

◆ b

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

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

Definition at line 685 of file vmath.h.

◆ g

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

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

Definition at line 666 of file vmath.h.

◆ r

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

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

Definition at line 648 of file vmath.h.

◆ s

template<class T>
T VMATH_NAMESPACE::Vector3< T >::s

First element of vector, alias for S-coordinate. For textures notation.

Definition at line 642 of file vmath.h.

◆ t

template<class T>
T VMATH_NAMESPACE::Vector3< T >::t

Second element of vector, alias for T-coordinate. For textures notation.

Definition at line 661 of file vmath.h.

◆ u

template<class T>
T VMATH_NAMESPACE::Vector3< T >::u

Third element of vector, alias for U-coordinate. For textures notation.

Definition at line 680 of file vmath.h.

◆ x

template<class T>
T VMATH_NAMESPACE::Vector3< T >::x

First element of vector, alias for X-coordinate.

Definition at line 636 of file vmath.h.

◆ y

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

Second element of vector, alias for Y-coordinate.

Definition at line 656 of file vmath.h.

◆ z

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

Third element of vector, alias for Z-coordinate.

Definition at line 674 of file vmath.h.


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