La matrice rotation et de translation

Matrice de translation :

Soit le vecteur de translation (x, y, z). Pour obtenir la matrice de translation on a :

     1           0           0           0     
0 1 0 0
0 0 1 0
x y z 1

Matrice de rotation sur l'axe des X suivant l'angle alpha :

     1      0 0      0     
0 cos(alpha) sin(alpha) 0
0 -sin(alpha) cos(alpha) 0
0 0 0 1

Matrice de rotation sur l'axe des Y :

cos(alpha)      0      -sin(alpha)      0     
0 1 0 0
sin(alpha) 0 cos(alpha) 0
0 0 0 1

Matrice de rotation sur l'axe des Z :

cos(alpha) sin(alpha)      0           0     
-sin(alpha) cos(alpha) 0 0
0 0 1 0
0 0 0 1

Et voici les fonctions qui permettent d'effectuer les transformations dans le ficher vect_matr.cpp :


float produit_scalaire(D3DVECTOR a, D3DVECTOR b) {
return a.x * b.x + a.y * b.y + a.z * b.z;
}

D3DVECTOR scalaire(float s, D3DVECTOR vecteur) {
D3DVECTOR v = {s*vecteur.x, s*vecteur.y, s*vecteur.z};

return v;
}

D3DMATRIX identite(void) {

// matrice identite
D3DMATRIX ident;
ZeroMemory( &ident, sizeof(D3DMATRIX));

// création de la matrice identité
ident._11 = ident._22 = ident._33 = ident._44 = 1;

return ident;
}

void translation(D3DMATRIX *matrice, float x, float y, float z) {
matrice->_41 = x;
matrice->_42 = y;
matrice->_43 = z;
}

void rotation_X(D3DMATRIX *matrice, float koef) {

// rotation autour des X
matrice->_22 = cosf(koef);
matrice->_23 = sinf(koef);
matrice->_32 = -sinf(koef);
matrice->_33 = cosf(koef);

}

void rotation_Y(D3DMATRIX *matrice, float koef) {

// rotation autour des Y
float _cos = cosf(koef);
float _sin = sinf(koef);

matrice->_11 = _cos;
matrice->_13 = -_sin;
matrice->_31 = _sin;
matrice->_33 = _cos;

}

Pour le fichier decl_vect_matr.h on aura :

#include <d3d9.h>
#include <math.h>

// calcule le vecteur unitaire
D3DVECTOR normalisation(D3DVECTOR);
// calcule la soustraction de deux vecteurs
D3DVECTOR soustraction(D3DVECTOR, D3DVECTOR);
// calcule le produit vectoriel de deux vecteurs
D3DVECTOR produit_vectoriel(D3DVECTOR, D3DVECTOR);
// calcule le produit scalaire de deux vecteurs
float produit_scalaire(D3DVECTOR, D3DVECTOR);
// scalaire * vecteur
D3DVECTOR scalaire(float, D3DVECTOR);
// calcule la matrice identité
D3DMATRIX identite(void);

// translation d'une matrice
void translation(D3DMATRIX*, float, float, float);
// effectue la rotation au tour de l'axe des X
void rotation_X(D3DMATRIX*, float);
// effectue la rotation au tour de l'axe des Y
void rotation_Y(D3DMATRIX*, float);