vrfileman

view src/app.cc @ 2:282da6123fd4

lalalala
author John Tsiombikas <nuclear@member.fsf.org>
date Sun, 01 Feb 2015 12:51:10 +0200
parents dca518e371cf
children 2cbf85690e03
line source
1 #include <assert.h>
2 #include "opengl.h"
3 #include "app.h"
4 #include "user.h"
6 static void draw_grid(int num, float sep);
8 static User user;
9 static float eye_level = 1.6;
11 bool app_init()
12 {
13 if(!init_opengl()) {
14 return false;
15 }
16 return true;
17 }
19 void app_shutdown()
20 {
21 }
23 void app_display()
24 {
25 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
27 glMatrixMode(GL_MODELVIEW);
28 glLoadIdentity();
30 Matrix4x4 viewmat;
31 user.posrot.calc_inv_matrix(&viewmat);
32 glLoadTransposeMatrixf(viewmat.m[0]);
33 glTranslatef(0, -eye_level, 0);
35 draw_grid(20, 1.0);
37 swap_buffers();
38 assert(glGetError() == GL_NO_ERROR);
39 }
41 void app_reshape(int x, int y)
42 {
43 glViewport(0, 0, x, y);
45 glMatrixMode(GL_PROJECTION);
46 glLoadIdentity();
47 gluPerspective(50.0, (float)x / (float)y, 0.5, 500.0);
48 }
50 void app_keyboard(int key, bool pressed, int x, int y)
51 {
52 if(pressed) {
53 switch(key) {
54 case 27:
55 quit();
56 }
57 }
58 }
60 void app_mouse_button(int bn, bool pressed, int x, int y)
61 {
62 }
64 void app_mouse_motion(int x, int y)
65 {
66 }
68 void app_sball_motion(float x, float y, float z)
69 {
70 }
72 void app_sball_rotate(float x, float y, float z)
73 {
74 }
76 void app_sball_button(int bn, bool pressed)
77 {
78 }
80 static void draw_grid(int num, float sep)
81 {
82 int hnum = num / 2;
83 float max_dist = hnum * sep;
85 glBegin(GL_LINES);
86 glVertex3f(0, 0, -max_dist);
87 glVertex3f(0, 0, max_dist);
88 glVertex3f(-max_dist, 0, 0);
89 glVertex3f(max_dist, 0, 0);
91 for(int i=1; i<hnum; i++) {
92 float x = i * sep;
94 glVertex3f(-x, 0, -max_dist);
95 glVertex3f(-x, 0, max_dist);
96 glVertex3f(x, 0, -max_dist);
97 glVertex3f(x, 0, max_dist);
98 glVertex3f(-max_dist, 0, -x);
99 glVertex3f(max_dist, 0, -x);
100 glVertex3f(-max_dist, 0, x);
101 glVertex3f(max_dist, 0, x);
102 }
103 glEnd();
104 }