intravenous

view src/ship.cc @ 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
line source
1 #include "opengl.h"
2 #include "ship.h"
4 Ship::Ship()
5 {
6 friction = 0.2;
7 }
9 void Ship::accelerate(double a)
10 {
11 velocity += get_direction() * a;
12 }
14 void Ship::turn(double yaw, double pitch)
15 {
16 Quaternion qyaw(Vector3(0, 1, 0), yaw);
17 Quaternion qpitch(Vector3(1, 0, 0), pitch);
19 rot *= qpitch;
20 rot *= qyaw;
21 }
23 void Ship::update(time_sec_t dt)
24 {
25 pos += velocity * dt;
26 velocity -= velocity * friction * dt;
27 }
29 const Vector3 &Ship::get_position() const
30 {
31 return pos;
32 }
34 Vector3 Ship::get_direction() const
35 {
36 static const Vector3 dir{0, 0, -1};
37 return dir.transformed(rot);
38 }
40 Matrix4x4 Ship::get_matrix() const
41 {
42 Matrix3x3 rmat = rot.get_rotation_matrix().transposed();
43 Matrix4x4 tmat;
44 tmat.set_translation(pos);
46 return tmat * Matrix4x4(rmat);
47 }
49 void Ship::dbg_draw() const
50 {
51 glPushAttrib(GL_POINT_BIT | GL_ENABLE_BIT);
53 glPointSize(3.0);
54 glDisable(GL_LIGHTING);
56 glBegin(GL_LINES);
57 glColor3f(0, 0, 1);
58 glVertex3f(pos.x, pos.y, pos.z);
60 Vector3 end = pos + get_direction();
61 glVertex3f(end.x, end.y, end.z);
62 glEnd();
64 glBegin(GL_POINTS);
65 glColor3f(1, 0, 0);
66 glVertex3f(pos.x, pos.y, pos.z);
67 glEnd();
69 glMatrixMode(GL_MODELVIEW);
70 glPushMatrix();
71 mult_gl_matrix(get_matrix());
73 glScalef(1, 1, -1);
74 glColor3f(1, 1, 0);
75 glutWireCone(0.1, 0.6, 12, 2);
77 glPopMatrix();
79 glPopAttrib();
80 }