[612] | 1 | /* |
---|
[708] | 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 | */ |
---|
[612] | 27 | |
---|
[786] | 28 | #include "OrxonoxStableHeaders.h" |
---|
[784] | 29 | |
---|
[708] | 30 | #include <OgreNode.h> |
---|
| 31 | #include <OgreSceneNode.h> |
---|
| 32 | |
---|
[728] | 33 | #include "core/Debug.h" |
---|
[742] | 34 | #include "util/Math.h" |
---|
[612] | 35 | #include "SpaceshipSteering.h" |
---|
| 36 | |
---|
[708] | 37 | namespace orxonox |
---|
| 38 | { |
---|
[612] | 39 | |
---|
[708] | 40 | SpaceshipSteering::SpaceshipSteering(float maxSpeedForward, float |
---|
| 41 | maxSpeedRotateUpDown, float maxSpeedRotateRightLeft, float |
---|
| 42 | maxSpeedLoopRightLeft) |
---|
| 43 | { |
---|
[612] | 44 | |
---|
[708] | 45 | COUT(3) << "Info: Steering was loaded" << std::endl; |
---|
| 46 | moveForward_ = 0; |
---|
| 47 | rotateUp_ = 0; |
---|
| 48 | rotateDown_ = 0; |
---|
| 49 | rotateRight_ = 0; |
---|
| 50 | rotateLeft_ = 0; |
---|
| 51 | loopRight_ = 0; |
---|
| 52 | loopLeft_ = 0; |
---|
| 53 | brakeForward_ = 0; |
---|
| 54 | brakeRotate_ = 0; |
---|
| 55 | brakeLoop_ = 0; |
---|
| 56 | speedForward_ = 0; |
---|
| 57 | speedRotateUpDown_ = 0; |
---|
| 58 | speedRotateRightLeft_ = 0; |
---|
| 59 | speedLoopRightLeft_ = 0; |
---|
| 60 | maxSpeedForward_ = maxSpeedForward; |
---|
| 61 | maxSpeedRotateUpDown_ = maxSpeedRotateUpDown; |
---|
| 62 | maxSpeedRotateRightLeft_ = maxSpeedRotateRightLeft; |
---|
| 63 | maxSpeedLoopRightLeft_ = maxSpeedLoopRightLeft; |
---|
| 64 | accelerationForward_ = 0; |
---|
| 65 | accelerationRotateUpDown_ = 0; |
---|
| 66 | accelerationRotateRightLeft_ = 0; |
---|
| 67 | accelerationLoopRightLeft_ = 0; |
---|
| 68 | } |
---|
[612] | 69 | |
---|
[708] | 70 | void SpaceshipSteering::tick(float time) |
---|
| 71 | { |
---|
[612] | 72 | |
---|
[708] | 73 | if(moveForward_ > 0) { |
---|
| 74 | accelerationForward_ = moveForward_; |
---|
| 75 | if(speedForward_ < maxSpeedForward_) |
---|
| 76 | speedForward_ += accelerationForward_*time; |
---|
| 77 | if(speedForward_ > maxSpeedForward_) |
---|
| 78 | speedForward_ = maxSpeedForward_; |
---|
| 79 | } |
---|
| 80 | if(moveForward_ <= 0) { |
---|
| 81 | accelerationForward_ = brakeForward_; |
---|
| 82 | if(speedForward_ > 0) |
---|
| 83 | speedForward_ -= accelerationForward_*time; |
---|
| 84 | if(speedForward_ < 0) |
---|
| 85 | speedForward_ = 0; |
---|
| 86 | } |
---|
| 87 | |
---|
| 88 | if(rotateUp_ > 0) { |
---|
| 89 | accelerationRotateUpDown_ = rotateUp_; |
---|
| 90 | if(speedRotateUpDown_ < maxSpeedRotateUpDown_) |
---|
| 91 | speedRotateUpDown_ += accelerationRotateUpDown_*time; |
---|
| 92 | if(speedRotateUpDown_ > maxSpeedRotateUpDown_) |
---|
| 93 | speedRotateUpDown_ = maxSpeedRotateUpDown_; |
---|
| 94 | } |
---|
| 95 | if(rotateDown_ > 0) { |
---|
| 96 | accelerationRotateUpDown_ = rotateDown_; |
---|
| 97 | if(speedRotateUpDown_ > -maxSpeedRotateUpDown_) |
---|
| 98 | speedRotateUpDown_ -= accelerationRotateUpDown_*time; |
---|
| 99 | if(speedRotateUpDown_ < -maxSpeedRotateUpDown_) |
---|
| 100 | speedRotateUpDown_ = -maxSpeedRotateUpDown_; |
---|
| 101 | } |
---|
| 102 | if(rotateUp_ == 0 && rotateDown_ == 0) { |
---|
| 103 | accelerationRotateUpDown_ = brakeRotate_; |
---|
| 104 | if(speedRotateUpDown_ > 0) |
---|
| 105 | speedRotateUpDown_ -= accelerationRotateUpDown_*time; |
---|
| 106 | if(speedRotateUpDown_ < 0) |
---|
| 107 | speedRotateUpDown_ += accelerationRotateUpDown_*time; |
---|
[768] | 108 | if(fabsf(speedRotateUpDown_)<accelerationRotateUpDown_*time) |
---|
[708] | 109 | speedRotateUpDown_ = 0; |
---|
| 110 | } |
---|
| 111 | |
---|
| 112 | if(rotateRight_ > 0) { |
---|
| 113 | accelerationRotateRightLeft_ = rotateRight_; |
---|
| 114 | if(speedRotateRightLeft_ > -maxSpeedRotateRightLeft_) |
---|
| 115 | speedRotateRightLeft_ -= accelerationRotateRightLeft_*time; |
---|
| 116 | if(speedRotateRightLeft_ < -maxSpeedRotateRightLeft_) |
---|
| 117 | speedRotateRightLeft_ = -maxSpeedRotateRightLeft_; |
---|
| 118 | } |
---|
| 119 | if(rotateLeft_ > 0) { |
---|
| 120 | accelerationRotateRightLeft_ = rotateLeft_; |
---|
| 121 | if(speedRotateRightLeft_ < maxSpeedRotateRightLeft_) |
---|
| 122 | speedRotateRightLeft_ += accelerationRotateRightLeft_*time; |
---|
| 123 | if(speedRotateRightLeft_ > maxSpeedRotateRightLeft_) |
---|
| 124 | speedRotateRightLeft_ = maxSpeedRotateRightLeft_; |
---|
| 125 | } |
---|
| 126 | if(rotateRight_ == 0 && rotateLeft_ == 0) { |
---|
| 127 | accelerationRotateRightLeft_ = brakeRotate_; |
---|
| 128 | if(speedRotateRightLeft_ > 0) |
---|
| 129 | speedRotateRightLeft_ -= accelerationRotateRightLeft_*time; |
---|
| 130 | if(speedRotateRightLeft_ < 0) |
---|
| 131 | speedRotateRightLeft_ += accelerationRotateRightLeft_*time; |
---|
[768] | 132 | if(fabsf(speedRotateRightLeft_)<accelerationRotateRightLeft_*time) |
---|
[708] | 133 | speedRotateRightLeft_ = 0; |
---|
| 134 | } |
---|
| 135 | |
---|
| 136 | if(loopRight_ > 0) { |
---|
| 137 | accelerationLoopRightLeft_ = loopRight_; |
---|
| 138 | if(speedLoopRightLeft_ < maxSpeedLoopRightLeft_) |
---|
| 139 | speedLoopRightLeft_ += accelerationLoopRightLeft_*time; |
---|
| 140 | if(speedLoopRightLeft_ > maxSpeedLoopRightLeft_) |
---|
| 141 | speedLoopRightLeft_ = maxSpeedLoopRightLeft_; |
---|
| 142 | } |
---|
| 143 | if(loopLeft_ > 0) { |
---|
| 144 | accelerationLoopRightLeft_ = loopLeft_; |
---|
| 145 | if(speedLoopRightLeft_ > -maxSpeedLoopRightLeft_) |
---|
| 146 | speedLoopRightLeft_ -= accelerationLoopRightLeft_*time; |
---|
| 147 | if(speedLoopRightLeft_ < -maxSpeedLoopRightLeft_) |
---|
| 148 | speedLoopRightLeft_ = -maxSpeedLoopRightLeft_; |
---|
| 149 | } |
---|
| 150 | if(loopLeft_ == 0 && loopRight_ == 0) { |
---|
| 151 | accelerationLoopRightLeft_ = brakeLoop_; |
---|
| 152 | if(speedLoopRightLeft_ > 0) |
---|
| 153 | speedLoopRightLeft_ -= accelerationLoopRightLeft_*time; |
---|
| 154 | if(speedLoopRightLeft_ < 0) |
---|
| 155 | speedLoopRightLeft_ += accelerationLoopRightLeft_*time; |
---|
[768] | 156 | if(fabsf(speedLoopRightLeft_)<accelerationLoopRightLeft_*time) |
---|
[708] | 157 | speedLoopRightLeft_ = 0; |
---|
| 158 | } |
---|
| 159 | |
---|
| 160 | Vector3 transVector = Vector3::ZERO; |
---|
| 161 | transVector.z = 1; |
---|
| 162 | steeringNode_->translate(transVector*speedForward_*time, |
---|
| 163 | Ogre::SceneNode::TS_LOCAL); |
---|
| 164 | steeringNode_->pitch(Degree(speedRotateUpDown_*time), |
---|
| 165 | Ogre::SceneNode::TS_LOCAL); |
---|
| 166 | steeringNode_->yaw(Degree(speedRotateRightLeft_*time), |
---|
| 167 | Ogre::SceneNode::TS_LOCAL); |
---|
| 168 | steeringNode_->roll(Degree(speedLoopRightLeft_*time), |
---|
| 169 | Ogre::SceneNode::TS_LOCAL); |
---|
| 170 | |
---|
[612] | 171 | } |
---|
[708] | 172 | |
---|
| 173 | void SpaceshipSteering::moveForward(float moveForward) { |
---|
| 174 | moveForward_ = moveForward; |
---|
[612] | 175 | } |
---|
| 176 | |
---|
[708] | 177 | void SpaceshipSteering::rotateUp(float rotateUp) { |
---|
| 178 | rotateUp_ = rotateUp; |
---|
[612] | 179 | } |
---|
[708] | 180 | |
---|
| 181 | void SpaceshipSteering::rotateDown(float rotateDown) { |
---|
| 182 | rotateDown_ = rotateDown; |
---|
[612] | 183 | } |
---|
[708] | 184 | |
---|
| 185 | void SpaceshipSteering::rotateLeft(float rotateLeft) { |
---|
| 186 | rotateLeft_ = rotateLeft; |
---|
[612] | 187 | } |
---|
| 188 | |
---|
[708] | 189 | void SpaceshipSteering::rotateRight(float rotateRight) { |
---|
| 190 | rotateRight_ = rotateRight; |
---|
[612] | 191 | } |
---|
[708] | 192 | |
---|
| 193 | void SpaceshipSteering::loopLeft(float loopLeft) { |
---|
| 194 | loopLeft_ = loopLeft; |
---|
[612] | 195 | } |
---|
[708] | 196 | |
---|
| 197 | void SpaceshipSteering::loopRight(float loopRight) { |
---|
| 198 | loopRight_ = loopRight; |
---|
[612] | 199 | } |
---|
| 200 | |
---|
[708] | 201 | void SpaceshipSteering::brakeForward(float brakeForward) { |
---|
| 202 | brakeForward_ = brakeForward; |
---|
[612] | 203 | } |
---|
[708] | 204 | |
---|
| 205 | void SpaceshipSteering::brakeRotate(float brakeRotate) { |
---|
| 206 | brakeRotate_ = brakeRotate; |
---|
[612] | 207 | } |
---|
[708] | 208 | |
---|
| 209 | void SpaceshipSteering::brakeLoop(float brakeLoop) { |
---|
| 210 | brakeLoop_ = brakeLoop; |
---|
[612] | 211 | } |
---|
| 212 | |
---|
[708] | 213 | void SpaceshipSteering::maxSpeedForward(float maxSpeedForward) { |
---|
| 214 | maxSpeedForward_ = maxSpeedForward; |
---|
| 215 | } |
---|
[612] | 216 | |
---|
[708] | 217 | void SpaceshipSteering::maxSpeedRotateUpDown(float maxSpeedRotateUpDown) { |
---|
| 218 | maxSpeedRotateUpDown_ = maxSpeedRotateUpDown; |
---|
| 219 | } |
---|
[612] | 220 | |
---|
[708] | 221 | void SpaceshipSteering::maxSpeedRotateRightLeft(float maxSpeedRotateRightLeft) { |
---|
| 222 | maxSpeedRotateRightLeft_ = maxSpeedRotateRightLeft; |
---|
| 223 | } |
---|
[612] | 224 | |
---|
[708] | 225 | void SpaceshipSteering::maxSpeedLoopRightLeft(float maxSpeedLoopRightLeft) { |
---|
| 226 | maxSpeedLoopRightLeft_ = maxSpeedLoopRightLeft; |
---|
| 227 | } |
---|
[612] | 228 | |
---|
[708] | 229 | void SpaceshipSteering::addNode(Ogre::SceneNode *steeringNode) { |
---|
| 230 | steeringNode_ = steeringNode; |
---|
| 231 | } |
---|
[612] | 232 | |
---|
[728] | 233 | } |
---|