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