Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 588 was 560, checked in by landauf, 17 years ago
  • changed output from std::cout to COUT(level)
  • added SoftDebugLevel config-variable (its a hack, but it works fine)
File size: 6.9 KB
Line 
1/*
2 *   ORXONOX - the hottest 3D action shooter ever to exist
3 *
4 *
5 *   License notice:
6 *
7 *   This program is free software; you can redistribute it and/or
8 *   modify it under the terms of the GNU General Public License
9 *   as published by the Free Software Foundation; either version 2
10 *   of the License, or (at your option) any later version.
11 *
12 *   This program is distributed in the hope that it will be useful,
13 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
14 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 *   GNU General Public License for more details.
16 *
17 *   You should have received a copy of the GNU General Public License
18 *   along with this program; if not, write to the Free Software
19 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
20 *
21 *   Author:
22 *      ...
23 *   Co-authors:
24 *      ...
25 *
26 */
27
28#include "Ogre.h"
29#include "spaceship_steering.h"
30#include <iostream>
31#include "core/Debug.h"
32
33using namespace Ogre;
34
35SpaceshipSteering::SpaceshipSteering(float maxSpeedForward, float
36maxSpeedRotateUpDown, float maxSpeedRotateRightLeft, float
37maxSpeedLoopRightLeft) {
38
39  COUT(3) << "Info: Steering was loaded" << std::endl;
40  moveForward_ = 0;
41  rotateUp_ = 0;
42  rotateDown_ = 0;
43  rotateRight_ = 0;
44  rotateLeft_ = 0;
45  loopRight_ = 0;
46  loopLeft_ = 0;
47  brakeForward_ = 0;
48  brakeRotate_ = 0;
49  brakeLoop_ = 0;
50  speedForward_ = 0;
51  speedRotateUpDown_ = 0;
52  speedRotateRightLeft_ = 0;
53  speedLoopRightLeft_ = 0;
54  maxSpeedForward_ = maxSpeedForward;
55  maxSpeedRotateUpDown_ = maxSpeedRotateUpDown;
56  maxSpeedRotateRightLeft_ = maxSpeedRotateRightLeft;
57  maxSpeedLoopRightLeft_ = maxSpeedLoopRightLeft;
58  accelerationForward_ = 0;
59  accelerationRotateUpDown_ = 0;
60  accelerationRotateRightLeft_ = 0;
61  accelerationLoopRightLeft_ = 0;
62}
63
64void SpaceshipSteering::tick(float time) {
65
66  if(moveForward_ > 0) {
67    accelerationForward_ = moveForward_;
68    if(speedForward_ < maxSpeedForward_)
69      speedForward_ += accelerationForward_*time;
70    if(speedForward_ > maxSpeedForward_)
71      speedForward_ = maxSpeedForward_;
72  }
73  if(moveForward_ <= 0) {
74    accelerationForward_ = brakeForward_;
75    if(speedForward_ > 0)
76      speedForward_ -= accelerationForward_*time;
77    if(speedForward_ < 0)
78      speedForward_ = 0;
79  }
80
81  if(rotateUp_ > 0) {
82    accelerationRotateUpDown_ = rotateUp_;
83    if(speedRotateUpDown_ < maxSpeedRotateUpDown_)
84      speedRotateUpDown_ += accelerationRotateUpDown_*time;
85    if(speedRotateUpDown_ > maxSpeedRotateUpDown_)
86      speedRotateUpDown_ = maxSpeedRotateUpDown_;
87  }
88  if(rotateDown_ > 0) {
89    accelerationRotateUpDown_ = rotateDown_;
90    if(speedRotateUpDown_ > -maxSpeedRotateUpDown_)
91      speedRotateUpDown_ -= accelerationRotateUpDown_*time;
92    if(speedRotateUpDown_ < -maxSpeedRotateUpDown_)
93      speedRotateUpDown_ = -maxSpeedRotateUpDown_;
94  }
95  if(rotateUp_ == 0 && rotateDown_ == 0) {
96    accelerationRotateUpDown_ = brakeRotate_;
97    if(speedRotateUpDown_ > 0)
98      speedRotateUpDown_ -= accelerationRotateUpDown_*time;
99    if(speedRotateUpDown_ < 0)
100      speedRotateUpDown_ += accelerationRotateUpDown_*time;
101    if(abs(speedRotateUpDown_)<accelerationRotateUpDown_*time)
102      speedRotateUpDown_ = 0;
103  }
104
105  if(rotateRight_ > 0) {
106    accelerationRotateRightLeft_ = rotateRight_;
107    if(speedRotateRightLeft_ > -maxSpeedRotateRightLeft_)
108      speedRotateRightLeft_ -= accelerationRotateRightLeft_*time;
109    if(speedRotateRightLeft_ < -maxSpeedRotateRightLeft_)
110      speedRotateRightLeft_ = -maxSpeedRotateRightLeft_;
111  }
112  if(rotateLeft_ > 0) {
113    accelerationRotateRightLeft_ = rotateLeft_;
114    if(speedRotateRightLeft_ < maxSpeedRotateRightLeft_)
115      speedRotateRightLeft_ += accelerationRotateRightLeft_*time;
116    if(speedRotateRightLeft_ > maxSpeedRotateRightLeft_)
117      speedRotateRightLeft_ = maxSpeedRotateRightLeft_;
118  }
119  if(rotateRight_ == 0 && rotateLeft_ == 0) {
120    accelerationRotateRightLeft_ = brakeRotate_;
121    if(speedRotateRightLeft_ > 0)
122      speedRotateRightLeft_ -= accelerationRotateRightLeft_*time;
123    if(speedRotateRightLeft_ < 0)
124      speedRotateRightLeft_ += accelerationRotateRightLeft_*time;
125    if(abs(speedRotateRightLeft_)<accelerationRotateRightLeft_*time)
126      speedRotateRightLeft_ = 0;
127  }
128
129  if(loopRight_ > 0) {
130    accelerationLoopRightLeft_ = loopRight_;
131    if(speedLoopRightLeft_ < maxSpeedLoopRightLeft_)
132      speedLoopRightLeft_ += accelerationLoopRightLeft_*time;
133    if(speedLoopRightLeft_ > maxSpeedLoopRightLeft_)
134      speedLoopRightLeft_ = maxSpeedLoopRightLeft_;
135  }
136  if(loopLeft_ > 0) {
137    accelerationLoopRightLeft_ = loopLeft_;
138    if(speedLoopRightLeft_ > -maxSpeedLoopRightLeft_)
139      speedLoopRightLeft_ -= accelerationLoopRightLeft_*time;
140    if(speedLoopRightLeft_ < -maxSpeedLoopRightLeft_)
141      speedLoopRightLeft_ = -maxSpeedLoopRightLeft_;
142  }
143  if(loopLeft_ == 0 && loopRight_ == 0) {
144    accelerationLoopRightLeft_ = brakeLoop_;
145    if(speedLoopRightLeft_ > 0)
146      speedLoopRightLeft_ -= accelerationLoopRightLeft_*time;
147    if(speedLoopRightLeft_ < 0)
148      speedLoopRightLeft_ += accelerationLoopRightLeft_*time;
149    if(abs(speedLoopRightLeft_)<accelerationLoopRightLeft_*time)
150      speedLoopRightLeft_ = 0;
151  }
152
153  Vector3 transVector = Vector3::ZERO;
154  transVector.z = 1;
155  steeringNode_->translate(transVector*speedForward_*time,
156  Node::TS_LOCAL);
157  steeringNode_->pitch(Degree(speedRotateUpDown_*time),
158  Node::TS_LOCAL);
159  steeringNode_->yaw(Degree(speedRotateRightLeft_*time),
160  Node::TS_LOCAL);
161  steeringNode_->roll(Degree(speedLoopRightLeft_*time),
162  Node::TS_LOCAL);
163
164}
165
166void SpaceshipSteering::moveForward(float moveForward) {
167  moveForward_ = moveForward;
168}
169
170void SpaceshipSteering::rotateUp(float rotateUp) {
171  rotateUp_ = rotateUp;
172}
173
174void SpaceshipSteering::rotateDown(float rotateDown) {
175  rotateDown_ = rotateDown;
176}
177
178void SpaceshipSteering::rotateLeft(float rotateLeft) {
179  rotateLeft_ = rotateLeft;
180}
181
182void SpaceshipSteering::rotateRight(float rotateRight) {
183  rotateRight_ = rotateRight;
184}
185
186void SpaceshipSteering::loopLeft(float loopLeft) {
187  loopLeft_ = loopLeft;
188}
189
190void SpaceshipSteering::loopRight(float loopRight) {
191  loopRight_ = loopRight;
192}
193
194void SpaceshipSteering::brakeForward(float brakeForward) {
195  brakeForward_ = brakeForward;
196}
197
198void SpaceshipSteering::brakeRotate(float brakeRotate) {
199  brakeRotate_ = brakeRotate;
200}
201
202void SpaceshipSteering::brakeLoop(float brakeLoop) {
203  brakeLoop_ = brakeLoop;
204}
205
206void SpaceshipSteering::maxSpeedForward(float maxSpeedForward) {
207  maxSpeedForward_ = maxSpeedForward;
208}
209
210void SpaceshipSteering::maxSpeedRotateUpDown(float maxSpeedRotateUpDown) {
211  maxSpeedRotateUpDown_ = maxSpeedRotateUpDown;
212}
213
214void SpaceshipSteering::maxSpeedRotateRightLeft(float maxSpeedRotateRightLeft) {
215  maxSpeedRotateRightLeft_ = maxSpeedRotateRightLeft;
216}
217
218void SpaceshipSteering::maxSpeedLoopRightLeft(float maxSpeedLoopRightLeft) {
219  maxSpeedLoopRightLeft_ = maxSpeedLoopRightLeft;
220}
221
222void SpaceshipSteering::addNode(Ogre::SceneNode *steeringNode) {
223  steeringNode_ = steeringNode;
224}
Note: See TracBrowser for help on using the repository browser.