10 void reshape(int x, int y);
11 void keyb(unsigned char key, int x, int y);
12 void mouse(int bn, int st, int x, int y);
13 void motion(int x, int y);
14 void sball_motion(int x, int y, int z);
15 void sball_rotate(int rx, int ry, int rz);
16 void sball_button(int bn, int st);
18 float cam_theta, cam_phi, cam_dist = 10;
24 int main(int argc, char **argv)
26 glutInit(&argc, argv);
27 glutInitWindowSize(800, 600);
28 glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE);
29 glutCreateWindow("ropesim");
31 glutDisplayFunc(display);
33 glutReshapeFunc(reshape);
34 glutKeyboardFunc(keyb);
36 glutMotionFunc(motion);
37 glutSpaceballMotionFunc(sball_motion);
38 glutSpaceballRotateFunc(sball_rotate);
39 glutSpaceballButtonFunc(sball_button);
53 float amb[] = {0.05, 0.05, 0.08, 1};
55 glEnable(GL_CULL_FACE);
56 glEnable(GL_DEPTH_TEST);
57 glEnable(GL_LIGHTING);
62 glLightModelfv(GL_LIGHT_MODEL_AMBIENT, amb);
64 if(!(scn = cmesh_alloc()) || cmesh_load(scn, "gimbal.obj") == -1) {
65 fprintf(stderr, "failed to load scene file\n");
78 static const float lpos[][4] = {
83 static const float lcol[][4] = {
90 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
92 glMatrixMode(GL_MODELVIEW);
94 glTranslatef(0, 0, -cam_dist);
95 glRotatef(cam_phi, 1, 0, 0);
96 glRotatef(cam_theta, 0, 1, 0);
99 glLightfv(GL_LIGHT0 + i, GL_POSITION, lpos[i]);
100 glLightfv(GL_LIGHT0 + i, GL_DIFFUSE, lcol[i]);
112 void reshape(int x, int y)
114 glViewport(0, 0, x, y);
115 glMatrixMode(GL_PROJECTION);
117 gluPerspective(50.0, (float)x / (float)y, 0.5, 500.0);
120 void keyb(unsigned char key, int x, int y)
128 void mouse(int bn, int st, int x, int y)
132 bnstate[bn - GLUT_LEFT_BUTTON] = st == GLUT_DOWN;
135 void motion(int x, int y)
137 int dx = x - prev_mx;
138 int dy = y - prev_my;
142 if(!(dx | dy)) return;
145 cam_theta += dx * 0.5;
147 if(cam_phi < -90) cam_phi = -90;
148 if(cam_phi > 90) cam_phi = 90;
152 cam_dist += dy * 0.1;
153 if(cam_dist < 0.0f) cam_dist = 0.0f;
157 void sball_motion(int x, int y, int z)
161 void sball_rotate(int rx, int ry, int rz)
165 void sball_button(int bn, int st)