gKit2 light
Files | Classes | Functions
manipulations de points, vecteur, matrices, transformations

Files

file  mat.h
 
file  vec.h
 

Classes

struct  Transform
 representation d'une transformation, une matrice 4x4, organisee par ligne / row major. More...
 
struct  Point
 representation d'un point 3d. More...
 
struct  Vector
 representation d'un vecteur 3d. More...
 
struct  vec2
 vecteur generique, utilitaire. More...
 
struct  vec3
 vecteur generique, utilitaire. More...
 
struct  vec4
 vecteur generique 4d, ou 3d homogene, utilitaire. More...
 

Functions

float radians (const float deg)
 conversion en radians. More...
 
float degrees (const float rad)
 conversion en degres. More...
 
Transform Identity ()
 construit la transformation identite. More...
 
Transform Transpose (const Transform &m)
 renvoie la transposee de la matrice. More...
 
Transform Inverse (const Transform &m)
 renvoie l'inverse de la matrice. More...
 
Transform Normal (const Transform &m)
 renvoie la transformation a appliquer aux normales d'un objet transforme par la matrice m. More...
 
Transform Scale (const float x, const float y, const float z)
 renvoie la matrice representant une mise a l'echelle / etirement. More...
 
Transform Translation (const Vector &v)
 renvoie la matrice representant une translation par un vecteur. More...
 
Transform Translation (const float x, const float y, const float z)
 renvoie la matrice representant une translation par un vecteur x y z. More...
 
Transform RotationX (const float angle)
 renvoie la matrice representation une rotation de angle degree autour de l'axe X. More...
 
Transform RotationY (const float angle)
 renvoie la matrice representation une rotation de a degree autour de l'axe Y. More...
 
Transform RotationZ (const float angle)
 renvoie la matrice representation une rotation de angle degree autour de l'axe Z. More...
 
Transform Rotation (const Vector &axis, const float angle)
 renvoie la matrice representation une rotation de angle degree autour de l'axe axis. More...
 
Transform Viewport (const float width, const float height)
 renvoie la matrice representant une transformation viewport. More...
 
Transform Perspective (const float fov, const float aspect, const float znear, const float zfar)
 renvoie la matrice representant une transformation projection perspective. More...
 
Transform Lookat (const Point &from, const Point &to, const Vector &up)
 renvoie la matrice representant le placement et l'orientation d'une camera pour observer le point to. More...
 
Transform compose_transform (const Transform &a, const Transform &b)
 renvoie la composition des transformations a et b, t= a * b. More...
 
Transform operator* (const Transform &a, const Transform &b)
 renvoie la composition des transformations a et b, t = a * b. More...
 
float distance (const Point &a, const Point &b)
 renvoie la distance etre 2 points. More...
 
float distance2 (const Point &a, const Point &b)
 renvoie le carre de la distance etre 2 points. More...
 
Point center (const Point &a, const Point &b)
 renvoie le milieu du segment ab. More...
 
Vector normalize (const Vector &v)
 renvoie un vecteur unitaire / longueur == 1. More...
 
Vector cross (const Vector &u, const Vector &v)
 renvoie le produit vectoriel de 2 vecteurs. More...
 
float dot (const Vector &u, const Vector &v)
 renvoie le produit scalaire de 2 vecteurs. More...
 
float length (const Vector &v)
 renvoie la longueur d'un vecteur. More...
 
float length2 (const Vector &v)
 renvoie la carre de la longueur d'un vecteur. More...
 
Vector operator- (const Point &a, const Point &b)
 renvoie le vecteur a - b. More...
 
Vector operator- (const Vector &v)
 renvoie le vecteur -v. More...
 
Point operator+ (const Point &a, const Vector &v)
 renvoie le point a+v. More...
 
Point operator+ (const Vector &v, const Point &a)
 renvoie le point a+v. More...
 
Point operator- (const Vector &v, const Point &a)
 renvoie le point a-v. More...
 
Point operator- (const Point &a, const Vector &v)
 renvoie le point a-v. More...
 
Vector operator+ (const Vector &u, const Vector &v)
 renvoie le vecteur u+v. More...
 
Vector operator- (const Vector &u, const Vector &v)
 renvoie le vecteur u-v. More...
 
Vector operator* (const float k, const Vector &v)
 renvoie le vecteur k*u; More...
 
Vector operator* (const Vector &v, const float k)
 renvoie le vecteur k*v; More...
 
Vector operator/ (const Vector &v, const float k)
 renvoie le vecteur v/k; More...
 
std::ostream & operator<< (std::ostream &o, const Point &p)
 
std::ostream & operator<< (std::ostream &o, const Vector &v)
 
 Point::Point (const vec3 &v)
 cree un point a partir des coordonnees du vecteur generique (v.x, v.y, v.z). More...
 
 Point::Point (const Vector &v)
 cree un point a partir des coordonnes du vecteur (v.x, v.y, v.z). More...
 
 Vector::Vector (const vec3 &v)
 cree un vecteur a partir des coordonnees du vecteur generique (v.x, v.y, v.z). More...
 
 Vector::Vector (const Point &a)
 cree un vecteur a partir des coordonnes du vecteur (v.x, v.y, v.z). More...
 
 vec3::vec3 (const Point &a)
 cree un vecteur generique a partir des coordonnees du point a. More...
 
 vec3::vec3 (const Vector &v)
 cree un vecteur generique a partir des coordonnees du vecteur v. More...
 
 vec4::vec4 (const Point &a)
 cree un vecteur generique a partir des coordonnees du point a, (a.x, a.y, a.z, 1). More...
 
 vec4::vec4 (const Vector &v)
 cree un vecteur generique a partir des coordonnees du vecteur v, (v.x, v.y, v.z, 0). More...
 

Detailed Description

Function Documentation

float radians ( const float  deg)

conversion en radians.

Definition at line 11 of file mat.cpp.

12 {
13  const float pi = 3.1415926535f;
14  return (pi / 180.f) * deg;
15 }
float degrees ( const float  rad)

conversion en degres.

Definition at line 17 of file mat.cpp.

18 {
19  const float pi = 3.1415926535f;
20  return (180.f / pi) * rad;
21 }
Transform Identity ( )

construit la transformation identite.

Definition at line 103 of file mat.cpp.

104 {
105  return Transform();
106 }
representation d'une transformation, une matrice 4x4, organisee par ligne / row major.
Definition: mat.h:20
Transform Transpose ( const Transform m)

renvoie la transposee de la matrice.

Definition at line 108 of file mat.cpp.

109 {
110  return m.transpose();
111 }
Transform transpose() const
renvoie la transposee de la matrice.
Definition: mat.cpp:87
Transform Inverse ( const Transform m)

renvoie l'inverse de la matrice.

Definition at line 113 of file mat.cpp.

114 {
115  return m.inverse();
116 }
Transform inverse() const
renvoie l'inverse de la matrice.
Definition: mat.cpp:263
Transform Normal ( const Transform m)

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

Definition at line 118 of file mat.cpp.

119 {
120  return m.normal();
121 }
Transform normal() const
renvoie la transformation a appliquer aux normales d'un objet transforme par la matrice m...
Definition: mat.cpp:97
Transform Scale ( const float  x,
const float  y,
const float  z 
)

renvoie la matrice representant une mise a l'echelle / etirement.

Definition at line 123 of file mat.cpp.

124 {
125  return Transform(
126  x, 0, 0, 0,
127  0, y, 0, 0,
128  0, 0, z, 0,
129  0, 0, 0, 1);
130 }
representation d'une transformation, une matrice 4x4, organisee par ligne / row major.
Definition: mat.h:20
Transform Translation ( const Vector v)

renvoie la matrice representant une translation par un vecteur.

Definition at line 132 of file mat.cpp.

133 {
134  return Transform(
135  1, 0, 0, v.x,
136  0, 1, 0, v.y,
137  0, 0, 1, v.z,
138  0, 0, 0, 1);
139 }
representation d'une transformation, une matrice 4x4, organisee par ligne / row major.
Definition: mat.h:20
Transform Translation ( const float  x,
const float  y,
const float  z 
)

renvoie la matrice representant une translation par un vecteur x y z.

Definition at line 141 of file mat.cpp.

142 {
143  return Translation( Vector(x, y, z) );
144 }
representation d'un vecteur 3d.
Definition: vec.h:42
Transform Translation(const Vector &v)
renvoie la matrice representant une translation par un vecteur.
Definition: mat.cpp:132
Transform RotationX ( const float  angle)

renvoie la matrice representation une rotation de angle degree autour de l'axe X.

Definition at line 146 of file mat.cpp.

147 {
148  float sin_t= sinf(radians(a));
149  float cos_t= cosf(radians(a));
150 
151  return Transform(
152  1, 0, 0, 0,
153  0, cos_t, -sin_t, 0,
154  0, sin_t, cos_t, 0,
155  0, 0, 0, 1 );
156 }
float radians(const float deg)
conversion en radians.
Definition: mat.cpp:11
representation d'une transformation, une matrice 4x4, organisee par ligne / row major.
Definition: mat.h:20
Transform RotationY ( const float  angle)

renvoie la matrice representation une rotation de a degree autour de l'axe Y.

Definition at line 158 of file mat.cpp.

159 {
160  float sin_t= sinf(radians(a));
161  float cos_t= cosf(radians(a));
162 
163  return Transform(
164  cos_t, 0, sin_t, 0,
165  0, 1, 0, 0,
166  -sin_t, 0, cos_t, 0,
167  0, 0, 0, 1 );
168 }
float radians(const float deg)
conversion en radians.
Definition: mat.cpp:11
representation d'une transformation, une matrice 4x4, organisee par ligne / row major.
Definition: mat.h:20
Transform RotationZ ( const float  angle)

renvoie la matrice representation une rotation de angle degree autour de l'axe Z.

Definition at line 170 of file mat.cpp.

171 {
172  float sin_t= sinf(radians(a));
173  float cos_t= cosf(radians(a));
174 
175  return Transform(
176  cos_t, -sin_t, 0, 0,
177  sin_t, cos_t, 0, 0,
178  0, 0, 1, 0,
179  0, 0, 0, 1 );
180 }
float radians(const float deg)
conversion en radians.
Definition: mat.cpp:11
representation d'une transformation, une matrice 4x4, organisee par ligne / row major.
Definition: mat.h:20
Transform Rotation ( const Vector axis,
const float  angle 
)

renvoie la matrice representation une rotation de angle degree autour de l'axe axis.

Definition at line 182 of file mat.cpp.

183 {
184  Vector a= normalize(axis);
185  float s= sinf(radians(angle));
186  float c= cosf(radians(angle));
187 
188  return Transform(
189  a.x * a.x + (1 - a.x * a.x ) * c,
190  a.x * a.y * (1 - c ) - a.z * s,
191  a.x * a.z * (1 - c ) + a.y * s,
192  0,
193 
194  a.x * a.y * (1 - c ) + a.z * s,
195  a.y * a.y + (1 - a.y * a.y ) * c,
196  a.y * a.z * (1 - c ) - a.x * s,
197  0,
198 
199  a.x * a.z * (1 - c ) - a.y * s,
200  a.y * a.z * (1 - c ) + a.x * s,
201  a.z * a.z + (1 - a.z * a.z ) * c,
202  0,
203 
204  0, 0, 0, 1);
205 }
Vector normalize(const Vector &v)
renvoie un vecteur unitaire / longueur == 1.
Definition: vec.cpp:79
float radians(const float deg)
conversion en radians.
Definition: mat.cpp:11
representation d'un vecteur 3d.
Definition: vec.h:42
representation d'une transformation, une matrice 4x4, organisee par ligne / row major.
Definition: mat.h:20
Transform Viewport ( const float  width,
const float  height 
)

renvoie la matrice representant une transformation viewport.

Definition at line 221 of file mat.cpp.

222 {
223  float w= width / 2.f;
224  float h= height / 2.f;
225 
226  return Transform(
227  w, 0, 0, w,
228  0, h, 0, h,
229  0, 0, .5f, .5f,
230  0, 0, 0, 1);
231 }
representation d'une transformation, une matrice 4x4, organisee par ligne / row major.
Definition: mat.h:20
Transform Perspective ( const float  fov,
const float  aspect,
const float  znear,
const float  zfar 
)

renvoie la matrice representant une transformation projection perspective.

Definition at line 208 of file mat.cpp.

209 {
210  // perspective, openGL version
211  float itan= 1 / tanf(radians(fov) * 0.5f);
212  float id= 1 / (znear - zfar);
213 
214  return Transform(
215  itan/aspect, 0, 0, 0,
216  0, itan, 0, 0,
217  0, 0, (zfar+znear)*id, 2.f*zfar*znear*id,
218  0, 0, -1, 0);
219 }
float radians(const float deg)
conversion en radians.
Definition: mat.cpp:11
representation d'une transformation, une matrice 4x4, organisee par ligne / row major.
Definition: mat.h:20
Transform Lookat ( const Point from,
const Point to,
const Vector up 
)

renvoie la matrice representant le placement et l'orientation d'une camera pour observer le point to.

Definition at line 233 of file mat.cpp.

234 {
235  Vector dir= normalize( Vector(from, to) );
236  Vector right= normalize( cross(dir, normalize(up)) );
237  Vector newUp= normalize( cross(right, dir) );
238 
239  Transform m(
240  right.x, newUp.x, -dir.x, from.x,
241  right.y, newUp.y, -dir.y, from.y,
242  right.z, newUp.z, -dir.z, from.z,
243  0, 0, 0, 1);
244 
245  return m.inverse();
246 }
Vector normalize(const Vector &v)
renvoie un vecteur unitaire / longueur == 1.
Definition: vec.cpp:79
representation d'un vecteur 3d.
Definition: vec.h:42
representation d'une transformation, une matrice 4x4, organisee par ligne / row major.
Definition: mat.h:20
Vector cross(const Vector &u, const Vector &v)
renvoie le produit vectoriel de 2 vecteurs.
Definition: vec.cpp:85
Transform compose_transform ( const Transform a,
const Transform b 
)

renvoie la composition des transformations a et b, t= a * b.

Definition at line 248 of file mat.cpp.

249 {
250  Transform m;
251  for(int i = 0; i < 4; i++)
252  for(int j = 0; j < 4; j++)
253  m.m[i][j]= a.m[i][0] * b.m[0][j] + a.m[i][1] * b.m[1][j] + a.m[i][2] * b.m[2][j] + a.m[i][3] * b.m[3][j];
254 
255  return m;
256 }
representation d'une transformation, une matrice 4x4, organisee par ligne / row major.
Definition: mat.h:20
Transform operator* ( const Transform a,
const Transform b 
)

renvoie la composition des transformations a et b, t = a * b.

Definition at line 258 of file mat.cpp.

259 {
260  return compose_transform(a, b);
261 }
Transform compose_transform(const Transform &a, const Transform &b)
renvoie la composition des transformations a et b, t= a * b.
Definition: mat.cpp:248
float distance ( const Point a,
const Point b 
)

renvoie la distance etre 2 points.

Definition at line 7 of file vec.cpp.

8 {
9  return length(a - b);
10 }
float length(const Vector &v)
renvoie la longueur d'un vecteur.
Definition: vec.cpp:98
float distance2 ( const Point a,
const Point b 
)

renvoie le carre de la distance etre 2 points.

Definition at line 12 of file vec.cpp.

13 {
14  return length2(a - b);
15 }
float length2(const Vector &v)
renvoie la carre de la longueur d'un vecteur.
Definition: vec.cpp:103
Point center ( const Point a,
const Point b 
)

renvoie le milieu du segment ab.

Definition at line 17 of file vec.cpp.

18 {
19  return Point((a.x + b.x) * 0.5f, (a.y + b.y) * 0.5f, (a.z + b.z) * 0.5f);
20 }
representation d'un point 3d.
Definition: vec.h:19
Vector normalize ( const Vector v)

renvoie un vecteur unitaire / longueur == 1.

Definition at line 79 of file vec.cpp.

80 {
81  float kk= 1 / length(v);
82  return kk * v;
83 }
float length(const Vector &v)
renvoie la longueur d'un vecteur.
Definition: vec.cpp:98
Vector cross ( const Vector u,
const Vector v 
)

renvoie le produit vectoriel de 2 vecteurs.

Definition at line 85 of file vec.cpp.

86 {
87  return Vector(
88  (u.y * v.z) - (u.z * v.y),
89  (u.z * v.x) - (u.x * v.z),
90  (u.x * v.y) - (u.y * v.x));
91 }
representation d'un vecteur 3d.
Definition: vec.h:42
float dot ( const Vector u,
const Vector v 
)

renvoie le produit scalaire de 2 vecteurs.

Definition at line 93 of file vec.cpp.

94 {
95  return u.x * v.x + u.y * v.y + u.z * v.z;
96 }
float length ( const Vector v)

renvoie la longueur d'un vecteur.

Definition at line 98 of file vec.cpp.

99 {
100  return std::sqrt(length2(v));
101 }
float length2(const Vector &v)
renvoie la carre de la longueur d'un vecteur.
Definition: vec.cpp:103
float length2 ( const Vector v)

renvoie la carre de la longueur d'un vecteur.

Definition at line 103 of file vec.cpp.

104 {
105  return v.x * v.x + v.y * v.y + v.z * v.z;
106 }
Vector operator- ( const Point a,
const Point b 
)

renvoie le vecteur a - b.

Definition at line 22 of file vec.cpp.

23 {
24  //~ return make_vector(a.x - b.x, a.y - b.y, a.z - b.z);
25  return Vector(a.x - b.x, a.y - b.y, a.z - b.z);
26 }
representation d'un vecteur 3d.
Definition: vec.h:42
Vector operator- ( const Vector v)

renvoie le vecteur -v.

Definition at line 28 of file vec.cpp.

29 {
30  return Vector(-v.x, -v.y, -v.z);
31 }
representation d'un vecteur 3d.
Definition: vec.h:42
Point operator+ ( const Point a,
const Vector v 
)

renvoie le point a+v.

Definition at line 33 of file vec.cpp.

34 {
35  return Point(a.x + v.x, a.y + v.y, a.z + v.z);
36 }
representation d'un point 3d.
Definition: vec.h:19
Point operator+ ( const Vector v,
const Point a 
)

renvoie le point a+v.

Definition at line 38 of file vec.cpp.

39 {
40  return a + v;
41 }
Point operator- ( const Vector v,
const Point a 
)

renvoie le point a-v.

Definition at line 43 of file vec.cpp.

44 {
45  return a + (-v);
46 }
Point operator- ( const Point a,
const Vector v 
)

renvoie le point a-v.

Definition at line 48 of file vec.cpp.

49 {
50  return a + (-v);
51 }
Vector operator+ ( const Vector u,
const Vector v 
)

renvoie le vecteur u+v.

Definition at line 53 of file vec.cpp.

54 {
55  return Vector(u.x + v.x, u.y + v.y, u.z + v.z);
56 }
representation d'un vecteur 3d.
Definition: vec.h:42
Vector operator- ( const Vector u,
const Vector v 
)

renvoie le vecteur u-v.

Definition at line 58 of file vec.cpp.

59 {
60  return Vector(u.x - v.x, u.y - v.y, u.z - v.z);
61 }
representation d'un vecteur 3d.
Definition: vec.h:42
Vector operator* ( const float  k,
const Vector v 
)

renvoie le vecteur k*u;

Definition at line 63 of file vec.cpp.

64 {
65  return Vector(k * v.x, k * v.y, k * v.z);
66 }
representation d'un vecteur 3d.
Definition: vec.h:42
Vector operator* ( const Vector v,
const float  k 
)

renvoie le vecteur k*v;

Definition at line 68 of file vec.cpp.

69 {
70  return k * v;
71 }
Vector operator/ ( const Vector v,
const float  k 
)

renvoie le vecteur v/k;

Definition at line 73 of file vec.cpp.

74 {
75  float kk= 1 / k;
76  return kk * v;
77 }
Point::Point ( const vec3 v)
inlineexplicit

cree un point a partir des coordonnees du vecteur generique (v.x, v.y, v.z).

Definition at line 140 of file vec.h.

140 : x(v.x), y(v.y), z(v.z) {}
Point::Point ( const Vector v)
inlineexplicit

cree un point a partir des coordonnes du vecteur (v.x, v.y, v.z).

Definition at line 141 of file vec.h.

141 : x(v.x), y(v.y), z(v.z) {}
Vector::Vector ( const vec3 v)
inlineexplicit

cree un vecteur a partir des coordonnees du vecteur generique (v.x, v.y, v.z).

Definition at line 143 of file vec.h.

143 : x(v.x), y(v.y), z(v.z) {}
Vector::Vector ( const Point a)
inlineexplicit

cree un vecteur a partir des coordonnes du vecteur (v.x, v.y, v.z).

Definition at line 144 of file vec.h.

144 : x(a.x), y(a.y), z(a.z) {}
vec3::vec3 ( const Point a)
inlineexplicit

cree un vecteur generique a partir des coordonnees du point a.

Definition at line 146 of file vec.h.

146 : x(a.x), y(a.y), z(a.z) {}
vec3::vec3 ( const Vector v)
inlineexplicit

cree un vecteur generique a partir des coordonnees du vecteur v.

Definition at line 147 of file vec.h.

147 : x(v.x), y(v.y), z(v.z) {}
vec4::vec4 ( const Point a)
inlineexplicit

cree un vecteur generique a partir des coordonnees du point a, (a.x, a.y, a.z, 1).

Definition at line 149 of file vec.h.

149 : x(a.x), y(a.y), z(a.z), w(1.f) {}
vec4::vec4 ( const Vector v)
inlineexplicit

cree un vecteur generique a partir des coordonnees du vecteur v, (v.x, v.y, v.z, 0).

Definition at line 150 of file vec.h.

150 : x(v.x), y(v.y), z(v.z), w(0.f) {}