vrchess

annotate src/main.cc @ 0:b326d53321f7

initial commit
author John Tsiombikas <nuclear@member.fsf.org>
date Fri, 25 Apr 2014 05:20:53 +0300
parents
children 879194e4b1f0
rev   line source
nuclear@0 1 #include <stdio.h>
nuclear@0 2 #include <stdlib.h>
nuclear@0 3 #include "opengl.h"
nuclear@0 4 #include "game.h"
nuclear@0 5
nuclear@0 6 static bool init();
nuclear@0 7 static void cleanup();
nuclear@0 8
nuclear@0 9 static void display();
nuclear@0 10 static void idle();
nuclear@0 11 static void reshape(int x, int y);
nuclear@0 12 static void keyb(unsigned char key, int x, int y);
nuclear@0 13 static void keyb_up(unsigned char key, int x, int y);
nuclear@0 14 static void mouse(int bn, int st, int x, int y);
nuclear@0 15 static void motion(int x, int y);
nuclear@0 16 static void sball_motion(int x, int y, int z);
nuclear@0 17 static void sball_rotate(int x, int y, int z);
nuclear@0 18
nuclear@0 19 int main(int argc, char **argv)
nuclear@0 20 {
nuclear@0 21 glutInitWindowSize(1024, 600);
nuclear@0 22 glutInit(&argc, argv);
nuclear@0 23 glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE);
nuclear@0 24 glutCreateWindow("VR Chess");
nuclear@0 25
nuclear@0 26 glutDisplayFunc(display);
nuclear@0 27 glutIdleFunc(idle);
nuclear@0 28 glutReshapeFunc(reshape);
nuclear@0 29 glutKeyboardFunc(keyb);
nuclear@0 30 glutKeyboardUpFunc(keyb_up);
nuclear@0 31 glutMouseFunc(mouse);
nuclear@0 32 glutMotionFunc(motion);
nuclear@0 33 glutSpaceballMotionFunc(sball_motion);
nuclear@0 34 glutSpaceballRotateFunc(sball_rotate);
nuclear@0 35
nuclear@0 36 if(!init()) {
nuclear@0 37 return 1;
nuclear@0 38 }
nuclear@0 39 atexit(cleanup);
nuclear@0 40
nuclear@0 41 glutMainLoop();
nuclear@0 42 return 0;
nuclear@0 43 }
nuclear@0 44
nuclear@0 45 static bool init()
nuclear@0 46 {
nuclear@0 47 glewInit();
nuclear@0 48
nuclear@0 49 if(!game_init()) {
nuclear@0 50 return false;
nuclear@0 51 }
nuclear@0 52 return true;
nuclear@0 53 }
nuclear@0 54
nuclear@0 55 static void cleanup()
nuclear@0 56 {
nuclear@0 57 game_cleanup();
nuclear@0 58 }
nuclear@0 59
nuclear@0 60 static void display()
nuclear@0 61 {
nuclear@0 62 unsigned int msec = glutGet(GLUT_ELAPSED_TIME);
nuclear@0 63
nuclear@0 64 game_update(msec);
nuclear@0 65 game_render(0);
nuclear@0 66
nuclear@0 67 glutSwapBuffers();
nuclear@0 68 }
nuclear@0 69
nuclear@0 70 static void idle()
nuclear@0 71 {
nuclear@0 72 glutPostRedisplay();
nuclear@0 73 }
nuclear@0 74
nuclear@0 75 static void reshape(int x, int y)
nuclear@0 76 {
nuclear@0 77 game_reshape(x, y);
nuclear@0 78 }
nuclear@0 79
nuclear@0 80 static void keyb(unsigned char key, int x, int y)
nuclear@0 81 {
nuclear@0 82 game_keyboard(key, true, x, y);
nuclear@0 83 }
nuclear@0 84
nuclear@0 85 static void keyb_up(unsigned char key, int x, int y)
nuclear@0 86 {
nuclear@0 87 game_keyboard(key, false, x, y);
nuclear@0 88 }
nuclear@0 89
nuclear@0 90 static void mouse(int bn, int st, int x, int y)
nuclear@0 91 {
nuclear@0 92 game_mouse(bn - GLUT_LEFT_BUTTON, st == GLUT_DOWN, x, y);
nuclear@0 93 }
nuclear@0 94
nuclear@0 95 static void motion(int x, int y)
nuclear@0 96 {
nuclear@0 97 game_motion(x, y);
nuclear@0 98 }
nuclear@0 99
nuclear@0 100 #define SBALL_MOVE_SCALE 0.00025
nuclear@0 101 #define SBALL_ROT_SCALE 0.01
nuclear@0 102
nuclear@0 103 static void sball_motion(int x, int y, int z)
nuclear@0 104 {
nuclear@0 105 game_6dof_move(x * SBALL_MOVE_SCALE, y * SBALL_MOVE_SCALE, z * SBALL_MOVE_SCALE);
nuclear@0 106 }
nuclear@0 107
nuclear@0 108 static void sball_rotate(int x, int y, int z)
nuclear@0 109 {
nuclear@0 110 game_6dof_rotate(x * SBALL_ROT_SCALE, y * SBALL_ROT_SCALE, z * SBALL_ROT_SCALE);
nuclear@0 111 }