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 mouse(int bn, int st, int x, int y);
21 static void motion(int x, int y);
23 static std::vector<Mesh*> meshes;
24 static Mesh *mesh_head;
27 static int win_width, win_height;
28 static float cam_theta, cam_phi = 25, cam_dist = 8;
30 int main(int argc, char **argv)
32 glutInit(&argc, argv);
33 glutInitWindowSize(800, 600);
34 glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE);
35 glutCreateWindow("hair test");
37 glutDisplayFunc(display);
38 glutReshapeFunc(reshape);
39 glutKeyboardFunc(keydown);
41 glutMotionFunc(motion);
56 glEnable(GL_DEPTH_TEST);
57 glEnable(GL_CULL_FACE);
58 glEnable(GL_COLOR_MATERIAL);
60 glEnable(GL_LIGHTING);
63 glClearColor(0.5, 0.5, 0.5, 1);
64 meshes = load_meshes("data/head.fbx");
66 fprintf(stderr, "Failed to load mesh.\n");
70 for(size_t i=0; i<meshes.size(); i++) {
71 meshes[i]->calc_bbox();
73 Vec3 v0 = meshes[i]->bbox.v0;
74 Vec3 v1 = meshes[i]->bbox.v1;
76 printf("mesh: %s\n", meshes[i]->name.c_str());
77 printf("AABB mesh %d: v0: (%f, %f, %f) v1: (%f, %f, %f)\n",
78 (int)i, v0.x, v0.y, v0.z, v1.x, v1.y, v1.z);
80 meshes[i]->update_vbo(MESH_ALL);
82 printf("num vertices: %d num triangles: %d\n",
83 (int)meshes[i]->vertices.size(),
84 (int)meshes[i]->indices.size() / 3);
86 if(meshes[i]->name == "head") {
87 mesh_head = meshes[i];
91 fprintf(stderr, "Failed to find the head mesh.\n");
95 if(!hair.init(mesh_head, MAX_NUM_SPAWNS, THRESH)) {
96 fprintf(stderr, "Failed to initialize hair\n");
103 static void cleanup()
105 for(size_t i=0; i<meshes.size(); i++) {
110 static void display()
112 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
114 glMatrixMode(GL_MODELVIEW);
116 glTranslatef(0, 0, -cam_dist);
117 glRotatef(cam_phi, 1, 0, 0);
118 glRotatef(cam_theta, 0, 1, 0);
120 for(size_t i=0; i<meshes.size(); i++) {
127 assert(glGetError() == GL_NO_ERROR);
130 static void reshape(int x, int y)
132 glViewport(0, 0, x, y);
136 glMatrixMode(GL_PROJECTION);
138 gluPerspective(50.0, (float)x / (float)y, 0.5, 500.0);
141 static void keydown(unsigned char key, int /*x*/, int /*y*/)
152 static void mouse(int bn, int st, int x, int y)
154 bnstate[bn] = st == GLUT_DOWN;
159 static void motion(int x, int y)
166 if(!dx && !dy) return;
169 cam_theta += dx * 0.5;
172 if(cam_phi < -90) cam_phi = -90;
173 if(cam_phi > 90) cam_phi = 90;
177 cam_dist += dy * 0.1;
178 if(cam_dist < 0) cam_dist = 0;