nuclear@2: #include nuclear@2: #include nuclear@2: #include "opengl.h" nuclear@2: #include "game.h" nuclear@2: nuclear@2: static bool init(); nuclear@2: static void cleanup(); nuclear@2: nuclear@2: static void display(); nuclear@2: static void idle(); nuclear@2: static void reshape(int x, int y); nuclear@2: static void keyb(unsigned char key, int x, int y); nuclear@2: static void keyb_up(unsigned char key, int x, int y); nuclear@2: static void mouse(int bn, int st, int x, int y); nuclear@2: static void motion(int x, int y); nuclear@2: static void sball_motion(int x, int y, int z); nuclear@2: static void sball_rotate(int x, int y, int z); nuclear@2: nuclear@2: int main(int argc, char **argv) nuclear@2: { nuclear@2: glutInitWindowSize(1024, 600); nuclear@2: glutInit(&argc, argv); nuclear@2: glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE); nuclear@2: glutCreateWindow("VR Chess"); nuclear@2: nuclear@2: glutDisplayFunc(display); nuclear@2: glutIdleFunc(idle); nuclear@2: glutReshapeFunc(reshape); nuclear@2: glutKeyboardFunc(keyb); nuclear@2: glutKeyboardUpFunc(keyb_up); nuclear@2: glutMouseFunc(mouse); nuclear@2: glutMotionFunc(motion); nuclear@2: glutSpaceballMotionFunc(sball_motion); nuclear@2: glutSpaceballRotateFunc(sball_rotate); nuclear@2: nuclear@2: if(!init()) { nuclear@2: return 1; nuclear@2: } nuclear@2: atexit(cleanup); nuclear@2: nuclear@2: glutMainLoop(); nuclear@2: return 0; nuclear@2: } nuclear@2: nuclear@2: static bool init() nuclear@2: { nuclear@2: glewInit(); nuclear@2: nuclear@2: if(!game_init()) { nuclear@2: return false; nuclear@2: } nuclear@2: return true; nuclear@2: } nuclear@2: nuclear@2: static void cleanup() nuclear@2: { nuclear@2: game_cleanup(); nuclear@2: } nuclear@2: nuclear@2: static void display() nuclear@2: { nuclear@2: unsigned int msec = glutGet(GLUT_ELAPSED_TIME); nuclear@2: nuclear@2: game_update(msec); nuclear@2: game_render(0); nuclear@2: nuclear@2: glutSwapBuffers(); nuclear@2: } nuclear@2: nuclear@2: static void idle() nuclear@2: { nuclear@2: glutPostRedisplay(); nuclear@2: } nuclear@2: nuclear@2: static void reshape(int x, int y) nuclear@2: { nuclear@2: game_reshape(x, y); nuclear@2: } nuclear@2: nuclear@2: static void keyb(unsigned char key, int x, int y) nuclear@2: { nuclear@2: game_keyboard(key, true, x, y); nuclear@2: } nuclear@2: nuclear@2: static void keyb_up(unsigned char key, int x, int y) nuclear@2: { nuclear@2: game_keyboard(key, false, x, y); nuclear@2: } nuclear@2: nuclear@2: static void mouse(int bn, int st, int x, int y) nuclear@2: { nuclear@3: switch(bn) { nuclear@3: case GLUT_RIGHT_BUTTON + 1: nuclear@3: if(st == GLUT_DOWN) { nuclear@3: game_mwheel(1); nuclear@3: } nuclear@3: break; nuclear@3: nuclear@3: case GLUT_RIGHT_BUTTON + 2: nuclear@3: if(st == GLUT_DOWN) { nuclear@3: game_mwheel(-1); nuclear@3: } nuclear@3: break; nuclear@3: nuclear@3: default: nuclear@3: game_mouse(bn - GLUT_LEFT_BUTTON, st == GLUT_DOWN, x, y); nuclear@3: } nuclear@2: } nuclear@2: nuclear@2: static void motion(int x, int y) nuclear@2: { nuclear@2: game_motion(x, y); nuclear@2: } nuclear@2: nuclear@2: #define SBALL_MOVE_SCALE 0.00025 nuclear@2: #define SBALL_ROT_SCALE 0.01 nuclear@2: nuclear@2: static void sball_motion(int x, int y, int z) nuclear@2: { nuclear@2: game_6dof_move(x * SBALL_MOVE_SCALE, y * SBALL_MOVE_SCALE, z * SBALL_MOVE_SCALE); nuclear@2: } nuclear@2: nuclear@2: static void sball_rotate(int x, int y, int z) nuclear@2: { nuclear@2: game_6dof_rotate(x * SBALL_ROT_SCALE, y * SBALL_ROT_SCALE, z * SBALL_ROT_SCALE); nuclear@2: }