gKit2 light
Loading...
Searching...
No Matches
manipulations de points, vecteur, matrices, transformations

Files

file  src/gKit/mat.h
file  src/gKit/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.
float degrees (const float rad)
 conversion en degres.
Transform Identity ()
 construit la transformation identite.
Transform Transpose (const Transform &m)
 renvoie la transposee de la matrice.
Transform Inverse (const Transform &m)
 renvoie l'inverse de la matrice.
Transform Normal (const Transform &m)
 renvoie la transformation a appliquer aux normales d'un objet transforme par la matrice m.
Transform Scale (const float x, const float y, const float z)
 renvoie la matrice representant une mise a l'echelle / etirement.
Transform Scale (const float s)
Transform Translation (const Vector &v)
 renvoie la matrice representant une translation par un vecteur.
Transform Translation (const float x, const float y, const float z)
 renvoie la matrice representant une translation par un vecteur x y z.
Transform RotationX (const float angle)
 renvoie la matrice representation une rotation de angle degree autour de l'axe X.
Transform RotationY (const float angle)
 renvoie la matrice representation une rotation de a degree autour de l'axe Y.
Transform RotationZ (const float angle)
 renvoie la matrice representation une rotation de angle degree autour de l'axe Z.
Transform Rotation (const Vector &axis, const float angle)
 renvoie la matrice representation une rotation de angle degree autour de l'axe axis.
Transform Rotation (const Vector &u, const Vector &v)
 renvoie la matrice de rotation entre u et v.
Transform Viewport (const float width, const float height)
 renvoie la matrice representant une transformation viewport.
Transform Perspective (const float fov, const float aspect, const float znear, const float zfar)
 renvoie la matrice representant une transformation projection perspective.
Transform Ortho (const float left, const float right, const float bottom, const float top, const float znear, const float zfar)
 renvoie la matrice representant une transformation orthographique, passage d'un cube []x[]x[] vers [-1 1]x[-1 1]x[-1 1].
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.
Transform compose_transform (const Transform &a, const Transform &b)
 renvoie la composition des transformations a et b, t= a * b.
Transform operator* (const Transform &a, const Transform &b)
 renvoie la composition des transformations a et b, t = a * b.
std::ostream & operator<< (std::ostream &o, const Transform &t)
Point Origin ()
 renvoie le point origine (0, 0, 0)
float distance (const Point &a, const Point &b)
 renvoie la distance etre 2 points.
float distance2 (const Point &a, const Point &b)
 renvoie le carre de la distance etre 2 points.
Point center (const Point &a, const Point &b)
 renvoie le milieu du segment ab.
Point min (const Point &a, const Point &b)
 renvoie la plus petite composante de chaque point { min(a.x, b.x), min(a.y, b.y), min(a.z, b.z) }.
Point max (const Point &a, const Point &b)
 renvoie la plus grande composante de chaque point { max(a.x, b.x), max(a.y, b.y), max(a.z, b.z) }.
Vector min (const Vector &a, const Vector &b)
 renvoie la plus petite composante de chaque vecteur { min(a.x, b.x), min(a.y, b.y), min(a.z, b.z) }.
Vector max (const Vector &a, const Vector &b)
 renvoie la plus grande composante de chaque vecteur { max(a.x, b.x), max(a.y, b.y), max(a.z, b.z) }.
void minmax (const Vector &a, const Vector &b, Vector &vmin, Vector &vmax)
 renvoie min(a, b) dans vmin, et max(a, b) dans vmax. mais en plus rapide.
Vector normalize (const Vector &v)
 renvoie un vecteur unitaire / longueur == 1.
Vector cross (const Vector &u, const Vector &v)
 renvoie le produit vectoriel de 2 vecteurs.
float dot (const Vector &u, const Vector &v)
 renvoie le produit scalaire de 2 vecteurs.
float length (const Vector &v)
 renvoie la longueur d'un vecteur.
float length2 (const Vector &v)
 renvoie la carre de la longueur d'un vecteur.
Vector operator- (const Point &a, const Point &b)
 renvoie le vecteur a - b.
Point operator+ (const Point &a, const Point &b)
 renvoie le "point" a + b.
Point operator* (const float k, const Point &a)
 renvoie le "point" k*a;
Point operator* (const Point &a, const float k)
 renvoie le "point" a*k;
Point operator* (const Point &a, const Point &b)
 renvoie le "point" a*b;
Point operator/ (const Point &a, const float k)
 renvoie le "point" a/k;
Point operator/ (const float k, const Point &a)
 renvoie le "point" k/a;
Point operator/ (const Point &a, const Point &b)
 renvoie le "point" a/b;
Vector operator- (const Vector &v)
 renvoie le vecteur -v.
Point operator+ (const Point &a, const Vector &v)
 renvoie le point a+v.
Point operator+ (const Vector &v, const Point &a)
 renvoie le point a+v.
Point operator- (const Vector &v, const Point &a)
 renvoie le point a-v.
Point operator- (const Point &a, const Vector &v)
 renvoie le point a-v.
Vector operator+ (const Vector &u, const Vector &v)
 renvoie le vecteur u+v.
Vector operator- (const Vector &u, const Vector &v)
 renvoie le vecteur u-v.
Vector operator+ (const float k, const Vector &v)
 renvoie le vecteur u+k;
Vector operator+ (const Vector &v, const float k)
Vector operator* (const float k, const Vector &v)
 renvoie le vecteur k*u;
Vector operator* (const Vector &v, const float k)
 renvoie le vecteur k*v;
Vector operator* (const Vector &a, const Vector &b)
 renvoie le vecteur (a.x*b.x, a.y*b.y, a.z*b.z ).
Vector operator/ (const Vector &v, const float k)
 renvoie le vecteur v/k;
Vector operator/ (const Vector &u, const Vector &v)
 renvoie le vecteur u/v;
std::ostream & operator<< (std::ostream &o, const Point &p)
std::ostream & operator<< (std::ostream &o, const Vector &v)
 Point::Point (const vec2 &v, const float z)
 Point::Point (const vec3 &v)
 cree un point a partir des coordonnees du vecteur generique (v.x, v.y, v.z).
 Point::Point (const vec4 &v)
 Point::Point (const Vector &v)
 cree un point a partir des coordonnes du vecteur (v.x, v.y, v.z).
 Vector::Vector (const vec3 &v)
 cree un vecteur a partir des coordonnees du vecteur generique (v.x, v.y, v.z).
 Vector::Vector (const vec4 &v)
 Vector::Vector (const Point &a)
 cree un vecteur a partir des coordonnes du point (a.x, a.y, a.z).
 vec2::vec2 (const vec3 &v)
 vec2::vec2 (const vec4 &v)
 vec3::vec3 (const vec4 &v)
 vec3::vec3 (const Point &a)
 cree un vecteur generique a partir des coordonnees du point a.
 vec3::vec3 (const Vector &v)
 cree un vecteur generique a partir des coordonnees du vecteur v.
 vec4::vec4 (const Point &a)
 cree un vecteur generique a partir des coordonnees du point a, (a.x, a.y, a.z, 1).
 vec4::vec4 (const Vector &v)
 cree un vecteur generique a partir des coordonnees du vecteur v, (v.x, v.y, v.z, 0).
float Point::operator() (const unsigned int i) const
 renvoie la ieme composante du point.
float Vector::operator() (const unsigned int i) const
 renvoie la ieme composante du vecteur.
float & Point::operator() (const unsigned int i)
float & Vector::operator() (const unsigned int i)

Detailed Description

Function Documentation

◆ radians()

float radians ( const float deg)

conversion en radians.

Definition at line 10 of file mat.cpp.

11{
12 return float(M_PI / 180) * angle;
13}

◆ degrees()

float degrees ( const float rad)

conversion en degres.

Definition at line 15 of file mat.cpp.

16{
17 return float(180 / M_PI) * angle;
18}

◆ Identity()

Transform Identity ( )

construit la transformation identite.

Definition at line 187 of file mat.cpp.

188{
189 return Transform();
190}
representation d'une transformation, une matrice 4x4, organisee par ligne / row major.
Definition mat.h:21

◆ Transpose()

Transform Transpose ( const Transform & m)

renvoie la transposee de la matrice.

Definition at line 192 of file mat.cpp.

193{
194 return m.transpose();
195}
Transform transpose() const
renvoie la transposee de la matrice.
Definition mat.cpp:165

◆ Inverse()

Transform Inverse ( const Transform & m)

renvoie l'inverse de la matrice.

Definition at line 197 of file mat.cpp.

198{
199 return m.inverse();
200}
Transform inverse() const
renvoie l'inverse de la matrice.
Definition mat.cpp:399

◆ Normal()

Transform Normal ( const Transform & m)

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

Definition at line 202 of file mat.cpp.

203{
204 return m.normal();
205}
Transform normal() const
renvoie la transformation a appliquer aux normales d'un objet transforme par la matrice m.
Definition mat.cpp:181

◆ Scale() [1/2]

Transform Scale ( const float x,
const float y,
const float z )

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

Definition at line 207 of file mat.cpp.

208{
209 return Transform(
210 x, 0, 0, 0,
211 0, y, 0, 0,
212 0, 0, z, 0,
213 0, 0, 0, 1);
214}

◆ Scale() [2/2]

Transform Scale ( const float s)
inline

Definition at line 92 of file mat.h.

92{ return Scale(s, s, s); }
Transform Scale(const float x, const float y, const float z)
renvoie la matrice representant une mise a l'echelle / etirement.
Definition mat.cpp:207

◆ Translation() [1/2]

Transform Translation ( const Vector & v)

renvoie la matrice representant une translation par un vecteur.

Definition at line 216 of file mat.cpp.

217{
218 return Transform(
219 1, 0, 0, v.x,
220 0, 1, 0, v.y,
221 0, 0, 1, v.z,
222 0, 0, 0, 1);
223}

◆ Translation() [2/2]

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 225 of file mat.cpp.

226{
227 return Translation( Vector(x, y, z) );
228}
Transform Translation(const Vector &v)
renvoie la matrice representant une translation par un vecteur.
Definition mat.cpp:216
representation d'un vecteur 3d.
Definition vec.h:67

◆ RotationX()

Transform RotationX ( const float angle)

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

Definition at line 230 of file mat.cpp.

231{
232 float sin_t= sinf(radians(a));
233 float cos_t= cosf(radians(a));
234
235 return Transform(
236 1, 0, 0, 0,
237 0, cos_t, -sin_t, 0,
238 0, sin_t, cos_t, 0,
239 0, 0, 0, 1 );
240}
float radians(const float angle)
conversion en radians.
Definition mat.cpp:10

◆ RotationY()

Transform RotationY ( const float angle)

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

Definition at line 242 of file mat.cpp.

243{
244 float sin_t= sinf(radians(a));
245 float cos_t= cosf(radians(a));
246
247 return Transform(
248 cos_t, 0, sin_t, 0,
249 0, 1, 0, 0,
250 -sin_t, 0, cos_t, 0,
251 0, 0, 0, 1 );
252}

◆ RotationZ()

Transform RotationZ ( const float angle)

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

Definition at line 254 of file mat.cpp.

255{
256 float sin_t= sinf(radians(a));
257 float cos_t= cosf(radians(a));
258
259 return Transform(
260 cos_t, -sin_t, 0, 0,
261 sin_t, cos_t, 0, 0,
262 0, 0, 1, 0,
263 0, 0, 0, 1 );
264}

◆ Rotation() [1/2]

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 266 of file mat.cpp.

267{
268 Vector a= normalize(axis);
269 float s= sinf(radians(angle));
270 float c= cosf(radians(angle));
271
272 return Transform(
273 a.x * a.x + (1 - a.x * a.x ) * c,
274 a.x * a.y * (1 - c ) - a.z * s,
275 a.x * a.z * (1 - c ) + a.y * s,
276 0,
277
278 a.x * a.y * (1 - c ) + a.z * s,
279 a.y * a.y + (1 - a.y * a.y ) * c,
280 a.y * a.z * (1 - c ) - a.x * s,
281 0,
282
283 a.x * a.z * (1 - c ) - a.y * s,
284 a.y * a.z * (1 - c ) + a.x * s,
285 a.z * a.z + (1 - a.z * a.z ) * c,
286 0,
287
288 0, 0, 0, 1);
289}
Vector normalize(const Vector &v)
renvoie un vecteur unitaire / longueur == 1.
Definition vec.cpp:167

◆ Rotation() [2/2]

Transform Rotation ( const Vector & u,
const Vector & v )

renvoie la matrice de rotation entre u et v.

Todo
ajuster epsilon, ou trouver une autre formulation non degeneree...

Definition at line 292 of file mat.cpp.

293{
294 Vector a= normalize(u);
295 Vector b= normalize(v);
296 Vector w= cross(a, b); // rotation autour de w, un vecteur perpendiculaire a u et v
297 float s= length(w); // sin theta
298 float c= dot(a, b); // cos theta
299
300 // si u et v sont colineaires, pas d'axe de rotation, renvoyer +1 ou -1
301 if(s < float(0.00001))
303 return Scale(std::copysign(c, 1));
304
305 // normalise l'axe de rotation
306 w= w / s;
307
308 // meme matrice de rotation qu'au dessus , cf Rotation(axis, angle), l'axe est le vecteur w, s et c sont le sinus et le cosinus de l'angle
309 return Transform(
310 w.x * w.x + (1 - w.x * w.x ) * c,
311 w.x * w.y * (1 - c ) - w.z * s,
312 w.x * w.z * (1 - c ) + w.y * s,
313 0,
314
315 w.x * w.y * (1 - c ) + w.z * s,
316 w.y * w.y + (1 - w.y * w.y ) * c,
317 w.y * w.z * (1 - c ) - w.x * s,
318 0,
319
320 w.x * w.z * (1 - c ) - w.y * s,
321 w.y * w.z * (1 - c ) + w.x * s,
322 w.z * w.z + (1 - w.z * w.z ) * c,
323 0,
324
325 0, 0, 0, 1);
326}
float dot(const Vector &u, const Vector &v)
renvoie le produit scalaire de 2 vecteurs.
Definition vec.cpp:181
Vector cross(const Vector &u, const Vector &v)
renvoie le produit vectoriel de 2 vecteurs.
Definition vec.cpp:173

◆ Viewport()

Transform Viewport ( const float width,
const float height )

renvoie la matrice representant une transformation viewport.

Definition at line 357 of file mat.cpp.

358{
359 float w= width / 2.f;
360 float h= height / 2.f;
361
362 return Transform(
363 w, 0, 0, w,
364 0, h, 0, h,
365 0, 0, .5f, .5f,
366 0, 0, 0, 1);
367}

◆ Perspective()

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 329 of file mat.cpp.

330{
331 // perspective, openGL version
332 float itan= 1 / tanf(radians(fov) * 0.5f);
333 float id= 1 / (znear - zfar);
334
335 return Transform(
336 itan/aspect, 0, 0, 0,
337 0, itan, 0, 0,
338 0, 0, (zfar+znear)*id, 2.f*zfar*znear*id,
339 0, 0, -1, 0);
340}

◆ Ortho()

Transform Ortho ( const float left,
const float right,
const float bottom,
const float top,
const float znear,
const float zfar )

renvoie la matrice representant une transformation orthographique, passage d'un cube []x[]x[] vers [-1 1]x[-1 1]x[-1 1].

Definition at line 343 of file mat.cpp.

344{
345 float tx= - (right + left) / (right - left);
346 float ty= - (top + bottom) / (top - bottom);
347 float tz= - (zfar + znear) / (zfar - znear);
348
349 return Transform(
350 2.f / (right - left), 0, 0, tx,
351 0, 2.f / (top - bottom), 0, ty,
352 0, 0, -2.f / (zfar - znear), tz,
353 0, 0, 0, 1);
354}

◆ Lookat()

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 369 of file mat.cpp.

370{
371 Vector dir= normalize( Vector(from, to) );
372 Vector right= normalize( cross(dir, normalize(up)) );
373 Vector newUp= normalize( cross(right, dir) );
374
375 Transform m(
376 right.x, newUp.x, -dir.x, from.x,
377 right.y, newUp.y, -dir.y, from.y,
378 right.z, newUp.z, -dir.z, from.z,
379 0, 0, 0, 1);
380
381 return m.inverse();
382}

◆ compose_transform()

Transform compose_transform ( const Transform & a,
const Transform & b )

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

Definition at line 384 of file mat.cpp.

385{
386 Transform m;
387 for(int i = 0; i < 4; i++)
388 for(int j = 0; j < 4; j++)
389 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];
390
391 return m;
392}

◆ operator*() [1/7]

Transform operator* ( const Transform & a,
const Transform & b )

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

Definition at line 394 of file mat.cpp.

395{
396 return compose_transform(a, b);
397}
Transform compose_transform(const Transform &a, const Transform &b)
renvoie la composition des transformations a et b, t= a * b.
Definition mat.cpp:384

◆ operator<<() [1/3]

std::ostream & operator<< ( std::ostream & o,
const Transform & t )
inline

Definition at line 127 of file mat.h.

128{
129 o << t.m[0][0] << " " << t.m[0][1] << " " << t.m[0][2] << " " << t.m[0][3] << " " << std::endl;
130 o << t.m[1][0] << " " << t.m[1][1] << " " << t.m[1][2] << " " << t.m[1][3] << " " << std::endl;
131 o << t.m[2][0] << " " << t.m[2][1] << " " << t.m[2][2] << " " << t.m[2][3] << " " << std::endl;
132 o << t.m[3][0] << " " << t.m[3][1] << " " << t.m[3][2] << " " << t.m[3][3] << " " << std::endl;
133 return o;
134}

◆ Origin()

Point Origin ( )

renvoie le point origine (0, 0, 0)

Definition at line 8 of file vec.cpp.

9{
10 return Point(0, 0, 0);
11}
representation d'un point 3d.
Definition vec.h:21

◆ distance()

float distance ( const Point & a,
const Point & b )

renvoie la distance etre 2 points.

Definition at line 14 of file vec.cpp.

15{
16 return length(a - b);
17}
float length(const Vector &v)
renvoie la longueur d'un vecteur.
Definition vec.cpp:186

◆ distance2()

float distance2 ( const Point & a,
const Point & b )

renvoie le carre de la distance etre 2 points.

Definition at line 19 of file vec.cpp.

20{
21 return length2(a - b);
22}
float length2(const Vector &v)
renvoie la carre de la longueur d'un vecteur.
Definition vec.cpp:191

◆ center()

Point center ( const Point & a,
const Point & b )

renvoie le milieu du segment ab.

Definition at line 24 of file vec.cpp.

25{
26 return Point((a.x + b.x) / 2, (a.y + b.y) / 2, (a.z + b.z) / 2);
27}

◆ min() [1/2]

Point min ( const Point & a,
const Point & b )

renvoie la plus petite composante de chaque point { min(a.x, b.x), min(a.y, b.y), min(a.z, b.z) }.

Definition at line 30 of file vec.cpp.

31{
32 return { std::min(a.x, b.x), std::min(a.y, b.y), std::min(a.z, b.z) };
33}

◆ max() [1/2]

Point max ( const Point & a,
const Point & b )

renvoie la plus grande composante de chaque point { max(a.x, b.x), max(a.y, b.y), max(a.z, b.z) }.

Definition at line 35 of file vec.cpp.

36{
37 return { std::max(a.x, b.x), std::max(a.y, b.y), std::max(a.z, b.z) };
38}

◆ min() [2/2]

Vector min ( const Vector & a,
const Vector & b )

renvoie la plus petite composante de chaque vecteur { min(a.x, b.x), min(a.y, b.y), min(a.z, b.z) }.

Definition at line 40 of file vec.cpp.

41{
42 return { std::min(a.x, b.x), std::min(a.y, b.y), std::min(a.z, b.z) };
43}

◆ max() [2/2]

Vector max ( const Vector & a,
const Vector & b )

renvoie la plus grande composante de chaque vecteur { max(a.x, b.x), max(a.y, b.y), max(a.z, b.z) }.

Definition at line 45 of file vec.cpp.

46{
47 return { std::max(a.x, b.x), std::max(a.y, b.y), std::max(a.z, b.z) };
48}

◆ minmax()

void minmax ( const Vector & a,
const Vector & b,
Vector & vmin,
Vector & vmax )

renvoie min(a, b) dans vmin, et max(a, b) dans vmax. mais en plus rapide.

Definition at line 50 of file vec.cpp.

51{
52 if(a.x < b.x) { vmin.x= a.x; vmax.x= b.x; } else { vmin.x= b.x; vmax.x= a.x; }
53 if(a.y < b.y) { vmin.y= a.y; vmax.y= b.y; } else { vmin.y= b.y; vmax.y= a.y; }
54 if(a.z < b.z) { vmin.z= a.z; vmax.z= b.z; } else { vmin.z= b.z; vmax.z= a.z; }
55}

◆ normalize()

Vector normalize ( const Vector & v)

renvoie un vecteur unitaire / longueur == 1.

Definition at line 167 of file vec.cpp.

168{
169 float kk= 1 / length(v);
170 return kk * v;
171}

◆ cross()

Vector cross ( const Vector & u,
const Vector & v )

renvoie le produit vectoriel de 2 vecteurs.

Definition at line 173 of file vec.cpp.

174{
175 return Vector(
176 u.y * v.z - u.z * v.y,
177 u.z * v.x - u.x * v.z,
178 u.x * v.y - u.y * v.x);
179}

◆ dot()

float dot ( const Vector & u,
const Vector & v )

renvoie le produit scalaire de 2 vecteurs.

Definition at line 181 of file vec.cpp.

182{
183 return u.x * v.x + u.y * v.y + u.z * v.z;
184}

◆ length()

float length ( const Vector & v)

renvoie la longueur d'un vecteur.

Definition at line 186 of file vec.cpp.

187{
188 return std::sqrt(length2(v));
189}

◆ length2()

float length2 ( const Vector & v)

renvoie la carre de la longueur d'un vecteur.

Definition at line 191 of file vec.cpp.

192{
193 return v.x * v.x + v.y * v.y + v.z * v.z;
194}

◆ operator-() [1/5]

Vector operator- ( const Point & a,
const Point & b )

renvoie le vecteur a - b.

Definition at line 58 of file vec.cpp.

59{
60 return Vector(a.x - b.x, a.y - b.y, a.z - b.z);
61}

◆ operator+() [1/6]

Point operator+ ( const Point & a,
const Point & b )

renvoie le "point" a + b.

Definition at line 86 of file vec.cpp.

87{
88 return Point(a.x + b.x, a.y + b.y, a.z + b.z);
89}

◆ operator*() [2/7]

Point operator* ( const float k,
const Point & a )

renvoie le "point" k*a;

Definition at line 63 of file vec.cpp.

64{
65 return Point(k * a.x, k * a.y, k * a.z);
66}

◆ operator*() [3/7]

Point operator* ( const Point & a,
const float k )

renvoie le "point" a*k;

Definition at line 68 of file vec.cpp.

69{
70 return k * a;
71}

◆ operator*() [4/7]

Point operator* ( const Point & a,
const Point & b )

renvoie le "point" a*b;

◆ operator/() [1/5]

Point operator/ ( const Point & a,
const float k )

renvoie le "point" a/k;

Definition at line 73 of file vec.cpp.

74{
75 return Point(a.x / k, a.y / k, a.z / k);
76}

◆ operator/() [2/5]

Point operator/ ( const float k,
const Point & a )

renvoie le "point" k/a;

Definition at line 77 of file vec.cpp.

78{
79 return Point(k/ a.x, k / a.y, k / a.z);
80}

◆ operator/() [3/5]

Point operator/ ( const Point & a,
const Point & b )

renvoie le "point" a/b;

Definition at line 81 of file vec.cpp.

82{
83 return Point(a.x / b.x, a.y / b.y, a.z / b.z);
84}

◆ operator-() [2/5]

Vector operator- ( const Vector & v)

renvoie le vecteur -v.

Definition at line 91 of file vec.cpp.

92{
93 return Vector(-v.x, -v.y, -v.z);
94}

◆ operator+() [2/6]

Point operator+ ( const Point & a,
const Vector & v )

renvoie le point a+v.

Definition at line 96 of file vec.cpp.

97{
98 return Point(a.x + v.x, a.y + v.y, a.z + v.z);
99}

◆ operator+() [3/6]

Point operator+ ( const Vector & v,
const Point & a )

renvoie le point a+v.

Definition at line 101 of file vec.cpp.

102{
103 return a + v;
104}

◆ operator-() [3/5]

Point operator- ( const Vector & v,
const Point & a )

renvoie le point a-v.

Definition at line 106 of file vec.cpp.

107{
108 return a + (-v);
109}

◆ operator-() [4/5]

Point operator- ( const Point & a,
const Vector & v )

renvoie le point a-v.

Definition at line 111 of file vec.cpp.

112{
113 return a + (-v);
114}

◆ operator+() [4/6]

Vector operator+ ( const Vector & u,
const Vector & v )

renvoie le vecteur u+v.

Definition at line 116 of file vec.cpp.

117{
118 return Vector(u.x + v.x, u.y + v.y, u.z + v.z);
119}

◆ operator-() [5/5]

Vector operator- ( const Vector & u,
const Vector & v )

renvoie le vecteur u-v.

Definition at line 121 of file vec.cpp.

122{
123 return Vector(u.x - v.x, u.y - v.y, u.z - v.z);
124}

◆ operator+() [5/6]

Vector operator+ ( const float k,
const Vector & v )

renvoie le vecteur u+k;

Definition at line 127 of file vec.cpp.

128{
129 return Vector(k + v.x, k + v.y, k + v.z);
130}

◆ operator+() [6/6]

Vector operator+ ( const Vector & v,
const float k )

Definition at line 131 of file vec.cpp.

132{
133 return k + v;
134}

◆ operator*() [5/7]

Vector operator* ( const float k,
const Vector & v )

renvoie le vecteur k*u;

Definition at line 136 of file vec.cpp.

137{
138 return Vector(k * v.x, k * v.y, k * v.z);
139}

◆ operator*() [6/7]

Vector operator* ( const Vector & v,
const float k )

renvoie le vecteur k*v;

Definition at line 141 of file vec.cpp.

142{
143 return k * v;
144}

◆ operator*() [7/7]

Vector operator* ( const Vector & a,
const Vector & b )

renvoie le vecteur (a.x*b.x, a.y*b.y, a.z*b.z ).

Definition at line 146 of file vec.cpp.

147{
148 return Vector(a.x * b.x, a.y * b.y, a.z * b.z);
149}

◆ operator/() [4/5]

Vector operator/ ( const Vector & v,
const float k )

renvoie le vecteur v/k;

Definition at line 151 of file vec.cpp.

152{
153 return Vector(v.x / k, v.y / k, v.z / k);
154}

◆ operator/() [5/5]

Vector operator/ ( const Vector & u,
const Vector & v )

renvoie le vecteur u/v;

Definition at line 161 of file vec.cpp.

162{
163 // si division par zero... inf dans le resultat.
164 return Vector(u.x / v.x, u.y / v.y, u.z / v.z);
165}

◆ operator<<() [2/3]

std::ostream & operator<< ( std::ostream & o,
const Point & p )
inline

Definition at line 245 of file vec.h.

246{
247 o<<"p("<<p.x<<","<<p.y<<","<<p.z<<")";
248 return o;
249}

◆ operator<<() [3/3]

std::ostream & operator<< ( std::ostream & o,
const Vector & v )
inline

Definition at line 251 of file vec.h.

252{
253 o<<"v("<<v.x<<","<<v.y<<","<<v.z<<")";
254 return o;
255}

◆ Point() [1/4]

Point::Point ( const vec2 & v,
const float z )
inline

Definition at line 215 of file vec.h.

215: x(v.x), y(v.y), z(z) {}

◆ Point() [2/4]

Point::Point ( const vec3 & v)
inline

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

Definition at line 216 of file vec.h.

216: x(v.x), y(v.y), z(v.z) {}

◆ Point() [3/4]

Point::Point ( const vec4 & v)
inline

Definition at line 217 of file vec.h.

217: x(v.x), y(v.y), z(v.z) {}

◆ Point() [4/4]

Point::Point ( const Vector & v)
inline

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

Definition at line 218 of file vec.h.

218: x(v.x), y(v.y), z(v.z) {}

◆ Vector() [1/3]

Vector::Vector ( const vec3 & v)
inline

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

Definition at line 220 of file vec.h.

220: x(v.x), y(v.y), z(v.z) {}

◆ Vector() [2/3]

Vector::Vector ( const vec4 & v)
inline

Definition at line 221 of file vec.h.

221: x(v.x), y(v.y), z(v.z) {}

◆ Vector() [3/3]

Vector::Vector ( const Point & a)
inline

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

Definition at line 222 of file vec.h.

222: x(a.x), y(a.y), z(a.z) {}

◆ vec2() [1/2]

vec2::vec2 ( const vec3 & v)
inline

Definition at line 224 of file vec.h.

224: x(v.x), y(v.y) {}

◆ vec2() [2/2]

vec2::vec2 ( const vec4 & v)
inline

Definition at line 225 of file vec.h.

225: x(v.x), y(v.y) {}

◆ vec3() [1/3]

vec3::vec3 ( const vec4 & v)
inline

Definition at line 227 of file vec.h.

227: x(v.x), y(v.y), z(v.z) {}

◆ vec3() [2/3]

vec3::vec3 ( const Point & a)
inline

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

Definition at line 229 of file vec.h.

229: x(a.x), y(a.y), z(a.z) {}

◆ vec3() [3/3]

vec3::vec3 ( const Vector & v)
inline

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

Definition at line 230 of file vec.h.

230: x(v.x), y(v.y), z(v.z) {}

◆ vec4() [1/2]

vec4::vec4 ( const Point & a)
inline

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

Definition at line 232 of file vec.h.

232: x(a.x), y(a.y), z(a.z), w(1.f) {}

◆ vec4() [2/2]

vec4::vec4 ( const Vector & v)
inline

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

Definition at line 233 of file vec.h.

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

◆ operator()() [1/4]

float Point::operator() ( const unsigned int i) const
inline

renvoie la ieme composante du point.

Definition at line 236 of file vec.h.

236{ return (&x)[i]; }

◆ operator()() [2/4]

float Vector::operator() ( const unsigned int i) const
inline

renvoie la ieme composante du vecteur.

Definition at line 237 of file vec.h.

237{ return (&x)[i]; }

◆ operator()() [3/4]

float & Point::operator() ( const unsigned int i)
inline

Definition at line 239 of file vec.h.

239{ return (&x)[i]; }

◆ operator()() [4/4]

float & Vector::operator() ( const unsigned int i)
inline

Definition at line 240 of file vec.h.

240{ return (&x)[i]; }