29 displacement(make_vector(0.f, 0.f, 0.f)),
38 displacement(make_vector(0.f, 0.f, 0.f)),
47 Transform get_parent_transform(
float time)
52 res = res*parent->get_parent_transform(time) ;
54 res = res*make_rotationY(revolution*time) ;
55 res = res*make_translation(displacement) ;
64 res = res*parent->get_parent_transform(time) ;
66 res = res*make_rotationY(revolution*time) ;
67 res = res*make_translation(displacement) ;
68 res = res*make_rotationY(spin*time) ;
69 res = res*make_scale(scale, scale, scale) ;
78 draw(body.mesh, body.get_transform(time), orbiter);
91 Mesh grid= create_mesh(GL_LINES);
93 for(
int x= 0; x < 10; x++)
95 float px= (float) x - 5.f + 0.5f;
96 push_vertex(grid, make_point(px, 0, -4.5f));
97 push_vertex(grid, make_point(px, 0, 4.5f));
100 for(
int z= 0; z < 10; z++)
102 float pz= (float) z - 5.f + 0.5f;
103 push_vertex(grid, make_point(-4.5f, 0, pz));
104 push_vertex(grid, make_point(4.5f, 0, pz));
115 if(cube.positions.size() == 0)
118 sun =
Body(cube, make_red());
121 planet =
Body(cube, make_blue());
122 planet.displacement = make_vector(4, 0, 0) ;
125 planet.revolution = 0.05 ;
126 planet.parent = &sun ;
128 moon =
Body(cube, make_green()) ;
129 moon.displacement = make_vector(1, 0, 0) ;
132 moon.revolution = -0.1 ;
133 moon.parent = &planet ;
135 camera= make_orbiter();
139 glClearColor(0.2, 0.2, 0.2, 1);
142 glDepthFunc(GL_LEQUAL);
144 glEnable(GL_DEPTH_TEST);
156 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
161 unsigned int mb= SDL_GetRelativeMouseState(&mx, &my);
164 if(mb & SDL_BUTTON(1))
166 orbiter_rotation(camera, mx, my);
168 else if(mb & SDL_BUTTON(3))
170 orbiter_move(camera, mx);
172 else if(mb & SDL_BUTTON(2))
190 sun.displacement = sun.displacement + make_vector(sunx, 0, sunz) ;
192 float planet_dist= 0;
198 planet.displacement = planet.displacement + make_vector(planet_dist, 0, 0) ;
206 moon.displacement = moon.displacement + make_vector(moon_dist, 0, 0) ;
208 float time = (float) SDL_GetTicks() ;
211 draw(sun, time, camera);
212 draw(planet, time, camera);
213 draw(moon, time, camera);
216 static bool video=
false;
223 printf(
"start video capture...\n");
225 printf(
"stop video capture.\n");
241 int main(
int argc,
char **argv )
256 printf(
"[error] init failed.\n");
Context create_context(Window window, const int major, const int minor)
cree et configure un contexte opengl
representation de la camera, type orbiter, placee sur une sphere autour du centre de l'objet...
void clear_key_state(const SDL_Keycode key)
desactive une touche du clavier.
Mesh & color(const vec4 &c)
definit la couleur du prochain sommet.
representation d'un objet / maillage.
representation d'une couleur (rgba) transparente ou opaque.
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 window_width()
renvoie la largeur de la fenetre de l'application.
int capture(const char *prefix)
representation d'un vecteur 3d.
Window create_window(const int w, const int h)
creation d'une fenetre pour l'application.
int key_state(const SDL_Keycode key)
renvoie l'etat d'une touche du clavier. cf la doc SDL2 pour les codes.
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 window_height()
renvoie la hauteur de la fenetre de l'application.
void release_context(Context context)
detruit le contexte openGL.
void release_window(Window window)
destruction de la fenetre.
int run(Window window, int(*draw)(void))
fonction principale. gestion des evenements et appel de la fonction draw de l'application.
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( ).