17 void reshape(int x, int y);
18 void keyb(unsigned char key, int x, int y);
19 void mouse(int bn, int st, int x, int y);
20 void motion(int x, int y);
22 static float cam_dist = 2;
23 static float cam_theta, cam_phi;
24 static int prev_mx, prev_my;
25 static bool bnstate[8];
27 static unsigned int start_time, prev_msec;
28 static Machine *machine;
30 int main(int argc, char **argv)
32 glutInitWindowSize(1024, 768);
33 glutInit(&argc, argv);
34 glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE | GLUT_MULTISAMPLE);
35 glutCreateWindow("Antikythera");
37 glutDisplayFunc(display);
39 glutReshapeFunc(reshape);
40 glutKeyboardFunc(keyb);
42 glutMotionFunc(motion);
57 glEnable(GL_MULTISAMPLE);
58 glEnable(GL_DEPTH_TEST);
59 glEnable(GL_CULL_FACE);
60 glEnable(GL_LIGHTING);
62 glEnable(GL_NORMALIZE);
64 Mesh::use_custom_sdr_attr = false;
66 machine = new Machine;
68 const float pitch = 10.0f;
70 Gear *gear1 = new Gear;
71 gear1->pos = Vec3(-50, 0, 0);
72 gear1->set_teeth(16, pitch);
74 machine->add_gear(gear1);
76 Gear *gear2 = new Gear;
77 gear2->set_teeth(32, pitch);
78 gear2->pos = gear1->pos + Vec3(gear1->radius + gear2->radius - gear1->teeth_length * 0.75, 0, 0);
81 machine->add_gear(gear2);
83 Gear *gear3 = new Gear;
84 gear3->set_teeth(8, pitch);
85 gear3->pos = gear2->pos + Vec3(0, gear2->radius + gear3->radius - gear2->teeth_length * 0.75, 0);
87 machine->add_gear(gear3);
89 machine->add_motor(0, 1.0);
90 machine->calc_meshing();
92 start_time = glutGet(GLUT_ELAPSED_TIME);
103 unsigned int msec = glutGet(GLUT_ELAPSED_TIME) - start_time;
104 float dt = (float)(msec - prev_msec) / 1000.0f;
109 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
111 glMatrixMode(GL_MODELVIEW);
113 glTranslatef(0, 0, -cam_dist);
114 glRotatef(cam_phi, 1, 0, 0);
115 glRotatef(cam_theta, 0, 1, 0);
120 assert(glGetError() == GL_NO_ERROR);
130 /* world scale is in meters, gears are in millimeters, sclae by 1/1000 */
132 glScalef(0.001, 0.001, 0.001);
139 void reshape(int x, int y)
141 glViewport(0, 0, x, y);
143 glMatrixMode(GL_PROJECTION);
145 gluPerspective(50.0, (float)x / (float)y, 0.05, 100.0);
148 void keyb(unsigned char key, int x, int y)
156 void mouse(int bn, int st, int x, int y)
160 bnstate[bn - GLUT_LEFT_BUTTON] = st == GLUT_DOWN;
163 void motion(int x, int y)
165 int dx = x - prev_mx;
166 int dy = y - prev_my;
170 if(!dx && !dy) return;
173 cam_theta += dx * 0.5;
176 if(cam_phi < -90) cam_phi = -90;
177 if(cam_phi > 90) cam_phi = 90;
181 cam_dist += dy * 0.01;
182 if(cam_dist < 0.0) cam_dist = 0.0;