qCC_db  version 2.5.4 (Qt) - 19 Apr 2014
 All Classes Functions Variables Typedefs Enumerations Enumerator Pages
Public Member Functions | Static Public Member Functions | Protected Attributes | List of all members
ccGLMatrix Class Reference

A 4x4 'transformation' matrix (column major order) More...

#include <ccGLMatrix.h>

Inheritance diagram for ccGLMatrix:
Inheritance graph
[legend]
Collaboration diagram for ccGLMatrix:
Collaboration graph
[legend]

Public Member Functions

 ccGLMatrix ()
 Default constructor. More...
 
 ccGLMatrix (const float *mat16f)
 Constructor from a float GL matrix array. More...
 
 ccGLMatrix (const double *mat16d)
 Constructor from a double GL matrix array. More...
 
 ccGLMatrix (const CCVector3 &X, const CCVector3 &Y, const CCVector3 &Z, const CCVector3 &T)
 Constructor from 4 columns (X,Y,Z,T) More...
 
 ccGLMatrix (const CCLib::SquareMatrix &R, const CCVector3 &T)
 Constructor from a 3x3 rotation matrix R and a vector T.
 
 ccGLMatrix (const CCLib::SquareMatrix &R, const CCVector3 &T, PointCoordinateType S)
 Constructor from a 3x3 rotation matrix R, a vector T, a scale S.
 
 ccGLMatrix (const CCLib::SquareMatrix &R, const CCVector3 &T, const CCVector3 &rotCenter)
 Constructor from a rotation center G, a 3x3 rotation matrix R and a vector T.
 
 ccGLMatrix (const ccGLMatrix &mat)
 Copy constructor.
 
QString toString (int precision=12, QChar separator= ' ') const
 Returns matrix as a string. More...
 
ccGLMatrix xRotation () const
 Returns the rotation component around X only.
 
ccGLMatrix yRotation () const
 Returns the rotation component around Y only.
 
ccGLMatrix zRotation () const
 Returns the rotation component around Z only.
 
virtual void toZero ()
 Clears matrix. More...
 
virtual void toIdentity ()
 Sets matrix to identity.
 
void clearTranslation ()
 Clears translation. More...
 
void initFromParameters (PointCoordinateType alpha_rad, const CCVector3 &axis3D, const CCVector3 &t3D)
 Inits transformation from a rotation axis, an angle and a translation. More...
 
void initFromParameters (PointCoordinateType phi_rad, PointCoordinateType theta_rad, PointCoordinateType psi_rad, const CCVector3 &t3D)
 Inits transformation from 3 rotation angles and a translation. More...
 
void getParameters (PointCoordinateType &alpha_rad, CCVector3 &axis3D, CCVector3 &t3D) const
 Returns equivalent parameters: a rotation axis, an angle and a translation. More...
 
void getParameters (PointCoordinateType &phi_rad, PointCoordinateType &theta_rad, PointCoordinateType &psi_rad, CCVector3 &t3D) const
 Returns equivalent parameters: 3 rotation angles and a translation. More...
 
float * data ()
 Returns a pointer to internal data.
 
const float * data () const
 Returns a const pointer to internal data.
 
float * getTranslation ()
 Retruns a pointer to internal translation. More...
 
const float * getTranslation () const
 Retruns a const pointer to internal translation. More...
 
CCVector3 getTranslationAsVec3D () const
 Returns a copy of the translation as a CCVector3. More...
 
void setTranslation (const CCVector3 &T)
 Sets translation. More...
 
void setTranslation (const float T[3])
 Sets translation. More...
 
float * getColumn (unsigned index)
 Returns a pointer to a given column. More...
 
const float * getColumn (unsigned index) const
 Returns a const pointer to a given column. More...
 
CCVector3 getColumnAsVec3D (unsigned index) const
 Returns a copy of a given column as a CCVector3. More...
 
ccGLMatrix operator* (const ccGLMatrix &mat) const
 Multiplication by a matrix operator.
 
CCVector3 operator* (const CCVector3 &vec) const
 Multiplication by a vector operator.
 
ccGLMatrixoperator*= (const ccGLMatrix &mat)
 (in place) Multiplication operator
 
ccGLMatrixoperator+= (const CCVector3 &T)
 (in place) Translation operator
 
ccGLMatrixoperator-= (const CCVector3 &T)
 (in place) Translation operator
 
void apply (CCVector3 &vec) const
 Applies transformation to a 3D vector (in place) More...
 
PointCoordinateType applyX (const CCVector3 &vec) const
 Get the resulting transformation along X dimension.
 
PointCoordinateType applyY (const CCVector3 &vec) const
 Get the resulting transformation along Y dimension.
 
PointCoordinateType applyZ (const CCVector3 &vec) const
 Get the resulting transformation along Z dimension.
 
void applyRotation (CCVector3 &vec) const
 Applies rotation only to a 3D vector (in place) More...
 
void applyRotation (float vec[3]) const
 Applies rotation only to a 3D vector (in place) More...
 
void shiftRotationCenter (const CCVector3 &vec)
 Shifts rotation center. More...
 
void transpose ()
 Transposes matrix (in place)
 
ccGLMatrix transposed () const
 Returns transposed matrix.
 
void invert ()
 Inverts transformation.
 
ccGLMatrix inverse () const
 Returns inverse transformation.
 
virtual bool toAsciiFile (const char *filename) const
 Saves matrix to an ASCII file.
 
virtual bool fomAsciiFile (const char *filename)
 Loads matrix from an ASCII file.
 
void scale (float coef)
 Scales the whole matrix. More...
 
void scaleLine (unsigned lineIndex, float coef)
 Scales one line of the matrix. More...
 
void scaleColumn (unsigned colIndex, float coef)
 Scales one column of the matrix. More...
 
virtual bool isSerializable () const
 Returns whether object is serializable of not.
 
virtual bool toFile (QFile &out) const
 Saves data to binay stream. More...
 
virtual bool fromFile (QFile &in, short dataVersion, int flags)
 Loads data from binay stream. More...
 
- Public Member Functions inherited from ccSerializableObject
virtual ~ccSerializableObject ()
 Desctructor.
 

Static Public Member Functions

static ccGLMatrix Interpolate (PointCoordinateType coef, const ccGLMatrix &glMat1, const ccGLMatrix &glMat2)
 Interpolates two matrices at relative position 'coef'. More...
 
static ccGLMatrix FromToRotation (const CCVector3 &from, const CCVector3 &to)
 Creates a transformation matrix that rotates a vector to another. More...
 
static ccGLMatrix FromQuaternion (const float q[])
 Converts a quaternion to a rotation matrix. More...
 
static ccGLMatrix FromString (QString matText, bool &success)
 Converts a 'text' matrix to a ccGLMatrix. More...
 
- Static Public Member Functions inherited from ccSerializableObject
static bool WriteError ()
 Sends a custom error message (write error) and returns 'false'. More...
 
static bool ReadError ()
 Sends a custom error message (read error) and returns 'false'. More...
 
static bool MemoryError ()
 Sends a custom error message (not enough memory) and returns 'false'. More...
 
static bool CorruptError ()
 Sends a custom error message (corrupted file) and returns 'false'. More...
 

Protected Attributes

float m_mat [OPENGL_MATRIX_SIZE]
 Internal 4x4 GL-style matrix data.
 

Additional Inherited Members

- Public Types inherited from ccSerializableObject
enum  DeserializationFlags { DF_POINT_COORDS_64_BITS = 1, DF_SCALAR_VAL_32_BITS = 2 }
 Deserialization flags (bit-field) More...
 

Detailed Description

A 4x4 'transformation' matrix (column major order)

Transformation (M) is composed by a rotation (R) and a translation (T): M*X = R*X + T

Constructor & Destructor Documentation

ccGLMatrix::ccGLMatrix ( )

Default constructor.

Matrix is set to identity (see toIdentity) by default.

ccGLMatrix::ccGLMatrix ( const float *  mat16f)

Constructor from a float GL matrix array.

Parameters
mat16fa 16 elements array (column major order)
ccGLMatrix::ccGLMatrix ( const double *  mat16d)

Constructor from a double GL matrix array.

Warning
Will implicitly cast the elements to float!
Parameters
mat16da 16 elements array (column major order)
ccGLMatrix::ccGLMatrix ( const CCVector3 &  X,
const CCVector3 &  Y,
const CCVector3 &  Z,
const CCVector3 &  T 
)

Constructor from 4 columns (X,Y,Z,T)

Parameters
X3 first elements of the 1st column (last one is 0)
Y3 first elements of the 2nd column (last one is 0)
Z3 first elements of the 3rd column (last one is 0)
T3 first elements of the last column (last one is 1)

Member Function Documentation

void ccGLMatrix::apply ( CCVector3 &  vec) const
inline

Applies transformation to a 3D vector (in place)

Input vector is directly modified after calling this method

void ccGLMatrix::applyRotation ( CCVector3 &  vec) const
inline

Applies rotation only to a 3D vector (in place)

Input vector is directly modified after calling this method

void ccGLMatrix::applyRotation ( float  vec[3]) const
inline

Applies rotation only to a 3D vector (in place)

Input array is directly modified after calling this method

void ccGLMatrix::clearTranslation ( )

Clears translation.

Translation is set to (0,0,0).

bool ccGLMatrix::fromFile ( QFile &  in,
short  dataVersion,
int  flags 
)
virtual

Loads data from binay stream.

Parameters
ininput file (already opened)
dataVersionfile version
flagsdeserialization flags (see ccSerializableObject::DeserializationFlags)
Returns
success

Reimplemented from ccSerializableObject.

Reimplemented in ccIndexedTransformation.

ccGLMatrix ccGLMatrix::FromQuaternion ( const float  q[])
static

Converts a quaternion to a rotation matrix.

Parameters
qquaternion (4 values: w,x,y,z)
Returns
corresponding rotation matrix
ccGLMatrix ccGLMatrix::FromString ( QString  matText,
bool &  success 
)
static

Converts a 'text' matrix to a ccGLMatrix.

Parameters
[in]matTextmatrix text
[out]successwhether input matrix text is valid or not
ccGLMatrix ccGLMatrix::FromToRotation ( const CCVector3 &  from,
const CCVector3 &  to 
)
static

Creates a transformation matrix that rotates a vector to another.

Adapted from "Efficiently Building a Matrix to Rotate One Vector to Another" By Tomas Möller, John Hughes, Journal of Graphics Tools, 4(4):1-4, 1999

Parameters
fromnormalized non-zero source vector
tonormalized non-zero destination vector
float* ccGLMatrix::getColumn ( unsigned  index)
inline

Returns a pointer to a given column.

Parameters
indexcolumn index (between 0 and 3)
Returns
pointer to the first element of the corresponding column
const float* ccGLMatrix::getColumn ( unsigned  index) const
inline

Returns a const pointer to a given column.

Parameters
indexcolumn index (between 0 and 3)
Returns
pointer to the first element of the corresponding column
CCVector3 ccGLMatrix::getColumnAsVec3D ( unsigned  index) const
inline

Returns a copy of a given column as a CCVector3.

4th value is ignored.

Parameters
indexcolumn index (between 0 and 3)
Returns
copy of the three first elements of the corresponding column
void ccGLMatrix::getParameters ( PointCoordinateType &  alpha_rad,
CCVector3 &  axis3D,
CCVector3 &  t3D 
) const

Returns equivalent parameters: a rotation axis, an angle and a translation.

Parameters
[out]alpha_radrotation angle (in radians)
[out]axis3Drotation axis
[out]t3Dtranslation
void ccGLMatrix::getParameters ( PointCoordinateType &  phi_rad,
PointCoordinateType &  theta_rad,
PointCoordinateType &  psi_rad,
CCVector3 &  t3D 
) const

Returns equivalent parameters: 3 rotation angles and a translation.

See http://en.wikipedia.org/wiki/Euler_angles

Parameters
[out]phi_radPhi angle (in radians)
[out]theta_radTheta angle (in radians)
[out]psi_radPsi angle (in radians)
[out]t3Dtranslation
float* ccGLMatrix::getTranslation ( )
inline

Retruns a pointer to internal translation.

Translation corresponds to the begining of the third column of the matrix.

const float* ccGLMatrix::getTranslation ( ) const
inline

Retruns a const pointer to internal translation.

Translation corresponds to the begining of the third column of the matrix.

CCVector3 ccGLMatrix::getTranslationAsVec3D ( ) const
inline

Returns a copy of the translation as a CCVector3.

Returns
translation vector
void ccGLMatrix::initFromParameters ( PointCoordinateType  alpha_rad,
const CCVector3 &  axis3D,
const CCVector3 &  t3D 
)

Inits transformation from a rotation axis, an angle and a translation.

Parameters
[in]alpha_radrotation angle (in radians)
[in]axis3Drotation axis
[in]t3Dtranslation
void ccGLMatrix::initFromParameters ( PointCoordinateType  phi_rad,
PointCoordinateType  theta_rad,
PointCoordinateType  psi_rad,
const CCVector3 &  t3D 
)

Inits transformation from 3 rotation angles and a translation.

See http://en.wikipedia.org/wiki/Euler_angles

Parameters
[in]phi_radPhi angle (in radians)
[in]theta_radTheta angle (in radians)
[in]psi_radPsi angle (in radians)
[in]t3Dtranslation
ccGLMatrix ccGLMatrix::Interpolate ( PointCoordinateType  coef,
const ccGLMatrix glMat1,
const ccGLMatrix glMat2 
)
static

Interpolates two matrices at relative position 'coef'.

Parameters
coefinterpolation position (should be between 0 and 1).
glMat1'left' matrix
glMat2'right' matrix
void ccGLMatrix::scale ( float  coef)

Scales the whole matrix.

Parameters
coefscaling coef.
void ccGLMatrix::scaleColumn ( unsigned  colIndex,
float  coef 
)

Scales one column of the matrix.

Parameters
colIndex(0-3)
coefscaling coef.
void ccGLMatrix::scaleLine ( unsigned  lineIndex,
float  coef 
)

Scales one line of the matrix.

Parameters
lineIndex(0-3)
coefscaling coef.
void ccGLMatrix::setTranslation ( const CCVector3 &  T)

Sets translation.

Parameters
T3D vector
void ccGLMatrix::setTranslation ( const float  T[3])

Sets translation.

Parameters
T3D vector as a float array
void ccGLMatrix::shiftRotationCenter ( const CCVector3 &  vec)

Shifts rotation center.

Warning, this method only applies a shift (i.e. relatively to the current rotation center). This is not a way to set an absolute rotation center 'directly'.

bool ccGLMatrix::toFile ( QFile &  out) const
virtual

Saves data to binay stream.

Parameters
outoutput file (already opened)
Returns
success

Reimplemented from ccSerializableObject.

Reimplemented in ccIndexedTransformation.

QString ccGLMatrix::toString ( int  precision = 12,
QChar  separator = ' ' 
) const

Returns matrix as a string.

Parameters
precisionnumerical precision
separatorseparator
Returns
string
void ccGLMatrix::toZero ( )
virtual

Clears matrix.

Matrix is set to 0.


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