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);
35 glutCreateWindow("Antikythera");
37 glutDisplayFunc(display);
39 glutReshapeFunc(reshape);
40 glutKeyboardFunc(keyb);
42 glutMotionFunc(motion);
57 glEnable(GL_DEPTH_TEST);
58 glEnable(GL_CULL_FACE);
59 glEnable(GL_LIGHTING);
61 glEnable(GL_NORMALIZE);
63 Mesh::use_custom_sdr_attr = false;
65 machine = new Machine;
67 const float pitch = 10.0f;
69 Gear *gear1 = new Gear;
70 gear1->pos = Vec3(-50, 0, 0);
71 gear1->set_teeth(16, pitch);
73 machine->add_gear(gear1);
75 Gear *gear2 = new Gear;
76 gear2->set_teeth(32, pitch);
77 gear2->pos = gear1->pos + Vec3(gear1->radius + gear2->radius - gear1->teeth_length * 0.75, 0, 0);
80 machine->add_gear(gear2);
82 Gear *gear3 = new Gear;
83 gear3->set_teeth(8, pitch);
84 gear3->pos = gear2->pos + Vec3(0, gear2->radius + gear3->radius - gear2->teeth_length * 0.75, 0);
86 machine->add_gear(gear3);
88 machine->add_motor(0, 1.0);
89 machine->calc_meshing();
91 start_time = glutGet(GLUT_ELAPSED_TIME);
102 unsigned int msec = glutGet(GLUT_ELAPSED_TIME) - start_time;
103 float dt = (float)(msec - prev_msec) / 1000.0f;
108 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
110 glMatrixMode(GL_MODELVIEW);
112 glTranslatef(0, 0, -cam_dist);
113 glRotatef(cam_phi, 1, 0, 0);
114 glRotatef(cam_theta, 0, 1, 0);
119 assert(glGetError() == GL_NO_ERROR);
129 /* world scale is in meters, gears are in millimeters, sclae by 1/1000 */
131 glScalef(0.001, 0.001, 0.001);
138 void reshape(int x, int y)
140 glViewport(0, 0, x, y);
142 glMatrixMode(GL_PROJECTION);
144 gluPerspective(50.0, (float)x / (float)y, 0.05, 100.0);
147 void keyb(unsigned char key, int x, int y)
155 void mouse(int bn, int st, int x, int y)
159 bnstate[bn - GLUT_LEFT_BUTTON] = st == GLUT_DOWN;
162 void motion(int x, int y)
164 int dx = x - prev_mx;
165 int dy = y - prev_my;
169 if(!dx && !dy) return;
172 cam_theta += dx * 0.5;
175 if(cam_phi < -90) cam_phi = -90;
176 if(cam_phi > 90) cam_phi = 90;
180 cam_dist += dy * 0.05;
181 if(cam_dist < 0.0) cam_dist = 0.0;