18 for(
unsigned int i= 0; i < 8; i++)
21 if(i & 1) p.x= pmax.x;
22 if(i & 2) p.y= pmax.y;
23 if(i & 4) p.z= pmax.z;
29 if(h.x < -h.w) planes[0]++;
30 if(h.x > h.w) planes[1]++;
32 if(h.y < -h.w) planes[2]++;
33 if(h.y > h.w) planes[3]++;
35 if(h.z < -h.w) planes[4]++;
36 if(h.z > h.w) planes[5]++;
40 for(
unsigned int i= 0; i < 6; i++)
53 TP( ) :
App(1024, 640) {}
61 m_grid.create(GL_LINES);
62 for(
int x= 0; x < 10; x++)
64 float px= (float) x - 5.f + 0.5f;
65 m_grid.vertex(px, 0, -4.5f);
66 m_grid.vertex(px, 0, 4.5f);
69 for(
int z= 0; z < 10; z++)
71 float pz= (float) z - 5.f + 0.5f;
72 m_grid.vertex(-4.5f, 0, pz);
73 m_grid.vertex(4.5f, 0, pz);
80 m_objet.bounds(m_pmin, m_pmax);
81 m_camera.lookat(m_pmin, m_pmax);
84 m_objet.default_color(
Green());
87 glClearColor(0.2f, 0.2f, 0.2f, 1.f);
91 glEnable(GL_DEPTH_TEST);
102 glDeleteTextures(1, &m_texture);
107 int update(
const float time,
const float delta )
120 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
124 unsigned int mb= SDL_GetRelativeMouseState(&mx, &my);
129 if(mb & SDL_BUTTON(1))
130 m_camera.rotation((
float) mx, (
float) my);
131 else if(mb & SDL_BUTTON(3))
132 m_camera.move((
float) mx);
133 else if(mb & SDL_BUTTON(2))
139 if(mb & SDL_BUTTON(1))
140 m_observer.rotation((
float) mx / 10, (
float) my / 10);
141 else if(mb & SDL_BUTTON(3))
142 m_observer.move((
float) mx / 10);
143 else if(mb & SDL_BUTTON(2))
148 if(visible(m_camera.projection((
float)
window_width(), (
float)
window_height(), 45) * m_camera.view() * m_model, m_pmin, m_pmax))
149 m_objet.default_color(
Green());
151 m_objet.default_color(
Red());
157 static bool wireframe=
false;
160 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
163 draw(m_grid, m_camera);
164 draw(m_objet, m_model, m_camera);
171 wireframe= !wireframe;
175 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
177 glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
181 draw(m_grid,
Identity(), view, projection);
183 draw(m_objet, m_model, view, projection);
206 Point m_pmin, m_pmax;
210int main(
int argc,
char **argv )
App(const int width, const int height, const int major=3, const int minor=3, const int samples=0)
constructeur, dimensions de la fenetre et version d'openGL.
int run()
execution de l'application.
representation d'un objet / maillage.
representation de la camera, type orbiter, placee sur une sphere autour du centre de l'objet.
int render()
a deriver pour afficher les objets. renvoie 1 pour continuer, 0 pour fermer l'application.
int quit()
a deriver pour detruire les objets openGL. renvoie -1 pour indiquer une erreur, 0 sinon.
int update(const float time, const float delta)
a deriver et redefinir pour animer les objets en fonction du temps.
int init()
a deriver pour creer les objets openGL. renvoie -1 pour indiquer une erreur, 0 sinon.
int window_height()
renvoie la hauteur de la fenetre de l'application.
void clear_key_state(const SDL_Keycode key)
desactive une touche du clavier.
int key_state(const SDL_Keycode key)
renvoie l'etat d'une touche du clavier. cf la doc SDL2 pour les codes.
int window_width()
renvoie la largeur de la fenetre de l'application.
Color Red()
utilitaire. renvoie une couleur rouge.
Color Green()
utilitaire. renvoie une couleur verte.
Transform Inverse(const Transform &m)
renvoie l'inverse de la matrice.
Transform Identity()
construit la transformation identite.
Transform RotationY(const float a)
renvoie la matrice representation une rotation de a degree autour de l'axe Y.
Transform Perspective(const float fov, const float aspect, const float znear, const float zfar)
renvoie la matrice representant une transformation projection perspective.
Mesh read_mesh(const char *filename)
charge un fichier wavefront .obj et renvoie un mesh compose de triangles non indexes....
representation d'un point 3d.
vecteur generique 4d, ou 3d homogene, utilitaire.