# HG changeset patch # User John Tsiombikas # Date 1335038616 -10800 # Node ID 472c28b8b875ee353844128926cbaf43a86e22d5 # Parent 3ea290d359840c53d476349d6b4f77bb507d0800 I think I pretty much nailed the camera diff -r 3ea290d35984 -r 472c28b8b875 src/game.cc --- a/src/game.cc Sat Apr 21 22:42:43 2012 +0300 +++ b/src/game.cc Sat Apr 21 23:03:36 2012 +0300 @@ -9,6 +9,7 @@ static Ship ship; static int keystate[256]; +static int dbg_inside = false; static OrbitCamera dbgcam; @@ -61,10 +62,10 @@ ship.turn(1.0 * dt, 0.0); } if(keystate['e'] || keystate['E']) { - ship.turn(0.0, -1.0 * dt); + ship.turn(0.0, 1.0 * dt); } if(keystate['c'] || keystate['C']) { - ship.turn(0.0, 1.0 * dt); + ship.turn(0.0, -1.0 * dt); } ship.update(dt); @@ -77,8 +78,11 @@ glMatrixMode(GL_MODELVIEW); dbgcam.use(); + if(dbg_inside) { + load_gl_matrix(ship.get_matrix().inverse()); + } + vein->draw(ship.get_position()); - ship.dbg_draw(); } @@ -90,6 +94,10 @@ game_shutdown(); break; + case '\b': + dbg_inside = !dbg_inside; + break; + default: break; } diff -r 3ea290d35984 -r 472c28b8b875 src/main.cc --- a/src/main.cc Sat Apr 21 22:42:43 2012 +0300 +++ b/src/main.cc Sat Apr 21 23:03:36 2012 +0300 @@ -65,7 +65,7 @@ glMatrixMode(GL_PROJECTION); glLoadIdentity(); - gluPerspective(FOV_DEG, (float)x / (float)y, 1.0, 1000.0); + gluPerspective(FOV_DEG, (float)x / (float)y, 0.1, 200.0); win_xsz = x; win_ysz = y; diff -r 3ea290d35984 -r 472c28b8b875 src/opengl.h --- a/src/opengl.h Sat Apr 21 22:42:43 2012 +0300 +++ b/src/opengl.h Sat Apr 21 23:03:36 2012 +0300 @@ -9,4 +9,9 @@ #include #endif +#include + +void load_gl_matrix(const Matrix4x4 &mat); +void mult_gl_matrix(const Matrix4x4 &mat); + #endif /* OPENGL_H_ */ diff -r 3ea290d35984 -r 472c28b8b875 src/ship.cc --- a/src/ship.cc Sat Apr 21 22:42:43 2012 +0300 +++ b/src/ship.cc Sat Apr 21 23:03:36 2012 +0300 @@ -4,7 +4,6 @@ Ship::Ship() { friction = 0.2; - //theta = phi = 0.0; } void Ship::accelerate(double a) @@ -19,8 +18,6 @@ rot *= qpitch; rot *= qyaw; - /*theta += yaw; - phi += pitch;*/ } void Ship::update(time_sec_t dt) @@ -36,18 +33,17 @@ Vector3 Ship::get_direction() const { - static const Vector3 dir{0, 0, 1}; + static const Vector3 dir{0, 0, -1}; return dir.transformed(rot); - /*Vector3 dir; - dir.x = sin(theta) * sin(phi); - dir.z = cos(phi); - dir.y = cos(theta) * sin(phi); - return dir;*/ } Matrix4x4 Ship::get_matrix() const { - return Matrix4x4::identity; + Matrix3x3 rmat = rot.get_rotation_matrix().transposed(); + Matrix4x4 tmat; + tmat.set_translation(pos); + + return tmat * Matrix4x4(rmat); } void Ship::dbg_draw() const @@ -70,5 +66,15 @@ glVertex3f(pos.x, pos.y, pos.z); glEnd(); + glMatrixMode(GL_MODELVIEW); + glPushMatrix(); + mult_gl_matrix(get_matrix()); + + glScalef(1, 1, -1); + glColor3f(1, 1, 0); + glutWireCone(0.1, 0.6, 12, 2); + + glPopMatrix(); + glPopAttrib(); }