[608] | 1 | /* |
---|
| 2 | * ORXONOX - the hottest 3D action shooter ever to exist |
---|
[1056] | 3 | * > www.orxonox.net < |
---|
[608] | 4 | * |
---|
| 5 | * |
---|
| 6 | * License notice: |
---|
| 7 | * |
---|
| 8 | * This program is free software; you can redistribute it and/or |
---|
| 9 | * modify it under the terms of the GNU General Public License |
---|
| 10 | * as published by the Free Software Foundation; either version 2 |
---|
| 11 | * of the License, or (at your option) any later version. |
---|
| 12 | * |
---|
| 13 | * This program is distributed in the hope that it will be useful, |
---|
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 16 | * GNU General Public License for more details. |
---|
| 17 | * |
---|
| 18 | * You should have received a copy of the GNU General Public License |
---|
| 19 | * along with this program; if not, write to the Free Software |
---|
| 20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
---|
| 21 | * |
---|
| 22 | * Author: |
---|
[670] | 23 | * Fabian 'x3n' Landau |
---|
[608] | 24 | * Co-authors: |
---|
[1293] | 25 | * Benjamin Knecht |
---|
[608] | 26 | * |
---|
| 27 | */ |
---|
| 28 | |
---|
[786] | 29 | #include "OrxonoxStableHeaders.h" |
---|
[1039] | 30 | #include "SpaceShip.h" |
---|
[784] | 31 | |
---|
[708] | 32 | #include <OgreCamera.h> |
---|
| 33 | #include <OgreRenderWindow.h> |
---|
| 34 | #include <OgreParticleSystem.h> |
---|
| 35 | #include <OgreSceneNode.h> |
---|
[608] | 36 | |
---|
[1293] | 37 | #include "CameraHandler.h" |
---|
[1362] | 38 | #include "util/Convert.h" |
---|
[742] | 39 | #include "util/Math.h" |
---|
[1021] | 40 | #include "core/CoreIncludes.h" |
---|
[1052] | 41 | #include "core/ConfigValueIncludes.h" |
---|
[1021] | 42 | #include "core/Debug.h" |
---|
[1032] | 43 | #include "GraphicsEngine.h" |
---|
[1024] | 44 | #include "core/InputManager.h" |
---|
[1021] | 45 | #include "particle/ParticleInterface.h" |
---|
[708] | 46 | #include "Projectile.h" |
---|
[871] | 47 | #include "core/XMLPort.h" |
---|
[1052] | 48 | #include "core/ConsoleCommand.h" |
---|
[1293] | 49 | #include "network/Client.h" |
---|
[608] | 50 | |
---|
| 51 | namespace orxonox |
---|
| 52 | { |
---|
[1386] | 53 | ConsoleCommand(SpaceShip, setMaxSpeedTest, AccessLevel::Debug, false); |
---|
[1362] | 54 | ConsoleCommand(SpaceShip, whereAmI, AccessLevel::User, true); |
---|
[1391] | 55 | ConsoleCommand(SpaceShip, moveLongitudinal, AccessLevel::User, true).setDefaultValue(0, 1.0f).setAxisParamIndex(0).setKeybindMode(KeybindMode::OnHold); |
---|
| 56 | ConsoleCommand(SpaceShip, moveLateral, AccessLevel::User, true).setDefaultValue(0, 1.0f).setAxisParamIndex(0).setKeybindMode(KeybindMode::OnHold); |
---|
| 57 | ConsoleCommand(SpaceShip, moveYaw, AccessLevel::User, true).setDefaultValue(0, 1.0f).setAxisParamIndex(0).setKeybindMode(KeybindMode::OnHold); |
---|
| 58 | ConsoleCommand(SpaceShip, movePitch, AccessLevel::User, true).setDefaultValue(0, 1.0f).setAxisParamIndex(0).setKeybindMode(KeybindMode::OnHold); |
---|
| 59 | ConsoleCommand(SpaceShip, moveRoll, AccessLevel::User, true).setDefaultValue(0, 1.0f).setAxisParamIndex(0).setKeybindMode(KeybindMode::OnHold); |
---|
| 60 | ConsoleCommand(SpaceShip, fire, AccessLevel::User, true).setKeybindMode(KeybindMode::OnHold); |
---|
[1052] | 61 | ConsoleCommandGeneric(test1, SpaceShip, createExecutor(createFunctor(&SpaceShip::setMaxSpeedTest), "setMaxSpeed", AccessLevel::Debug), false); |
---|
| 62 | ConsoleCommandGeneric(test2, SpaceShip, createExecutor(createFunctor(&SpaceShip::setMaxSpeedTest), "setMaxBlubber", AccessLevel::Debug), false); |
---|
[1386] | 63 | ConsoleCommandGeneric(test3, SpaceShip, createExecutor(createFunctor(&SpaceShip::setMaxSpeedTest), "setRofl", AccessLevel::Debug), false); |
---|
[1052] | 64 | |
---|
[608] | 65 | CreateFactory(SpaceShip); |
---|
| 66 | |
---|
[1052] | 67 | SpaceShip* SpaceShip::instance_s; |
---|
| 68 | |
---|
[1360] | 69 | SpaceShip *SpaceShip::getLocalShip(){ |
---|
| 70 | Iterator<SpaceShip> it; |
---|
| 71 | for(it = ObjectList<SpaceShip>::start(); it; ++it){ |
---|
| 72 | if((it)->server_ || ( network::Client::getSingleton() && network::Client::getSingleton()->getShipID()==it->objectID ) ) |
---|
| 73 | return *it; |
---|
| 74 | } |
---|
| 75 | return NULL; |
---|
| 76 | } |
---|
| 77 | |
---|
[1293] | 78 | SpaceShip::SpaceShip() : |
---|
| 79 | //testvector_(0,0,0), |
---|
| 80 | //bInvertYAxis_(false), |
---|
| 81 | setMouseEventCallback_(false), |
---|
| 82 | bLMousePressed_(false), |
---|
| 83 | bRMousePressed_(false), |
---|
| 84 | camNode_(0), |
---|
| 85 | cam_(0), |
---|
| 86 | camName_("CamNode"), |
---|
| 87 | tt_(0), |
---|
| 88 | redNode_(0), |
---|
| 89 | greenNode_(0), |
---|
| 90 | blinkTime_(0.0f), |
---|
| 91 | chNearNode_(0), |
---|
| 92 | chFarNode_(0), |
---|
| 93 | timeToReload_(0.0f), |
---|
| 94 | //reloadTime_(0.0f), |
---|
| 95 | maxSideAndBackSpeed_(0.0f), |
---|
| 96 | maxSpeed_(0.0f), |
---|
| 97 | maxRotation_(0.0f), |
---|
| 98 | translationAcceleration_(0.0f), |
---|
| 99 | rotationAcceleration_(0.0f), |
---|
| 100 | translationDamping_(0.0f), |
---|
| 101 | rotationDamping_(0.0f), |
---|
| 102 | maxRotationRadian_(0), |
---|
| 103 | rotationAccelerationRadian_(0), |
---|
| 104 | rotationDampingRadian_(0), |
---|
| 105 | zeroRadian_(0), |
---|
| 106 | mouseXRotation_(0), |
---|
| 107 | mouseYRotation_(0), |
---|
| 108 | mouseX_(0.0f), |
---|
| 109 | mouseY_(0.0f), |
---|
| 110 | emitterRate_(0.0f), |
---|
| 111 | server_(false) |
---|
[608] | 112 | { |
---|
| 113 | RegisterObject(SpaceShip); |
---|
[1021] | 114 | this->registerAllVariables(); |
---|
[608] | 115 | |
---|
[1052] | 116 | SpaceShip::instance_s = this; |
---|
| 117 | |
---|
[697] | 118 | this->setConfigValues(); |
---|
[608] | 119 | |
---|
| 120 | |
---|
[647] | 121 | this->setRotationAxis(1, 0, 0); |
---|
| 122 | this->setStatic(false); |
---|
[608] | 123 | |
---|
| 124 | COUT(3) << "Info: SpaceShip was loaded" << std::endl; |
---|
| 125 | } |
---|
| 126 | |
---|
| 127 | SpaceShip::~SpaceShip() |
---|
| 128 | { |
---|
[647] | 129 | if (this->tt_) |
---|
| 130 | delete this->tt_; |
---|
[1293] | 131 | if(setMouseEventCallback_) |
---|
| 132 | InputManager::removeMouseHandler("SpaceShip"); |
---|
| 133 | if (this->cam_) |
---|
| 134 | delete this->cam_; |
---|
[608] | 135 | } |
---|
| 136 | |
---|
[1021] | 137 | bool SpaceShip::create(){ |
---|
| 138 | if(Model::create()) |
---|
| 139 | this->init(); |
---|
| 140 | else |
---|
| 141 | return false; |
---|
| 142 | return true; |
---|
| 143 | } |
---|
[1056] | 144 | |
---|
[1021] | 145 | void SpaceShip::registerAllVariables(){ |
---|
[1293] | 146 | registerVar( &camName_, camName_.length()+1, network::STRING, 0x1); |
---|
| 147 | registerVar( &maxSpeed_, sizeof(maxSpeed_), network::DATA, 0x1); |
---|
| 148 | registerVar( &maxSideAndBackSpeed_, sizeof(maxSideAndBackSpeed_), network::DATA, 0x1); |
---|
| 149 | registerVar( &maxRotation_, sizeof(maxRotation_), network::DATA, 0x1); |
---|
| 150 | registerVar( &translationAcceleration_, sizeof(translationAcceleration_), network::DATA, 0x1); |
---|
| 151 | registerVar( &rotationAcceleration_, sizeof(rotationAcceleration_), network::DATA, 0x1); |
---|
| 152 | registerVar( &rotationAccelerationRadian_, sizeof(rotationAccelerationRadian_), network::DATA, 0x1); |
---|
| 153 | registerVar( &translationDamping_, sizeof(translationDamping_), network::DATA, 0x1); |
---|
| 154 | registerVar( &rotationDamping_, sizeof(rotationDamping_), network::DATA, 0x1); |
---|
| 155 | registerVar( &rotationDampingRadian_, sizeof(rotationDampingRadian_), network::DATA, 0x1); |
---|
[1056] | 156 | |
---|
[1021] | 157 | } |
---|
[1056] | 158 | |
---|
[871] | 159 | void SpaceShip::init() |
---|
[697] | 160 | { |
---|
[633] | 161 | // START CREATING THRUSTER |
---|
[1032] | 162 | this->tt_ = new ParticleInterface(GraphicsEngine::getSingleton().getSceneManager(),"twinthruster" + this->getName(),"Orxonox/engineglow"); |
---|
[647] | 163 | this->tt_->getParticleSystem()->setParameter("local_space","true"); |
---|
[978] | 164 | this->tt_->newEmitter(); |
---|
[608] | 165 | /* |
---|
[647] | 166 | this->tt_->setDirection(Vector3(0,0,1)); |
---|
| 167 | this->tt_->setPositionOfEmitter(0, Vector3(20,-1,-15)); |
---|
| 168 | this->tt_->setPositionOfEmitter(1, Vector3(-20,-1,-15)); |
---|
[608] | 169 | */ |
---|
[647] | 170 | this->tt_->setDirection(Vector3(-1,0,0)); |
---|
[978] | 171 | this->tt_->setPositionOfEmitter(0, Vector3(-15,20,-1)); |
---|
| 172 | this->tt_->setPositionOfEmitter(1, Vector3(-15,-20,-1)); |
---|
[647] | 173 | this->tt_->setVelocity(50); |
---|
[608] | 174 | |
---|
[633] | 175 | emitterRate_ = tt_->getRate(); |
---|
[626] | 176 | |
---|
[633] | 177 | Ogre::SceneNode* node2 = this->getNode()->createChildSceneNode(this->getName() + "particle2"); |
---|
| 178 | node2->setInheritScale(false); |
---|
| 179 | tt_->addToSceneNode(node2); |
---|
| 180 | // END CREATING THRUSTER |
---|
[608] | 181 | |
---|
[633] | 182 | // START CREATING BLINKING LIGHTS |
---|
| 183 | this->redBillboard_.setBillboardSet("Examples/Flare", ColourValue(1.0, 0.0, 0.0), 1); |
---|
| 184 | this->greenBillboard_.setBillboardSet("Examples/Flare", ColourValue(0.0, 1.0, 0.0), 1); |
---|
[608] | 185 | |
---|
[1293] | 186 | this->redNode_ = this->getNode()->createChildSceneNode(this->getName() + "red", Vector3(0.3, 4.0, -0.3)); |
---|
[633] | 187 | this->redNode_->setInheritScale(false); |
---|
[1293] | 188 | this->greenNode_ = this->getNode()->createChildSceneNode(this->getName() + "green", Vector3(0.3, -4.0, -0.3)); |
---|
[633] | 189 | this->greenNode_->setInheritScale(false); |
---|
[608] | 190 | |
---|
[633] | 191 | this->redNode_->attachObject(this->redBillboard_.getBillboardSet()); |
---|
| 192 | this->redNode_->setScale(0.3, 0.3, 0.3); |
---|
[608] | 193 | |
---|
[633] | 194 | this->greenNode_->attachObject(this->greenBillboard_.getBillboardSet()); |
---|
| 195 | this->greenNode_->setScale(0.3, 0.3, 0.3); |
---|
| 196 | // END CREATING BLINKING LIGHTS |
---|
[608] | 197 | |
---|
[661] | 198 | // START of testing crosshair |
---|
| 199 | this->crosshairNear_.setBillboardSet("Orxonox/Crosshair", ColourValue(1.0, 1.0, 0.0), 1); |
---|
| 200 | this->crosshairFar_.setBillboardSet("Orxonox/Crosshair", ColourValue(1.0, 1.0, 0.0), 1); |
---|
[608] | 201 | |
---|
[661] | 202 | this->chNearNode_ = this->getNode()->createChildSceneNode(this->getName() + "near", Vector3(50.0, 0.0, 0.0)); |
---|
| 203 | this->chNearNode_->setInheritScale(false); |
---|
| 204 | this->chFarNode_ = this->getNode()->createChildSceneNode(this->getName() + "far", Vector3(200.0, 0.0, 0.0)); |
---|
| 205 | this->chFarNode_->setInheritScale(false); |
---|
| 206 | |
---|
| 207 | this->chNearNode_->attachObject(this->crosshairNear_.getBillboardSet()); |
---|
| 208 | this->chNearNode_->setScale(0.2, 0.2, 0.2); |
---|
| 209 | |
---|
| 210 | this->chFarNode_->attachObject(this->crosshairFar_.getBillboardSet()); |
---|
| 211 | this->chFarNode_->setScale(0.4, 0.4, 0.4); |
---|
| 212 | |
---|
[1293] | 213 | createCamera(); |
---|
[661] | 214 | // END of testing crosshair |
---|
[871] | 215 | } |
---|
[661] | 216 | |
---|
[871] | 217 | void SpaceShip::setConfigValues() |
---|
| 218 | { |
---|
| 219 | SetConfigValue(bInvertYAxis_, false).description("Set this to true for joystick-like mouse behaviour (mouse up = ship down)."); |
---|
| 220 | SetConfigValue(reloadTime_, 0.125).description("The reload time of the weapon in seconds"); |
---|
| 221 | SetConfigValue(testvector_, Vector3()).description("asdfblah"); |
---|
| 222 | } |
---|
| 223 | |
---|
| 224 | void SpaceShip::setCamera(const std::string& camera) |
---|
| 225 | { |
---|
[1293] | 226 | camName_=camera; |
---|
| 227 | // change camera attributes here, if you want to ;) |
---|
| 228 | } |
---|
[1362] | 229 | |
---|
[1293] | 230 | void SpaceShip::getFocus(){ |
---|
| 231 | COUT(4) << "requesting focus" << std::endl; |
---|
| 232 | if(network::Client::getSingleton()==0 || network::Client::getSingleton()->getShipID()==objectID) |
---|
| 233 | CameraHandler::getInstance()->requestFocus(cam_); |
---|
[1362] | 234 | |
---|
[1293] | 235 | } |
---|
[1362] | 236 | |
---|
[1293] | 237 | void SpaceShip::createCamera(){ |
---|
| 238 | // COUT(4) << "begin camera creation" << std::endl; |
---|
| 239 | this->camNode_ = this->getNode()->createChildSceneNode(camName_); |
---|
| 240 | COUT(4) << "position: (this)" << this->getNode()->getPosition() << std::endl; |
---|
| 241 | this->camNode_->setPosition(Vector3(-50,0,10)); |
---|
[1362] | 242 | // Quaternion q1 = Quaternion(Radian(Degree(90)),Vector3(0,-1,0)); |
---|
| 243 | // Quaternion q2 = Quaternion(Radian(Degree(90)),Vector3(0,0,-1)); |
---|
| 244 | // camNode_->setOrientation(q1*q2); |
---|
[1293] | 245 | COUT(4) << "position: (cam)" << this->camNode_->getPosition() << std::endl; |
---|
| 246 | cam_ = new Camera(this->camNode_); |
---|
[608] | 247 | |
---|
[1293] | 248 | cam_->setTargetNode(this->getNode()); |
---|
[1386] | 249 | // cam->setPosition(Vector3(0,-350,0)); |
---|
| 250 | Quaternion q1 = Quaternion(Radian(Degree(90)),Vector3(0,-1,0)); |
---|
| 251 | Quaternion q2 = Quaternion(Radian(Degree(90)),Vector3(1,0,0)); |
---|
[1362] | 252 | camNode_->setOrientation(q2*q1); |
---|
[1293] | 253 | if(network::Client::getSingleton()!=0 && network::Client::getSingleton()->getShipID()==objectID){ |
---|
| 254 | this->setBacksync(true); |
---|
| 255 | CameraHandler::getInstance()->requestFocus(cam_); |
---|
| 256 | } |
---|
[608] | 257 | |
---|
| 258 | } |
---|
| 259 | |
---|
[871] | 260 | void SpaceShip::setMaxSpeed(float value) |
---|
| 261 | { this->maxSpeed_ = value; } |
---|
| 262 | void SpaceShip::setMaxSideAndBackSpeed(float value) |
---|
| 263 | { this->maxSideAndBackSpeed_ = value; } |
---|
| 264 | void SpaceShip::setMaxRotation(float value) |
---|
| 265 | { this->maxRotation_ = value; this->maxRotationRadian_ = Radian(value); } |
---|
| 266 | void SpaceShip::setTransAcc(float value) |
---|
| 267 | { this->translationAcceleration_ = value; } |
---|
| 268 | void SpaceShip::setRotAcc(float value) |
---|
| 269 | { this->rotationAcceleration_ = value; this->rotationAccelerationRadian_ = Radian(value); } |
---|
| 270 | void SpaceShip::setTransDamp(float value) |
---|
| 271 | { this->translationDamping_ = value; } |
---|
| 272 | void SpaceShip::setRotDamp(float value) |
---|
| 273 | { this->rotationDamping_ = value; this->rotationDampingRadian_ = Radian(value); } |
---|
| 274 | |
---|
| 275 | /** |
---|
| 276 | @brief XML loading and saving. |
---|
| 277 | @param xmlelement The XML-element |
---|
| 278 | @param loading Loading (true) or saving (false) |
---|
| 279 | @return The XML-element |
---|
| 280 | */ |
---|
[1052] | 281 | void SpaceShip::XMLPort(Element& xmlelement, XMLPort::Mode mode) |
---|
[871] | 282 | { |
---|
[1052] | 283 | Model::XMLPort(xmlelement, mode); |
---|
[871] | 284 | |
---|
[1052] | 285 | XMLPortParamLoadOnly(SpaceShip, "camera", setCamera, xmlelement, mode); |
---|
| 286 | XMLPortParamLoadOnly(SpaceShip, "maxSpeed", setMaxSpeed, xmlelement, mode); |
---|
| 287 | XMLPortParamLoadOnly(SpaceShip, "maxSideAndBackSpeed", setMaxSideAndBackSpeed, xmlelement, mode); |
---|
| 288 | XMLPortParamLoadOnly(SpaceShip, "maxRotation", setMaxRotation, xmlelement, mode); |
---|
| 289 | XMLPortParamLoadOnly(SpaceShip, "transAcc", setTransAcc, xmlelement, mode); |
---|
| 290 | XMLPortParamLoadOnly(SpaceShip, "rotAcc", setRotAcc, xmlelement, mode); |
---|
| 291 | XMLPortParamLoadOnly(SpaceShip, "transDamp", setTransDamp, xmlelement, mode); |
---|
| 292 | XMLPortParamLoadOnly(SpaceShip, "rotDamp", setRotDamp, xmlelement, mode); |
---|
[1293] | 293 | server_=true; // TODO: this is only a hack |
---|
| 294 | SpaceShip::create(); |
---|
| 295 | getFocus(); |
---|
[871] | 296 | } |
---|
| 297 | |
---|
[647] | 298 | int sgn(float x) |
---|
| 299 | { |
---|
| 300 | if (x >= 0) |
---|
| 301 | return 1; |
---|
| 302 | else |
---|
| 303 | return -1; |
---|
| 304 | } |
---|
| 305 | |
---|
[1386] | 306 | std::string SpaceShip::whereAmI() { |
---|
| 307 | return getConvertedValue<float, std::string>(SpaceShip::getLocalShip()->getPosition().x) |
---|
| 308 | + " " + getConvertedValue<float, std::string>(SpaceShip::getLocalShip()->getPosition().y) |
---|
| 309 | + " " + getConvertedValue<float, std::string>(SpaceShip::getLocalShip()->getPosition().z); |
---|
| 310 | } |
---|
| 311 | |
---|
| 312 | Vector3 SpaceShip::getSPosition() { |
---|
| 313 | return SpaceShip::getLocalShip()->getPosition(); |
---|
| 314 | } |
---|
| 315 | |
---|
| 316 | Quaternion SpaceShip::getSOrientation() { |
---|
| 317 | return SpaceShip::getLocalShip()->getOrientation(); |
---|
| 318 | } |
---|
| 319 | |
---|
| 320 | float SpaceShip::getMaxSpeed() { return maxSpeed_; } |
---|
| 321 | |
---|
[608] | 322 | void SpaceShip::tick(float dt) |
---|
| 323 | { |
---|
[1293] | 324 | if (this->cam_) |
---|
| 325 | this->cam_->tick(dt); |
---|
[608] | 326 | |
---|
[633] | 327 | if (this->redNode_ && this->greenNode_) |
---|
| 328 | { |
---|
| 329 | this->blinkTime_ += dt; |
---|
| 330 | float redScale = 0.15 + 0.15 * sin(this->blinkTime_ * 10.0); |
---|
| 331 | float greenScale = 0.15 - 0.15 * sin(this->blinkTime_ * 10.0); |
---|
| 332 | this->redNode_->setScale(redScale, redScale, redScale); |
---|
| 333 | this->greenNode_->setScale(greenScale, greenScale, greenScale); |
---|
| 334 | } |
---|
| 335 | |
---|
[643] | 336 | if (this->timeToReload_ > 0) |
---|
| 337 | this->timeToReload_ -= dt; |
---|
| 338 | else |
---|
| 339 | this->timeToReload_ = 0; |
---|
| 340 | |
---|
[644] | 341 | if (this->bLMousePressed_ && this->timeToReload_ <= 0) |
---|
[643] | 342 | { |
---|
[1360] | 343 | |
---|
[1293] | 344 | Projectile *p = new Projectile(this); |
---|
[1360] | 345 | |
---|
[1293] | 346 | p->setBacksync(true); |
---|
[643] | 347 | this->timeToReload_ = this->reloadTime_; |
---|
| 348 | } |
---|
| 349 | |
---|
[608] | 350 | |
---|
[647] | 351 | // ##################################### |
---|
| 352 | // ############# STEERING ############## |
---|
| 353 | // ##################################### |
---|
| 354 | |
---|
| 355 | if (this->velocity_.x > this->maxSpeed_) |
---|
| 356 | this->velocity_.x = this->maxSpeed_; |
---|
| 357 | if (this->velocity_.x < -this->maxSideAndBackSpeed_) |
---|
| 358 | this->velocity_.x = -this->maxSideAndBackSpeed_; |
---|
| 359 | if (this->velocity_.y > this->maxSideAndBackSpeed_) |
---|
| 360 | this->velocity_.y = this->maxSideAndBackSpeed_; |
---|
| 361 | if (this->velocity_.y < -this->maxSideAndBackSpeed_) |
---|
| 362 | this->velocity_.y = -this->maxSideAndBackSpeed_; |
---|
| 363 | if (this->rotationRate_ > this->maxRotationRadian_) |
---|
| 364 | this->rotationRate_ = this->maxRotationRadian_; |
---|
| 365 | if (this->rotationRate_ < -this->maxRotationRadian_) |
---|
| 366 | this->rotationRate_ = -this->maxRotationRadian_; |
---|
| 367 | |
---|
| 368 | if (this->acceleration_.x == 0) |
---|
| 369 | { |
---|
| 370 | if (this->velocity_.x > 0) |
---|
| 371 | { |
---|
| 372 | this->velocity_.x -= (this->translationDamping_ * dt); |
---|
| 373 | if (this->velocity_.x < 0) |
---|
| 374 | this->velocity_.x = 0; |
---|
| 375 | } |
---|
| 376 | else if (this->velocity_.x < 0) |
---|
| 377 | { |
---|
| 378 | this->velocity_.x += (this->translationDamping_ * dt); |
---|
| 379 | if (this->velocity_.x > 0) |
---|
| 380 | this->velocity_.x = 0; |
---|
| 381 | } |
---|
| 382 | } |
---|
| 383 | |
---|
| 384 | if (this->acceleration_.y == 0) |
---|
| 385 | { |
---|
| 386 | if (this->velocity_.y > 0) |
---|
| 387 | { |
---|
| 388 | this->velocity_.y -= (this->translationDamping_ * dt); |
---|
| 389 | if (this->velocity_.y < 0) |
---|
| 390 | this->velocity_.y = 0; |
---|
| 391 | } |
---|
| 392 | else if (this->velocity_.y < 0) |
---|
| 393 | { |
---|
| 394 | this->velocity_.y += (this->translationDamping_ * dt); |
---|
| 395 | if (this->velocity_.y > 0) |
---|
| 396 | this->velocity_.y = 0; |
---|
| 397 | } |
---|
| 398 | } |
---|
| 399 | |
---|
| 400 | if (this->momentum_ == this->zeroRadian_) |
---|
| 401 | { |
---|
| 402 | if (this->rotationRate_ > this->zeroRadian_) |
---|
| 403 | { |
---|
| 404 | this->rotationRate_ -= (this->rotationDampingRadian_ * dt); |
---|
| 405 | if (this->rotationRate_ < this->zeroRadian_) |
---|
| 406 | this->rotationRate_ = 0; |
---|
| 407 | } |
---|
| 408 | else if (this->rotationRate_ < this->zeroRadian_) |
---|
| 409 | { |
---|
| 410 | this->rotationRate_ += (this->rotationDampingRadian_ * dt); |
---|
| 411 | if (this->rotationRate_ > this->zeroRadian_) |
---|
| 412 | this->rotationRate_ = 0; |
---|
| 413 | } |
---|
| 414 | } |
---|
| 415 | |
---|
| 416 | |
---|
| 417 | WorldEntity::tick(dt); |
---|
| 418 | |
---|
| 419 | this->roll(this->mouseXRotation_ * dt); |
---|
| 420 | if (this->bInvertYAxis_) |
---|
| 421 | this->yaw(Radian(-this->mouseYRotation_ * dt)); |
---|
| 422 | else |
---|
| 423 | this->yaw(Radian(this->mouseYRotation_ * dt)); |
---|
| 424 | |
---|
| 425 | if (this->acceleration_.x > 0) |
---|
| 426 | this->tt_->setRate(emitterRate_); |
---|
| 427 | else |
---|
| 428 | this->tt_->setRate(0); |
---|
[1391] | 429 | |
---|
| 430 | if( (network::Client::getSingleton() && network::Client::getSingleton()->getShipID() == objectID) || server_ ) |
---|
| 431 | { |
---|
| 432 | COUT(4) << "steering our ship: " << objectID << std::endl; |
---|
| 433 | this->acceleration_.x = 0; |
---|
| 434 | this->acceleration_.y = 0; |
---|
| 435 | this->momentum_ = 0; |
---|
| 436 | this->mouseXRotation_ = Radian(0); |
---|
| 437 | this->mouseYRotation_ = Radian(0); |
---|
| 438 | this->bLMousePressed_ = false; |
---|
| 439 | }/*else |
---|
| 440 | COUT(4) << "not steering ship: " << objectID << " our ship: " << network::Client::getSingleton()->getShipID() << std::endl;*/ |
---|
[608] | 441 | } |
---|
[1391] | 442 | void SpaceShip::movePitch(float val) |
---|
| 443 | { |
---|
| 444 | SpaceShip* this_ = getLocalShip(); |
---|
| 445 | val = -val * val * sgn(val) * this_->rotationAcceleration_; |
---|
| 446 | if (val > this_->maxRotation_) |
---|
| 447 | val = this_->maxRotation_; |
---|
| 448 | if (val < -this_->maxRotation_) |
---|
| 449 | val = -this_->maxRotation_; |
---|
| 450 | this_->mouseYRotation_ = Radian(val); |
---|
| 451 | } |
---|
[608] | 452 | |
---|
[1391] | 453 | void SpaceShip::moveYaw(float val) |
---|
| 454 | { |
---|
| 455 | SpaceShip* this_ = getLocalShip(); |
---|
| 456 | val = -val * val * sgn(val) * this_->rotationAcceleration_; |
---|
| 457 | if (val > this_->maxRotation_) |
---|
| 458 | val = this_->maxRotation_; |
---|
| 459 | if (val < -this_->maxRotation_) |
---|
| 460 | val = -this_->maxRotation_; |
---|
| 461 | this_->mouseXRotation_ = Radian(val); |
---|
| 462 | } |
---|
| 463 | |
---|
| 464 | void SpaceShip::moveRoll(float val) |
---|
| 465 | { |
---|
| 466 | SpaceShip* this_ = getLocalShip(); |
---|
| 467 | this_->momentum_ = Radian(-this_->rotationAccelerationRadian_ * val); |
---|
| 468 | } |
---|
| 469 | |
---|
| 470 | void SpaceShip::moveLongitudinal(float val) |
---|
| 471 | { |
---|
| 472 | SpaceShip* this_ = getLocalShip(); |
---|
| 473 | COUT(3) << val << std::endl; |
---|
| 474 | this_->acceleration_.x = this_->translationAcceleration_ * val; |
---|
| 475 | } |
---|
| 476 | |
---|
| 477 | void SpaceShip::moveLateral(float val) |
---|
| 478 | { |
---|
| 479 | SpaceShip* this_ = getLocalShip(); |
---|
| 480 | this_->acceleration_.y = -this_->translationAcceleration_ * val; |
---|
| 481 | } |
---|
| 482 | |
---|
| 483 | void SpaceShip::fire() |
---|
| 484 | { |
---|
| 485 | SpaceShip* this_ = getLocalShip(); |
---|
| 486 | this_->bLMousePressed_ = true; |
---|
| 487 | } |
---|
[608] | 488 | } |
---|