To home page

3D source code. Matrix 4x4

Home page

This class is a 4x4 matrix. Most of matrix operations are implemented with parallel XMM instructions. Matrix elements are 4-byte floats. Such a matrix is very useful in coordinate transformations.

Operators defined : M3 = M1 + M2; - addition
M1 += M2;
M3 = M1 - M2; - subtraction
M1 -= M2;
M3 = M1 * M2; - multiply
V2 = M1 * V1; - multiply by CXMMVector
M1 /= D; - operations with scalar
M1 *= D;
M1 += D;
M1 -= D;

The following methods are used to prepare matrices for coordinate transformations :

  • void SetIdentity(); - set identity matrix
  • void SetTranslation(float x, float y, float z); - set matrix for translation
  • void SetScaling(float coefx, float coefy, float coefz); - for scaling
  • void SetRotation(CXMMVector angles); - set rotation matrix with angles in radians
  • void SetRotation(float Ux, float Uy, float Uz, float theta); - set rotation around axis (Ux,Uy,Uz), theta is in radians
  • void SetPerspective(float d); - set perspective projection, d is the distance from eyes to screen
  • and others...
  • The most impressive is the method Multiply() to be used for multiply of a (the longer the better) array of vectors by a matrix. Once I succeeded acceleration of 28 times due to XMM parallelisation.

    See source code for descriptions and examples.

    © Copyright 2007..2009 MI Simulators