intravenous

annotate 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
rev   line source
nuclear@1 1 #include "opengl.h"
nuclear@1 2 #include "ship.h"
nuclear@1 3
nuclear@1 4 Ship::Ship()
nuclear@1 5 {
nuclear@1 6 friction = 0.2;
nuclear@1 7 //theta = phi = 0.0;
nuclear@1 8 }
nuclear@1 9
nuclear@1 10 void Ship::accelerate(double a)
nuclear@1 11 {
nuclear@1 12 velocity += get_direction() * a;
nuclear@1 13 }
nuclear@1 14
nuclear@1 15 void Ship::turn(double yaw, double pitch)
nuclear@1 16 {
nuclear@1 17 Quaternion qyaw(Vector3(0, 1, 0), yaw);
nuclear@1 18 Quaternion qpitch(Vector3(1, 0, 0), pitch);
nuclear@1 19
nuclear@1 20 rot *= qpitch;
nuclear@1 21 rot *= qyaw;
nuclear@1 22 /*theta += yaw;
nuclear@1 23 phi += pitch;*/
nuclear@1 24 }
nuclear@1 25
nuclear@1 26 void Ship::update(time_sec_t dt)
nuclear@1 27 {
nuclear@1 28 pos += velocity * dt;
nuclear@1 29 velocity -= velocity * friction * dt;
nuclear@1 30 }
nuclear@1 31
nuclear@1 32 const Vector3 &Ship::get_position() const
nuclear@1 33 {
nuclear@1 34 return pos;
nuclear@1 35 }
nuclear@1 36
nuclear@1 37 Vector3 Ship::get_direction() const
nuclear@1 38 {
nuclear@1 39 static const Vector3 dir{0, 0, 1};
nuclear@1 40 return dir.transformed(rot);
nuclear@1 41 /*Vector3 dir;
nuclear@1 42 dir.x = sin(theta) * sin(phi);
nuclear@1 43 dir.z = cos(phi);
nuclear@1 44 dir.y = cos(theta) * sin(phi);
nuclear@1 45 return dir;*/
nuclear@1 46 }
nuclear@1 47
nuclear@1 48 Matrix4x4 Ship::get_matrix() const
nuclear@1 49 {
nuclear@1 50 return Matrix4x4::identity;
nuclear@1 51 }
nuclear@1 52
nuclear@1 53 void Ship::dbg_draw() const
nuclear@1 54 {
nuclear@1 55 glPushAttrib(GL_POINT_BIT | GL_ENABLE_BIT);
nuclear@1 56
nuclear@1 57 glPointSize(3.0);
nuclear@1 58 glDisable(GL_LIGHTING);
nuclear@1 59
nuclear@1 60 glBegin(GL_LINES);
nuclear@1 61 glColor3f(0, 0, 1);
nuclear@1 62 glVertex3f(pos.x, pos.y, pos.z);
nuclear@1 63
nuclear@1 64 Vector3 end = pos + get_direction();
nuclear@1 65 glVertex3f(end.x, end.y, end.z);
nuclear@1 66 glEnd();
nuclear@1 67
nuclear@1 68 glBegin(GL_POINTS);
nuclear@1 69 glColor3f(1, 0, 0);
nuclear@1 70 glVertex3f(pos.x, pos.y, pos.z);
nuclear@1 71 glEnd();
nuclear@1 72
nuclear@1 73 glPopAttrib();
nuclear@1 74 }