mElite  1.0
An Elite clone based on TextElite by Jan-Philipp Kappmeier and Melanie Schmidt.
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
MovingObject.cpp
Go to the documentation of this file.
1 
6 #include "MovingObject.h"
7 #include "Vector3.h"
8 #include "Vectormath.h"
9 
15  view = Vector3( 0, 0, 1 );
16  up = Vector3( 0, 1, 0 );
17  m_speed = 0.0;
18  m_maxspeed = 1.0;
19  m_minspeed = -0.09f;
20  m_step = 1.0f/20.0f;
21 }
22 
27 MovingObject::MovingObject( Vector3 position ) : GameObject( position ) {
28  view = Vector3( 0, 0, 1 );
29  up = Vector3( 0, 1, 0 );
30  m_speed = 0.0f;
31  m_maxspeed = 1.0f;
32  m_minspeed = -0.09f;
33  m_step = 1.0f/20.0f;
34 }
35 
42 MovingObject::MovingObject( float x, float y, float z ) : GameObject( x, y, z ) {
43  view = Vector3( 0, 0, 1 );
44  up = Vector3( 0, 1, 0 );
45  m_speed = 0.0f;
46  m_maxspeed = 1.0f;
47  m_minspeed = -0.09f;
48  m_step = 1.0f/20.0f;
49 }
50 
55 
56 }
57 
59 
63 void MovingObject::pitch( float angle ) {
64  Vector3 xa;
65 
66  xa = view * up;
67  view = VectorMath::rotateVector( angle, xa, view );
68  up = VectorMath::rotateVector( angle, xa, up );
69 }
70 
72 
76 void MovingObject::roll( float angle ) {
77  up = VectorMath::rotateVector( angle, view, up );
78 }
79 
84  return view * up;
85 }
86 
91  return up;
92 }
93 
98  return view;
99 }
100 
105  view = v;
106 }
107 
109 
115 void MovingObject::accelerate( float step ) {
116  m_speed += step * m_step;
117  if( m_speed < m_minspeed )
118  m_speed = m_minspeed;
119  if( m_speed > this->m_maxspeed )
120  m_speed = this->m_maxspeed;
121 }
122 
127 void MovingObject::advance( float t ) {
128  setPos( getPos().x + t * m_speed * view.x, getPos().y + t * m_speed * view.y, getPos().z + t * m_speed * view.z );
129 }
130 
135  return m_maxspeed;
136 }
137 
142  return m_minspeed;
143 }
144 
149  return m_speed;
150 }
151 
156 void MovingObject::setMaxSpeed( float speed) {
157  m_maxspeed = speed;
158 }
159 
164 void MovingObject::setMinSpeed( float speed ) {
165  m_minspeed = speed;
166 }
167 
172 void MovingObject::setSpeed( float speed ) {
173  if( speed < m_minspeed )
174  m_speed = m_minspeed;
175  else if( speed > m_maxspeed )
176  m_speed = m_maxspeed;
177  else
178  m_speed = speed;
179 }
180 
185 void MovingObject::setStep( float step ) {
186  m_step = step;
187 }