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