syBR::Core::Matrix Class Reference

4x4 matrix class More...

#include <Matrix.hpp>

List of all members.

Public Types

enum  Mode { MODE_DEGREES = 0, MODE_RADIANS }
 Angle specification mode enumeration. More...

Public Member Functions

 Matrix ()
 Constructor #1.
 Matrix (const Mode mode)
 Constructor #2.
 Matrix (const Matrix &matrix)
 Copy constructor.
void rotate (float x, float y, float z)
 Rotate the current matrix.
void rotate (float angle, const Vector3D &axis)
 Rotate the matrix around an arbitray axis.
void translate (const float x, const float y, const float z)
 Translate the current matrix.
void scale (const float x, const float y, const float z)
 Scale the current matrix.
void transpose ()
 Transpose the current matrix.
void identity ()
 Set the current matrix to the identity matrix.
void zero ()
 Set the current matrix to the zero matrix.
void from3x3Array (const float array[3][3])
 Build the current matrix from a 3x3 array.
void from4x4Array (const float array[4][4])
 Build the current matrix from a 4x4 array.
void from16Array (const float array[16])
 Build the current matrix from a 16 elements array.
float & operator() (const unsigned int line, const unsigned int column)
 Get/set an element.
const float & operator() (const unsigned int line, const unsigned int column) const
 Get an element (constant).
Matrixoperator= (const Matrix &arg)
 Set the content of the current matrix.
Matrix operator+ (const Matrix &arg) const
 Add a matrix to the current matrix.
Matrix operator- (const Matrix &arg) const
 Substract a matrix from the current matrix.
Matrix operator * (const float arg) const
 Multiply the current matrix by a scalar.
Matrix operator/ (const float arg) const
 Divide the current matrix by a scalar.
Vector3D operator * (const Vector3D &arg) const
 Multiply the current matrix by a vector.
void operator+= (const Matrix &arg)
 Add the content of a matrix to this.
void operator-= (const Matrix &arg)
 Substract the content of a matrix from this.
void operator *= (const float arg)
 Multiply the content of this by a scalar.
void operator/= (const float arg)
 Divide the content of this by a scalar.
Matrix operator * (const Matrix &arg) const
 Multiply the current matrix by another matrix.
void operator *= (const Matrix &arg)
 Multiply this by another matrix.
 operator const float * () const
 Convert the matrix to a float array.
bool operator== (const Matrix &arg) const
 Compare the current matrix to another matrix.
bool operator!= (const Matrix &arg) const
 Compare the current matrix to another matrix.
bool fastCompare (const Matrix &arg) const
 Check if two matrices are equal (fast version, binary compare).

Private Member Functions

void multiply (float matrix[16])
 Multiply m_content[] by matrix[].
void swap (float &arg1, float &arg2)
 Swap the content of two variables.

Private Attributes

float m_content [16]
 Internal content of the matrix.
bool m_mode
 Indicates if we use degrees or radians when rotating.

Friends

Matrix operator * (const float scalar, const Matrix &matrix)
 Multiply a matrix by a scalar.
Matrix operator/ (const float scalar, const Matrix &matrix)
 Divide a matrix by a scalar.
Vector3D operator * (const Vector3D &vector, const Matrix &matrix)
 Multiply a matrix by a vector.


Detailed Description

4x4 matrix class

A 4x4 matrix is the same as a 3x3 matrix (3D transformations) except that it contains a fourth column (not used here) and a fourth line used for adding translation informations. The internal memory representation of the matrix is a 16-element column-major array :
| array[0] array[4] array[8]   array[12] |
| array[1] array[5] array[9]   array[13] |
| array[2] array[6] array[10] array[14] |
| array[3] array[7] array[11] array[15] |


Member Enumeration Documentation

enum syBR::Core::Matrix::Mode

Angle specification mode enumeration.

Enumerator:
MODE_DEGREES  All angles are specified using degrees.
MODE_RADIANS  All angles are specified using radians.


Constructor & Destructor Documentation

syBR::Core::Matrix::Matrix (  ) 

Constructor #1.

It specifies by default that degrees are used when rotating (angles) and the matrix is initialized as the identity matrix.

syBR::Core::Matrix::Matrix ( const Mode  mode  ) 

Constructor #2.

It receives a parametre which specify if the matrix is using radians or degrees when rotating (angles) and the matrix is initialized as the identity matrix.

Parameters:
mode One of these:
  • MODE_RADIANS if angles are specified using radians
  • MODE_DEGREES if angles are specified using degrees

syBR::Core::Matrix::Matrix ( const Matrix matrix  ) 

Copy constructor.

Parameters:
matrix Matrix from which content must be copied


Member Function Documentation

void syBR::Core::Matrix::rotate ( float  x,
float  y,
float  z 
)

Rotate the current matrix.

Create a rotation matrix using the parametres values and then, multiply the current matrix by this rotation matrix.

Parameters:
x X-axis rotation angle
y Y-axis rotation angle
z Z-axis rotation angle

void syBR::Core::Matrix::rotate ( float  angle,
const Vector3D axis 
)

Rotate the matrix around an arbitray axis.

Parameters:
angle Rotation angle
axis Axis to rotate around

void syBR::Core::Matrix::translate ( const float  x,
const float  y,
const float  z 
)

Translate the current matrix.

As we are using 4x4 matrices, we simply put the translation informations in the fourth line.

Parameters:
x X-axis translation
y Y-axis translation
z Z-axis translation

void syBR::Core::Matrix::scale ( const float  x,
const float  y,
const float  z 
)

Scale the current matrix.

Parameters:
x X-axis scaling
y Y-axis scaling
z Z-axis scaling

void syBR::Core::Matrix::transpose (  ) 

Transpose the current matrix.

Revert colums and lines of the current matrix.

void syBR::Core::Matrix::identity (  ) 

Set the current matrix to the identity matrix.

void syBR::Core::Matrix::zero (  ) 

Set the current matrix to the zero matrix.

void syBR::Core::Matrix::from3x3Array ( const float  array[3][3]  ) 

Build the current matrix from a 3x3 array.

Fill the 3x3 part of the matrix using the content of the array and set the other parts to default value (no translation). The array must be defined column-major.

Parameters:
array Array to be used to fill the content of the matrix

void syBR::Core::Matrix::from4x4Array ( const float  array[4][4]  ) 

Build the current matrix from a 4x4 array.

Fill the matrix using the content of the array. The array must be defined row-major : first index is the line index and the second is the column index.

Parameters:
array Array to be used to fill the content of the matrix

void syBR::Core::Matrix::from16Array ( const float  array[16]  ) 

Build the current matrix from a 16 elements array.

Fill the matrix using the content of the array. The array must be defined column-major.

Parameters:
array Array to be used to fill the content of the matrix

float & syBR::Core::Matrix::operator() ( const unsigned int  line,
const unsigned int  column 
)

Get/set an element.

Parameters:
line line index of the item (0-based)
column Column index of the item (0-based)
Returns:
Requested element value or the value of the element located at (0,0) if the indexes are out of range

const float & syBR::Core::Matrix::operator() ( const unsigned int  line,
const unsigned int  column 
) const

Get an element (constant).

Parameters:
line line index of the item (0-based)
column Column index of the item (0-based)
Returns:
Requested element value or the value of the element located at (0,0) if the indexes are out of range

Matrix & syBR::Core::Matrix::operator= ( const Matrix arg  ) 

Set the content of the current matrix.

Parameters:
arg New content for the matrix
Returns:
Matrix containing the new content (a reference to this)

Matrix syBR::Core::Matrix::operator+ ( const Matrix arg  )  const

Add a matrix to the current matrix.

Parameters:
arg Matrix to be added to the current matrix
Returns:
Matrix containing the sum of the two matrices

Matrix syBR::Core::Matrix::operator- ( const Matrix arg  )  const

Substract a matrix from the current matrix.

Parameters:
arg Matrix to be substracted from the current matrix
Returns:
Matrix containing the difference of the two matrices

Matrix syBR::Core::Matrix::operator * ( const float  arg  )  const

Multiply the current matrix by a scalar.

The multiplication of a matrix by a scalar is simple: every element of the matrix will be multiplied by this scalar.

Parameters:
arg Scalar to multiply the matrix by
Returns:
Matrix containing the result of the multiplication of the matrix by the scalar

Matrix syBR::Core::Matrix::operator/ ( const float  arg  )  const

Divide the current matrix by a scalar.

The division of a matrix by a scalar is simple: every element of the matrix will be divided by this scalar.

Parameters:
arg Scalar to divide the matrix by
Returns:
One of these:
  • Matrix containing the result of the division of the matrix by the scalar
  • Unmodified matrix if arg is zero

Vector3D syBR::Core::Matrix::operator * ( const Vector3D arg  )  const

Multiply the current matrix by a vector.

Parameters:
arg Vector to multiply the matrix to
Returns:
Vector containing the result of the multiplication of the matrix by the vector

void syBR::Core::Matrix::operator+= ( const Matrix arg  ) 

Add the content of a matrix to this.

Parameters:
arg Matrix to add

void syBR::Core::Matrix::operator-= ( const Matrix arg  ) 

Substract the content of a matrix from this.

Parameters:
arg Matrix to substract

void syBR::Core::Matrix::operator *= ( const float  arg  ) 

Multiply the content of this by a scalar.

Parameters:
arg Scalar to multiply

void syBR::Core::Matrix::operator/= ( const float  arg  ) 

Divide the content of this by a scalar.

Parameters:
arg Scalar to divide

Matrix syBR::Core::Matrix::operator * ( const Matrix arg  )  const

Multiply the current matrix by another matrix.

Parameters:
arg Matrix to multiply to
Returns:
Matrix containing the result of the multiplication of the current matrix by the other matrix

void syBR::Core::Matrix::operator *= ( const Matrix arg  ) 

Multiply this by another matrix.

Parameters:
arg Matrix to multiply to

syBR::Core::Matrix::operator const float * (  )  const

Convert the matrix to a float array.

Returns:
Pointer to the first element of the array

bool syBR::Core::Matrix::operator== ( const Matrix arg  )  const

Compare the current matrix to another matrix.

Parameters:
arg Matrix to be compared
Returns:
One of these:
  • true if the matrices are identical
  • false otherwise
Note:
The comparison takes rounding errors in account by using the Math::EPSILON() constant.

bool syBR::Core::Matrix::operator!= ( const Matrix arg  )  const

Compare the current matrix to another matrix.

Parameters:
arg Matrix to be compared
Returns:
One of these:
  • true if the matrices are different
  • false otherwise
Note:
The comparison takes rounding errors in account by using the Math::EPSILON() constant.

bool syBR::Core::Matrix::fastCompare ( const Matrix arg  )  const

Check if two matrices are equal (fast version, binary compare).

Parameters:
arg Matrix to be compared
Returns:
One of these:
  • true if the matrices are identical
  • false otherwise
Note:
This function compares the matrices using a binary compare which should be faster but don't take any EPSILON into account (doesn't handle rounding errors).

void syBR::Core::Matrix::multiply ( float  matrix[16]  )  [inline, private]

Multiply m_content[] by matrix[].

Private function used only when rotating the matrix. It computes the result of the multiplication of m_content (current matrix content) and matrix and then fills m_content with it.

Parameters:
matrix Matrix to be used as second member of the multiplication

void syBR::Core::Matrix::swap ( float &  arg1,
float &  arg2 
) [inline, private]

Swap the content of two variables.

Parameters:
arg1 First variable
arg2 Second variable


Friends And Related Function Documentation

Matrix operator * ( const float  scalar,
const Matrix matrix 
) [friend]

Multiply a matrix by a scalar.

The multiplication of a matrix by a scalar is simple: every element of the matrix will be multiplied by this scalar.

Parameters:
scalar Scalar to multiply the matrix by
matrix Matrix to be multiplied
Returns:
Matrix containing the result of the multiplication of the matrix by the scalar

Matrix operator/ ( const float  scalar,
const Matrix matrix 
) [friend]

Divide a matrix by a scalar.

The division of a matrix by a scalar is simple: every element of the matrix will be divided by this scalar.

Parameters:
scalar Scalar to divide the matrix by
matrix Matrix to be divided
Returns:
One of these:
  • Matrix containing the result of the division of the matrix by the scalar
  • Unmodified matrix if scalar is zero

Vector3D operator * ( const Vector3D vector,
const Matrix matrix 
) [friend]

Multiply a matrix by a vector.

Parameters:
vector Vector to multiply the matrix to
matrix Matrix to be multiplied by
Returns:
Vector containing the result of the multiplication of the matrix by the vector
Note:
This is a convenience operator used to allow two syntaxes for the multiplication of a matrix by a vector even if it isn't strictly correct mathematically speaking :
  • matrix * vector
  • vector * matrix


Member Data Documentation

float syBR::Core::Matrix::m_content[16] [private]

Internal content of the matrix.

bool syBR::Core::Matrix::m_mode [private]

Indicates if we use degrees or radians when rotating.


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

Copyright © 2008 by Sebastien Frippiat
Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 License.
Last modified Tue Dec 30 17:57:33 2008