Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/FICN/src/orxonox/spaceship_steering.cc @ 342

Last change on this file since 342 was 337, checked in by bknecht, 17 years ago

merged merger to FICN branch

File size: 5.7 KB
RevLine 
[209]1#include "Ogre.h"
2#include "spaceship_steering.h"
3using namespace Ogre;
4
5SpaceshipSteering::SpaceshipSteering(float maxSpeedForward, float
6maxSpeedRotateUpDown, float maxSpeedRotateRightLeft, float
7maxSpeedLoopRightLeft) {
8  moveForward_ = 0;
9  rotateUp_ = 0;
10  rotateDown_ = 0;
11  rotateRight_ = 0;
12  rotateLeft_ = 0;
13  loopRight_ = 0;
14  loopLeft_ = 0;
[317]15  brakeForward_ = 0;
16  brakeRotate_ = 0;
17  brakeLoop_ = 0;
[209]18  speedForward_ = 0;
19  speedRotateUpDown_ = 0;
20  speedRotateRightLeft_ = 0;
21  speedLoopRightLeft_ = 0;
22  maxSpeedForward_ = maxSpeedForward;
23  maxSpeedRotateUpDown_ = maxSpeedRotateUpDown;
24  maxSpeedRotateRightLeft_ = maxSpeedRotateRightLeft;
25  maxSpeedLoopRightLeft_ = maxSpeedLoopRightLeft;
26  accelerationForward_ = 0;
27  accelerationRotateUpDown_ = 0;
28  accelerationRotateRightLeft_ = 0;
29  accelerationLoopRightLeft_ = 0;
30}
31
32void SpaceshipSteering::tick(float time) {
33
34  if(moveForward_ > 0) {
35    accelerationForward_ = moveForward_;
36    if(speedForward_ < maxSpeedForward_)
[317]37      speedForward_ += accelerationForward_*time;
[209]38    if(speedForward_ > maxSpeedForward_)
39      speedForward_ = maxSpeedForward_;
40  }
[317]41  if(moveForward_ <= 0) {
42    accelerationForward_ = brakeForward_;
[209]43    if(speedForward_ > 0)
[317]44      speedForward_ -= accelerationForward_*time;
[209]45    if(speedForward_ < 0)
46      speedForward_ = 0;
47  }
48
49  if(rotateUp_ > 0) {
50    accelerationRotateUpDown_ = rotateUp_;
51    if(speedRotateUpDown_ < maxSpeedRotateUpDown_)
[317]52      speedRotateUpDown_ += accelerationRotateUpDown_*time;
[209]53    if(speedRotateUpDown_ > maxSpeedRotateUpDown_)
54      speedRotateUpDown_ = maxSpeedRotateUpDown_;
55  }
[317]56  if(rotateDown_ > 0) {
[209]57    accelerationRotateUpDown_ = rotateDown_;
58    if(speedRotateUpDown_ > -maxSpeedRotateUpDown_)
[317]59      speedRotateUpDown_ -= accelerationRotateUpDown_*time;
[209]60    if(speedRotateUpDown_ < -maxSpeedRotateUpDown_)
61      speedRotateUpDown_ = -maxSpeedRotateUpDown_;
62  }
[317]63  if(rotateUp_ == 0 && rotateDown_ == 0) {
64    accelerationRotateUpDown_ = brakeRotate_;
[209]65    if(speedRotateUpDown_ > 0)
[317]66      speedRotateUpDown_ -= accelerationRotateUpDown_*time;
[209]67    if(speedRotateUpDown_ < 0)
[317]68      speedRotateUpDown_ += accelerationRotateUpDown_*time;
[209]69  }
70
71  if(rotateRight_ > 0) {
72    accelerationRotateRightLeft_ = rotateRight_;
73    if(speedRotateRightLeft_ > -maxSpeedRotateRightLeft_)
[317]74      speedRotateRightLeft_ -= accelerationRotateRightLeft_*time;
[209]75    if(speedRotateRightLeft_ < -maxSpeedRotateRightLeft_)
76      speedRotateRightLeft_ = -maxSpeedRotateRightLeft_;
77  }
[317]78  if(rotateLeft_ > 0) {
[209]79    accelerationRotateRightLeft_ = rotateLeft_;
80    if(speedRotateRightLeft_ < maxSpeedRotateRightLeft_)
[317]81      speedRotateRightLeft_ += accelerationRotateRightLeft_*time;
[209]82    if(speedRotateRightLeft_ > maxSpeedRotateRightLeft_)
83      speedRotateRightLeft_ = maxSpeedRotateRightLeft_;
84  }
[317]85  if(rotateRight_ == 0 && rotateLeft_ == 0) {
86    accelerationRotateRightLeft_ = brakeRotate_;
[209]87    if(speedRotateRightLeft_ > 0)
[317]88      speedRotateRightLeft_ -= accelerationRotateRightLeft_*time;
[209]89    if(speedRotateRightLeft_ < 0)
[317]90      speedRotateRightLeft_ += accelerationRotateRightLeft_*time;
[209]91  }
92
93  if(loopRight_ > 0) {
94    accelerationLoopRightLeft_ = loopRight_;
95    if(speedLoopRightLeft_ < maxSpeedLoopRightLeft_)
[317]96      speedLoopRightLeft_ += accelerationLoopRightLeft_*time;
[209]97    if(speedLoopRightLeft_ > maxSpeedLoopRightLeft_)
98      speedLoopRightLeft_ = maxSpeedLoopRightLeft_;
99  }
[317]100  if(loopLeft_ > 0) {
[209]101    accelerationLoopRightLeft_ = loopLeft_;
102    if(speedLoopRightLeft_ > -maxSpeedLoopRightLeft_)
[317]103      speedLoopRightLeft_ -= accelerationLoopRightLeft_*time;
[209]104    if(speedLoopRightLeft_ < -maxSpeedLoopRightLeft_)
105      speedLoopRightLeft_ = -maxSpeedLoopRightLeft_;
106  }
[317]107  if(loopLeft_ == 0 && loopRight_ == 0) {
108    accelerationLoopRightLeft_ = brakeLoop_;
[209]109    if(speedLoopRightLeft_ > 0)
[317]110      speedLoopRightLeft_ -= accelerationLoopRightLeft_*time;
[209]111    if(speedLoopRightLeft_ < 0)
[317]112      speedLoopRightLeft_ += accelerationLoopRightLeft_*time;
[209]113  }
114
115  Vector3 transVector = Vector3::ZERO;
116  transVector.z = 1;
117  steeringNode_->translate(transVector*speedForward_*time,
118  Node::TS_LOCAL);
119  steeringNode_->pitch(Degree(speedRotateUpDown_*time),
120  Node::TS_LOCAL);
121  steeringNode_->yaw(Degree(speedRotateRightLeft_*time),
122  Node::TS_LOCAL);
123  steeringNode_->roll(Degree(speedLoopRightLeft_*time),
124  Node::TS_LOCAL);
125
126}
127
128void SpaceshipSteering::moveForward(float moveForward) {
129  moveForward_ = moveForward;
130}
131
132void SpaceshipSteering::rotateUp(float rotateUp) {
133  rotateUp_ = rotateUp;
134}
135
136void SpaceshipSteering::rotateDown(float rotateDown) {
137  rotateDown_ = rotateDown;
138}
139
140void SpaceshipSteering::rotateLeft(float rotateLeft) {
141  rotateLeft_ = rotateLeft;
142}
143
144void SpaceshipSteering::rotateRight(float rotateRight) {
145  rotateRight_ = rotateRight;
146}
147
148void SpaceshipSteering::loopLeft(float loopLeft) {
149  loopLeft_ = loopLeft;
150}
151
152void SpaceshipSteering::loopRight(float loopRight) {
153  loopRight_ = loopRight;
154}
155
[317]156void SpaceshipSteering::brakeForward(float brakeForward) {
157  brakeForward_ = brakeForward;
158}
159
160void SpaceshipSteering::brakeRotate(float brakeRotate) {
161  brakeRotate_ = brakeRotate;
162}
163
164void SpaceshipSteering::brakeLoop(float brakeLoop) {
165  brakeLoop_ = brakeLoop;
166}
167
[209]168void SpaceshipSteering::maxSpeedForward(float maxSpeedForward) {
169  maxSpeedForward_ = maxSpeedForward;
170}
171
172void SpaceshipSteering::maxSpeedRotateUpDown(float maxSpeedRotateUpDown) {
173  maxSpeedRotateUpDown_ = maxSpeedRotateUpDown;
174}
175
176void SpaceshipSteering::maxSpeedRotateRightLeft(float maxSpeedRotateRightLeft) {
177  maxSpeedRotateRightLeft_ = maxSpeedRotateRightLeft;
178}
179
180void SpaceshipSteering::maxSpeedLoopRightLeft(float maxSpeedLoopRightLeft) {
181  maxSpeedLoopRightLeft_ = maxSpeedLoopRightLeft;
182}
183
184void SpaceshipSteering::addNode(Ogre::SceneNode *steeringNode) {
185  steeringNode_ = steeringNode;
186}
Note: See TracBrowser for help on using the repository browser.