gKit2 light

- Main Page
- Related Pages
- Modules
- Classes
- Files

- Class List
- Class Index
- Class Hierarchy
- Class Members

Public Member Functions | Public Attributes | List of all members
Transform Struct Reference
manipulations de points, vecteur, matrices, transformations

representation d'une transformation, une matrice 4x4, organisee par ligne / row major. More...

`#include <mat.h>`

## Public Member Functions
| Transform (const float t00=1.f, const float t01=0.f, const float t02=0.f, const float t03=0.f, const float t10=0.f, const float t11=1.f, const float t12=0.f, const float t13=0.f, const float t20=0.f, const float t21=0.f, const float t22=1.f, const float t23=0.f, const float t30=0.f, const float t31=0.f, const float t32=0.f, const float t33=1.f)
| constructeur. More...
Point | operator() (const Point &p) const
| renvoie le point transforme. More...
Vector | operator() (const Vector &v) const
| renvoie le vecteur transforme. More...
vec4 | operator() (const vec4 &v) const
| renvoie le point/vecteur homogene transforme. More...
Transform | transpose () const
| renvoie la transposee de la matrice. More...
Transform | inverse () const
| renvoie l'inverse de la matrice. More...
Transform | normal () const
| renvoie la transformation a appliquer aux normales d'un objet transforme par la matrice m. More...
const float * | buffer () const
| renvoie l'adresse de la premiere valeur de la matrice. More...

## Public Attributes
float | m [4][4]

## Detailed Description

representation d'une transformation, une matrice 4x4, organisee par ligne / row major.

Definition at line 20 of file mat.h.

## Constructor & Destructor Documentation

Transform::Transform | ( | const float | t00 = `1.f`,
|  | const float | t01 = `0.f`,
|  | const float | t02 = `0.f`,
|  | const float | t03 = `0.f`,
|  | const float | t10 = `0.f`,
|  | const float | t11 = `1.f`,
|  | const float | t12 = `0.f`,
|  | const float | t13 = `0.f`,
|  | const float | t20 = `0.f`,
|  | const float | t21 = `0.f`,
|  | const float | t22 = `1.f`,
|  | const float | t23 = `0.f`,
|  | const float | t30 = `0.f`,
|  | const float | t31 = `0.f`,
|  | const float | t32 = `0.f`,
|  | const float | t33 = `1.f`
| ) |  |

constructeur.

Definition at line 23 of file mat.cpp.

28 {
29 m[0][0]= t00; m[0][1]= t01; m[0][2]= t02; m[0][3]= t03;
30 m[1][0]= t10; m[1][1]= t11; m[1][2]= t12; m[1][3]= t13;
31 m[2][0]= t20; m[2][1]= t21; m[2][2]= t22; m[2][3]= t23;
32 m[3][0]= t30; m[3][1]= t31; m[3][2]= t32; m[3][3]= t33;
33 }

## Member Function Documentation

Point Transform::operator() | ( | const Point & | p | ) | const

renvoie le point transforme.

Definition at line 36 of file mat.cpp.

37 {
38 float x= p.x;
39 float y= p.y;
40 float z= p.z;
41
42 float xt= m[0][0] * x + m[0][1] * y + m[0][2] * z + m[0][3]; // dot(vec4(m[0]), vec4(p, 1))
43 float yt= m[1][0] * x + m[1][1] * y + m[1][2] * z + m[1][3]; // dot(vec4(m[1]), vec4(p, 1))
44 float zt= m[2][0] * x + m[2][1] * y + m[2][2] * z + m[2][3]; // dot(vec4(m[2]), vec4(p, 1))
45 float wt= m[3][0] * x + m[3][1] * y + m[3][2] * z + m[3][3]; // dot(vec4(m[3]), vec4(p, 1))
46
47 assert(wt != 0);
48 float w= 1.f / wt;
49 if(wt == 1.f)
50 return Point(xt, yt, zt);
51 else
52 return Point(xt*w, yt*w, zt*w);
53 }
Point
representation d'un point 3d.
Definition: vec.h:19

Vector Transform::operator() | ( | const Vector & | v | ) | const

renvoie le vecteur transforme.

Definition at line 56 of file mat.cpp.

57 {
58 float x= v.x;
59 float y= v.y;
60 float z= v.z;
61
62 float xt= m[0][0] * x + m[0][1] * y + m[0][2] * z; // dot(vec4(m[0]), vec4(v, 0))
63 float yt= m[1][0] * x + m[1][1] * y + m[1][2] * z; // dot(vec4(m[1]), vec4(v, 0))
64 float zt= m[2][0] * x + m[2][1] * y + m[2][2] * z; // dot(vec4(m[2]), vec4(v, 0))
65 // dot(vec4(m[3]), vec4(v, 0)) == dot(vec4(0, 0, 0, 1), vec4(v, 0)) == 0 par definition
66
67 return Vector(xt, yt, zt);
68 }
Vector
representation d'un vecteur 3d.
Definition: vec.h:42

vec4 Transform::operator() | ( | const vec4 & | v | ) | const

renvoie le point/vecteur homogene transforme.

Definition at line 71 of file mat.cpp.

72 {
73 float x= v.x;
74 float y= v.y;
75 float z= v.z;
76 float w= v.w;
77
78 float xt= m[0][0] * x + m[0][1] * y + m[0][2] * z + m[0][3] * w; // dot(vec4(m[0]), v)
79 float yt= m[1][0] * x + m[1][1] * y + m[1][2] * z + m[1][3] * w; // dot(vec4(m[1]), v)
80 float zt= m[2][0] * x + m[2][1] * y + m[2][2] * z + m[2][3] * w; // dot(vec4(m[2]), v)
81 float wt= m[3][0] * x + m[3][1] * y + m[3][2] * z + m[3][3] * w; // dot(vec4(m[3]), v)
82
83 return vec4(xt, yt, zt, wt);
84 }
vec4
vecteur generique 4d, ou 3d homogene, utilitaire.
Definition: vec.h:121

Transform Transform::transpose | ( |  | ) | const

renvoie la transposee de la matrice.

Definition at line 87 of file mat.cpp.

88 {
89 return Transform(
90 m[0][0], m[1][0], m[2][0], m[3][0],
91 m[0][1], m[1][1], m[2][1], m[3][1],
92 m[0][2], m[1][2], m[2][2], m[3][2],
93 m[0][3], m[1][3], m[2][3], m[3][3]);
94 }
Transform::Transform
Transform(const float t00=1.f, const float t01=0.f, const float t02=0.f, const float t03=0.f, const float t10=0.f, const float t11=1.f, const float t12=0.f, const float t13=0.f, const float t20=0.f, const float t21=0.f, const float t22=1.f, const float t23=0.f, const float t30=0.f, const float t31=0.f, const float t32=0.f, const float t33=1.f)
constructeur.
Definition: mat.cpp:23

Transform Transform::inverse | ( |  | ) | const

renvoie l'inverse de la matrice.

Definition at line 263 of file mat.cpp.

264 {
265 Transform minv= *this;
266
267 int indxc[4], indxr[4];
268 int ipiv[4] = { 0, 0, 0, 0 };
269
270 for (int i = 0; i < 4; i++) {
271 int irow = -1, icol = -1;
272 float big = 0.f;
273
274 // Choose pivot
275 for (int j = 0; j < 4; j++) {
276 if (ipiv[j] != 1) {
277 for (int k = 0; k < 4; k++) {
278 if (ipiv[k] == 0) {
279 if (fabsf(minv.m[j][k]) >= big) {
280 big = std::abs(minv.m[j][k]);
281 irow = j;
282 icol = k;
283 }
284 }
285 else if (ipiv[k] > 1)
286 printf("singular matrix in make_inverse()\n");
287 }
288 }
289 }
290
291 assert(irow >= 0 && irow < 4);
292 assert(icol >= 0 && icol < 4);
293
294 ++ipiv[icol];
295 // Swap rows _irow_ and _icol_ for pivot
296 if (irow != icol) {
297 for (int k = 0; k < 4; ++k)
298 std::swap(minv.m[irow][k], minv.m[icol][k]);
299 }
300
301 indxr[i] = irow;
302 indxc[i] = icol;
303 if (minv.m[icol][icol] == 0.)
304 printf("singular matrix in make_inverse()\n");
305
306 // Set $m[icol][icol]$ to one by scaling row _icol_ appropriately
307 float pivinv = 1.f / minv.m[icol][icol];
308 minv.m[icol][icol] = 1.f;
309 for (int j = 0; j < 4; j++)
310 minv.m[icol][j] *= pivinv;
311
312 // Subtract this row from others to zero out their columns
313 for (int j = 0; j < 4; j++) {
314 if (j != icol) {
315 float save = minv.m[j][icol];
316 minv.m[j][icol] = 0;
317 for (int k = 0; k < 4; k++)
318 minv.m[j][k] -= minv.m[icol][k]*save;
319 }
320 }
321 }
322
323 // Swap columns to reflect permutation
324 for (int j = 3; j >= 0; j--) {
325 if (indxr[j] != indxc[j]) {
326 for (int k = 0; k < 4; k++)
327 std::swap(minv.m[k][indxr[j]], minv.m[k][indxc[j]]);
328 }
329 }
330
331 return minv;
332 }
printf
void printf(Text &text, const int px, const int py, const char *format,...)
affiche un texte a la position x, y. meme utilisation que printf().
Definition: text.cpp:140
Transform
representation d'une transformation, une matrice 4x4, organisee par ligne / row major.
Definition: mat.h:20

Transform Transform::normal | ( |  | ) | const

renvoie la transformation a appliquer aux normales d'un objet transforme par la matrice m.

Definition at line 97 of file mat.cpp.

98 {
99 return inverse().transpose();
100 }
Transform::inverse
Transform inverse() const
renvoie l'inverse de la matrice.
Definition: mat.cpp:263
Transform::transpose
Transform transpose() const
renvoie la transposee de la matrice.
Definition: mat.cpp:87

const float* Transform::buffer | ( |  | ) | const
| inline

renvoie l'adresse de la premiere valeur de la matrice.

Definition at line 44 of file mat.h.

44 { return &m[0][0]; }

The documentation for this struct was generated from the following files:

- src/gKit/mat.h
- src/gKit/mat.cpp