15Mesh make_grid(
const int n= 10 )
21 float w= float(n-1) / 2;
22 for(
int x= 0; x < n; x++)
28 for(
int z= 0; z < n; z++)
58 camera.vertex(-0.5, -0.5, -1);
60 camera.vertex(-0.5, 0.5, -1);
62 camera.vertex(0.5, 0.5, -1);
64 camera.vertex(0.5, -0.5, -1);
66 camera.vertex(-0.5, -0.5, -1);
67 camera.vertex(-0.5, 0.5, -1);
69 camera.vertex(-0.5, 0.5, -1);
70 camera.vertex(0.5, 0.5, -1);
72 camera.vertex(0.5, 0.5, -1);
73 camera.vertex(0.5, -0.5, -1);
75 camera.vertex(0.5, -0.5, -1);
76 camera.vertex(-0.5, -0.5, -1);
80 camera.vertex(
Point(0, 0, 0));
81 camera.vertex(
Point(1, 0, 0));
83 camera.color(
Green());
84 camera.vertex(
Point(0, 0, 0));
85 camera.vertex(
Point(0, 1, 0));
88 camera.vertex(
Point(0, 0, 0));
89 camera.vertex(
Point(0, 0, 1));
106 m_repere= make_grid(20);
107 m_local= make_grid(2);
108 m_proxy= make_camera();
119 m_repere.bounds(pmin, pmax);
124 glClearColor(0.2f, 0.2f, 0.2f, 1.f);
127 glDepthFunc(GL_LESS);
128 glEnable(GL_DEPTH_TEST);
146 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
190 draw(m_objet, m_position, view, projection);
194 draw(m_proxy, m_position * m, view, projection);
197 draw(m_local, m_position, view, projection);
200 draw(m_repere,
Identity(), view, projection);
223int main(
int argc,
char **argv )
225 printf(
"appuyez sur 'espace' pour fixer la position de la camera\n");
226 printf(
"appuyez sur 'c' pour dessiner avec la camera\n");
227 printf(
"appuyez sur 'c' et 'espace' pour dessiner avec la camera attachee derriere le cube\n");
228 printf(
"deplacez le cube avec les fleches de directions\n");
const Orbiter & camera() const
renvoie l'orbiter gere par l'application.
AppCamera(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.
unsigned int vertex(const vec3 &p)
insere un sommet de position p, et ses attributs (s'ils sont definis par color(), texcoord(),...
Mesh & color(const vec4 &c)
definit la couleur du prochain sommet.
void lookat(const Point ¢er, const float size)
observe le point center a une distance size.
Transform projection(const int width, const int height, const float fov)
fixe la projection reglee pour une image d'aspect width / height, et une demi ouverture de fov degres...
Transform view() const
renvoie la transformation vue.
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 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.
void printf(Text &text, const int px, const int py, const char *format,...)
affiche un texte a la position x, y. meme utilisation que printf().
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.
float global_time()
renvoie le temps ecoule depuis le lancement de l'application, en millisecondes.
Color Red()
utilitaire. renvoie une couleur rouge.
Color Yellow()
utilitaire. renvoie une couleur jaune.
Color Blue()
utilitaire. renvoie une couleur bleue.
Color Green()
utilitaire. renvoie une couleur verte.
Color White()
utilitaire. renvoie une couleur blanche.
Transform Inverse(const Transform &m)
renvoie l'inverse de la matrice.
Transform Identity()
construit la transformation identite.
Transform RotationX(const float a)
renvoie la matrice representation une rotation de angle degree autour de l'axe X.
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.
Transform Translation(const Vector &v)
renvoie la matrice representant une translation par un vecteur.
Mesh read_mesh(const char *filename)
charge un fichier wavefront .obj et renvoie un mesh compose de triangles non indexes....
int screenshot(const char *filename)
enregistre le contenu de la fenetre dans un fichier. doit etre de type .png / .bmp
representation d'un point 3d.