Main Page   Modules   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

Generators: make( ... ), set( ... ).

Make get and set functions for all math types in gmtl. More...

Generic Generators (any type)

template<typename TARGET_TYPE, typename SOURCE_TYPE> TARGET_TYPE make (const SOURCE_TYPE &src, Type2Type< TARGET_TYPE > t=Type2Type< TARGET_TYPE >())
 Construct an object from another object of a different type. More...

template<typename ROTATION_TYPE, typename SOURCE_TYPE> ROTATION_TYPE makeRot (const SOURCE_TYPE &coord, Type2Type< ROTATION_TYPE > t=Type2Type< ROTATION_TYPE >())
 Create a rotation datatype from another rotation datatype. More...

template<typename ROTATION_TYPE> ROTATION_TYPE makeDirCos (const Vec< typename ROTATION_TYPE::DataType, 3 > &xDestAxis, const Vec< typename ROTATION_TYPE::DataType, 3 > &yDestAxis, const Vec< typename ROTATION_TYPE::DataType, 3 > &zDestAxis, const Vec< typename ROTATION_TYPE::DataType, 3 > &xSrcAxis=Vec< typename ROTATION_TYPE::DataType, 3 >(1, 0, 0), const Vec< typename ROTATION_TYPE::DataType, 3 > &ySrcAxis=Vec< typename ROTATION_TYPE::DataType, 3 >(0, 1, 0), const Vec< typename ROTATION_TYPE::DataType, 3 > &zSrcAxis=Vec< typename ROTATION_TYPE::DataType, 3 >(0, 0, 1), Type2Type< ROTATION_TYPE > t=Type2Type< ROTATION_TYPE >())
 Create a rotation matrix or quaternion (or any other rotation data type) using direction cosines. More...

template<typename TRANS_TYPE, typename SRC_TYPE> TRANS_TYPE makeTrans (const SRC_TYPE &arg, Type2Type< TRANS_TYPE > t=Type2Type< TRANS_TYPE >())
 Make a translation datatype from another translation datatype. More...

template<typename ROTATION_TYPE> ROTATION_TYPE makeRot (const Vec< typename ROTATION_TYPE::DataType, 3 > &from, const Vec< typename ROTATION_TYPE::DataType, 3 > &to)
 Create a rotation datatype that will xform first vector to the second. More...

template<typename DEST_TYPE, typename DATA_TYPE> DEST_TYPE & setRot (DEST_TYPE &result, const Vec< DATA_TYPE, 3 > &from, const Vec< DATA_TYPE, 3 > &to)
 set a rotation datatype that will xform first vector to the second. More...


Vec Generators

template<typename DATA_TYPE> Vec< DATA_TYPE, 3 > makeVec (const Quat< DATA_TYPE > &quat)
 create a vector from the vector component of a quaternion. More...

template<typename DATA_TYPE, unsigned SIZE> Vec< DATA_TYPE, SIZE > makeNormal (Vec< DATA_TYPE, SIZE > vec)
 create a normalized vector from the given vector. More...

template<typename VEC_TYPE, typename DATA_TYPE, unsigned ROWS, unsigned COLS> VEC_TYPE & setTrans (VEC_TYPE &result, const Matrix< DATA_TYPE, ROWS, COLS > &arg)
 Set vector using translation portion of the matrix. More...


Quat Generators

template<typename DATA_TYPE> Quat< DATA_TYPE > & setPure (Quat< DATA_TYPE > &quat, const Vec< DATA_TYPE, 3 > &vec)
 Set pure quaternion. More...

template<typename DATA_TYPE> Quat< DATA_TYPE > makePure (const Vec< DATA_TYPE, 3 > &vec)
 create a pure quaternion. More...

template<typename DATA_TYPE> Quat< DATA_TYPE > makeNormal (const Quat< DATA_TYPE > &quat)
 Normalize a quaternion. More...

template<typename DATA_TYPE> Quat< DATA_TYPE > makeConj (const Quat< DATA_TYPE > &quat)
 quaternion complex conjugate. More...

template<typename DATA_TYPE> Quat< DATA_TYPE > makeInvert (const Quat< DATA_TYPE > &quat)
 create quaternion from the inverse of another quaternion. More...

template<typename DATA_TYPE> Quat< DATA_TYPE > & set (Quat< DATA_TYPE > &result, const AxisAngle< DATA_TYPE > &axisAngle)
 Convert an AxisAngle to a Quat. More...

template<typename DATA_TYPE> Quat< DATA_TYPE > & setRot (Quat< DATA_TYPE > &result, const AxisAngle< DATA_TYPE > &axisAngle)
 Redundant duplication of the set(quat,axisangle) function, this is provided only for template compatibility. More...

template<typename DATA_TYPE, typename ROT_ORDER> Quat< DATA_TYPE > & set (Quat< DATA_TYPE > &result, const EulerAngle< DATA_TYPE, ROT_ORDER > &euler)
 Convert an EulerAngle rotation to a Quaternion rotation. More...

template<typename DATA_TYPE, typename ROT_ORDER> Quat< DATA_TYPE > & setRot (Quat< DATA_TYPE > &result, const EulerAngle< DATA_TYPE, ROT_ORDER > &euler)
 Redundant duplication of the set(quat,eulerangle) function, this is provided only for template compatibility. More...

template<typename DATA_TYPE, unsigned ROWS, unsigned COLS> Quat< DATA_TYPE > & set (Quat< DATA_TYPE > &quat, const Matrix< DATA_TYPE, ROWS, COLS > &mat)
 Convert a Matrix to a Quat. More...

template<typename DATA_TYPE, unsigned ROWS, unsigned COLS> Quat< DATA_TYPE > & setRot (Quat< DATA_TYPE > &result, const Matrix< DATA_TYPE, ROWS, COLS > &mat)
 Redundant duplication of the set(quat,mat) function, this is provided only for template compatibility. More...


AxisAngle Generators

template<typename DATA_TYPE> AxisAngle< DATA_TYPE > & set (AxisAngle< DATA_TYPE > &axisAngle, Quat< DATA_TYPE > quat)
 Convert a rotation quaternion to an AxisAngle. More...

template<typename DATA_TYPE> AxisAngle< DATA_TYPE > & setRot (AxisAngle< DATA_TYPE > &result, Quat< DATA_TYPE > quat)
 Redundant duplication of the set(axisangle,quat) function, this is provided only for template compatibility. More...

template<typename DATA_TYPE> AxisAngle< DATA_TYPE > makeNormal (const AxisAngle< DATA_TYPE > &a)
 make the axis of an AxisAngle normalized. More...


EulerAngle Generators

template<typename DATA_TYPE, unsigned ROWS, unsigned COLS, typename ROT_ORDER> EulerAngle< DATA_TYPE, ROT_ORDER > & set (EulerAngle< DATA_TYPE, ROT_ORDER > &euler, const Matrix< DATA_TYPE, ROWS, COLS > &mat)
 Convert Matrix to EulerAngle. More...

template<typename DATA_TYPE, unsigned ROWS, unsigned COLS, typename ROT_ORDER> EulerAngle< DATA_TYPE, ROT_ORDER > & setRot (EulerAngle< DATA_TYPE, ROT_ORDER > &result, const Matrix< DATA_TYPE, ROWS, COLS > &mat)
 Redundant duplication of the set(eulerangle,quat) function, this is provided only for template compatibility. More...


Matrix Generators

template<typename DATA_TYPE, unsigned ROWS, unsigned COLS, unsigned SIZE> Matrix< DATA_TYPE, ROWS, COLS > & setTrans (Matrix< DATA_TYPE, ROWS, COLS > &result, const Vec< DATA_TYPE, SIZE > &trans)
 Set matrix translation from vec. More...

template<typename DATA_TYPE, unsigned ROWS, unsigned COLS, unsigned SIZE> Matrix< DATA_TYPE, ROWS, COLS > & setScale (Matrix< DATA_TYPE, ROWS, COLS > &result, const Vec< DATA_TYPE, SIZE > &scale)
 Set the scale part of a matrix. More...

template<typename MATRIX_TYPE, unsigned SIZE> MATRIX_TYPE makeScale (const Vec< typename MATRIX_TYPE::DataType, SIZE > &scale, Type2Type< MATRIX_TYPE > t=Type2Type< MATRIX_TYPE >())
 Create a scale matrix. More...

template<typename DATA_TYPE, unsigned ROWS, unsigned COLS> Matrix< DATA_TYPE, ROWS, COLS > & setScale (Matrix< DATA_TYPE, ROWS, COLS > &result, const DATA_TYPE scale)
 Sets the scale part of a matrix. More...

template<typename MATRIX_TYPE> MATRIX_TYPE makeScale (const typename MATRIX_TYPE::DataType scale, Type2Type< MATRIX_TYPE > t=Type2Type< MATRIX_TYPE >())
 Create a scale matrix. More...

template<typename DATA_TYPE, unsigned ROWS, unsigned COLS> Matrix< DATA_TYPE, ROWS, COLS > & setRot (Matrix< DATA_TYPE, ROWS, COLS > &result, const AxisAngle< DATA_TYPE > &axisAngle)
 Set the rotation portion of a rotation matrix using an axis and an angle (in radians). More...

template<typename DATA_TYPE, unsigned ROWS, unsigned COLS> Matrix< DATA_TYPE, ROWS, COLS > & set (Matrix< DATA_TYPE, ROWS, COLS > &result, const AxisAngle< DATA_TYPE > &axisAngle)
 Convert an AxisAngle to a rotation matrix. More...

template<typename DATA_TYPE, unsigned ROWS, unsigned COLS, typename ROT_ORDER> Matrix< DATA_TYPE, ROWS, COLS > & setRot (Matrix< DATA_TYPE, ROWS, COLS > &result, const EulerAngle< DATA_TYPE, ROT_ORDER > &euler)
 Set (only) the rotation part of a matrix using an EulerAngle (angles are in radians). More...

template<typename DATA_TYPE, unsigned ROWS, unsigned COLS, typename ROT_ORDER> Matrix< DATA_TYPE, ROWS, COLS > & set (Matrix< DATA_TYPE, ROWS, COLS > &result, const EulerAngle< DATA_TYPE, ROT_ORDER > &euler)
 Convert an EulerAngle to a rotation matrix. More...

template<typename DATA_TYPE, unsigned ROWS, unsigned COLS> DATA_TYPE makeYRot (const Matrix< DATA_TYPE, ROWS, COLS > &mat)
 Extracts the Y axis rotation information from the matrix. More...

template<typename DATA_TYPE, unsigned ROWS, unsigned COLS> DATA_TYPE makeXRot (const Matrix< DATA_TYPE, ROWS, COLS > &mat)
 Extracts the X-axis rotation information from the matrix. More...

template<typename DATA_TYPE, unsigned ROWS, unsigned COLS> DATA_TYPE makeZRot (const Matrix< DATA_TYPE, ROWS, COLS > &mat)
 Extracts the Z-axis rotation information from the matrix. More...

template<typename DATA_TYPE, unsigned ROWS, unsigned COLS> Matrix< DATA_TYPE, ROWS, COLS > & setDirCos (Matrix< DATA_TYPE, ROWS, COLS > &result, const Vec< DATA_TYPE, 3 > &xDestAxis, const Vec< DATA_TYPE, 3 > &yDestAxis, const Vec< DATA_TYPE, 3 > &zDestAxis, const Vec< DATA_TYPE, 3 > &xSrcAxis=Vec< DATA_TYPE, 3 >(1, 0, 0), const Vec< DATA_TYPE, 3 > &ySrcAxis=Vec< DATA_TYPE, 3 >(0, 1, 0), const Vec< DATA_TYPE, 3 > &zSrcAxis=Vec< DATA_TYPE, 3 >(0, 0, 1))
 create a rotation matrix that will rotate from SrcAxis to DestAxis. More...

template<typename DATA_TYPE, unsigned ROWS, unsigned COLS> Matrix< DATA_TYPE, ROWS, COLS > & setAxes (Matrix< DATA_TYPE, ROWS, COLS > &result, const Vec< DATA_TYPE, 3 > &xAxis, const Vec< DATA_TYPE, 3 > &yAxis, const Vec< DATA_TYPE, 3 > &zAxis)
 set the matrix given the raw coordinate axes. More...

template<typename ROTATION_TYPE> ROTATION_TYPE makeAxes (const Vec< typename ROTATION_TYPE::DataType, 3 > &xAxis, const Vec< typename ROTATION_TYPE::DataType, 3 > &yAxis, const Vec< typename ROTATION_TYPE::DataType, 3 > &zAxis, Type2Type< ROTATION_TYPE > t=Type2Type< ROTATION_TYPE >())
 set the matrix given the raw coordinate axes. More...

template<typename DATA_TYPE, unsigned ROWS, unsigned COLS> Matrix< DATA_TYPE, ROWS, COLS > makeTranspose (const Matrix< DATA_TYPE, ROWS, COLS > &m)
 create a matrix transposed from the source. More...

template<typename DATA_TYPE, unsigned ROWS, unsigned COLS> Matrix< DATA_TYPE, ROWS, COLS > makeInverse (const Matrix< DATA_TYPE, ROWS, COLS > &src)
 Creates a matrix that is the inverse of the given source matrix. More...

template<typename DATATYPE, typename POS_TYPE, typename ROT_TYPE, unsigned MATCOLS, unsigned MATROWS> Matrix< DATATYPE, MATROWS,
MATCOLS > & 
set (Matrix< DATATYPE, MATROWS, MATCOLS > &mat, const Coord< POS_TYPE, ROT_TYPE > &coord)
 Convert a Coord to a Matrix. More...

template<typename DATA_TYPE, unsigned ROWS, unsigned COLS> Matrix< DATA_TYPE, ROWS, COLS > & setRot (Matrix< DATA_TYPE, ROWS, COLS > &mat, const Quat< DATA_TYPE > &q)
 Set the rotation portion of a matrix (3x3) from a rotation quaternion. More...

template<typename DATA_TYPE, unsigned ROWS, unsigned COLS> Matrix< DATA_TYPE, ROWS, COLS > & set (Matrix< DATA_TYPE, ROWS, COLS > &mat, const Quat< DATA_TYPE > &q)
 Convert a Quat to a rotation Matrix. More...


Coord Generators

template<typename DATATYPE, typename POS_TYPE, typename ROT_TYPE, unsigned MATCOLS, unsigned MATROWS> Coord< POS_TYPE, ROT_TYPE > & set (Coord< POS_TYPE, ROT_TYPE > &eulercoord, const Matrix< DATATYPE, MATROWS, MATCOLS > &mat)
 convert Matrix to Coord. More...

template<typename DATATYPE, typename POS_TYPE, typename ROT_TYPE, unsigned MATCOLS, unsigned MATROWS> Coord< POS_TYPE, ROT_TYPE > & setRot (Coord< POS_TYPE, ROT_TYPE > &result, const Matrix< DATATYPE, MATROWS, MATCOLS > &mat)
 Redundant duplication of the set(coord,mat) function, this is provided only for template compatibility. More...


Detailed Description

Make get and set functions for all math types in gmtl.


Function Documentation

template<typename TARGET_TYPE, typename SOURCE_TYPE>
TARGET_TYPE make const SOURCE_TYPE &    src,
Type2Type< TARGET_TYPE >    t = Type2Type< TARGET_TYPE >()
[inline]
 

Construct an object from another object of a different type.

This allows us to automatically convert from any type to any other type.

Precondition:
must have a set() function defined that converts between the two types.
Parameters:
src  the object to use for creation
Returns:
a new object with values based on the src variable
See also:
OpenSGGenerate.h for an example

Definition at line 70 of file Generate.h.

00072    {
00073       gmtl::ignore_unused_variable_warning(t);
00074       TARGET_TYPE target;
00075       return gmtl::set( target, src );
00076    }

template<typename ROTATION_TYPE>
ROTATION_TYPE makeAxes const Vec< typename ROTATION_TYPE::DataType, 3 > &    xAxis,
const Vec< typename ROTATION_TYPE::DataType, 3 > &    yAxis,
const Vec< typename ROTATION_TYPE::DataType, 3 > &    zAxis,
Type2Type< ROTATION_TYPE >    t = Type2Type< ROTATION_TYPE >()
[inline]
 

set the matrix given the raw coordinate axes.

Postcondition:
this function only produces 3x3, 3x4, 4x3, and 4x4 matrices, and is undefined otherwise
these axes are copied direct to the 3x3 in the matrix

Definition at line 1036 of file Generate.h.

01040    {
01041       gmtl::ignore_unused_variable_warning(t);
01042       ROTATION_TYPE temporary;
01043       return setAxes( temporary, xAxis, yAxis, zAxis );
01044    }

template<typename DATA_TYPE>
Quat<DATA_TYPE> makeConj const Quat< DATA_TYPE > &    quat [inline]
 

quaternion complex conjugate.

Parameters:
quat  any quaternion object
Postcondition:
set result to the complex conjugate of result.
result'[x,y,z,w] == result[-x,-y,-z,w]
See also:
Quat

Definition at line 311 of file Generate.h.

00312    {
00313       Quat<DATA_TYPE> temporary( quat );
00314       return conj( temporary );
00315    }

template<typename ROTATION_TYPE>
ROTATION_TYPE makeDirCos const Vec< typename ROTATION_TYPE::DataType, 3 > &    xDestAxis,
const Vec< typename ROTATION_TYPE::DataType, 3 > &    yDestAxis,
const Vec< typename ROTATION_TYPE::DataType, 3 > &    zDestAxis,
const Vec< typename ROTATION_TYPE::DataType, 3 > &    xSrcAxis = Vec<typename ROTATION_TYPE::DataType, 3>(1,0,0),
const Vec< typename ROTATION_TYPE::DataType, 3 > &    ySrcAxis = Vec<typename ROTATION_TYPE::DataType, 3>(0,1,0),
const Vec< typename ROTATION_TYPE::DataType, 3 > &    zSrcAxis = Vec<typename ROTATION_TYPE::DataType, 3>(0,0,1),
Type2Type< ROTATION_TYPE >    t = Type2Type< ROTATION_TYPE >()
[inline]
 

Create a rotation matrix or quaternion (or any other rotation data type) using direction cosines.

If the two coordinate frames are labeled: SRC and TARGET, the matrix produced is: src_M_target this means that it will transform a point in TARGET to SRC but moves the base frame from SRC to TARGET.

Parameters:
DestAxis  required to specify
SrcAxis  optional to specify
Precondition:
specify 1 axis (3 vectors), or 2 axes (6 vectors).
Postcondition:
Creates a rotation from SrcAxis to DestAxis
this function only produces 3x3, 3x4, 4x3, and 4x4 matrices, and is undefined otherwise

Definition at line 103 of file Generate.h.

00110    {
00111       gmtl::ignore_unused_variable_warning(t);
00112       ROTATION_TYPE temporary;
00113       return setDirCos( temporary, xDestAxis, yDestAxis, zDestAxis, xSrcAxis, ySrcAxis, zSrcAxis );
00114    }

template<typename DATA_TYPE, unsigned ROWS, unsigned COLS>
Matrix<DATA_TYPE, ROWS, COLS> makeInverse const Matrix< DATA_TYPE, ROWS, COLS > &    src [inline]
 

Creates a matrix that is the inverse of the given source matrix.

Parameters:
src  the matrix to compute the inverse of
Returns:
the inverse of source

Definition at line 1065 of file Generate.h.

01066    {
01067       Matrix<DATA_TYPE, ROWS, COLS> result;
01068       return invert( result, src );
01069    }

template<typename DATA_TYPE>
Quat<DATA_TYPE> makeInvert const Quat< DATA_TYPE > &    quat [inline]
 

create quaternion from the inverse of another quaternion.

Parameters:
quat  any quaternion object
Returns:
a quaternion that is the multiplicative inverse of quat
See also:
Quat

Definition at line 323 of file Generate.h.

00324    {
00325       Quat<DATA_TYPE> temporary( quat );
00326       return invert( temporary );
00327    }

template<typename DATA_TYPE>
AxisAngle<DATA_TYPE> makeNormal const AxisAngle< DATA_TYPE > &    a
 

make the axis of an AxisAngle normalized.

Definition at line 565 of file Generate.h.

00566    {
00567       return AxisAngle<DATA_TYPE>( a.getAngle(), makeNormal( a.getAxis() ) );
00568    }

template<typename DATA_TYPE>
Quat<DATA_TYPE> makeNormal const Quat< DATA_TYPE > &    quat [inline]
 

Normalize a quaternion.

Parameters:
quat  a quaternion
Postcondition:
quat is normalized

Definition at line 298 of file Generate.h.

00299    {
00300       Quat<DATA_TYPE> temporary( quat );
00301       return normalize( temporary );
00302    }

template<typename DATA_TYPE, unsigned SIZE>
Vec<DATA_TYPE, SIZE> makeNormal Vec< DATA_TYPE, SIZE >    vec [inline]
 

create a normalized vector from the given vector.

Definition at line 216 of file Generate.h.

00217    {
00218       normalize( vec );
00219       return vec;
00220    }

template<typename DATA_TYPE>
Quat<DATA_TYPE> makePure const Vec< DATA_TYPE, 3 > &    vec [inline]
 

create a pure quaternion.

Precondition:
vec should be normalized
Parameters:
vec  a normalized vector representing an axis
Returns:
a quaternion with vec as its axis, and no rotation
Postcondition:
quat = [v,0] = [v0,v1,v2,0]

Definition at line 288 of file Generate.h.

00289    {
00290       return Quat<DATA_TYPE>( vec[0], vec[1], vec[2], 0 );
00291    }

template<typename ROTATION_TYPE>
ROTATION_TYPE makeRot const Vec< typename ROTATION_TYPE::DataType, 3 > &    from,
const Vec< typename ROTATION_TYPE::DataType, 3 > &    to
[inline]
 

Create a rotation datatype that will xform first vector to the second.

Precondition:
each vec needs to be normalized.
Postcondition:
This function returns a temporary object.

Definition at line 145 of file Generate.h.

00147    {
00148       ROTATION_TYPE temporary;
00149       return setRot( temporary, from, to );
00150    }

template<typename ROTATION_TYPE, typename SOURCE_TYPE>
ROTATION_TYPE makeRot const SOURCE_TYPE &    coord,
Type2Type< ROTATION_TYPE >    t = Type2Type< ROTATION_TYPE >()
[inline]
 

Create a rotation datatype from another rotation datatype.

Postcondition:
converts the source rotation to a to another type (usually Matrix, Quat, Euler, AxisAngle),
returns a temporary object.

Definition at line 83 of file Generate.h.

00085    {
00086       gmtl::ignore_unused_variable_warning(t);
00087       ROTATION_TYPE temporary;
00088       return gmtl::set( temporary, coord );
00089    }

template<typename MATRIX_TYPE>
MATRIX_TYPE makeScale const typename MATRIX_TYPE::DataType    scale,
Type2Type< MATRIX_TYPE >    t = Type2Type< MATRIX_TYPE >()
[inline]
 

Create a scale matrix.

Definition at line 756 of file Generate.h.

00758    {
00759       gmtl::ignore_unused_variable_warning(t);
00760       MATRIX_TYPE temporary;
00761       return setScale( temporary, scale );
00762    }

template<typename MATRIX_TYPE, unsigned SIZE>
MATRIX_TYPE makeScale const Vec< typename MATRIX_TYPE::DataType, SIZE > &    scale,
Type2Type< MATRIX_TYPE >    t = Type2Type< MATRIX_TYPE >()
[inline]
 

Create a scale matrix.

Definition at line 733 of file Generate.h.

00735    {
00736       gmtl::ignore_unused_variable_warning(t);
00737       MATRIX_TYPE temporary;
00738       return setScale( temporary, scale );
00739    }

template<typename TRANS_TYPE, typename SRC_TYPE>
TRANS_TYPE makeTrans const SRC_TYPE &    arg,
Type2Type< TRANS_TYPE >    t = Type2Type< TRANS_TYPE >()
[inline]
 

Make a translation datatype from another translation datatype.

Typically this is from Matrix to Vec or Vec to Matrix. This function reads only translation information from the src datatype.

Parameters:
arg  the matrix to extract the translation from
Precondition:
if making an n x n matrix, then for
  • vector is homogeneous: SIZE of vector needs to equal number of Matrix ROWS - 1
  • vector has scale component: SIZE of vector needs to equal number of Matrix ROWS
    if making an n x n+1 matrix, then for
  • vector is homogeneous: SIZE of vector needs to equal number of Matrix ROWS
  • vector has scale component: SIZE of vector needs to equal number of Matrix ROWS + 1
Postcondition:
if preconditions are not met, then function is undefined (will not compile)

Definition at line 132 of file Generate.h.

00134    {
00135       gmtl::ignore_unused_variable_warning(t);
00136       TRANS_TYPE temporary;
00137       return setTrans( temporary, arg );
00138    }

template<typename DATA_TYPE, unsigned ROWS, unsigned COLS>
Matrix<DATA_TYPE, ROWS, COLS> makeTranspose const Matrix< DATA_TYPE, ROWS, COLS > &    m [inline]
 

create a matrix transposed from the source.

Postcondition:
returns the transpose of m
See also:
Quat

Definition at line 1051 of file Generate.h.

01052    {
01053       Matrix<DATA_TYPE, ROWS, COLS> temporary( m );
01054       return transpose( temporary );
01055    }

template<typename DATA_TYPE>
Vec<DATA_TYPE, 3> makeVec const Quat< DATA_TYPE > &    quat [inline]
 

create a vector from the vector component of a quaternion.

Returns:
a vector of the quaternion's axis. quat = [v,0] = [v0,v1,v2,0]

Definition at line 208 of file Generate.h.

00209    {
00210       return Vec<DATA_TYPE, 3>( quat[Xelt], quat[Yelt], quat[Zelt] );
00211    }

template<typename DATA_TYPE, unsigned ROWS, unsigned COLS>
DATA_TYPE makeXRot const Matrix< DATA_TYPE, ROWS, COLS > &    mat [inline]
 

Extracts the X-axis rotation information from the matrix.

Postcondition:
Returned value is from -PI to PI, where 0 is no rotation.

Definition at line 905 of file Generate.h.

00906    {
00907       const gmtl::Vec<DATA_TYPE, 3> forward_point(0.0f, 0.0f, -1.0f);   // -Z
00908       const gmtl::Vec<DATA_TYPE, 3> origin_point(0.0f, 0.0f, 0.0f);
00909       gmtl::Vec<DATA_TYPE, 3> end_point, start_point;
00910 
00911       gmtl::xform(end_point, mat, forward_point);
00912       gmtl::xform(start_point, mat, origin_point);
00913       gmtl::Vec<DATA_TYPE, 3> direction_vector = end_point - start_point;
00914 
00915       // Constrain the direction to YZ-plane only.
00916       direction_vector[0] = 0.0f;                  // Eliminate X value
00917       gmtl::normalize(direction_vector);
00918       DATA_TYPE x_rot = gmtl::Math::aCos(gmtl::dot(direction_vector,
00919                                                    forward_point));
00920 
00921       gmtl::Vec<DATA_TYPE, 3> which_side = gmtl::cross(forward_point,
00922                                                        direction_vector);
00923 
00924       // If direction vector to "bottom" (negative) side of forward
00925       if ( which_side[0] < 0.0f )
00926       {
00927          x_rot = -x_rot;
00928       }
00929 
00930       return x_rot;
00931    }

template<typename DATA_TYPE, unsigned ROWS, unsigned COLS>
DATA_TYPE makeYRot const Matrix< DATA_TYPE, ROWS, COLS > &    mat [inline]
 

Extracts the Y axis rotation information from the matrix.

Postcondition:
Returned value is from -PI to PI, where 0 is none.

Definition at line 872 of file Generate.h.

00873    {
00874       const gmtl::Vec<DATA_TYPE, 3> forward_point(0.0f, 0.0f, -1.0f);   // -Z
00875       const gmtl::Vec<DATA_TYPE, 3> origin_point(0.0f, 0.0f, 0.0f);
00876       gmtl::Vec<DATA_TYPE, 3> end_point, start_point;
00877 
00878       gmtl::xform(end_point, mat, forward_point);
00879       gmtl::xform(start_point, mat, origin_point);
00880       gmtl::Vec<DATA_TYPE, 3> direction_vector = end_point - start_point;
00881 
00882       // Constrain the direction to XZ-plane only.
00883       direction_vector[1] = 0.0f;                  // Eliminate Y value
00884       gmtl::normalize(direction_vector);
00885       DATA_TYPE y_rot = gmtl::Math::aCos(gmtl::dot(direction_vector,
00886                                                    forward_point));
00887 
00888       gmtl::Vec<DATA_TYPE, 3> which_side = gmtl::cross(forward_point,
00889                                                        direction_vector);
00890 
00891       // If direction vector to "right" (negative) side of forward
00892       if ( which_side[1] < 0.0f )
00893       {
00894          y_rot = -y_rot;
00895       }
00896 
00897       return y_rot;
00898    }

template<typename DATA_TYPE, unsigned ROWS, unsigned COLS>
DATA_TYPE makeZRot const Matrix< DATA_TYPE, ROWS, COLS > &    mat [inline]
 

Extracts the Z-axis rotation information from the matrix.

Postcondition:
Returned value is from -PI to PI, where 0 is no rotation.

Definition at line 938 of file Generate.h.

00939    {
00940       const gmtl::Vec<DATA_TYPE, 3> forward_point(0.0f, 0.0f, -1.0f);   // -Z
00941       const gmtl::Vec<DATA_TYPE, 3> origin_point(0.0f, 0.0f, 0.0f);
00942       gmtl::Vec<DATA_TYPE, 3> end_point, start_point;
00943 
00944       gmtl::xform(end_point, mat, forward_point);
00945       gmtl::xform(start_point, mat, origin_point);
00946       gmtl::Vec<DATA_TYPE, 3> direction_vector = end_point - start_point;
00947 
00948       // Constrain the direction to XY-plane only.
00949       direction_vector[2] = 0.0f;                  // Eliminate Z value
00950       gmtl::normalize(direction_vector);
00951       DATA_TYPE z_rot = gmtl::Math::aCos(gmtl::dot(direction_vector,
00952                                                    forward_point));
00953 
00954       gmtl::Vec<DATA_TYPE, 3> which_side = gmtl::cross(forward_point,
00955                                                        direction_vector);
00956 
00957       // If direction vector to "right" (negative) side of forward
00958       if ( which_side[2] < 0.0f )
00959       {
00960          z_rot = -z_rot;
00961       }
00962 
00963       return z_rot;
00964    }

template<typename DATA_TYPE, unsigned ROWS, unsigned COLS>
Matrix<DATA_TYPE, ROWS, COLS>& set Matrix< DATA_TYPE, ROWS, COLS > &    mat,
const Quat< DATA_TYPE > &    q
 

Convert a Quat to a rotation Matrix.

Precondition:
only 3x3, 3x4, 4x3, or 4x4 matrices are allowed, function is undefined otherwise.
Postcondition:
Matrix is entirely overwritten.
Todo:
Implement using setRot

Definition at line 1133 of file Generate.h.

01134    {
01135       setRot( mat, q );
01136 
01137       if (ROWS == 4)
01138       {
01139          mat( 3, 0 ) = DATA_TYPE(0.0);
01140          mat( 3, 1 ) = DATA_TYPE(0.0);
01141          mat( 3, 2 ) = DATA_TYPE(0.0);
01142       }
01143 
01144       if (COLS == 4)
01145       {
01146          mat( 0, 3 ) = DATA_TYPE(0.0);
01147          mat( 1, 3 ) = DATA_TYPE(0.0);
01148          mat( 2, 3 ) = DATA_TYPE(0.0);
01149       }
01150 
01151       if (ROWS == 4 && COLS == 4)
01152          mat( 3, 3 ) = DATA_TYPE(1.0);
01153 
01154       return mat;
01155    }

template<typename DATATYPE, typename POS_TYPE, typename ROT_TYPE, unsigned MATCOLS, unsigned MATROWS>
Matrix<DATATYPE, MATROWS, MATCOLS>& set Matrix< DATATYPE, MATROWS, MATCOLS > &    mat,
const Coord< POS_TYPE, ROT_TYPE > &    coord
[inline]
 

Convert a Coord to a Matrix.

See also:
Coord , Matrix

Definition at line 1076 of file Generate.h.

01078    {
01079       // set to ident first...
01080       gmtl::identity( mat );
01081 
01082       // set translation
01083       // @todo metaprogram this out for 3x3 and 2x2 matrices
01084       if (MATCOLS == 4)
01085       {
01086          setTrans( mat, coord.getPos() );// filtered (only sets the trans part).
01087       }
01088       setRot( mat, coord.getRot() ); // filtered (only sets the rot part).
01089       return mat;
01090    }

template<typename DATA_TYPE, unsigned ROWS, unsigned COLS, typename ROT_ORDER>
Matrix<DATA_TYPE, ROWS, COLS>& set Matrix< DATA_TYPE, ROWS, COLS > &    result,
const EulerAngle< DATA_TYPE, ROT_ORDER > &    euler
[inline]
 

Convert an EulerAngle to a rotation matrix.

Postcondition:
this function only writes to 3x3, 3x4, 4x3, and 4x4 matrices, and is undefined otherwise

Definition at line 861 of file Generate.h.

00862    {
00863       gmtl::identity( result );
00864       return setRot( result, euler );
00865    }

template<typename DATA_TYPE, unsigned ROWS, unsigned COLS>
Matrix<DATA_TYPE, ROWS, COLS>& set Matrix< DATA_TYPE, ROWS, COLS > &    result,
const AxisAngle< DATA_TYPE > &    axisAngle
[inline]
 

Convert an AxisAngle to a rotation matrix.

Postcondition:
this function only writes to 3x3, 3x4, 4x3, and 4x4 matrices, and is undefined otherwise
Precondition:
AxisAngle must be normalized (the axis part), results are undefined if not.

Definition at line 802 of file Generate.h.

00803    {
00804       gmtl::identity( result );
00805       return setRot( result, axisAngle );
00806    }

template<typename DATA_TYPE, unsigned ROWS, unsigned COLS>
Quat<DATA_TYPE>& set Quat< DATA_TYPE > &    quat,
const Matrix< DATA_TYPE, ROWS, COLS > &    mat
[inline]
 

Convert a Matrix to a Quat.

Sets the rotation quaternion using the given matrix (3x3, 3x4, 4x3, or 4x4 are all valid sizes).

Definition at line 429 of file Generate.h.

00430    {
00431       gmtlASSERT( ((ROWS == 3 && COLS == 3) ||
00432                (ROWS == 3 && COLS == 4) ||
00433                (ROWS == 4 && COLS == 3) ||
00434                (ROWS == 4 && COLS == 4)) &&
00435                "pre conditions not met on set( quat, pos, mat ) which only sets a quaternion to the rotation part of a 3x3, 3x4, 4x3, or 4x4 matrix." );
00436 
00437       DATA_TYPE tr( mat( 0, 0 ) + mat( 1, 1 ) + mat( 2, 2 ) ), s( 0.0f );
00438 
00439       // If diagonal is positive
00440       if (tr > (DATA_TYPE)0.0)
00441       {
00442          s = Math::sqrt( tr + (DATA_TYPE)1.0 );
00443          quat[Welt] = s * (DATA_TYPE)0.5;
00444          s = DATA_TYPE(0.5) / s;
00445 
00446          quat[Xelt] = (mat( 2, 1 ) - mat( 1, 2 )) * s;
00447          quat[Yelt] = (mat( 0, 2 ) - mat( 2, 0 )) * s;
00448          quat[Zelt] = (mat( 1, 0 ) - mat( 0, 1 )) * s;
00449       }
00450 
00451       // when Diagonal is negative
00452       else
00453       {
00454          static const unsigned int nxt[3] = { 1, 2, 0 };
00455          unsigned int i( Xelt ), j, k;
00456 
00457          if (mat( 1, 1 ) > mat( 0, 0 ))
00458             i = 1;
00459 
00460          if (mat( 2, 2 ) > mat( i, i ))
00461             i = 2;
00462 
00463          j = nxt[i];
00464          k = nxt[j];
00465 
00466          s = Math::sqrt( (mat( i, i )-(mat( j, j )+mat( k, k ))) + (DATA_TYPE)1.0 );
00467 
00468          DATA_TYPE q[4];
00469          q[i] = s * (DATA_TYPE)0.5;
00470 
00471          if (s != (DATA_TYPE)0.0)
00472             s = DATA_TYPE(0.5) / s;
00473 
00474          q[3] = (mat( k, j ) - mat( j, k )) * s;
00475          q[j] = (mat( j, i ) + mat( i, j )) * s;
00476          q[k] = (mat( k, i ) + mat( i, k )) * s;
00477 
00478          quat[Xelt] = q[0];
00479          quat[Yelt] = q[1];
00480          quat[Zelt] = q[2];
00481          quat[Welt] = q[3];
00482       }
00483 
00484       return quat;
00485    }

template<typename DATA_TYPE, typename ROT_ORDER>
Quat<DATA_TYPE>& set Quat< DATA_TYPE > &    result,
const EulerAngle< DATA_TYPE, ROT_ORDER > &    euler
[inline]
 

Convert an EulerAngle rotation to a Quaternion rotation.

Sets a rotation quaternion using euler angles (each angle in radians).

Precondition:
pass in your angles in the same order as the RotationOrder you specify

Definition at line 365 of file Generate.h.

00366    {
00367       // this might be faster if put into the switch statement... (testme)
00368       const int& order = ROT_ORDER::ID;
00369       const DATA_TYPE xRot = (order == XYZ::ID) ? euler[0] : ((order == ZXY::ID) ? euler[1] : euler[2]);
00370       const DATA_TYPE yRot = (order == XYZ::ID) ? euler[1] : ((order == ZXY::ID) ? euler[2] : euler[1]);
00371       const DATA_TYPE zRot = (order == XYZ::ID) ? euler[2] : ((order == ZXY::ID) ? euler[0] : euler[0]);
00372 
00373       // this could be written better for each rotation order, but this is really general...
00374       Quat<DATA_TYPE> qx, qy, qz;
00375 
00376       // precompute half angles
00377       DATA_TYPE xOver2 = xRot * (DATA_TYPE)0.5;
00378       DATA_TYPE yOver2 = yRot * (DATA_TYPE)0.5;
00379       DATA_TYPE zOver2 = zRot * (DATA_TYPE)0.5;
00380 
00381       // set the pitch quat
00382       qx[Xelt] = Math::sin( xOver2 );
00383       qx[Yelt] = (DATA_TYPE)0.0;
00384       qx[Zelt] = (DATA_TYPE)0.0;
00385       qx[Welt] = Math::cos( xOver2 );
00386 
00387       // set the yaw quat
00388       qy[Xelt] = (DATA_TYPE)0.0;
00389       qy[Yelt] = Math::sin( yOver2 );
00390       qy[Zelt] = (DATA_TYPE)0.0;
00391       qy[Welt] = Math::cos( yOver2 );
00392 
00393       // set the roll quat
00394       qz[Xelt] = (DATA_TYPE)0.0;
00395       qz[Yelt] = (DATA_TYPE)0.0;
00396       qz[Zelt] = Math::sin( zOver2 );
00397       qz[Welt] = Math::cos( zOver2 );
00398 
00399       // compose the three in pyr order...
00400       switch (order)
00401       {
00402       case XYZ::ID: result = qx * qy * qz; break;
00403       case ZYX::ID: result = qz * qy * qx; break;
00404       case ZXY::ID: result = qz * qx * qy; break;
00405       default:
00406          gmtlASSERT( false && "unknown rotation order passed to setRot" );
00407          break;
00408       }
00409 
00410       // ensure the quaternion is normalized
00411       normalize( result );
00412       return result;
00413    }

template<typename DATA_TYPE>
Quat<DATA_TYPE>& set Quat< DATA_TYPE > &    result,
const AxisAngle< DATA_TYPE > &    axisAngle
[inline]
 

Convert an AxisAngle to a Quat.

sets a rotation quaternion from an angle and an axis.

Precondition:
AxisAngle::axis must be normalized to length == 1 prior to calling this.
Postcondition:
q = [ cos(rad/2), sin(rad/2) * [x,y,z] ]

Definition at line 334 of file Generate.h.

00335    {
00336       gmtlASSERT( (Math::isEqual( lengthSquared( axisAngle.getAxis() ), (DATA_TYPE)1.0, (DATA_TYPE)0.0001 )) &&
00337                    "you must pass in a normalized vector to setRot( quat, rad, vec )" );
00338 
00339       DATA_TYPE half_angle = axisAngle.getAngle() * (DATA_TYPE)0.5;
00340       DATA_TYPE sin_half_angle = Math::sin( half_angle );
00341 
00342       result[Welt] = Math::cos( half_angle );
00343       result[Xelt] = sin_half_angle * axisAngle.getAxis()[0];
00344       result[Yelt] = sin_half_angle * axisAngle.getAxis()[1];
00345       result[Zelt] = sin_half_angle * axisAngle.getAxis()[2];
00346 
00347       // should automagically be normalized (unit magnitude) now...
00348       return result;
00349    }

template<typename DATATYPE, typename POS_TYPE, typename ROT_TYPE, unsigned MATCOLS, unsigned MATROWS>
Coord<POS_TYPE, ROT_TYPE>& set Coord< POS_TYPE, ROT_TYPE > &    eulercoord,
const Matrix< DATATYPE, MATROWS, MATCOLS > &    mat
[inline]
 

convert Matrix to Coord.

Definition at line 1166 of file Generate.h.

Referenced by gmtl::AxisAngle::set.

01167    {
01168       gmtl::setTrans( eulercoord.pos(), mat );
01169       gmtl::set( eulercoord.rot(), mat );
01170       return eulercoord;
01171    }

template<typename DATA_TYPE, unsigned ROWS, unsigned COLS, typename ROT_ORDER>
EulerAngle<DATA_TYPE, ROT_ORDER>& set EulerAngle< DATA_TYPE, ROT_ORDER > &    euler,
const Matrix< DATA_TYPE, ROWS, COLS > &    mat
[inline]
 

Convert Matrix to EulerAngle.

Set the Euler Angle from the given rotation portion (3x3) of the matrix.

Parameters:
input  order, mat
output  param0, param1, param2
Precondition:
pass in your args in the same order as the RotationOrder you specify
Postcondition:
this function only reads 3x3, 3x4, 4x3, and 4x4 matrices, and is undefined otherwise NOTE: Angles are returned in radians (this is always true in GMTL).

Definition at line 587 of file Generate.h.

00589    {
00590       // @todo set this a compile time assert...
00591       gmtlASSERT( ROWS >= 3 && COLS >= 3 && ROWS <= 4 && COLS <= 4 &&
00592             "this is undefined for Matrix smaller than 3x3 or bigger than 4x4" );
00593 
00594       DATA_TYPE sx;
00595       DATA_TYPE cz;
00596 
00597       // @todo metaprogram this!
00598       const int& order = ROT_ORDER::ID;
00599       switch (order)
00600       {
00601       case XYZ::ID:
00602          {
00603             euler[2] = Math::aTan2( -mat(0,1), mat(0,0) );       // -(-cy*sz)/(cy*cz) - cy falls out
00604             euler[0] = Math::aTan2( -mat(1,2), mat(2,2) );       // -(sx*cy)/(cx*cy) - cy falls out
00605             cz = Math::cos( euler[2] );
00606             euler[1] = Math::aTan2( mat(0,2), mat(0,0) / cz );   // (sy)/((cy*cz)/cz)
00607          }
00608          break;
00609       case ZYX::ID:
00610          {
00611             euler[0] = Math::aTan2( mat(1,0), mat(0,0) );        // (cy*sz)/(cy*cz) - cy falls out
00612             euler[2] = Math::aTan2( mat(2,1), mat(2,2) );        // (sx*cy)/(cx*cy) - cy falls out
00613             sx = Math::sin( euler[2] );
00614             euler[1] = Math::aTan2( -mat(2,0), mat(2,1) / sx );  // -(-sy)/((sx*cy)/sx)
00615          }
00616          break;
00617       case ZXY::ID:
00618          {
00619             // Extract the rotation directly from the matrix
00620             DATA_TYPE x_angle;
00621             DATA_TYPE y_angle;
00622             DATA_TYPE z_angle;
00623             DATA_TYPE cos_y, sin_y;
00624             DATA_TYPE cos_x, sin_x;
00625             DATA_TYPE cos_z, sin_z;
00626 
00627             sin_x = mat(2,1);
00628             x_angle = Math::aSin( sin_x );     // Get x angle
00629             cos_x = Math::cos( x_angle );
00630 
00631             // Check if cos_x = Zero
00632             if (cos_x != 0.0f)     // ASSERT: cos_x != 0
00633             {
00634                   // Get y Angle
00635                cos_y = mat(2,2) / cos_x;
00636                sin_y = -mat(2,0) / cos_x;
00637                y_angle = Math::aTan2( cos_y, sin_y );
00638 
00639                   // Get z Angle
00640                cos_z = mat(1,1) / cos_x;
00641                sin_z = -mat(0,1) / cos_x;
00642                z_angle = Math::aTan2( cos_z, sin_z );
00643             }
00644             else
00645             {
00646                // Arbitrarily set z_angle = 0
00647                z_angle = 0;
00648 
00649                   // Get y Angle
00650                cos_y = mat(0,0);
00651                sin_y = mat(1,0);
00652                y_angle = Math::aTan2( cos_y, sin_y );
00653             }
00654 
00655             euler[1] = x_angle;
00656             euler[2] = y_angle;
00657             euler[0] = z_angle;
00658          }
00659          break;
00660       default:
00661          gmtlASSERT( false && "unknown rotation order passed to setRot" );
00662          break;
00663       }
00664       return euler;
00665    }

template<typename DATA_TYPE>
AxisAngle<DATA_TYPE>& set AxisAngle< DATA_TYPE > &    axisAngle,
Quat< DATA_TYPE >    quat
[inline]
 

Convert a rotation quaternion to an AxisAngle.

Postcondition:
returns an angle in radians, and a normalized axis equivilent to the quaternion's rotation.
returns rad and xyz such that
  • rad = acos( w ) * 2.0
  • vec = v / (asin( w ) * 2.0) [where v is the xyz or vector component of the quat]
axisAngle = quat;

Definition at line 513 of file Generate.h.

00514    {
00515       // set sure we don't get a NaN result from acos...
00516       if (Math::abs( quat[Welt] ) > (DATA_TYPE)1.0)
00517       {
00518          gmtl::normalize( quat );
00519       }
00520       gmtlASSERT( Math::abs( quat[Welt] ) <= (DATA_TYPE)1.0 && "acos returns NaN when quat[Welt] > 1, try normalizing your quat." );
00521 
00522       // [acos( w ) * 2.0, v / (asin( w ) * 2.0)]
00523 
00524       // set the angle - aCos is mathematically defined to be between 0 and PI
00525       DATA_TYPE rad = Math::aCos( quat[Welt] ) * (DATA_TYPE)2.0;
00526       axisAngle.setAngle( rad );
00527 
00528       // set the axis: (use sin(rad) instead of asin(w))
00529       DATA_TYPE sin_half_angle = Math::sin( rad * (DATA_TYPE)0.5 );
00530       if (sin_half_angle >= (DATA_TYPE)0.0001) // because (PI >= rad >= 0)
00531       {
00532          DATA_TYPE sin_half_angle_inv = DATA_TYPE(1.0) / sin_half_angle;
00533          Vec<DATA_TYPE, 3> axis( quat[Xelt] * sin_half_angle_inv,
00534                                  quat[Yelt] * sin_half_angle_inv,
00535                                  quat[Zelt] * sin_half_angle_inv );
00536          normalize( axis );
00537          axisAngle.setAxis( axis );
00538       }
00539 
00540       // avoid NAN
00541       else
00542       {
00543          // one of the terms should be a 1,
00544          // so we can maintain unit-ness
00545          // in case w is 0 (which here w is 0)
00546          axisAngle.setAxis( gmtl::Vec<DATA_TYPE, 3>(
00547                              DATA_TYPE( 1.0 ) /*- gmtl::Math::abs( quat[Welt] )*/,
00548                             (DATA_TYPE)0.0,
00549                             (DATA_TYPE)0.0 ) );
00550       }
00551       return axisAngle;
00552    }

template<typename DATA_TYPE, unsigned ROWS, unsigned COLS>
Matrix<DATA_TYPE, ROWS, COLS>& setAxes Matrix< DATA_TYPE, ROWS, COLS > &    result,
const Vec< DATA_TYPE, 3 > &    xAxis,
const Vec< DATA_TYPE, 3 > &    yAxis,
const Vec< DATA_TYPE, 3 > &    zAxis
[inline]
 

set the matrix given the raw coordinate axes.

Postcondition:
this function only produces 3x3, 3x4, 4x3, and 4x4 matrices, and is undefined otherwise
these axes are copied direct to the 3x3 in the matrix

Definition at line 1008 of file Generate.h.

01012    {
01013       // @todo set this a compile time assert...
01014       gmtlASSERT( ROWS >= 3 && COLS >= 3 && ROWS <= 4 && COLS <= 4 && "this is undefined for Matrix smaller than 3x3 or bigger than 4x4" );
01015 
01016       result( 0, 0 ) = xAxis[0];
01017       result( 1, 0 ) = xAxis[1];
01018       result( 2, 0 ) = xAxis[2];
01019 
01020       result( 0, 1 ) = yAxis[0];
01021       result( 1, 1 ) = yAxis[1];
01022       result( 2, 1 ) = yAxis[2];
01023 
01024       result( 0, 2 ) = zAxis[0];
01025       result( 1, 2 ) = zAxis[1];
01026       result( 2, 2 ) = zAxis[2];
01027 
01028       return result;
01029    }

template<typename DATA_TYPE, unsigned ROWS, unsigned COLS>
Matrix<DATA_TYPE, ROWS, COLS>& setDirCos Matrix< DATA_TYPE, ROWS, COLS > &    result,
const Vec< DATA_TYPE, 3 > &    xDestAxis,
const Vec< DATA_TYPE, 3 > &    yDestAxis,
const Vec< DATA_TYPE, 3 > &    zDestAxis,
const Vec< DATA_TYPE, 3 > &    xSrcAxis = Vec<DATA_TYPE, 3>(1,0,0),
const Vec< DATA_TYPE, 3 > &    ySrcAxis = Vec<DATA_TYPE, 3>(0,1,0),
const Vec< DATA_TYPE, 3 > &    zSrcAxis = Vec<DATA_TYPE, 3>(0,0,1)
[inline]
 

create a rotation matrix that will rotate from SrcAxis to DestAxis.

xSrcAxis, ySrcAxis, zSrcAxis is the base rotation to go from and defaults to xSrcAxis(1,0,0), ySrcAxis(0,1,0), zSrcAxis(0,0,1) if you only pass in 3 axes.

If the two coordinate frames are labeled: SRC and TARGET, the matrix produced is: src_M_target this means that it will transform a point in TARGET to SRC but moves the base frame from SRC to TARGET.

Precondition:
pass in 3 axes, and setDirCos will give you the rotation from MATRIX_IDENTITY to DestAxis
pass in 6 axes, and setDirCos will give you the rotation from your 3-axis rotation to your second 3-axis rotation
Postcondition:
this function only produces 3x3, 3x4, 4x3, and 4x4 matrices

Definition at line 977 of file Generate.h.

00983    {
00984       // @todo set this a compile time assert...
00985       gmtlASSERT( ROWS >= 3 && COLS >= 3 && ROWS <= 4 && COLS <= 4 && "this is undefined for Matrix smaller than 3x3 or bigger than 4x4" );
00986 
00987       DATA_TYPE Xa, Xb, Xc;    // Direction cosines of the secondary x-axis
00988       DATA_TYPE Ya, Yb, Yc;    // Direction cosines of the secondary y-axis
00989       DATA_TYPE Za, Zb, Zc;    // Direction cosines of the secondary z-axis
00990 
00991       Xa = dot(xDestAxis, xSrcAxis);  Xb = dot(xDestAxis, ySrcAxis);  Xc = dot(xDestAxis, zSrcAxis);
00992       Ya = dot(yDestAxis, xSrcAxis);  Yb = dot(yDestAxis, ySrcAxis);  Yc = dot(yDestAxis, zSrcAxis);
00993       Za = dot(zDestAxis, xSrcAxis);  Zb = dot(zDestAxis, ySrcAxis);  Zc = dot(zDestAxis, zSrcAxis);
00994 
00995       // Set the matrix correctly
00996       result( 0, 0 ) = Xa; result( 0, 1 ) = Ya; result( 0, 2 ) = Za;
00997       result( 1, 0 ) = Xb; result( 1, 1 ) = Yb; result( 1, 2 ) = Zb;
00998       result( 2, 0 ) = Xc; result( 2, 1 ) = Yc; result( 2, 2 ) = Zc;
00999 
01000       return result;
01001    }

template<typename DATA_TYPE>
Quat<DATA_TYPE>& setPure Quat< DATA_TYPE > &    quat,
const Vec< DATA_TYPE, 3 > &    vec
[inline]
 

Set pure quaternion.

Precondition:
vec should be normalized
Parameters:
quat  any quaternion object
vec  a normalized vector representing an axis
Postcondition:
quat will have vec as its axis, and no rotation

Definition at line 275 of file Generate.h.

00276    {
00277       quat.set( vec[0], vec[1], vec[2], 0 );
00278       return quat;
00279    }

template<typename DATATYPE, typename POS_TYPE, typename ROT_TYPE, unsigned MATCOLS, unsigned MATROWS>
Coord<POS_TYPE, ROT_TYPE>& setRot Coord< POS_TYPE, ROT_TYPE > &    result,
const Matrix< DATATYPE, MATROWS, MATCOLS > &    mat
[inline]
 

Redundant duplication of the set(coord,mat) function, this is provided only for template compatibility.

unless you're writing template functions, you should use set(coord,mat) for clarity.

Definition at line 1177 of file Generate.h.

01178    {
01179       return gmtl::set( result, mat );
01180    }

template<typename DATA_TYPE, unsigned ROWS, unsigned COLS>
Matrix<DATA_TYPE, ROWS, COLS>& setRot Matrix< DATA_TYPE, ROWS, COLS > &    mat,
const Quat< DATA_TYPE > &    q
 

Set the rotation portion of a matrix (3x3) from a rotation quaternion.

Precondition:
only 3x3, 3x4, 4x3, or 4x4 matrices are allowed, function is undefined otherwise.

Definition at line 1096 of file Generate.h.

01097    {
01098       gmtlASSERT( ((ROWS == 3 && COLS == 3) ||
01099                (ROWS == 3 && COLS == 4) ||
01100                (ROWS == 4 && COLS == 3) ||
01101                (ROWS == 4 && COLS == 4)) &&
01102                "pre conditions not met on set( mat, quat ) which only sets a quaternion to the rotation part of a 3x3, 3x4, 4x3, or 4x4 matrix." );
01103 
01104       // From Watt & Watt
01105       DATA_TYPE wx, wy, wz, xx, yy, yz, xy, xz, zz, xs, ys, zs;
01106 
01107       xs = q[Xelt] + q[Xelt]; ys = q[Yelt] + q[Yelt]; zs = q[Zelt] + q[Zelt];
01108       xx = q[Xelt] * xs;      xy = q[Xelt] * ys;      xz = q[Xelt] * zs;
01109       yy = q[Yelt] * ys;      yz = q[Yelt] * zs;      zz = q[Zelt] * zs;
01110       wx = q[Welt] * xs;      wy = q[Welt] * ys;      wz = q[Welt] * zs;
01111 
01112       mat( 0, 0 ) = DATA_TYPE(1.0) - (yy + zz);
01113       mat( 1, 0 ) = xy + wz;
01114       mat( 2, 0 ) = xz - wy;
01115 
01116       mat( 0, 1 ) = xy - wz;
01117       mat( 1, 1 ) = DATA_TYPE(1.0) - (xx + zz);
01118       mat( 2, 1 ) = yz + wx;
01119 
01120       mat( 0, 2 ) = xz + wy;
01121       mat( 1, 2 ) = yz - wx;
01122       mat( 2, 2 ) = DATA_TYPE(1.0) - (xx + yy);
01123 
01124       return mat;
01125    }

template<typename DATA_TYPE, unsigned ROWS, unsigned COLS, typename ROT_ORDER>
Matrix<DATA_TYPE, ROWS, COLS>& setRot Matrix< DATA_TYPE, ROWS, COLS > &    result,
const EulerAngle< DATA_TYPE, ROT_ORDER > &    euler
[inline]
 

Set (only) the rotation part of a matrix using an EulerAngle (angles are in radians).

Postcondition:
this function only produces 3x3, 3x4, 4x3, and 4x4 matrices, and is undefined otherwise
See also:
EulerAngle for angle ordering (usually ordered based on RotationOrder)

Definition at line 813 of file Generate.h.

00814    {
00815       // @todo set this a compile time assert...
00816       gmtlASSERT( ROWS >= 3 && COLS >= 3 && ROWS <= 4 && COLS <= 4 && "this is undefined for Matrix smaller than 3x3 or bigger than 4x4" );
00817 
00818       // this might be faster if put into the switch statement... (testme)
00819       const int& order = ROT_ORDER::ID;
00820       const float xRot = (order == XYZ::ID) ? euler[0] : ((order == ZXY::ID) ? euler[1] : euler[2]);
00821       const float yRot = (order == XYZ::ID) ? euler[1] : ((order == ZXY::ID) ? euler[2] : euler[1]);
00822       const float zRot = (order == XYZ::ID) ? euler[2] : ((order == ZXY::ID) ? euler[0] : euler[0]);
00823 
00824       float sx = Math::sin( xRot );  float cx = Math::cos( xRot );
00825       float sy = Math::sin( yRot );  float cy = Math::cos( yRot );
00826       float sz = Math::sin( zRot );  float cz = Math::cos( zRot );
00827 
00828       // @todo metaprogram this!
00829       switch (order)
00830       {
00831       case XYZ::ID:
00832          // Derived by simply multiplying out the matrices by hand X * Y * Z
00833          result( 0, 0 ) = cy*cz;             result( 0, 1 ) = -cy*sz;            result( 0, 2 ) = sy;
00834          result( 1, 0 ) = sx*sy*cz + cx*sz;  result( 1, 1 ) = -sx*sy*sz + cx*cz; result( 1, 2 ) = -sx*cy;
00835          result( 2, 0 ) = -cx*sy*cz + sx*sz; result( 2, 1 ) = cx*sy*sz + sx*cz;  result( 2, 2 ) = cx*cy;
00836          break;
00837       case ZYX::ID:
00838          // Derived by simply multiplying out the matrices by hand Z * Y * Z
00839          result( 0, 0 ) = cy*cz; result( 0, 1 ) = -cx*sz + sx*sy*cz; result( 0, 2 ) = sx*sz + cx*sy*cz;
00840          result( 1, 0 ) = cy*sz; result( 1, 1 ) = cx*cz + sx*sy*sz;  result( 1, 2 ) = -sx*cz + cx*sy*sz;
00841          result( 2, 0 ) = -sy;   result( 2, 1 ) = sx*cy;             result( 2, 2 ) = cx*cy;
00842          break;
00843       case ZXY::ID:
00844          // Derived by simply multiplying out the matrices by hand Z * X * Y
00845          result( 0, 0 ) = cy*cz - sx*sy*sz; result( 0, 1 ) = -cx*sz; result( 0, 2 ) = sy*cz + sx*cy*sz;
00846          result( 1, 0 ) = cy*sz + sx*sy*cz; result( 1, 1 ) = cx*cz;  result( 1, 2 ) = sy*sz - sx*cy*cz;
00847          result( 2, 0 ) = -cx*sy;           result( 2, 1 ) = sx;     result( 2, 2 ) = cx*cy;
00848          break;
00849       default:
00850          gmtlASSERT( false && "unknown rotation order passed to setRot" );
00851          break;
00852       }
00853 
00854       return result;
00855    }

template<typename DATA_TYPE, unsigned ROWS, unsigned COLS>
Matrix<DATA_TYPE, ROWS, COLS>& setRot Matrix< DATA_TYPE, ROWS, COLS > &    result,
const AxisAngle< DATA_TYPE > &    axisAngle
[inline]
 

Set the rotation portion of a rotation matrix using an axis and an angle (in radians).

Only writes to the rotation matrix (3x3) defined by the rotation part of M

Postcondition:
this function only writes to 3x3, 3x4, 4x3, and 4x4 matrices, and is undefined otherwise
Precondition:
you must pass a normalized vector in for the axis, results are undefined if not.

Definition at line 772 of file Generate.h.

00773    {
00774       /* @todo set this a compile time assert... */
00775       gmtlASSERT( ROWS >= 3 && COLS >= 3 && ROWS <= 4 && COLS <= 4 &&
00776                      "this func is undefined for Matrix smaller than 3x3 or bigger than 4x4" );
00777       gmtlASSERT( Math::isEqual( lengthSquared( axisAngle.getAxis() ), (DATA_TYPE)1.0, (DATA_TYPE)0.001 ) &&
00778                      "you must pass in a normalized vector to setRot( mat, rad, vec )" );
00779 
00780       // GGI: pg 466
00781       DATA_TYPE s = Math::sin( axisAngle.getAngle() );
00782       DATA_TYPE c = Math::cos( axisAngle.getAngle() );
00783       DATA_TYPE t = DATA_TYPE( 1.0 ) - c;
00784       DATA_TYPE x = axisAngle.getAxis()[0];
00785       DATA_TYPE y = axisAngle.getAxis()[1];
00786       DATA_TYPE z = axisAngle.getAxis()[2];
00787 
00788       /* From: Introduction to robotic.  Craig.  Pg. 52 */
00789       result( 0, 0 ) = (t*x*x)+c;     result( 0, 1 ) = (t*x*y)-(s*z); result( 0, 2 ) = (t*x*z)+(s*y);
00790       result( 1, 0 ) = (t*x*y)+(s*z); result( 1, 1 ) = (t*y*y)+c;     result( 1, 2 ) = (t*y*z)-(s*x);
00791       result( 2, 0 ) = (t*x*z)-(s*y); result( 2, 1 ) = (t*y*z)+(s*x); result( 2, 2 ) = (t*z*z)+c;
00792 
00793       return result;
00794    }

template<typename DATA_TYPE, unsigned ROWS, unsigned COLS, typename ROT_ORDER>
EulerAngle<DATA_TYPE, ROT_ORDER>& setRot EulerAngle< DATA_TYPE, ROT_ORDER > &    result,
const Matrix< DATA_TYPE, ROWS, COLS > &    mat
[inline]
 

Redundant duplication of the set(eulerangle,quat) function, this is provided only for template compatibility.

unless you're writing template functions, you should use set(eulerangle,quat) for clarity.

Definition at line 671 of file Generate.h.

00672    {
00673       return gmtl::set( result, mat );
00674    }

template<typename DATA_TYPE>
AxisAngle<DATA_TYPE>& setRot AxisAngle< DATA_TYPE > &    result,
Quat< DATA_TYPE >    quat
[inline]
 

Redundant duplication of the set(axisangle,quat) function, this is provided only for template compatibility.

unless you're writing template functions, you should use set(axisangle,quat) for clarity.

Definition at line 558 of file Generate.h.

00559    {
00560       return gmtl::set( result, quat );
00561    }

template<typename DATA_TYPE, unsigned ROWS, unsigned COLS>
Quat<DATA_TYPE>& setRot Quat< DATA_TYPE > &    result,
const Matrix< DATA_TYPE, ROWS, COLS > &    mat
[inline]
 

Redundant duplication of the set(quat,mat) function, this is provided only for template compatibility.

unless you're writing template functions, you should use set(quat,mat).

Definition at line 491 of file Generate.h.

00492    {
00493       return gmtl::set( result, mat );
00494    }

template<typename DATA_TYPE, typename ROT_ORDER>
Quat<DATA_TYPE>& setRot Quat< DATA_TYPE > &    result,
const EulerAngle< DATA_TYPE, ROT_ORDER > &    euler
[inline]
 

Redundant duplication of the set(quat,eulerangle) function, this is provided only for template compatibility.

unless you're writing template functions, you should use set(quat,eulerangle).

Definition at line 419 of file Generate.h.

00420    {
00421       return gmtl::set( result, euler );
00422    }

template<typename DATA_TYPE>
Quat<DATA_TYPE>& setRot Quat< DATA_TYPE > &    result,
const AxisAngle< DATA_TYPE > &    axisAngle
[inline]
 

Redundant duplication of the set(quat,axisangle) function, this is provided only for template compatibility.

unless you're writing template functions, you should use set(quat,axisangle).

Definition at line 355 of file Generate.h.

00356    {
00357       return gmtl::set( result, axisAngle );
00358    }

template<typename DEST_TYPE, typename DATA_TYPE>
DEST_TYPE& setRot DEST_TYPE &    result,
const Vec< DATA_TYPE, 3 > &    from,
const Vec< DATA_TYPE, 3 > &    to
[inline]
 

set a rotation datatype that will xform first vector to the second.

Precondition:
each vec needs to be normalized.
Postcondition:
generate rotation datatype that is the rotation between the vectors. @note: only sets the rotation component of result, if result is a matrix, only sets the 3x3.

Definition at line 158 of file Generate.h.

00159    {
00160       // @todo should assert that DEST_TYPE::DataType == DATA_TYPE
00161       const DATA_TYPE epsilon = (DATA_TYPE)0.00001;
00162 
00163       gmtlASSERT( gmtl::Math::isEqual( gmtl::length( from ), (DATA_TYPE)1.0, epsilon ) &&
00164                   gmtl::Math::isEqual( gmtl::length( to ), (DATA_TYPE)1.0, epsilon ) &&
00165                   "input params not normalized" );
00166 
00167       DATA_TYPE cosangle = dot( from, to );
00168 
00169       // if cosangle is close to 1, so the vectors are close to being coincident
00170       // Need to generate an angle of zero with any vector we like
00171       // We'll choose identity (no rotation)
00172       if ( Math::isEqual( cosangle, (DATA_TYPE)1.0, epsilon ) )
00173       {
00174          return result = DEST_TYPE();
00175       }
00176 
00177       // vectors are close to being opposite, so rotate one a little...
00178       else if ( Math::isEqual( cosangle, (DATA_TYPE)-1.0, epsilon ) )
00179       {
00180          Vec<DATA_TYPE, 3> to_rot( to[0] + (DATA_TYPE)0.3, to[1] - (DATA_TYPE)0.15, to[2] - (DATA_TYPE)0.15 ), axis;
00181          normalize( cross( axis, from, to_rot ) ); // setRot requires normalized vec
00182          DATA_TYPE angle = Math::aCos( cosangle );
00183          return setRot( result, gmtl::AxisAngle<DATA_TYPE>( angle, axis ) );
00184       }
00185 
00186       // This is the usual situation - take a cross-product of vec1 and vec2
00187       // and that is the axis around which to rotate.
00188       else
00189       {
00190          Vec<DATA_TYPE, 3> axis;
00191          normalize( cross( axis, from, to ) ); // setRot requires normalized vec
00192          DATA_TYPE angle = Math::aCos( cosangle );
00193          return setRot( result, gmtl::AxisAngle<DATA_TYPE>( angle, axis ) );
00194       }
00195    }

template<typename DATA_TYPE, unsigned ROWS, unsigned COLS>
Matrix<DATA_TYPE, ROWS, COLS>& setScale Matrix< DATA_TYPE, ROWS, COLS > &    result,
const DATA_TYPE    scale
[inline]
 

Sets the scale part of a matrix.

Definition at line 746 of file Generate.h.

00747    {
00748       for (unsigned x = 0; x < Math::Min( ROWS, COLS, Math::Max( ROWS, COLS ) - 1 ); ++x) // account for 2x4 or other weird sizes...
00749          result( x, x ) = scale;
00750       return result;
00751    }

template<typename DATA_TYPE, unsigned ROWS, unsigned COLS, unsigned SIZE>
Matrix<DATA_TYPE, ROWS, COLS>& setScale Matrix< DATA_TYPE, ROWS, COLS > &    result,
const Vec< DATA_TYPE, SIZE > &    scale
[inline]
 

Set the scale part of a matrix.

Definition at line 722 of file Generate.h.

00723    {
00724       gmtlASSERT( ((SIZE == (ROWS-1) && SIZE == (COLS-1)) || (SIZE == (ROWS-1) && SIZE == COLS) || (SIZE == (COLS-1) && SIZE == ROWS)) && "the scale params must fit within the matrix, check your sizes." );
00725       for (unsigned x = 0; x < SIZE; ++x)
00726          result( x, x ) = scale[x];
00727       return result;
00728    }

template<typename VEC_TYPE, typename DATA_TYPE, unsigned ROWS, unsigned COLS>
VEC_TYPE& setTrans VEC_TYPE &    result,
const Matrix< DATA_TYPE, ROWS, COLS > &    arg
[inline]
 

Set vector using translation portion of the matrix.

Precondition:
if making an n x n matrix, then for
  • vector is homogeneous: SIZE of vector needs to equal number of Matrix ROWS - 1
  • vector has scale component: SIZE of vector needs to equal number of Matrix ROWS if making an n x n+1 matrix, then for
  • vector is homogeneous: SIZE of vector needs to equal number of Matrix ROWS
  • vector has scale component: SIZE of vector needs to equal number of Matrix ROWS + 1
Postcondition:
if preconditions are not met, then function is undefined (will not compile)

Definition at line 232 of file Generate.h.

00233    {
00234       // ASSERT: There are as many
00235 
00236       // if n x n   then (homogeneous case) vecsize == rows-1 or (scale component case) vecsize == rows
00237       // if n x n+1 then (homogeneous case) vecsize == rows   or (scale component case) vecsize == rows+1
00238       gmtlASSERT( ((ROWS == COLS && ( VEC_TYPE::Size == (ROWS-1) ||  VEC_TYPE::Size == ROWS)) ||
00239                (COLS == (ROWS+1) && ( VEC_TYPE::Size == ROWS ||  VEC_TYPE::Size == (ROWS+1)))) &&
00240               "preconditions not met for vector size in call to makeTrans.  Read your documentation." );
00241 
00242       // homogeneous case...
00243       if ((ROWS == COLS &&  VEC_TYPE::Size == ROWS)              // Square matrix and vec so assume homogeneous vector. ex. 4x4 with vec 4
00244           || (COLS == (ROWS+1) &&  VEC_TYPE::Size == (ROWS+1)))  // ex: 3x4 with vec4
00245       {
00246          result[VEC_TYPE::Size-1] = 1.0f;
00247       }
00248 
00249       // non-homogeneous case... (SIZE == ROWS),
00250       //else
00251       //{}
00252 
00253       for (unsigned x = 0; x < COLS - 1; ++x)
00254       {
00255          result[x] = arg( x, COLS - 1 );
00256       }
00257 
00258       return result;
00259    }

template<typename DATA_TYPE, unsigned ROWS, unsigned COLS, unsigned SIZE>
Matrix<DATA_TYPE, ROWS, COLS>& setTrans Matrix< DATA_TYPE, ROWS, COLS > &    result,
const Vec< DATA_TYPE, SIZE > &    trans
[inline]
 

Set matrix translation from vec.

Precondition:
if making an n x n matrix, then for
  • vector is homogeneous: SIZE of vector needs to equal number of Matrix ROWS - 1
  • vector has scale component: SIZE of vector needs to equal number of Matrix ROWS if making an n x n+1 matrix, then for
  • vector is homogeneous: SIZE of vector needs to equal number of Matrix ROWS
  • vector has scale component: SIZE of vector needs to equal number of Matrix ROWS + 1
Postcondition:
if preconditions are not met, then function is undefined (will not compile)

Definition at line 692 of file Generate.h.

00694    {
00695       /* @todo make this a compile time assert... */
00696       // if n x n   then (homogeneous case) vecsize == rows-1 or (scale component case) vecsize == rows
00697       // if n x n+1 then (homogeneous case) vecsize == rows   or (scale component case) vecsize == rows+1
00698       gmtlASSERT( ((ROWS == COLS && (SIZE == (ROWS-1) || SIZE == ROWS)) ||
00699                (COLS == (ROWS+1) && (SIZE == ROWS || SIZE == (ROWS+1)))) &&
00700               "preconditions not met for vector size in call to makeTrans.  Read your documentation." );
00701 
00702       // homogeneous case...
00703       if ((ROWS == COLS && SIZE == ROWS) /* Square matrix and vec so assume homogeneous vector. ex. 4x4 with vec 4 */
00704           || (COLS == (ROWS+1) && SIZE == (ROWS+1)))  /* ex: 3x4 with vec4 */
00705       {
00706          for (unsigned x = 0; x < COLS - 1; ++x)
00707             result( x, COLS - 1 ) = trans[x] / trans[SIZE-1];
00708       }
00709 
00710       // non-homogeneous case...
00711       else
00712       {
00713          for (unsigned x = 0; x < COLS - 1; ++x)
00714             result( x, COLS - 1 ) = trans[x];
00715       }
00716       return result;
00717    }


Generated on Mon Apr 7 15:29:25 2003 for GenericMathTemplateLibrary by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002