gKit2 light
Loading...
Searching...
No Matches
tuto_transform.cpp File Reference

visualisation du volume visible par une camera, + visualisation d'un objet (par rapport au volume visible) More...

#include "mat.h"
#include "wavefront.h"
#include "orbiter.h"
#include "draw.h"
#include "app.h"

Go to the source code of this file.

Classes

class  TP

Functions

bool visible (const Transform &mvp, const Point &pmin, const Point &pmax)
int main (int argc, char **argv)

Detailed Description

visualisation du volume visible par une camera, + visualisation d'un objet (par rapport au volume visible)

Definition in file tuto_transform.cpp.

Function Documentation

◆ visible()

bool visible ( const Transform & mvp,
const Point & pmin,
const Point & pmax )

Definition at line 13 of file tuto_transform.cpp.

14{
15 int planes[6] = { };
16
17 // enumere les 8 sommets de la boite englobante
18 for(unsigned int i= 0; i < 8; i++)
19 {
20 Point p= pmin;
21 if(i & 1) p.x= pmax.x;
22 if(i & 2) p.y= pmax.y;
23 if(i & 4) p.z= pmax.z;
24
25 // transformation du point homogene (x, y, z, w= 1)
26 vec4 h= mvp(vec4(p));
27
28 // teste la position du point homogene par rapport aux 6 faces de la region visible
29 if(h.x < -h.w) planes[0]++; // trop a gauche
30 if(h.x > h.w) planes[1]++; // trop a droite
31
32 if(h.y < -h.w) planes[2]++; // trop bas
33 if(h.y > h.w) planes[3]++; // trop haut
34
35 if(h.z < -h.w) planes[4]++; // trop pres
36 if(h.z > h.w) planes[5]++; // trop loin
37 }
38
39 // verifie si tous les sommets sont du "mauvais cote" d'une seule face, planes[i] == 8
40 for(unsigned int i= 0; i < 6; i++)
41 if(planes[i] == 8)
42 return false; // la boite englobante n'est pas visible
43
44 // l'objet doit etre visible, ou pas, il faut aussi le test dans l'autre sens...
45 return true;
46}
representation d'un point 3d.
Definition vec.h:21
vecteur generique 4d, ou 3d homogene, utilitaire.
Definition vec.h:192

◆ main()

int main ( int argc,
char ** argv )

Definition at line 210 of file tuto_transform.cpp.

211{
212 TP tp;
213 tp.run();
214
215 return 0;
216}
int run()
execution de l'application.
Definition app.cpp:36
Definition alpha.cpp:58