vrchess

view src/main.cc @ 2:879194e4b1f0

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