QSDK 1.1 Documentation
Main Page | Modules | Class Hierarchy | Alphabetical List | Compound List | File List | Compound Members | File Members | Related Pages

Maths::Vec3< T > Struct Template Reference
[Vectors]

A three-element vector template. More...

#include <Q/maths.h>

List of all members.

Public Member Functions

 Vec3 ()
 Create a new uninitialised vector.

 Vec3 (T v)
 Create a vector with all elements initialised to the same value.

 Vec3 (T tx, T ty, T tz)
 Create a vector from three existing values.

 Vec3 (const Vec2< T > &v)
 Convert a two element vector to a new three element vector.

 Vec3 (const Vec4< T > &v)
 Convert a four element vector to a new three element vector.

T & operator[] (unsigned int i)
 Return a reference to some element of the vector.

const T & operator[] (unsigned int i) const
 Return a reference to some element of the vector.

Vec2< T > & vec2 ()
 Cast a three element vector to a two element vector.

const Vec2< T > & vec2 () const
 Cast a three element vector to a two element vector.

bool isZero () const
 Test the value of a vector.

Vec3operator+= (const Vec3 &v)
 Calculate the sum of two vectors.

Vec3operator-= (const Vec3 &v)
 Calculate the difference of two vectors.

Vec3operator *= (const Vec3 &v)
 Calculate the elementwise product of two vectors.

Vec3operator/= (const Vec3 &v)
 Calculate the ratio of two vectors.

Vec3operator *= (T s)
 Calculate a scalar multiple of a vector.

Vec3operator/= (T s)
 Calculate a scalar ratio of a vector.

int operator== (const T &i) const
 Compare two vectors.

int operator!= (const T &i) const
 Compare two vectors.

modulus () const
 Calculate the length of a vector.

length () const
 Calculate the length of a vector.

lengthSquared () const
 Calculate the square of the length of a vector.

distanceTo (const Vec3 &v) const
 Calculate the distance between two points.

distanceToSquared (const Vec3 &there) const
 Calculate the square of the distance between two points.

bool equals (const Vec3 &v, T e=Epsilon) const
 Compare two vectors.

bool equal (const Vec3 &v, T e=Epsilon) const
 Compare two vectors.

void normalize ()
 Normalize the vector.

Vec3scaleTo (T newlen)
 Set the length of a vector.

void zero ()
 Zero a vector.

void clamp (const T min, const T max)
 Constrain a vector to a range.

Vec3sub (const Vec3 &a, const Vec3 &b)
 Calculate the difference of two vectors.

Vec3add (const Vec3 &a, const Vec3 &b)
 Calculate the sum of two vectors.

Vec3negate ()
 Negate a vector.

Vec3product (const Vec3 &a, const Vec3 &b)
 Calculate the product of two vectors.

Vec3product (const Vec3 &a, float b)
 Calculate the scalar product of a vector.

Vec3cross (const Vec3 &v1, const Vec3 &v2)
 Calculate the cross (or outer) product of two vectors.

dot (const Vec3 &b) const
 Calculate the inner product of two vectors.

void setNormalTo (const Vec3 &v)
 Calculate some vector normal to a vector.

Vec3 rotate (const Matrix4f &m) const
 Calculate the product of a vector and a matrix.

Vec3 rotate (const Affine4f &m) const
 Calculate the product of a vector and a matrix.

Vec3 transform (const Matrix4f &m) const
 Calculate the product of a vector and a matrix.

Vec3 transform (const Affine4f &m) const
 Calculate the product of a vector and a matrix.

Vec3 inverseRotate (const Matrix4f &m) const
 Calculate the product of a vector and a matrix.

Vec3 inverseTransform (const Matrix4f &m) const
 Calculate the product of a vector and a matrix.


Static Public Member Functions

const Vec3origin ()
 The vector representing the origin.

const Vec3xAxis ()
 The vector representing the X axis.

const Vec3yAxis ()
 The vector representing the Y axis.

const Vec3zAxis ()
 The vector representing the Z axis.


Public Attributes

x
 The first element of the vector.

y
 The second element of the vector.

z
 The third element of the vector.


Friends

Vec3 operator+ (const Vec3< T > &v)
 Return a copy of a vector.

Vec3 operator- (const Vec3 &v)
 Negate a vector.

Vec3 operator+ (const Vec3 &v1, const Vec3 &v2)
 Calculate the sum of two vectors.

Vec3 operator- (const Vec3 &v1, const Vec3 &v2)
 Calculate the difference of two vectors.

Vec3 operator * (const Vec3 &v1, const Vec3 &v2)
 Calculate the elementwise product of two vectors.

Vec3 operator * (const Vec3 &v, T s)
 Calculate a scalar multiple of a vector.

Vec3 operator * (T s, const Vec3 &v)
 Calculate a scalar multiple of a vector.

Vec3 operator * (const Vec3 &v, const Matrix4f &m)
 Calculate the product of a vector and a matrix.

Vec3 operator * (const Vec3 &v, const Matrix3f &m)
 Calculate the product of a vector and a matrix.

Vec3 operator * (const Matrix3f &m, const Vec3 &v)
 Calculate the product of a vector and a matrix.

Vec3 operator/ (const Vec3 &v1, const Vec3 &v2)
 Calculate the elementwise quotient of two vectors.

Vec3 operator/ (const Vec3 &v, T s)
 Calculate a scalar quotient of a vector.

Vec3 operator/ (T s, const Vec3 &v)
 Calculate the elementwise quotient of a vector and a scalar.

Vec3 operator/ (const Vec3 &v, const Matrix4f &m)
 Calculate the product of a vector and a matrix.

Vec3 operator^ (const Vec3 &v1, const Vec3 &v2)
Vec3 cross (const Vec3 &v1, const Vec3 &v2)
 Calculate the cross (or outer) product of two vectors.

dot (const Vec3 &v1, const Vec3 &v2)
 Calculate the inner product of two vectors.

Vec3 reflect (const Vec3 &n, const Vec3 &i)
 Calculate a reflection vector.

Vec3 refract (const Vec3 &n, const Vec3 &i, T indexRatio)
 Calculate a refraction vector.

Vec3 interpolate (T mul, const Vec3 &v1, const Vec3 &v2)
 Interpolate between two vectors.

bool operator< (const Vec3 &v1, const Vec3 &v2)
 Compare two vectors.

bool operator<= (const Vec3 &v1, const Vec3 &v2)
 Compare two vectors.

bool operator== (const Vec3 &v1, const Vec3 &v2)
 Compare two vectors.

bool operator!= (const Vec3 &v1, const Vec3 &v2)
 Compare two vectors.


Detailed Description

template<class T>
struct Maths::Vec3< T >

A three-element vector template.

Instantiate this template using an arithmetic type of the required precision. Various common types of three element vectors are pre-defined as templates (e.g. Vec3f, Vec3d, Vec3i).


Constructor & Destructor Documentation

template<class T>
Maths::Vec3< T >::Vec3 const Vec2< T > &  v  )  [inline, explicit]
 

Convert a two element vector to a new three element vector.

The first two elements of the new vector are initialised to the two elements of the existing vector and the third is set to zero.

template<class T>
Maths::Vec3< T >::Vec3 const Vec4< T > &  v  )  [inline, explicit]
 

Convert a four element vector to a new three element vector.

The three elements of the new vector are initialised to the first three elements of the existing vector divided by its fourth element


Member Function Documentation

template<class T>
Vec3& Maths::Vec3< T >::add const Vec3< T > &  a,
const Vec3< T > &  b
[inline]
 

Calculate the sum of two vectors.

Set the value of each element of this vector to the sum of the corresponding elements of a and b.

Returns:
A reference to this vector

template<class T>
void Maths::Vec3< T >::clamp const T  min,
const T  max
 

Constrain a vector to a range.

Set each element of the vector to the result of calling Maths::clamp with that element and the values min and max.

template<class T>
Vec3& Maths::Vec3< T >::cross const Vec3< T > &  v1,
const Vec3< T > &  v2
 

Calculate the cross (or outer) product of two vectors.

Set this vector to a vector which is normal to both v1 and v2, scaled by the product of the lengths of both v1 and v2 and the sine of the angle between them.

Returns:
A reference to this vector

template<class T>
T Maths::Vec3< T >::distanceTo const Vec3< T > &  v  )  const
 

Calculate the distance between two points.

Returns:
The length of the vector difference of this vector and v

template<class T>
T Maths::Vec3< T >::distanceToSquared const Vec3< T > &  there  )  const
 

Calculate the square of the distance between two points.

Returns:
The square of the length of the vector difference of this vector and v

template<class T>
T Maths::Vec3< T >::dot const Vec3< T > &  b  )  const
 

Calculate the inner product of two vectors.

Returns:
A value which is the product of the lengths of the two vectors and the cosine of the angle between them

template<class T>
bool Maths::Vec3< T >::equal const Vec3< T > &  v,
e = Epsilon
const
 

Compare two vectors.

Return values:
true if the absolute difference between each corresponding pair of element of the two vectors is less than e
false otherwise

Deprecated:
All other epsilon comparisons in QMaths use the name equals.

template<class T>
bool Maths::Vec3< T >::equals const Vec3< T > &  v,
e = Epsilon
const
 

Compare two vectors.

Return values:
true if all the absolute differences between each corresponding pair of elements of the two vectors are less than e
false otherwise

template<class T>
Vec3 Maths::Vec3< T >::inverseRotate const Matrix4f m  )  const
 

Calculate the product of a vector and a matrix.

Returns:
The vector formed by calculating the matrix product of this vector and the top-left three by three matrix of the inverse of m (i.e. the part of the matrix which encodes rotations).

template<class T>
Vec3 Maths::Vec3< T >::inverseTransform const Matrix4f m  )  const
 

Calculate the product of a vector and a matrix.

Returns:
The vector formed by calculating the matrix product of this vector and the top-left three by three matrix of the inverse of m (i.e. the part of the matrix which encodes rotations) and then adding the vector formed by the first three elements of the fourth row of the matrix (i.e. the part of the matrix encoding translations).

template<class T>
bool Maths::Vec3< T >::isZero  )  const
 

Test the value of a vector.

Return values:
true if all elements of the vector are zero.
false otherwise

template<class T>
T Maths::Vec3< T >::length  )  const [inline]
 

Calculate the length of a vector.

Returns:
The square root of the sum of the squares of each element of the vector

template<class T>
T Maths::Vec3< T >::lengthSquared  )  const [inline]
 

Calculate the square of the length of a vector.

Returns:
The square of the length of the vector

template<class T>
T Maths::Vec3< T >::modulus  )  const
 

Calculate the length of a vector.

Returns:
The square root of the sum of the squares of each element of the vector

template<class T>
Vec3& Maths::Vec3< T >::negate  )  [inline]
 

Negate a vector.

Negate each element of the vector.

Returns:
A reference to this vector

void Maths::Vec3<>::normalize  )  [inline]
 

Normalize the vector.

Normalize the vector by dividing each element by the vector's modulus.

See also:
Vec3::modulus.

template<class T>
Vec3& Maths::Vec3< T >::operator *= s  ) 
 

Calculate a scalar multiple of a vector.

Set the value of each element of this vector to the product of that element and s.

Returns:
A reference to this vector

template<class T>
Vec3& Maths::Vec3< T >::operator *= const Vec3< T > &  v  ) 
 

Calculate the elementwise product of two vectors.

Set the value of each element of this vector to the product of that element and the corresponding element of v.

Returns:
A reference to this vector

template<class T>
int Maths::Vec3< T >::operator!= const T &  i  )  const [inline]
 

Compare two vectors.

Return values:
true if some element of this vector is not equal to i
false otherwise

template<class T>
Vec3& Maths::Vec3< T >::operator+= const Vec3< T > &  v  ) 
 

Calculate the sum of two vectors.

Set the value of each element of this vector to the sum of that element and the corresponding element of v.

Returns:
A reference to this vector

template<class T>
Vec3& Maths::Vec3< T >::operator-= const Vec3< T > &  v  ) 
 

Calculate the difference of two vectors.

Set the value of each element of this vector to the difference of that element and the corresponding element of v.

Returns:
A reference to this vector

template<class T>
Vec3& Maths::Vec3< T >::operator/= s  ) 
 

Calculate a scalar ratio of a vector.

Set the value of each element of this vector to the ratio of that element and s.

Returns:
A reference to this vector

template<class T>
Vec3& Maths::Vec3< T >::operator/= const Vec3< T > &  v  ) 
 

Calculate the ratio of two vectors.

Set the value of each element of this vector to the ratio of that element and the corresponding element of v.

Returns:
A reference to this vector

template<class T>
int Maths::Vec3< T >::operator== const T &  i  )  const
 

Compare two vectors.

Return values:
true if each element of this vector equals i
false otherwise

template<class T>
const T& Maths::Vec3< T >::operator[] unsigned int  i  )  const
 

Return a reference to some element of the vector.

Parameters:
i The index of the required element, ranging from zero to two.

template<class T>
T& Maths::Vec3< T >::operator[] unsigned int  i  ) 
 

Return a reference to some element of the vector.

Parameters:
i The index of the required element, ranging from zero to two.

template<class T>
const Vec3& Maths::Vec3< T >::origin  )  [static]
 

The vector representing the origin.

Returns:
A vector with all elements set to zero

template<class T>
Vec3& Maths::Vec3< T >::product const Vec3< T > &  a,
float  b
[inline]
 

Calculate the scalar product of a vector.

Set the value of each element of this vector to the product of the corresponding element of a and b.

Returns:
A reference to this vector

template<class T>
Vec3& Maths::Vec3< T >::product const Vec3< T > &  a,
const Vec3< T > &  b
[inline]
 

Calculate the product of two vectors.

Set the value of each element of this vector to the product of the corresponding elements of a and b.

Returns:
A reference to this vector

template<class T>
Vec3 Maths::Vec3< T >::rotate const Affine4f m  )  const
 

Calculate the product of a vector and a matrix.

Returns:
The vector formed by calculating the matrix product of this vector and the top-left three by three matrix of m (i.e. the part of the matrix which encodes rotations).

template<class T>
Vec3 Maths::Vec3< T >::rotate const Matrix4f m  )  const
 

Calculate the product of a vector and a matrix.

Returns:
The vector formed by calculating the matrix product of this vector and the top-left three by three matrix of m (i.e. the part of the matrix which encodes rotations).

template<class T>
Vec3& Maths::Vec3< T >::scaleTo newlen  ) 
 

Set the length of a vector.

Normalize the vector and then scale each element by newlen.

Returns:
A reference to this vector.

template<class T>
void Maths::Vec3< T >::setNormalTo const Vec3< T > &  v  ) 
 

Calculate some vector normal to a vector.

Set this vector to a vector which is normal to v.

template<class T>
Vec3& Maths::Vec3< T >::sub const Vec3< T > &  a,
const Vec3< T > &  b
[inline]
 

Calculate the difference of two vectors.

Set the value of each element of this vector to the difference of the corresponding elements of a and b.

Returns:
A reference to this vector

template<class T>
Vec3 Maths::Vec3< T >::transform const Affine4f m  )  const
 

Calculate the product of a vector and a matrix.

Returns:
The vector formed by calculating the matrix product of this vector and the top-left three by three matrix of m (i.e. the part of the matrix which encodes rotations) and then adding the vector formed by the first three elements of the fourth row of the matrix (i.e. the part of the matrix encoding translations).

template<class T>
Vec3 Maths::Vec3< T >::transform const Matrix4f m  )  const
 

Calculate the product of a vector and a matrix.

Returns:
The vector formed by calculating the matrix product of this vector and the top-left three by three matrix of m (i.e. the part of the matrix which encodes rotations) and then adding the vector formed by the first three elements of the fourth row of the matrix (i.e. the part of the matrix encoding translations).

template<class T>
const Vec2<T>& Maths::Vec3< T >::vec2  )  const [inline]
 

Cast a three element vector to a two element vector.

Returns:
A reference to this vector, cast to a two element vector

template<class T>
Vec2<T>& Maths::Vec3< T >::vec2  )  [inline]
 

Cast a three element vector to a two element vector.

Returns:
A reference to this vector, cast to a two element vector

template<class T>
const Vec3& Maths::Vec3< T >::xAxis  )  [static]
 

The vector representing the X axis.

Returns:
A vector with the first element set to one and all other elements set to zero

template<class T>
const Vec3& Maths::Vec3< T >::yAxis  )  [static]
 

The vector representing the Y axis.

Returns:
A vector with the second element set to one and all other elements set to zero

template<class T>
const Vec3& Maths::Vec3< T >::zAxis  )  [static]
 

The vector representing the Z axis.

Returns:
A vector with the third element set to one and all other elements set to zero

template<class T>
void Maths::Vec3< T >::zero  )  [inline]
 

Zero a vector.

Set each element of the vector to zero.


Friends And Related Function Documentation

template<class T>
Vec3 cross const Vec3< T > &  v1,
const Vec3< T > &  v2
[friend]
 

Calculate the cross (or outer) product of two vectors.

Returns:
A vector which is normal to both v1 and v2, scaled by the product of the lengths of both v1 and v2 and the sine of the angle between them.

template<class T>
T dot const Vec3< T > &  v1,
const Vec3< T > &  v2
[friend]
 

Calculate the inner product of two vectors.

Returns:
A value which is the product of the lengths of the two vectors and the cosine of the angle between them

template<class T>
Vec3 interpolate mul,
const Vec3< T > &  v1,
const Vec3< T > &  v2
[friend]
 

Interpolate between two vectors.

Returns:
v1 + (v2 - v1) * mul

template<class T>
Vec3 operator * const Matrix3f m,
const Vec3< T > &  v
[friend]
 

Calculate the product of a vector and a matrix.

Returns:
the vector formed by calculating the matrix product of m and the transpose of v

template<class T>
Vec3 operator * const Vec3< T > &  v,
const Matrix3f m
[friend]
 

Calculate the product of a vector and a matrix.

Returns:
the vector formed by calculating the matrix product of v and m

template<class T>
Vec3 operator * const Vec3< T > &  v,
const Matrix4f m
[friend]
 

Calculate the product of a vector and a matrix.

Returns:
The vector formed by calculating the matrix product of v and the top-left three by three matrix of m (i.e. the part of the matrix which encodes rotations) and then adding the vector formed by the first three elements of the fourth row of the matrix (i.e. the part of the matrix encoding translations).
See also:
Vec3::transform

template<class T>
Vec3 operator * s,
const Vec3< T > &  v
[friend]
 

Calculate a scalar multiple of a vector.

Returns:
A new vector where each element is set to the product of the corresponding elements of v and s

template<class T>
Vec3 operator * const Vec3< T > &  v,
s
[friend]
 

Calculate a scalar multiple of a vector.

Returns:
A new vector where each element is set to the product of the corresponding elements of v and s

template<class T>
Vec3 operator * const Vec3< T > &  v1,
const Vec3< T > &  v2
[friend]
 

Calculate the elementwise product of two vectors.

Returns:
A new vector where each element is set to the product of the corresponding elements of v1 and v2

template<class T>
bool operator!= const Vec3< T > &  v1,
const Vec3< T > &  v2
[friend]
 

Compare two vectors.

Return values:
true if the two vectors are not equal
false otherwise

template<class T>
Vec3 operator+ const Vec3< T > &  v1,
const Vec3< T > &  v2
[friend]
 

Calculate the sum of two vectors.

Returns:
A new vector where each element is set to the sum of the corresponding elements of v1 and v2

template<class T>
Vec3 operator- const Vec3< T > &  v1,
const Vec3< T > &  v2
[friend]
 

Calculate the difference of two vectors.

Returns:
A new vector where each element is set to the difference of the corresponding elements of v1 and v2

template<class T>
Vec3 operator- const Vec3< T > &  v  )  [friend]
 

Negate a vector.

Returns:
A vector with each element set to the negation of the corresponding element of v

template<class T>
Vec3 operator/ const Vec3< T > &  v,
const Matrix4f m
[friend]
 

Calculate the product of a vector and a matrix.

Returns:
The vector formed by calculating the matrix product of v and the top-left three by three matrix of the inverse of m (i.e. the part of the matrix which encodes rotations) and then adding the vector formed by the first three elements of the fourth row of the matrix (i.e. the part of the matrix encoding translations).
See also:
Vec3::inverseTransform

template<class T>
Vec3 operator/ s,
const Vec3< T > &  v
[friend]
 

Calculate the elementwise quotient of a vector and a scalar.

Returns:
A new vector where each element is set to the quotient of s and the corresponding element of v

template<class T>
Vec3 operator/ const Vec3< T > &  v,
s
[friend]
 

Calculate a scalar quotient of a vector.

Returns:
A new vector where each element is set to the quotient of the corresponding element of v and s

template<class T>
Vec3 operator/ const Vec3< T > &  v1,
const Vec3< T > &  v2
[friend]
 

Calculate the elementwise quotient of two vectors.

Returns:
A new vector where each element is set to the quotient of the corresponding elements of v and s

template<class T>
bool operator< const Vec3< T > &  v1,
const Vec3< T > &  v2
[friend]
 

Compare two vectors.

This operator performs elementwise comparison of the two vectors. Each element is compared in turn, starting with the first element. If the element of v1 is less than the corresponding element of v2, true is returned, if greater, false is returned, otherwise the next element in turn is compared.

Return values:
true if the value of v1 is less than v2
false otherwise

template<class T>
bool operator<= const Vec3< T > &  v1,
const Vec3< T > &  v2
[friend]
 

Compare two vectors.

Return values:
true if the value of v1 is less than or equal to v2
false otherwise

template<class T>
bool operator== const Vec3< T > &  v1,
const Vec3< T > &  v2
[friend]
 

Compare two vectors.

Return values:
true if the two vectors are equal
false otherwise

template<class T>
Vec3 operator^ const Vec3< T > &  v1,
const Vec3< T > &  v2
[friend]
 

Deprecated:
Calculate the cross (or outer) product of two vectors
Returns:
A vector which is normal to both v1 and v2, scaled by the product of the lengths of both v1 and v2 and the sine of the angle between them.

template<class T>
Vec3 reflect const Vec3< T > &  n,
const Vec3< T > &  i
[friend]
 

Calculate a reflection vector.

Returns:
The vector formed by reflecting the vector i with the plane normal to n.

template<class T>
Vec3 refract const Vec3< T > &  n,
const Vec3< T > &  i,
indexRatio
[friend]
 

Calculate a refraction vector.

Returns:
The vector formed by refracting the vector i with the plane normal to n, assuming that the ratio of the refractive indices of the materials on the two sides of the plane is indexRatio.

Return to QSDK documentation Contents page. Contact details for support, information and fault-reporting.
Qube Software Limited © 2000-2004