Table of contents |
Derived from: none
Declared in: MTMatrix.h
Library: 3DM.so
First I'd like to apologise if the vocabulary I use here isn't correct. I've done some maths, but in French only. If you find a mistake, please send me an email, and I'll correct it.
Matrices are used to do transformations on a group of points.
You can do translations, rotations, scaling, or any combinations of these transformations. Each transformation is represented by a matrix. If you multiply two matrices, you have one matrix that represent both transformations applied successively.
Here is an example of use of this class:
MTPoints myPoints = ...
MTMatrix transform = MTMatrix::Scale(2);
transform *= MTMatrix::RotateX(1.5);
transform *= MTMatrix::Translate(0,0.5,0);
transform *= MTMatrix::RotateZ(0.5);
myPoints *= transform;
First, a MTPoints object is created. It represents a list of 3D points. Then we create a MTMatrix object to apply a transformation on them. The first transformation is a scaling. We use Scale() , that returns a matrix that represents a scaling, by 2. RotateX() creates a rotating matrix, around the X axis, by 1.5 radians. transform is multiplied by this rotating matrix, so it now represents a complex transformation: a scaling, and a rotation. Then we create two other matrices, using Translate() and RotateZ() . These also are used to modify transform. At the end transform represent this transformation: a scaling by 2, a rotation around the X axis of 1.5 radians, a translation of 0.5 among the Y axis, and a rotation around the Z axis of 0.5 radians. Finaly, this matrix is applied to myPoints, a MTPoints object. The 3D object whose points are in myPoints is scaled, rotated, translated, and rotated again.
This matrix system can seem complex at first, but in fact it can be very useful and effective when you want to do lots of transformations successively. But you can also use it to do a simple transformation:
myPoints *= MTMatrix::RotateZ(1);
This will rotate the points stored in myPoints around the Z axis, by 1 radian.
|
You shouldn't normally use the constructor to build a transformation matrix. You should use instead the static functions ( Scale() , Translate() or Rotate() ) to build ready-made matrices.
If you really want to build matrices yourself, read on...
These methods build a matrix. The first constructor builds an identity matrix:
1 | 0 | 0 | 0 |
0 | 1 | 0 | 0 |
0 | 0 | 1 | 0 |
0 | 0 | 0 | 1 |
You can also use the second constructor to specify the elements yourself. You can do interesting transformations this way ;-). The matrices used are 4-by-4 matrices. The fourth dimension is used to represent translations. The fourth coordinate of each point is set to 1, and the fourth line of the matrix can be used to do the translation. The fourth column of the matrix is always the same, so you don't need to give it to the constructor.
m11 | m12 | m13 | 0 |
m21 | m22 | m33 | 0 |
m31 | m32 | m33 | 0 |
m41 | m42 | m43 | 1 |
|
Destroys the matrix
|
Returns a matrix that represents a rotation around one of the axes X, Y or Z. The angle alpha must be given in radians
|
Returns a matrix that represents a scaling. The first version use the same value scale on all axes, whereas the second one can let you specify different values for the 3 axes.
|
Returns a matrix that represents a translation. x, y and z indicate how much the points must be moved among the X, Y and Z axes, respectively.
These functions are here only to access to the matrix' elements. You shouldn't need them.
|
Returns the element of the matrix at the line i and at the column j. Ranges are 0..3 for i, and 0..2 for j. The call will crash if one of these values is out of range.
Elem() can also be used to modify the elements:
myMatrix.Elem(1,2) = 0;
|
This is a const version of Elem() . You can't modify the value. It is useful if you're working on a const MTMatrix .
|
Copies the src matrix into the left operand.
|
Returns the product of the two matrices. A*B is a matrix that represents the two transformations of A and B applied sucessively.
|
Returns the product of the two matrices and store the result in the left operand.