33 object->parent= parent;
40 if(object->parent == NULL)
43 return object->model * model_transform(object->parent);
48 if(object->parent == NULL)
51 return local *
object->model * model_transform(object->parent);
54std::vector<Object *> scene;
57void mesh_normalize(
Mesh& mesh )
60 Vector g= make_vector(mesh.positions[0]);
61 for(
unsigned int i= 1; i < (
unsigned int) mesh.positions.size(); i++)
62 g= g + make_vector(mesh.positions[i]);
63 g= g / (float) mesh.positions.size();
66 float dmax= length(make_vector(mesh.positions[0]) - g);
67 for(
unsigned int i= 1; i < (
unsigned int) mesh.positions.size(); i++)
68 dmax= std::max(dmax, length(make_vector(mesh.positions[i]) - g));
71 for(
unsigned int i= 0; i < (
unsigned int) mesh.positions.size(); i++)
73 Vector d= make_vector(mesh.positions[i]) - g;
74 mesh.positions[i]= make_vec3(d / dmax);
83 mesh_normalize(*mesh);
87 mesh_normalize(*mesh2);
96 for(
unsigned int i= 0; i < 200; i++)
98 float x= (float) rand() / (float) RAND_MAX * (grid_width -1) - grid_width / 2;
99 float z= (float) rand() / (float) RAND_MAX * (grid_height -1) - grid_height / 2;
100 float y= (float) rand() / (float) RAND_MAX - 0.5;
101 y*= (float) rand() / (float) RAND_MAX * 10;
102 float a= (float) rand() / (float) RAND_MAX;
103 Transform model= make_translation( make_vector(x, y, z) ) * make_rotationY(a * 180);
105 Object *parent= create_object(mesh, model, NULL);
106 parent->texture= texture;
107 scene.push_back(parent);
109 Transform local= make_translation(make_vector(0, 1.3, 0));
111 Object *
object= create_object(mesh2, local, parent);
113 scene.push_back(
object);
116 camera= make_orbiter_lookat( make_point(0, 0, 0), 32 );
119 glClearColor(0.2f, 0.2f, 0.2f, 1.f);
123 glDepthFunc(GL_LESS);
124 glEnable(GL_DEPTH_TEST);
134 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
139 unsigned int mb= SDL_GetRelativeMouseState(&mx, &my);
142 if(mb & SDL_BUTTON(1))
144 orbiter_rotation(camera, mx, my);
146 else if(mb & SDL_BUTTON(3))
148 orbiter_move(camera, mx);
150 else if(mb & SDL_BUTTON(2))
154 float time= SDL_GetTicks();
155 for(
unsigned int i= 0; i < scene.size(); i++)
158 float x= cosf(time / 100 + (
float) i / (
float) scene.size() - 0.5 ) * 0.5;
161 float z= sinf(time / 1000 + (
float) i / (
float) scene.size() - 0.5) * 0.25;
168 Transform local= make_translation( make_vector(0,
169 cosf(time / (100 - (
float) i / (
float) scene.size() * 80)
170 + (
float) i / (
float) scene.size() * M_PI / 2) * 0.25, 0) );
173 Transform model= model_transform(scene[i], local);
176 draw(*scene[i]->mesh,
178 orbiter_view_transform(camera),
193int main(
int argc,
char **argv )
208 printf(
"[error] init failed.\n");
representation d'un objet / maillage.
representation de la camera, type orbiter, placee sur une sphere autour du centre de l'objet.
Context create_context(Window window)
cree et configure un contexte opengl
int window_height()
renvoie la hauteur de la fenetre de l'application.
void release_window(Window window)
destruction de la fenetre.
int run(Window window, int(*draw)())
boucle de gestion des evenements de l'application.
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().
Window create_window(const int w, const int h, const int major, const int minor, const int samples)
creation d'une fenetre pour l'application.
void release_context(Context context)
detruit le contexte openGL.
int window_width()
renvoie la largeur de la fenetre de l'application.
Mesh read_mesh(const char *filename)
charge un fichier wavefront .obj et renvoie un mesh compose de triangles non indexes....
GLuint read_texture(const int unit, const char *filename, const GLenum texel_type)
int init(std::vector< const char * > &options)
representation d'un vecteur 3d.