1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
bool operator == (const Matrice4 & other1, const Matrice4 & other2){
unsigned int i(0);
while(i < 16){
if(other1.p_mat[i] != other2.p_mat[i]) return false;
i++;
}
return true;
}
bool operator != (const Matrice4 & other1, const Matrice4 & other2){
unsigned int i(0);
while(i < 16){
if(other1.p_mat[i] != other2.p_mat[i]) return true;
i++;
}
return false;
}
Matrice4 operator + (const Matrice4 & other1, const Matrice4 & other2){
Matrice4 matrice;
for(unsigned int i(0); i < 16; i++){
matrice.p_mat[i] = other1.p_mat[i] + other2.p_mat[i];
}
return matrice;
}
Matrice4 operator - (const Matrice4 & other1, const Matrice4 & other2){
Matrice4 matrice;
for(unsigned int i(0); i < 16; i++){
matrice.p_mat[i] = other1.p_mat[i] - other2.p_mat[i];
}
return matrice;
}
Matrice4 operator * (float nb, const Matrice4 & other1){
Matrice4 matrice;
for(unsigned int i(0); i < 16; i++){
matrice.p_mat[i] = other1.p_mat[i]*nb;
}
return matrice;
}
Matrice4 operator * (const Matrice4 & other1, float nb){
Matrice4 matrice;
for(unsigned int i(0); i < 16; i++){
matrice.p_mat[i] = other1.p_mat[i]*nb;
}
return matrice;
}
Matrice4 operator * (const Matrice4 & other1, const Matrice4 & other2){
Matrice4 matrice;
float calcul(0);
unsigned int i,j,k;
for(j = 0; j < 4; j++){
for(i = 0; i < 4; i++){
calcul = 0;
for(k = 0; k < 4; k++){
calcul += other1.p_mat[4*j + k]*other2.p_mat[4*k + i];
}
matrice.p_mat[4*j + i] = calcul;
}
}
return matrice;
}
Vecteur4 operator * (const Matrice4 & matrice, const Vecteur4 & vecteur){
float x(vecteur.getX()), y(vecteur.getY()), z(vecteur.getZ()), t(vecteur.getT());
Vecteur4 vect(matrice.p_mat[0]*x + matrice.p_mat[1]*y + matrice.p_mat[2]*z + matrice.p_mat[3]*t,
matrice.p_mat[4]*x + matrice.p_mat[5]*y + matrice.p_mat[6]*z + matrice.p_mat[7]*t,
matrice.p_mat[8]*x + matrice.p_mat[9]*y + matrice.p_mat[10]*z + matrice.p_mat[11]*t,
matrice.p_mat[12]*x + matrice.p_mat[13]*y + matrice.p_mat[14]*z + matrice.p_mat[15]*t);
return vect;
}
Matrice4 operator / (const Matrice4 & other1, float nb){
Matrice4 matrice;
for(unsigned int i(0); i < 16; i++){
matrice.p_mat[i] = other1.p_mat[i]/nb;
}
return matrice;
}
std::ostream & operator << (std::ostream & out, const Matrice4 & matrice){
if(matrice.p_mat == NULL){
out << "Pointeur NULL de matrice" << std::endl;
}else{
for(unsigned int k(0); k < 4; k++){
out << "| ";
for(unsigned int i(0); i < 4; i++){
out << " " << matrice.p_mat[4*k + i] << " ";
}
out << "| " << std::endl;
}
}
return out;
}
|