oculus1

diff src/main.cc @ 14:cceffea995a4

implemented wasd controls and clamping of the texcoords to [0, 1]
author John Tsiombikas <nuclear@member.fsf.org>
date Sat, 21 Sep 2013 03:35:53 +0300
parents 464e1d135d68
children f3672317e5c2
line diff
     1.1 --- a/src/main.cc	Sat Sep 21 03:00:47 2013 +0300
     1.2 +++ b/src/main.cc	Sat Sep 21 03:35:53 2013 +0300
     1.3 @@ -138,10 +138,35 @@
     1.4  	vr_shutdown();
     1.5  }
     1.6  
     1.7 +static void handle_input(float dt)
     1.8 +{
     1.9 +	Vector3 inpv;
    1.10 +	float offs = dt * 2.0;
    1.11 +
    1.12 +	if(keystate['w'] || keystate['W']) {
    1.13 +		inpv.z -= offs;
    1.14 +	}
    1.15 +	if(keystate['s'] || keystate['S']) {
    1.16 +		inpv.z += offs;
    1.17 +	}
    1.18 +	if(keystate['d'] || keystate['D']) {
    1.19 +		inpv.x += offs;
    1.20 +	}
    1.21 +	if(keystate['a'] || keystate['A']) {
    1.22 +		inpv.x -= offs;
    1.23 +	}
    1.24 +
    1.25 +	cam.input_move(inpv.x, inpv.y, inpv.z);
    1.26 +}
    1.27 +
    1.28  static void disp()
    1.29  {
    1.30 -	unsigned int msec = glutGet(GLUT_ELAPSED_TIME);
    1.31 +	static long prev_msec;
    1.32 +	long msec = glutGet(GLUT_ELAPSED_TIME);
    1.33 +	float dt = (msec - prev_msec) / 1000.0;
    1.34 +	prev_msec = msec;
    1.35  
    1.36 +	handle_input(dt);
    1.37  	cam.track_vr();
    1.38  
    1.39  	/*glMatrixMode(GL_PROJECTION);
    1.40 @@ -211,7 +236,7 @@
    1.41  	float lpos[] = {0, 60, 0, 1};
    1.42  	glLightfv(GL_LIGHT0, GL_POSITION, lpos);
    1.43  
    1.44 -	draw_grid(100.0, 2.5);
    1.45 +	draw_grid(50.0, 2.5);
    1.46  
    1.47  	static Vector2 teapos[] = {
    1.48  		Vector2(-8, 8), Vector2(8, 8), Vector2(8, -8), Vector2(-8, -8)
    1.49 @@ -245,7 +270,7 @@
    1.50  
    1.51  static void draw_squares()
    1.52  {
    1.53 -	static const int num_sq = 4;
    1.54 +	static const int num_sq = 8;
    1.55  
    1.56  	glPushAttrib(GL_ENABLE_BIT | GL_LINE_BIT);
    1.57  	glDisable(GL_LIGHTING);
    1.58 @@ -255,7 +280,7 @@
    1.59  	glTranslatef(0, 1, 0);
    1.60  
    1.61  
    1.62 -	glLineWidth(3.0);
    1.63 +	glLineWidth(2.0);
    1.64  	glColor3f(1.0, 0.7, 0.2);
    1.65  
    1.66  	float zdist = 2.0;
    1.67 @@ -267,7 +292,7 @@
    1.68  		glVertex3f(-1, 1, -zdist);
    1.69  		glEnd();
    1.70  
    1.71 -		zdist += 1.0;
    1.72 +		zdist += 2.0;
    1.73  	}
    1.74  
    1.75  	glPopMatrix();