nuclear@0: #include nuclear@0: #include nuclear@3: #include nuclear@0: #include "opengl.h" nuclear@3: #include "plane.h" nuclear@3: #include "disc.h" nuclear@3: #include "particle.h" nuclear@3: #include "simworld.h" nuclear@0: nuclear@0: static bool init(); nuclear@0: static void cleanup(); nuclear@0: static void disp(); nuclear@0: static void idle(); nuclear@0: static void reshape(int x, int y); nuclear@0: static void keyb(unsigned char key, int x, int y); nuclear@0: static void mouse(int bn, int state, int x, int y); nuclear@0: static void motion(int x, int y); nuclear@0: nuclear@0: static float cam_theta, cam_phi, cam_dist = 8.0; nuclear@0: nuclear@0: static bool moving_cloth; nuclear@0: nuclear@3: static SimWorld simworld; nuclear@3: nuclear@0: nuclear@0: int main(int argc, char **argv) nuclear@0: { nuclear@0: glutInit(&argc, argv); nuclear@0: glutInitWindowSize(800, 600); nuclear@0: glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE); nuclear@0: glutCreateWindow("cloth"); nuclear@0: nuclear@0: glutDisplayFunc(disp); nuclear@0: glutReshapeFunc(reshape); nuclear@0: glutKeyboardFunc(keyb); nuclear@0: glutMouseFunc(mouse); nuclear@0: glutMotionFunc(motion); nuclear@0: glutIdleFunc(idle); nuclear@0: nuclear@0: if(!init()) { nuclear@0: return 1; nuclear@0: } nuclear@0: atexit(cleanup); nuclear@0: nuclear@0: glutMainLoop(); nuclear@0: return 0; nuclear@0: } nuclear@0: nuclear@0: nuclear@0: static bool init() nuclear@0: { nuclear@0: glewInit(); nuclear@0: nuclear@0: glClearColor(0.2, 0.2, 0.2, 1.0); nuclear@0: nuclear@0: glEnable(GL_DEPTH_TEST); nuclear@0: glEnable(GL_CULL_FACE); nuclear@0: nuclear@3: Disc *disc = new Disc; nuclear@3: disc->normal = Vector3(0, 1, 0); nuclear@3: simworld.add_object(disc); nuclear@3: nuclear@0: return true; nuclear@0: } nuclear@0: nuclear@0: static void cleanup() nuclear@0: { nuclear@0: } nuclear@0: nuclear@0: static void disp() nuclear@0: { nuclear@0: glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); nuclear@0: nuclear@0: glMatrixMode(GL_MODELVIEW); nuclear@0: glLoadIdentity(); nuclear@0: glTranslatef(0, 0, -cam_dist); nuclear@0: glRotatef(cam_phi, 1.0, 0.0, 0.0); nuclear@0: glRotatef(cam_theta, 0.0, 1.0, 0.0); nuclear@0: nuclear@0: glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); nuclear@0: nuclear@3: for(int i=0; idraw(); nuclear@3: } nuclear@0: nuclear@0: glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); nuclear@0: nuclear@0: glutSwapBuffers(); nuclear@0: } nuclear@0: nuclear@0: static void idle() nuclear@0: { nuclear@0: glutPostRedisplay(); nuclear@0: } nuclear@0: nuclear@0: static void reshape(int x, int y) nuclear@0: { nuclear@0: glViewport(0, 0, x, y); nuclear@0: nuclear@0: glMatrixMode(GL_PROJECTION); nuclear@0: glLoadIdentity(); nuclear@0: gluPerspective(45.0, (float)x / (float)y, 0.5, 500.0); nuclear@0: } nuclear@0: nuclear@0: static void keyb(unsigned char key, int x, int y) nuclear@0: { nuclear@0: switch(key) { nuclear@0: case 27: nuclear@0: exit(0); nuclear@0: } nuclear@0: } nuclear@0: nuclear@0: static bool bnstate[16]; nuclear@0: static int prev_x, prev_y; nuclear@0: nuclear@0: static void mouse(int bn, int state, int x, int y) nuclear@0: { nuclear@0: int idx = bn - GLUT_LEFT_BUTTON; nuclear@0: int st = state == GLUT_DOWN ? 1 : 0; nuclear@0: nuclear@0: if(idx >= 0 && idx < 16) { nuclear@0: bnstate[idx] = st; nuclear@0: } nuclear@0: nuclear@0: prev_x = x; nuclear@0: prev_y = y; nuclear@0: } nuclear@0: nuclear@0: static void motion(int x, int y) nuclear@0: { nuclear@0: int dx = x - prev_x; nuclear@0: int dy = y - prev_y; nuclear@0: prev_x = x; nuclear@0: prev_y = y; nuclear@0: nuclear@0: if(moving_cloth) { nuclear@0: } else { nuclear@0: if(bnstate[0]) { nuclear@0: cam_theta += dx * 0.5; nuclear@0: cam_phi += dy * 0.5; nuclear@0: nuclear@0: if(cam_phi < -90.0) { nuclear@0: cam_phi = -90.0; nuclear@0: } nuclear@0: if(cam_phi > 90.0) { nuclear@0: cam_phi = 90.0; nuclear@0: } nuclear@0: } nuclear@0: if(bnstate[2]) { nuclear@0: cam_dist += dy * 0.1; nuclear@0: nuclear@0: if(cam_dist < 0.0) { nuclear@0: cam_dist = 0.0; nuclear@0: } nuclear@0: } nuclear@0: } nuclear@0: }