12 #define MAX_NUM_SPAWNS 500
15 static void cleanup();
16 static void display();
17 static void reshape(int x, int y);
18 static void keydown(unsigned char key, int x, int y);
19 static void mouse(int bn, int st, int x, int y);
20 static void motion(int x, int y);
22 static std::vector<Mesh*> meshes;
23 static Mesh *mesh_head;
26 int win_width, win_height;
27 float cam_theta, cam_phi = 25, cam_dist = 8;
29 int main(int argc, char **argv)
31 glutInit(&argc, argv);
32 glutInitWindowSize(800, 600);
33 glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE);
34 glutCreateWindow("hair test");
36 glutDisplayFunc(display);
37 glutReshapeFunc(reshape);
38 glutKeyboardFunc(keydown);
40 glutMotionFunc(motion);
55 glEnable(GL_DEPTH_TEST);
56 glEnable(GL_CULL_FACE);
57 glEnable(GL_COLOR_MATERIAL);
59 glEnable(GL_LIGHTING);
62 glClearColor(0.5, 0.5, 0.5, 1);
63 meshes = load_meshes("data/head.fbx");
65 fprintf(stderr, "Failed to load mesh.\n");
69 for(size_t i=0; i<meshes.size(); i++) {
70 meshes[i]->calc_bbox();
72 Vec3 v0 = meshes[i]->bbox.v0;
73 Vec3 v1 = meshes[i]->bbox.v1;
75 printf("mesh: %s\n", meshes[i]->name.c_str());
76 printf("AABB mesh %d: v0: (%f, %f, %f) v1: (%f, %f, %f)\n",
77 (int)i, v0.x, v0.y, v0.z, v1.x, v1.y, v1.z);
79 meshes[i]->update_vbo(MESH_ALL);
80 printf("num vertices: %d num triangles: %d\n",
81 (int)meshes[i]->vertices.size(),
82 (int)meshes[i]->indices.size() / 3);
84 if(meshes[i]->name == "head") {
85 mesh_head = meshes[i];
89 fprintf(stderr, "Failed to find the head mesh.\n");
93 if(!hair.init(mesh_head, MAX_NUM_SPAWNS, 0.1)) {
94 fprintf(stderr, "Failed to initialize hair\n");
101 static void cleanup()
103 for(size_t i=0; i<meshes.size(); i++) {
108 static void display()
110 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
112 glMatrixMode(GL_MODELVIEW);
114 glTranslatef(0, 0, -cam_dist);
115 glRotatef(cam_phi, 1, 0, 0);
116 glRotatef(cam_theta, 0, 1, 0);
118 for(size_t i=0; i<meshes.size(); i++) {
125 assert(glGetError() == GL_NO_ERROR);
128 static void reshape(int x, int y)
130 glViewport(0, 0, x, y);
134 glMatrixMode(GL_PROJECTION);
136 gluPerspective(50.0, (float)x / (float)y, 0.5, 500.0);
139 static void keydown(unsigned char key, int /*x*/, int /*y*/)
150 static void mouse(int bn, int st, int x, int y)
152 bnstate[bn] = st == GLUT_DOWN;
157 static void motion(int x, int y)
164 if(!dx && !dy) return;
167 cam_theta += dx * 0.5;
170 if(cam_phi < -90) cam_phi = -90;
171 if(cam_phi > 90) cam_phi = 90;
175 cam_dist += dy * 0.1;
176 if(cam_dist < 0) cam_dist = 0;