24 inline coord2d(
int x,
int y) {this->x =
x ; this->y =
y;}
25 inline void set(
int x,
int y) {this->x =
x; this->y =
y;}
27 inline void print(){std::cout <<
"x : " << x <<
" y : " << y << std::endl;}
37 inline void set(
float _x,
float _y,
float _z) { x=_x; y=_y; z=_z; }
39 inline void set(
float v) { x=v; y=v; z=v; }
49 inline void mul(
float v) { x*=v; y*=v; z*=v; }
51 inline float norm2(
void) {
return x*x+y*y+z*
z; }
55 inline bool normalize(
const float nrm) {
if (nrm == 0.f)
return false;
else mul(1.f/nrm);
return true; }
57 inline bool normalize2(
const float nrm2) {
if (nrm2 == 0.f)
return false;
else {
mul(1.f/sqrt(nrm2));
return true; } }
74 inline void print(){std::cout <<
"x : " << x <<
" y : " << y <<
" z : " << z << std::endl;}
99 inline void set(
float _x,
float _y,
float _z,
float _w) { x=_x; y=_y; z=_z; w=_w; }
105 inline vecteur4d(
float _x,
float _y,
float _z,
float _w) {
set(_x,_y,_z,_w); }
110 inline void mul(
float v) { x*=v; y*=v; z*=v; w*=v; }
112 inline float norm2(
void) {
return x*x+y*y+z*z+w*
w; }
116 inline bool normalize(
const float nrm) {
if (nrm == 0.f)
return false;
else mul(1.f/nrm);
return true; }
118 inline bool normalize2(
const float nrm2) {
if (nrm2 == 0.f)
return false;
else {
mul(1.f/sqrt(nrm2));
return true; } }
126 inline void print(){std::cout <<
"x : " << x <<
" y : " << y <<
" z : " << z <<
" w : " << w << std::endl;}
145 inline float _det3(
float *_v1,
float *_v2,
float *_v3) {
147 return v1.
x*( v2.y*v3.z - v2.z*v3.y) - v1.
y*( v2.x*v3.z - v2.z*v3.x) + v1.
z*( v2.x*v3.y - v3.x*v2.y);
159 inline matrice22(
float _m11,
float _m12,
float _m21,
float _m22) {
160 m11 = _m11; m12 = _m12; m21 = _m21; m22 = _m22;
164 return m11*m22 - m21*
m12;
168 m11 = + M.
m22 * invdet;
169 m12 = - M.
m12 * invdet;
170 m21 = - M.
m21 * invdet;
171 m22 = + M.
m11 * invdet;
202 inline void view(
void) { printf(
"%f %f\n%f %f\n",m11, m12, m21, m22); }
206 #define MulLC(A,a,B,b) (A.m##a##1 * B.m1##b + A.m##a##2 * B.m2##b + A.m##a##3 * B.m3##b + A.m##a##4 * B.m4##b )
212 float m11,
m12,
m13,
m14,
m21,
m22,
m23,
m24,
m31,
m32,
m33,
m34,
m41,
m42,
m43,
m44;
217 inline matrice44(
float _m11,
float _m12,
float _m13,
float _m14,
float _m21,
float _m22,
float _m23,
float _m24,
float _m31,
float _m32,
float _m33,
float _m34,
float _m41,
float _m42,
float _m43,
float _m44) {
218 set(_m11,_m12,_m13,_m14,_m21,_m22,_m23,_m24,_m31,_m32,_m33,_m34,_m41,_m42,_m43,_m44);
221 inline void set(
float _m11,
float _m12,
float _m13,
float _m14,
float _m21,
float _m22,
float _m23,
float _m24,
float _m31,
float _m32,
float _m33,
float _m34,
float _m41,
float _m42,
float _m43,
float _m44) {
222 m11=_m11; m12=_m12; m13=_m13; m14=_m14;
223 m21=_m21; m22=_m22; m23=_m23; m24=_m24;
224 m31=_m31; m32=_m32; m33=_m33; m34=_m34;
225 m41=_m41; m42=_m42; m43=_m43; m44=_m44;
263 inline void zero() { memset(&m11,0,16*
sizeof(
float)); }
265 inline void view() { std::cout << m11 <<
" " << m12 <<
" " << m13 <<
" " << m14 << std::endl << m21 <<
" " << m22 <<
" " << m23 <<
" " << m24 << std::endl << m31 <<
" " << m32 <<
" " << m33 <<
" " << m34 << std::endl << m41 <<
" " << m42 <<
" " << m43 <<
" " << m44 << std::endl ; }
267 inline void scale(
float a,
float b,
float c) {
zero(); m11=a; m22=b; m33=c; m44=1.f; }
273 inline void translate(
float a,
float b,
float c) {
scale(1.f,1.f,1.f); m14=a; m24=b; m34=c; }
275 inline void rotationX(
float th) {
scale(1.f,cos(th),cos(th)); m32=sin(th); m23=-sin(th); }
277 inline void rotationY(
float th) {
scale(cos(th),1.f,cos(th)); m31=sin(th); m13=-sin(th); }
279 inline void rotationZ(
float th) {
scale(cos(th),cos(th),1.f); m21=sin(th); m12=-sin(th); }
282 #define SWAP(a,b) { float c=a; a=b; b=c; }
291 + m11 *
_det3( &m22, &m32, &m42)
292 - m21 *
_det3( &m12, &m32, &m42)
293 + m31 *
_det3( &m12, &m22, &m42)
294 - m41 *
_det3( &m12, &m22, &m32);
302 m41 = m42 = m43 = 0.f; m44 = 1.f;
307 const float eps = 1e-6f;
311 float detP = P.det();
312 if (fabs(detP)<=eps)
return false;
319 float detSRiPQ = SRiPQ.
det();
320 if (fabs(detSRiPQ)<=eps)
return false;
322 Sb.
inverse(SRiPQ,1.f/detSRiPQ);
357 inline int sign(
int x) {
return (x>0 ? +1 : (x<0 ? -1 : 0 )); }
359 inline float clamp(
float x) {
return (x < 0.f ? 0.f : (x > 1.f ? 1.f : x)); }
360 const float pi = 3.14159265358979323846f;
vecteur4d()
constructeur par défaut (non initialisé)
void mul(matrice44 &M1, matrice44 &M2)
M.mul(M1,M2) multiplication de 2 matrices 4x4.
vecteur3d(float _x, float _y, float _z)
constructeur U=(x,y,z)
vecteur3d operator*(const vecteur3d &v1, const vecteur3d &v2)
permet l'écriture U=V1*V2. Multiplication de vecteurs par composante.
vecteur4d(vecteur3d &_v, float _w)
constructeur U=(V,w)
void transpose()
M.transpose(), transposition (sur place) de la matrice M.
void inverse(matrice22 &M, float invdet)
calcul de l'inverse de la matrice : M.inverse(M1)
void rotationZ(float th)
M.rotationZ(th), construit la matrice de transformation 4x4 associé à une rotation d'axe Z et d'angle...
matrice44()
constructeur par défaut (sans initialisation)
void set(float _x, float _y, float _z, float _w)
U.set(x,y,z,w) fixe les composantes du vecteur à partir des coordonnées.
void rotationY(float th)
M.rotationY(th), construit la matrice de transformation 4x4 associé à une rotation d'axe Y et d'angle...
void vector(vecteur3d v1, vecteur3d v2)
construit U = V1 - V2
void rotationX(float th)
M.rotationX(th), construit la matrice de transformation 4x4 associé à une rotation d'axe X et d'angle...
void cross(const vecteur3d &v1, const vecteur3d &v2)
U.cross(V1,V2) place dans U le produit vectoriel de V1 et V2.
float _det3(float *_v1, float *_v2, float *_v3)
calcul du déterminant 3x3 à partir de 3 vecteurs flottants (utilisé pour le calcul du déterminant 4x4...
vecteur4d & operator=(const vecteur4d &v)
permet l'écriture U = V. Egalité de vecteurs par composante.
void set(float _x, float _y, float _z)
U.set(x,y,z) fixe les composantes du vecteur.
bool normalize(void)
U.normalize() normalisation (sur place). Retourne faux si la norme est nulle.
void identity()
M.identity(), construit une matrice identité.
void add(matrice22 &M1, matrice22 &M2)
M = M1+M2, somme de 2 matrices 2x2 : M.add(M1,M2)
void view()
M.view(), affichage de la matrice.
void view(void)
affiche la matrice
void set(matrice44 &M)
setter par copie
structure pour les vecteurs 4D (de taille 4 = 3D + composante w).
float dot3(coord2d v1, coord2d v2)
float norm(void)
U.norm() renvoie la norme du vecteur U.
vecteur3d(float v)
constructeur U=(v,v,v)
vecteur3d()
constructeur par défaut (non initialisé)
structure pour les vecteurs 3D (de taille 3).
void ortho_inverse(matrice44 &M)
M.ortho_inverse(), calcul la matrice inverse associée à une transformation A.X+B où A est une matrice...
matrice22(float _m11, float _m12, float _m21, float _m22)
constructeur par valeur (en passant chaque valeur de la matrice)
matrice22()
constructeur par défaut (sans initialisation)
float norm2(void)
U.norm2() renvoie la norme du vecteur U au carré.
matrice44(float _m11, float _m12, float _m13, float _m14, float _m21, float _m22, float _m23, float _m24, float _m31, float _m32, float _m33, float _m34, float _m41, float _m42, float _m43, float _m44)
constructeur par valeur (en passant chaque valeur de la matrice)
vecteur3d & operator*=(const vecteur3d &v)
permet l'écriture U *= V. Multiplication de vecteurs par composante.
coord2d & operator-=(const coord2d &v)
bool normalize(void)
U.normalize() normalisation (sur place). Retourne faux si la norme est nulle.
vecteur3d & operator*=(const float v)
permet l'ecriture U *= v. Multiplication d'un vecteur par un scalaire.
coord2d operator-(const coord2d &v1, const coord2d &v2)
float determinant(void)
M.determinant(), retourne le déterminant de la matrice 4x4 M.
void mul(float v)
U.mul(v) multiplie (en place) U par le scalaire v.
bool normalize(const float nrm)
U.normalize(norm) normalisation (sur place) en passant la norme. Retourne faux si la norme est nulle...
vecteur3d & operator-=(const vecteur3d &v)
permet l'écriture U -= V. Addition de vecteurs par composante.
bool normalize(const float nrm)
U.normalize(norm) normalisation (sur place) en passant la norme. Retourne faux si la norme est nulle...
void diff(matrice22 &M1, matrice22 &M2)
M = M1-M2, difference de 2 matrices 2x2 : M.diff(M1,M2)
bool normalize2(const float nrm2)
U.normalize(norm2) normalisation (sur place) en passant la norme au carré. Retourne faux si la norme ...
bool inverse(matrice44 &M)
M.inverse(), inversion sur place de la matrice M. Renvoie true en cas de succès, false sinon...
float norm(void)
U.norm() renvoie la norme du vecteur U.
vecteur3d operator+(const vecteur3d &v1, const vecteur3d &v2)
permet l'écriture U=V1+V2. Addition de vecteurs par composante.
void set(float _m11, float _m12, float _m13, float _m14, float _m21, float _m22, float _m23, float _m24, float _m31, float _m32, float _m33, float _m34, float _m41, float _m42, float _m43, float _m44)
setter avec valeurs
void set(float v)
U.set(v) equivalent de U.set(v,v,v)
void zero()
M.zero(), mise à zéro de la matrice.
void translate(float a, float b, float c)
M.translate(V), construit la matrice de transformation 4x4 associée à une translation de vecteur (a...
void set(vecteur3d &_v, float _w)
U.set(V,w) fixe les composantes du vecteur à partir d'un vecteur 3D et d'une composante w...
float det(void)
calcul du déterminant: det = M.det()
void translate(vecteur3d v)
M.translate(V), construit la matrice de transformation 4x4 associée à une translation de vecteur V...
structure pour les matrices 4x4
vecteur3d & operator+=(const vecteur3d &v)
permet l'écriture U += V. Addition de vecteurs par composante.
void imul(matrice22 &M1, matrice22 &M2)
M = - M1*M2, opposé de la multiplication de 2 matrices 2x2 : M.imul(M1,M2)
int sign(int x)
renvoie le signe d'un entier (-1 si négatif, +1 si position, 0 si nul).
void mul(matrice22 &M1, matrice22 &M2)
M = M1*M2, multiplication de 2 matrices 2x2 : M.mul(M1,M2)
float clamp(float x)
seuillage: 0 si x<0, 1 si x>1, x sinon.
vecteur3d & operator=(const vecteur3d &v)
permet l'écriture U = V. Egalité de vecteurs par composante.
bool normalize2(const float nrm2)
U.normalize(norm2) normalisation (sur place) en passant la norme au carré. Retourne faux si la norme ...
void mul(float v)
U.mul(v) multiplie (en place) U par le scalaire v.
structure pour les matrices 2x2 : elles sont utilisées pour l'inversion par bloc de matrice 4x4...
float norm2(void)
U.norm2() renvoie la norme du vecteur U au carré.
vecteur4d(float _x, float _y, float _z, float _w)
constructeur U=(x,y,z,w)
void scale(float a, float b, float c)
M.scale(a,b,c), construit une matrice de mise à l'échelle de facteur (a,b,c) respectivement pour les ...