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) {}
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);
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))
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);
183 draw(m_objet, m_model, view, projection);
206 Point m_pmin, m_pmax;
210 int main(
int argc,
char **argv )
representation de la camera, type orbiter, placee sur une sphere autour du centre de l'objet...
int init()
a deriver pour creer les objets openGL.
void bounds(Point &pmin, Point &pmax)
renvoie min et max les coordonnees des extremites des positions des sommets de l'objet (boite engloba...
void clear_key_state(const SDL_Keycode key)
desactive une touche du clavier.
representation d'un objet / maillage.
void move(const float z)
rapproche / eloigne la camera du centre.
int update(const float time, const float delta)
a deriver et redefinir pour animer les objets en fonction du temps.
Transform Identity()
construit la transformation identite.
int run()
execution de l'application.
unsigned int vertex(const vec3 &p)
insere un sommet de position p, et ses attributs (s'ils sont definis par color(), texcoord()...
vecteur generique 4d, ou 3d homogene, utilitaire.
void draw(Mesh &m, const Transform &model, const Transform &view, const Transform &projection, const GLuint texture)
applique une texture a la surface de l'objet. ne fonctionne que si les coordonnees de textures sont f...
int quit()
a deriver pour detruire les objets openGL.
int create(const GLenum primitives)
construit les objets openGL.
Transform view() const
renvoie la transformation vue.
int window_width()
renvoie la largeur de la fenetre de l'application.
Transform Inverse(const Transform &m)
renvoie l'inverse de la matrice.
void release()
detruit les objets openGL.
Transform projection(const float width, const float height, const float fov) const
renvoie la projection reglee pour une image d'aspect width / height, et une ouverture de fov degres...
void lookat(const Point ¢er, const float size)
observe le point center a une distance size.
int key_state(const SDL_Keycode key)
renvoie l'etat d'une touche du clavier. cf la doc SDL2 pour les codes.
void translation(const float x, const float y)
deplace le centre / le point observe.
Transform Perspective(const float fov, const float aspect, const float znear, const float zfar)
renvoie la matrice representant une transformation projection perspective.
void rotation(const float x, const float y)
change le point de vue / la direction d'observation.
int window_height()
renvoie la hauteur de la fenetre de l'application.
representation d'un point 3d.
Color Red()
utilitaire. renvoie une couleur rouge.
int render()
a deriver pour afficher les objets.
Color Green()
utilitaire. renvoie une couleur verte.
Transform RotationY(const float a)
renvoie la matrice representation une rotation de a degree autour de l'axe Y.
Mesh read_mesh(const char *filename)
charge un fichier wavefront .obj et renvoie un mesh compose de triangles non indexes. utiliser glDrawArrays pour l'afficher. a detruire avec Mesh::release( ).
Color default_color() const
renvoie la couleur par defaut du mesh, utilisee si les sommets n'ont pas de couleur associee...