12 #define MAX_NUM_SPAWNS 4
16 static void cleanup();
17 static void display();
18 static void reshape(int x, int y);
19 static void keydown(unsigned char key, int x, int y);
20 static void keyup(unsigned char key, int x, int y);
21 static void mouse(int bn, int st, int x, int y);
22 static void motion(int x, int y);
24 static std::vector<Mesh*> meshes;
25 static Mesh *mesh_head;
28 static int win_width, win_height;
29 static float cam_theta, cam_phi = 25, cam_dist = 8;
30 static float hair_deg;
32 int main(int argc, char **argv)
34 glutInit(&argc, argv);
35 glutInitWindowSize(800, 600);
36 glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE);
37 glutCreateWindow("hair test");
39 glutDisplayFunc(display);
40 glutReshapeFunc(reshape);
41 glutKeyboardFunc(keydown);
42 glutKeyboardUpFunc(keyup);
44 glutMotionFunc(motion);
59 glEnable(GL_DEPTH_TEST);
60 glEnable(GL_CULL_FACE);
61 glEnable(GL_COLOR_MATERIAL);
63 glEnable(GL_LIGHTING);
66 glClearColor(0.5, 0.5, 0.5, 1);
67 meshes = load_meshes("data/head.fbx");
69 fprintf(stderr, "Failed to load mesh.\n");
73 for(size_t i=0; i<meshes.size(); i++) {
74 meshes[i]->calc_bbox();
76 Vec3 v0 = meshes[i]->bbox.v0;
77 Vec3 v1 = meshes[i]->bbox.v1;
79 printf("mesh: %s\n", meshes[i]->name.c_str());
80 printf("AABB mesh %d: v0: (%f, %f, %f) v1: (%f, %f, %f)\n",
81 (int)i, v0.x, v0.y, v0.z, v1.x, v1.y, v1.z);
83 meshes[i]->update_vbo(MESH_ALL);
85 printf("num vertices: %d num triangles: %d\n",
86 (int)meshes[i]->vertices.size(),
87 (int)meshes[i]->indices.size() / 3);
89 if(meshes[i]->name == "head") {
90 mesh_head = meshes[i];
94 fprintf(stderr, "Failed to find the head mesh.\n");
98 if(!hair.init(mesh_head, MAX_NUM_SPAWNS, THRESH)) {
99 fprintf(stderr, "Failed to initialize hair\n");
106 static void cleanup()
108 for(size_t i=0; i<meshes.size(); i++) {
113 static void display()
115 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
117 glMatrixMode(GL_MODELVIEW);
119 glTranslatef(0, 0, -cam_dist);
120 glRotatef(cam_phi, 1, 0, 0);
121 glRotatef(cam_theta, 0, 1, 0);
123 for(size_t i=0; i<meshes.size(); i++) {
130 assert(glGetError() == GL_NO_ERROR);
133 static void reshape(int x, int y)
135 glViewport(0, 0, x, y);
139 glMatrixMode(GL_PROJECTION);
141 gluPerspective(50.0, (float)x / (float)y, 0.5, 500.0);
144 static void keydown(unsigned char key, int /*x*/, int /*y*/)
149 printf("key %u down\n", key);
158 static void keyup(unsigned char key, int /*x*/, int /*y*/)
163 printf("key %u up\n", key);
173 static void mouse(int bn, int st, int x, int y)
175 bnstate[bn] = st == GLUT_DOWN;
180 static void motion(int x, int y)
187 if(!dx && !dy) return;
190 cam_theta += dx * 0.5;
193 if(cam_phi < -90) cam_phi = -90;
194 if(cam_phi > 90) cam_phi = 90;
198 cam_dist += dy * 0.1;
199 if(cam_dist < 0) cam_dist = 0;