intravenous
diff src/ship.cc @ 1:3ea290d35984
it's never going to finish but wth :)
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Sat, 21 Apr 2012 22:42:43 +0300 |
parents | |
children | 472c28b8b875 |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/ship.cc Sat Apr 21 22:42:43 2012 +0300 1.3 @@ -0,0 +1,74 @@ 1.4 +#include "opengl.h" 1.5 +#include "ship.h" 1.6 + 1.7 +Ship::Ship() 1.8 +{ 1.9 + friction = 0.2; 1.10 + //theta = phi = 0.0; 1.11 +} 1.12 + 1.13 +void Ship::accelerate(double a) 1.14 +{ 1.15 + velocity += get_direction() * a; 1.16 +} 1.17 + 1.18 +void Ship::turn(double yaw, double pitch) 1.19 +{ 1.20 + Quaternion qyaw(Vector3(0, 1, 0), yaw); 1.21 + Quaternion qpitch(Vector3(1, 0, 0), pitch); 1.22 + 1.23 + rot *= qpitch; 1.24 + rot *= qyaw; 1.25 + /*theta += yaw; 1.26 + phi += pitch;*/ 1.27 +} 1.28 + 1.29 +void Ship::update(time_sec_t dt) 1.30 +{ 1.31 + pos += velocity * dt; 1.32 + velocity -= velocity * friction * dt; 1.33 +} 1.34 + 1.35 +const Vector3 &Ship::get_position() const 1.36 +{ 1.37 + return pos; 1.38 +} 1.39 + 1.40 +Vector3 Ship::get_direction() const 1.41 +{ 1.42 + static const Vector3 dir{0, 0, 1}; 1.43 + return dir.transformed(rot); 1.44 + /*Vector3 dir; 1.45 + dir.x = sin(theta) * sin(phi); 1.46 + dir.z = cos(phi); 1.47 + dir.y = cos(theta) * sin(phi); 1.48 + return dir;*/ 1.49 +} 1.50 + 1.51 +Matrix4x4 Ship::get_matrix() const 1.52 +{ 1.53 + return Matrix4x4::identity; 1.54 +} 1.55 + 1.56 +void Ship::dbg_draw() const 1.57 +{ 1.58 + glPushAttrib(GL_POINT_BIT | GL_ENABLE_BIT); 1.59 + 1.60 + glPointSize(3.0); 1.61 + glDisable(GL_LIGHTING); 1.62 + 1.63 + glBegin(GL_LINES); 1.64 + glColor3f(0, 0, 1); 1.65 + glVertex3f(pos.x, pos.y, pos.z); 1.66 + 1.67 + Vector3 end = pos + get_direction(); 1.68 + glVertex3f(end.x, end.y, end.z); 1.69 + glEnd(); 1.70 + 1.71 + glBegin(GL_POINTS); 1.72 + glColor3f(1, 0, 0); 1.73 + glVertex3f(pos.x, pos.y, pos.z); 1.74 + glEnd(); 1.75 + 1.76 + glPopAttrib(); 1.77 +}