stratgame

diff src/game_part.cc @ 4:cd12944a8ea8

foo
author John Tsiombikas <nuclear@member.fsf.org>
date Fri, 25 May 2012 05:28:20 +0300
parents 8d95187cb3ee
children
line diff
     1.1 --- a/src/game_part.cc	Wed May 23 17:10:46 2012 +0300
     1.2 +++ b/src/game_part.cc	Fri May 25 05:28:20 2012 +0300
     1.3 @@ -3,6 +3,13 @@
     1.4  #include "game_part.h"
     1.5  #include "level.h"
     1.6  
     1.7 +Game::Game()
     1.8 +{
     1.9 +	cam_theta = 0;
    1.10 +	cam_phi = 45;
    1.11 +	cam_dist = 5;
    1.12 +}
    1.13 +
    1.14  Game::~Game() {}
    1.15  
    1.16  bool Game::init()
    1.17 @@ -26,9 +33,9 @@
    1.18  
    1.19  	glMatrixMode(GL_MODELVIEW);
    1.20  	glLoadIdentity();
    1.21 -	glTranslatef(0, 0, -4);
    1.22 -	glRotatef(50, 1, 0, 0);
    1.23 -	glRotatef(current_time / 100.0, 0, 1, 0);
    1.24 +	glTranslatef(0, 0, -cam_dist);
    1.25 +	glRotatef(cam_phi, 1, 0, 0);
    1.26 +	glRotatef(cam_theta, 0, 1, 0);
    1.27  
    1.28  	level.draw();
    1.29  }
    1.30 @@ -52,3 +59,39 @@
    1.31  		break;
    1.32  	}
    1.33  }
    1.34 +
    1.35 +static bool bnstate[32];
    1.36 +static int prev_x, prev_y;
    1.37 +
    1.38 +void Game::mouse_button(int bn, bool pressed)
    1.39 +{
    1.40 +	bnstate[bn] = pressed;
    1.41 +
    1.42 +	if(pressed) {
    1.43 +		if(bn == 3) {
    1.44 +			cam_dist -= 0.2;
    1.45 +			if(cam_dist < 0) {
    1.46 +				cam_dist = 0;
    1.47 +			}
    1.48 +		}
    1.49 +		if(bn == 4) {
    1.50 +			cam_dist += 0.2;
    1.51 +		}
    1.52 +	}
    1.53 +}
    1.54 +
    1.55 +void Game::mouse_motion(int x, int y)
    1.56 +{
    1.57 +	int dx = x - prev_x;
    1.58 +	int dy = y - prev_y;
    1.59 +	prev_x = x;
    1.60 +	prev_y = y;
    1.61 +
    1.62 +	if(bnstate[2]) {
    1.63 +		cam_theta += dx * 0.5;
    1.64 +		cam_phi += dy * 0.5;
    1.65 +
    1.66 +		if(cam_phi < 0) cam_phi = 0;
    1.67 +		if(cam_phi > 90) cam_phi = 90;
    1.68 +	}
    1.69 +}