intravenous

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