#include <Matrix.hpp>
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). | |
Matrix & | operator= (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. |
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] |
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.
mode | One of these:
|
syBR::Core::Matrix::Matrix | ( | const Matrix & | matrix | ) |
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.
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.
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.
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.
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.
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.
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.
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.
line | line index of the item (0-based) | |
column | Column index of the item (0-based) |
const float & syBR::Core::Matrix::operator() | ( | const unsigned int | line, | |
const unsigned int | column | |||
) | const |
Get an element (constant).
line | line index of the item (0-based) | |
column | Column index of the item (0-based) |
Set the content of the current matrix.
arg | New content for the matrix |
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.
arg | Scalar to multiply the matrix by |
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.
arg | Scalar to divide the matrix by |
Multiply the current matrix by a vector.
arg | Vector to multiply the matrix to |
void syBR::Core::Matrix::operator+= | ( | const Matrix & | arg | ) |
void syBR::Core::Matrix::operator-= | ( | const Matrix & | arg | ) |
void syBR::Core::Matrix::operator *= | ( | const float | arg | ) |
Multiply the content of this by a scalar.
arg | Scalar to multiply |
void syBR::Core::Matrix::operator/= | ( | const float | arg | ) |
Divide the content of this by a scalar.
arg | Scalar to divide |
void syBR::Core::Matrix::operator *= | ( | const Matrix & | arg | ) |
syBR::Core::Matrix::operator const float * | ( | ) | const |
Convert the matrix to a float array.
bool syBR::Core::Matrix::operator== | ( | const Matrix & | arg | ) | const |
Compare the current matrix to another matrix.
arg | Matrix to be compared |
bool syBR::Core::Matrix::operator!= | ( | const Matrix & | arg | ) | const |
Compare the current matrix to another matrix.
arg | Matrix to be compared |
bool syBR::Core::Matrix::fastCompare | ( | const Matrix & | arg | ) | const |
Check if two matrices are equal (fast version, binary compare).
arg | Matrix to be compared |
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.
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.
arg1 | First variable | |
arg2 | Second variable |
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.
scalar | Scalar to multiply the matrix by | |
matrix | Matrix to be multiplied |
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.
scalar | Scalar to divide the matrix by | |
matrix | Matrix to be divided |
Multiply a matrix by a vector.
vector | Vector to multiply the matrix to | |
matrix | Matrix to be multiplied by |
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.
Copyright © 2008 by Sebastien Frippiat
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 License.
Last modified Tue Dec 30 17:57:33 2008