intravenous

changeset 2:472c28b8b875

I think I pretty much nailed the camera
author John Tsiombikas <nuclear@member.fsf.org>
date Sat, 21 Apr 2012 23:03:36 +0300
parents 3ea290d35984
children 94d4c60af435
files src/game.cc src/main.cc src/opengl.h src/ship.cc
diffstat 4 files changed, 33 insertions(+), 14 deletions(-) [+]
line diff
     1.1 --- a/src/game.cc	Sat Apr 21 22:42:43 2012 +0300
     1.2 +++ b/src/game.cc	Sat Apr 21 23:03:36 2012 +0300
     1.3 @@ -9,6 +9,7 @@
     1.4  static Ship ship;
     1.5  
     1.6  static int keystate[256];
     1.7 +static int dbg_inside = false;
     1.8  
     1.9  static OrbitCamera dbgcam;
    1.10  
    1.11 @@ -61,10 +62,10 @@
    1.12  		ship.turn(1.0 * dt, 0.0);
    1.13  	}
    1.14  	if(keystate['e'] || keystate['E']) {
    1.15 -		ship.turn(0.0, -1.0 * dt);
    1.16 +		ship.turn(0.0, 1.0 * dt);
    1.17  	}
    1.18  	if(keystate['c'] || keystate['C']) {
    1.19 -		ship.turn(0.0, 1.0 * dt);
    1.20 +		ship.turn(0.0, -1.0 * dt);
    1.21  	}
    1.22  
    1.23  	ship.update(dt);
    1.24 @@ -77,8 +78,11 @@
    1.25  	glMatrixMode(GL_MODELVIEW);
    1.26  	dbgcam.use();
    1.27  
    1.28 +	if(dbg_inside) {
    1.29 +		load_gl_matrix(ship.get_matrix().inverse());
    1.30 +	}
    1.31 +
    1.32  	vein->draw(ship.get_position());
    1.33 -
    1.34  	ship.dbg_draw();
    1.35  }
    1.36  
    1.37 @@ -90,6 +94,10 @@
    1.38  			game_shutdown();
    1.39  			break;
    1.40  
    1.41 +		case '\b':
    1.42 +			dbg_inside = !dbg_inside;
    1.43 +			break;
    1.44 +
    1.45  		default:
    1.46  			break;
    1.47  		}
     2.1 --- a/src/main.cc	Sat Apr 21 22:42:43 2012 +0300
     2.2 +++ b/src/main.cc	Sat Apr 21 23:03:36 2012 +0300
     2.3 @@ -65,7 +65,7 @@
     2.4  
     2.5  	glMatrixMode(GL_PROJECTION);
     2.6  	glLoadIdentity();
     2.7 -	gluPerspective(FOV_DEG, (float)x / (float)y, 1.0, 1000.0);
     2.8 +	gluPerspective(FOV_DEG, (float)x / (float)y, 0.1, 200.0);
     2.9  
    2.10  	win_xsz = x;
    2.11  	win_ysz = y;
     3.1 --- a/src/opengl.h	Sat Apr 21 22:42:43 2012 +0300
     3.2 +++ b/src/opengl.h	Sat Apr 21 23:03:36 2012 +0300
     3.3 @@ -9,4 +9,9 @@
     3.4  #include <GLUT/glut.h>
     3.5  #endif
     3.6  
     3.7 +#include <vmath/vmath.h>
     3.8 +
     3.9 +void load_gl_matrix(const Matrix4x4 &mat);
    3.10 +void mult_gl_matrix(const Matrix4x4 &mat);
    3.11 +
    3.12  #endif	/* OPENGL_H_ */
     4.1 --- a/src/ship.cc	Sat Apr 21 22:42:43 2012 +0300
     4.2 +++ b/src/ship.cc	Sat Apr 21 23:03:36 2012 +0300
     4.3 @@ -4,7 +4,6 @@
     4.4  Ship::Ship()
     4.5  {
     4.6  	friction = 0.2;
     4.7 -	//theta = phi = 0.0;
     4.8  }
     4.9  
    4.10  void Ship::accelerate(double a)
    4.11 @@ -19,8 +18,6 @@
    4.12  
    4.13  	rot *= qpitch;
    4.14  	rot *= qyaw;
    4.15 -	/*theta += yaw;
    4.16 -	phi += pitch;*/
    4.17  }
    4.18  
    4.19  void Ship::update(time_sec_t dt)
    4.20 @@ -36,18 +33,17 @@
    4.21  
    4.22  Vector3 Ship::get_direction() const
    4.23  {
    4.24 -	static const Vector3 dir{0, 0, 1};
    4.25 +	static const Vector3 dir{0, 0, -1};
    4.26  	return dir.transformed(rot);
    4.27 -	/*Vector3 dir;
    4.28 -	dir.x = sin(theta) * sin(phi);
    4.29 -	dir.z = cos(phi);
    4.30 -	dir.y = cos(theta) * sin(phi);
    4.31 -	return dir;*/
    4.32  }
    4.33  
    4.34  Matrix4x4 Ship::get_matrix() const
    4.35  {
    4.36 -	return Matrix4x4::identity;
    4.37 +	Matrix3x3 rmat = rot.get_rotation_matrix().transposed();
    4.38 +	Matrix4x4 tmat;
    4.39 +	tmat.set_translation(pos);
    4.40 +
    4.41 +	return tmat * Matrix4x4(rmat);
    4.42  }
    4.43  
    4.44  void Ship::dbg_draw() const
    4.45 @@ -70,5 +66,15 @@
    4.46  	glVertex3f(pos.x, pos.y, pos.z);
    4.47  	glEnd();
    4.48  
    4.49 +	glMatrixMode(GL_MODELVIEW);
    4.50 +	glPushMatrix();
    4.51 +	mult_gl_matrix(get_matrix());
    4.52 +
    4.53 +	glScalef(1, 1, -1);
    4.54 +	glColor3f(1, 1, 0);
    4.55 +	glutWireCone(0.1, 0.6, 12, 2);
    4.56 +
    4.57 +	glPopMatrix();
    4.58 +
    4.59  	glPopAttrib();
    4.60  }