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