vrshoot
view src/scr_game.cc @ 2:334d17aed7de
visual studio project files
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Sun, 02 Feb 2014 18:36:38 +0200 |
parents | b2f14e535253 |
children |
line source
1 #include "scr_game.h"
2 #include "object.h"
3 #include "game.h"
4 #include "meshgen.h"
5 #include "opengl.h"
6 #include "unistate.h"
7 #include "logger.h"
8 #include "level.h"
10 static int win_width, win_height;
11 static bool bnstate[32];
12 static int prev_x, prev_y;
13 static float cam_theta, cam_phi = 23, cam_dist = 0;
14 static Object *floor_obj;
15 static Level *level;
16 static unsigned long msec;
18 const char *GameScreen::get_name() const
19 {
20 return "game";
21 }
23 bool GameScreen::init()
24 {
25 glEnable(GL_LIGHTING);
26 glEnable(GL_LIGHT0);
28 level = new Level;
30 return true;
31 }
33 void GameScreen::cleanup()
34 {
35 }
37 void GameScreen::update(unsigned long tmsec)
38 {
39 msec = tmsec;
40 }
42 void GameScreen::display() const
43 {
44 Matrix4x4 matrix;
45 matrix.translate(Vector3(0, 0, -cam_dist));
46 matrix.rotate(Vector3(1, 0, 0), DEG_TO_RAD(cam_phi));
47 matrix.rotate(Vector3(0, 1, 0), DEG_TO_RAD(cam_theta));
48 matrix.translate(Vector3(0, -2, 0));
49 set_view_matrix(matrix);
51 //glUseProgram(0);
53 bind_shader(defsdr);
54 level->draw(msec);
55 }
57 void GameScreen::reshape(int x, int y)
58 {
59 glViewport(0, 0, x, y);
61 win_width = x;
62 win_height = y;
64 Matrix4x4 proj;
65 proj.set_perspective(M_PI / 4.0, (float)x / (float)y, 0.5, 500.0);
66 set_projection_matrix(proj);
67 }
69 void GameScreen::button(int bn, bool pressed, int x, int y)
70 {
71 prev_x = x;
72 prev_y = y;
73 bnstate[bn] = pressed;
74 }
76 void GameScreen::motion(int x, int y, bool pressed)
77 {
78 int dx = x - prev_x;
79 int dy = y - prev_y;
80 prev_x = x;
81 prev_y = y;
83 if(!dx && !dy) return;
85 if(bnstate[0]) {
86 cam_theta += dx * 0.5;
87 cam_phi += dy * 0.5;
89 if(cam_phi > 90) cam_phi = 90;
90 if(cam_phi < 0) cam_phi = 0;
91 }
93 if(bnstate[2]) {
94 cam_dist += dy * 0.1;
96 if(cam_dist < 0) cam_dist = 0;
97 }
98 }
100 long GameScreen::redisplay_interval() const
101 {
102 return 1;
103 }