| 1 | /* | 
|---|
| 2 |  *   ORXONOX - the hottest 3D action shooter ever to exist | 
|---|
| 3 |  *                    > www.orxonox.net < | 
|---|
| 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: | 
|---|
| 23 |  *      Fabian 'x3n' Landau | 
|---|
| 24 |  *   Co-authors: | 
|---|
| 25 |  *      Benjamin Knecht | 
|---|
| 26 |  * | 
|---|
| 27 |  */ | 
|---|
| 28 |  | 
|---|
| 29 | #include "OrxonoxStableHeaders.h" | 
|---|
| 30 | #include "SpaceShip.h" | 
|---|
| 31 |  | 
|---|
| 32 | #include <OgreCamera.h> | 
|---|
| 33 | #include <OgreRenderWindow.h> | 
|---|
| 34 | #include <OgreParticleSystem.h> | 
|---|
| 35 | #include <OgreSceneNode.h> | 
|---|
| 36 |  | 
|---|
| 37 | #include "util/Convert.h" | 
|---|
| 38 | #include "util/Math.h" | 
|---|
| 39 |  | 
|---|
| 40 | #include "core/CoreIncludes.h" | 
|---|
| 41 | #include "core/ConfigValueIncludes.h" | 
|---|
| 42 | #include "core/Debug.h" | 
|---|
| 43 | #include "core/XMLPort.h" | 
|---|
| 44 | #include "core/ConsoleCommand.h" | 
|---|
| 45 |  | 
|---|
| 46 | #include "network/Client.h" | 
|---|
| 47 |  | 
|---|
| 48 | #include "tools/ParticleInterface.h" | 
|---|
| 49 |  | 
|---|
| 50 | #include "GraphicsEngine.h" | 
|---|
| 51 | #include "Settings.h" | 
|---|
| 52 | #include "RotatingProjectile.h" | 
|---|
| 53 | #include "ParticleProjectile.h" | 
|---|
| 54 | #include "ParticleSpawner.h" | 
|---|
| 55 | #include "Backlight.h" | 
|---|
| 56 | #include "CameraHandler.h" | 
|---|
| 57 |  | 
|---|
| 58 | namespace orxonox | 
|---|
| 59 | { | 
|---|
| 60 |     SetConsoleCommand(SpaceShip, setMaxSpeedTest, false).setAccessLevel(AccessLevel::Debug); | 
|---|
| 61 |     SetConsoleCommand(SpaceShip, whereAmI, true).setAccessLevel(AccessLevel::User); | 
|---|
| 62 |     SetConsoleCommand(SpaceShip, moveLongitudinal, true).setAccessLevel(AccessLevel::User).setDefaultValue(0, 1.0f).setAxisParamIndex(0).setKeybindMode(KeybindMode::OnHold); | 
|---|
| 63 |     SetConsoleCommand(SpaceShip, moveLateral, true).setAccessLevel(AccessLevel::User).setDefaultValue(0, 1.0f).setAxisParamIndex(0).setKeybindMode(KeybindMode::OnHold); | 
|---|
| 64 |     SetConsoleCommand(SpaceShip, moveYaw, true).setAccessLevel(AccessLevel::User).setDefaultValue(0, 1.0f).setAxisParamIndex(0).setKeybindMode(KeybindMode::OnHold); | 
|---|
| 65 |     SetConsoleCommand(SpaceShip, movePitch, true).setAccessLevel(AccessLevel::User).setDefaultValue(0, 1.0f).setAxisParamIndex(0).setKeybindMode(KeybindMode::OnHold); | 
|---|
| 66 |     SetConsoleCommand(SpaceShip, moveRoll, true).setAccessLevel(AccessLevel::User).setDefaultValue(0, 1.0f).setAxisParamIndex(0).setKeybindMode(KeybindMode::OnHold); | 
|---|
| 67 |     SetConsoleCommand(SpaceShip, fire, true).setAccessLevel(AccessLevel::User).setKeybindMode(KeybindMode::OnHold); | 
|---|
| 68 |     SetConsoleCommandGeneric(test1, SpaceShip, createConsoleCommand(createFunctor(&SpaceShip::setMaxSpeedTest), "setMaxSpeed"), false).setAccessLevel(AccessLevel::Debug); | 
|---|
| 69 |     SetConsoleCommandGeneric(test2, SpaceShip, createConsoleCommand(createFunctor(&SpaceShip::setMaxSpeedTest), "setMaxBlubber"), false).setAccessLevel(AccessLevel::Debug); | 
|---|
| 70 |     SetConsoleCommandGeneric(test3, SpaceShip, createConsoleCommand(createFunctor(&SpaceShip::setMaxSpeedTest), "setRofl"), false).setAccessLevel(AccessLevel::Debug); | 
|---|
| 71 |  | 
|---|
| 72 |     CreateFactory(SpaceShip); | 
|---|
| 73 |  | 
|---|
| 74 |     SpaceShip* SpaceShip::instance_s; | 
|---|
| 75 |  | 
|---|
| 76 |  | 
|---|
| 77 |     SpaceShip *SpaceShip::getLocalShip(){ | 
|---|
| 78 |       Iterator<SpaceShip> it; | 
|---|
| 79 |       for(it = ObjectList<SpaceShip>::start(); it; ++it){ | 
|---|
| 80 |         if( (it)->myShip_ ) | 
|---|
| 81 |           return *it; | 
|---|
| 82 |       } | 
|---|
| 83 |       return NULL; | 
|---|
| 84 |     } | 
|---|
| 85 |  | 
|---|
| 86 |     SpaceShip::SpaceShip() | 
|---|
| 87 |     { | 
|---|
| 88 |         RegisterObject(SpaceShip); | 
|---|
| 89 |  | 
|---|
| 90 |         this->setRotationAxis(1, 0, 0); | 
|---|
| 91 |         this->setStatic(false); | 
|---|
| 92 |  | 
|---|
| 93 |         this->zeroRadian_ = 0; | 
|---|
| 94 |         this->maxSideAndBackSpeed_ = 0; | 
|---|
| 95 |         this->maxSpeed_ = 0; | 
|---|
| 96 |         this->maxRotation_ = 0; | 
|---|
| 97 |         this->translationAcceleration_ = 0; | 
|---|
| 98 |         this->rotationAcceleration_ = 0; | 
|---|
| 99 |         this->translationDamping_ = 0; | 
|---|
| 100 |         this->rotationDamping_ = 0; | 
|---|
| 101 |         this->maxRotationRadian_ = 0; | 
|---|
| 102 |         this->rotationAccelerationRadian_ = 0; | 
|---|
| 103 |         this->rotationDampingRadian_ = 0; | 
|---|
| 104 |  | 
|---|
| 105 |         this->cam_ = 0; | 
|---|
| 106 |         this->tt1_ = 0; | 
|---|
| 107 |         this->tt2_ = 0; | 
|---|
| 108 |         this->smoke_ = 0; | 
|---|
| 109 |         this->fire_ = 0; | 
|---|
| 110 |  | 
|---|
| 111 |         this->backlight_ = 0; | 
|---|
| 112 |  | 
|---|
| 113 |         this->redNode_ = 0; | 
|---|
| 114 |         this->greenNode_ = 0; | 
|---|
| 115 |         this->blinkTime_ = 0; | 
|---|
| 116 |  | 
|---|
| 117 |         this->timeToReload_ = 0; | 
|---|
| 118 |  | 
|---|
| 119 |         this->bLMousePressed_ = false; | 
|---|
| 120 |         this->bRMousePressed_ = false; | 
|---|
| 121 |         this->mouseXRotation_ = 0; | 
|---|
| 122 |         this->mouseYRotation_ = 0; | 
|---|
| 123 |         this->myShip_ = false; | 
|---|
| 124 |  | 
|---|
| 125 |         this->registerAllVariables(); | 
|---|
| 126 |  | 
|---|
| 127 |         SpaceShip::instance_s = this; | 
|---|
| 128 |  | 
|---|
| 129 |         this->setConfigValues(); | 
|---|
| 130 |  | 
|---|
| 131 |         this->initialDir_ = Vector3(1.0, 0.0, 0.0); | 
|---|
| 132 |         this->currentDir_ = initialDir_; | 
|---|
| 133 |         this->initialOrth_ = Vector3(0.0, 0.0, 1.0); | 
|---|
| 134 |         this->currentOrth_ = initialOrth_; | 
|---|
| 135 |  | 
|---|
| 136 |         this->camName_ = this->getName() + "CamNode"; | 
|---|
| 137 |  | 
|---|
| 138 |         this->teamNr_ = 0; | 
|---|
| 139 |         this->health_ = 100; | 
|---|
| 140 |  | 
|---|
| 141 |         this->radarObject_ = static_cast<WorldEntity*>(this); | 
|---|
| 142 |     } | 
|---|
| 143 |  | 
|---|
| 144 |     SpaceShip::~SpaceShip() | 
|---|
| 145 |     { | 
|---|
| 146 |         if (this->isInitialized()) | 
|---|
| 147 |         { | 
|---|
| 148 |             if (this->tt1_) | 
|---|
| 149 |                 delete this->tt1_; | 
|---|
| 150 |             if (this->tt2_) | 
|---|
| 151 |                 delete this->tt2_; | 
|---|
| 152 |  | 
|---|
| 153 |             if (this->smoke_) | 
|---|
| 154 |                 this->smoke_->destroy(); | 
|---|
| 155 |             if (this->fire_) | 
|---|
| 156 |                 this->fire_->destroy(); | 
|---|
| 157 |  | 
|---|
| 158 |             if (this->backlight_) | 
|---|
| 159 |                 delete this->backlight_; | 
|---|
| 160 |  | 
|---|
| 161 |             if (this->cam_) | 
|---|
| 162 |                 delete this->cam_; | 
|---|
| 163 |         } | 
|---|
| 164 |     } | 
|---|
| 165 |  | 
|---|
| 166 |     bool SpaceShip::create(){ | 
|---|
| 167 |       if(!myShip_){ | 
|---|
| 168 |         if(network::Client::getSingleton() && objectID == network::Client::getSingleton()->getShipID()) | 
|---|
| 169 |           myShip_=true; | 
|---|
| 170 |         else | 
|---|
| 171 |           this->setRadarObjectColour(this->getProjectileColour()); | 
|---|
| 172 |       } | 
|---|
| 173 |       if(Model::create()) | 
|---|
| 174 |         this->init(); | 
|---|
| 175 |       else | 
|---|
| 176 |         return false; | 
|---|
| 177 |       return true; | 
|---|
| 178 |     } | 
|---|
| 179 |  | 
|---|
| 180 |     void SpaceShip::registerAllVariables(){ | 
|---|
| 181 |       registerVar( &camName_, camName_.length()+1, network::STRING, 0x1 ); | 
|---|
| 182 |       registerVar( &maxSpeed_, sizeof(maxSpeed_), network::DATA, 0x1); | 
|---|
| 183 |       registerVar( &maxSideAndBackSpeed_, sizeof(maxSideAndBackSpeed_), network::DATA, 0x1); | 
|---|
| 184 |       registerVar( &maxRotation_, sizeof(maxRotation_), network::DATA, 0x1); | 
|---|
| 185 |       registerVar( &translationAcceleration_, sizeof(translationAcceleration_), network::DATA, 0x1); | 
|---|
| 186 |       registerVar( &rotationAcceleration_, sizeof(rotationAcceleration_), network::DATA, 0x1); | 
|---|
| 187 |       registerVar( &rotationAccelerationRadian_, sizeof(rotationAccelerationRadian_), network::DATA, 0x1); | 
|---|
| 188 |       registerVar( &translationDamping_, sizeof(translationDamping_), network::DATA, 0x1); | 
|---|
| 189 |       registerVar( &rotationDamping_, sizeof(rotationDamping_), network::DATA, 0x1); | 
|---|
| 190 |       registerVar( &rotationDampingRadian_, sizeof(rotationDampingRadian_), network::DATA, 0x1); | 
|---|
| 191 |  | 
|---|
| 192 |     } | 
|---|
| 193 |  | 
|---|
| 194 |     void SpaceShip::init() | 
|---|
| 195 |     { | 
|---|
| 196 |         if (Settings::showsGraphics()) | 
|---|
| 197 |         { | 
|---|
| 198 |             // START CREATING THRUSTERS | 
|---|
| 199 |             this->tt1_ = new ParticleInterface("Orxonox/thruster1", LODParticle::low); | 
|---|
| 200 |             this->tt1_->createNewEmitter(); | 
|---|
| 201 |             this->tt1_->getAllEmitters()->setDirection(-this->getInitialDir()); | 
|---|
| 202 |             this->tt1_->getEmitter(0)->setPosition(Vector3(-15, 20, -1)); | 
|---|
| 203 |             this->tt1_->getEmitter(1)->setPosition(Vector3(-15, -20, -1)); | 
|---|
| 204 |             this->tt1_->setSpeedFactor(3.0); | 
|---|
| 205 |  | 
|---|
| 206 |             Ogre::SceneNode* node2a = this->getNode()->createChildSceneNode(this->getName() + "particle2a"); | 
|---|
| 207 |             node2a->setInheritScale(false); | 
|---|
| 208 |             node2a->setScale(1, 1, 1); | 
|---|
| 209 |             tt1_->addToSceneNode(node2a); | 
|---|
| 210 |  | 
|---|
| 211 |             this->tt2_ = new ParticleInterface("Orxonox/thruster2", LODParticle::normal); | 
|---|
| 212 |             this->tt2_->createNewEmitter(); | 
|---|
| 213 |             this->tt2_->getAllEmitters()->setDirection(Vector3(-1, 0, 0)); | 
|---|
| 214 |             this->tt2_->getEmitter(0)->setPosition(Vector3(-30, 40, -2)); | 
|---|
| 215 |             this->tt2_->getEmitter(1)->setPosition(Vector3(-30, -40, -2)); | 
|---|
| 216 |  | 
|---|
| 217 |             Ogre::SceneNode* node2b = this->getNode()->createChildSceneNode(this->getName() + "particle2b"); | 
|---|
| 218 |             node2b->setInheritScale(false); | 
|---|
| 219 |             node2b->setScale(0.5, 0.5, 0.5); | 
|---|
| 220 |             tt2_->addToSceneNode(node2b); | 
|---|
| 221 |  | 
|---|
| 222 |             this->leftThrusterFlare_.setBillboardSet("Flares/ThrusterFlare1", Vector3(-7.5, -10, -0.5)); | 
|---|
| 223 |             this->rightThrusterFlare_.setBillboardSet("Flares/ThrusterFlare1", Vector3(-7.5, 10, -0.5)); | 
|---|
| 224 |  | 
|---|
| 225 |             Ogre::SceneNode* node2c = this->getNode()->createChildSceneNode(this->getName() + "particle2c"); | 
|---|
| 226 |             node2c->setInheritScale(false); | 
|---|
| 227 |             node2c->setScale(2, 2, 2); | 
|---|
| 228 |             node2c->attachObject(this->leftThrusterFlare_.getBillboardSet()); | 
|---|
| 229 |             node2c->attachObject(this->rightThrusterFlare_.getBillboardSet()); | 
|---|
| 230 |             // END CREATING THRUSTERS | 
|---|
| 231 |  | 
|---|
| 232 |             // START CREATING BLINKING LIGHTS | 
|---|
| 233 |             this->redBillboard_.setBillboardSet("Examples/Flare", ColourValue(1.0, 0.0, 0.0), 1); | 
|---|
| 234 |             this->greenBillboard_.setBillboardSet("Examples/Flare", ColourValue(0.0, 1.0, 0.0), 1); | 
|---|
| 235 |  | 
|---|
| 236 |             this->redNode_ = this->getNode()->createChildSceneNode(this->getName() + "red", Vector3(0.3, 4.0, -0.3)); | 
|---|
| 237 |             this->redNode_->setInheritScale(false); | 
|---|
| 238 |             this->greenNode_ = this->getNode()->createChildSceneNode(this->getName() + "green", Vector3(0.3, -4.0, -0.3)); | 
|---|
| 239 |             this->greenNode_->setInheritScale(false); | 
|---|
| 240 |  | 
|---|
| 241 |             this->redNode_->attachObject(this->redBillboard_.getBillboardSet()); | 
|---|
| 242 |             this->redNode_->setScale(0.3, 0.3, 0.3); | 
|---|
| 243 |  | 
|---|
| 244 |             this->greenNode_->attachObject(this->greenBillboard_.getBillboardSet()); | 
|---|
| 245 |             this->greenNode_->setScale(0.3, 0.3, 0.3); | 
|---|
| 246 |             // END CREATING BLINKING LIGHTS | 
|---|
| 247 |  | 
|---|
| 248 |             // START CREATING ADDITIONAL EFFECTS | 
|---|
| 249 |             this->backlight_ = new Backlight(this->maxSpeed_, 0.8); | 
|---|
| 250 |             this->attachObject(this->backlight_); | 
|---|
| 251 |             this->backlight_->setPosition(-2.35, 0, 0.2); | 
|---|
| 252 |             this->backlight_->setColour(this->getProjectileColour()); | 
|---|
| 253 |  | 
|---|
| 254 |             this->smoke_ = new ParticleSpawner(); | 
|---|
| 255 |             this->smoke_->setParticle("Orxonox/smoke5", LODParticle::normal, 0, 0, 3); | 
|---|
| 256 |             this->attachObject(this->smoke_); | 
|---|
| 257 |  | 
|---|
| 258 |             this->fire_ = new ParticleSpawner(); | 
|---|
| 259 |             this->fire_->setParticle("Orxonox/fire3", LODParticle::normal, 0, 0, 1); | 
|---|
| 260 |             this->attachObject(this->fire_); | 
|---|
| 261 |             // END CREATING ADDITIONAL EFFECTS | 
|---|
| 262 |  | 
|---|
| 263 |             if (this->isExactlyA(Class(SpaceShip))) | 
|---|
| 264 |             { | 
|---|
| 265 |                 // START of testing crosshair | 
|---|
| 266 |                 this->crosshairNear_.setBillboardSet("Orxonox/Crosshair", ColourValue(1.0, 1.0, 0.0), 1); | 
|---|
| 267 |                 this->crosshairFar_.setBillboardSet("Orxonox/Crosshair", ColourValue(1.0, 1.0, 0.0), 1); | 
|---|
| 268 |  | 
|---|
| 269 |                 this->chNearNode_ = this->getNode()->createChildSceneNode(this->getName() + "near", Vector3(50.0, 0.0, 0.0)); | 
|---|
| 270 |                 this->chNearNode_->setInheritScale(false); | 
|---|
| 271 |                 this->chFarNode_ = this->getNode()->createChildSceneNode(this->getName() + "far", Vector3(200.0, 0.0, 0.0)); | 
|---|
| 272 |                 this->chFarNode_->setInheritScale(false); | 
|---|
| 273 |  | 
|---|
| 274 |                 this->chNearNode_->attachObject(this->crosshairNear_.getBillboardSet()); | 
|---|
| 275 |                 this->chNearNode_->setScale(0.2, 0.2, 0.2); | 
|---|
| 276 |  | 
|---|
| 277 |                 this->chFarNode_->attachObject(this->crosshairFar_.getBillboardSet()); | 
|---|
| 278 |                 this->chFarNode_->setScale(0.4, 0.4, 0.4); | 
|---|
| 279 |                 // END of testing crosshair | 
|---|
| 280 |             } | 
|---|
| 281 |         } | 
|---|
| 282 |  | 
|---|
| 283 |         createCamera(); | 
|---|
| 284 |     } | 
|---|
| 285 |  | 
|---|
| 286 |     void SpaceShip::setConfigValues() | 
|---|
| 287 |     { | 
|---|
| 288 |         SetConfigValue(bInvertYAxis_, false).description("Set this to true for joystick-like mouse behaviour (mouse up = ship down)."); | 
|---|
| 289 |         SetConfigValue(reloadTime_, 0.125).description("The reload time of the weapon in seconds"); | 
|---|
| 290 |         SetConfigValue(testvector_, Vector3()).description("asdfblah"); | 
|---|
| 291 |     } | 
|---|
| 292 |  | 
|---|
| 293 |     void SpaceShip::changedVisibility() | 
|---|
| 294 |     { | 
|---|
| 295 |         Model::changedVisibility(); | 
|---|
| 296 |  | 
|---|
| 297 |         this->tt1_->setEnabled(this->isVisible()); | 
|---|
| 298 |         this->tt2_->setEnabled(this->isVisible()); | 
|---|
| 299 |         this->redBillboard_.setVisible(this->isVisible()); | 
|---|
| 300 |         this->greenBillboard_.setVisible(this->isVisible()); | 
|---|
| 301 |         this->crosshairNear_.setVisible(this->isVisible()); | 
|---|
| 302 |         this->crosshairFar_.setVisible(this->isVisible()); | 
|---|
| 303 |         this->rightThrusterFlare_.setVisible(this->isVisible()); | 
|---|
| 304 |         this->leftThrusterFlare_.setVisible(this->isVisible()); | 
|---|
| 305 |         this->smoke_->setVisible(this->isVisible()); | 
|---|
| 306 |         this->fire_->setVisible(this->isVisible()); | 
|---|
| 307 |         this->backlight_->setVisible(this->isVisible()); | 
|---|
| 308 |     } | 
|---|
| 309 |  | 
|---|
| 310 |     void SpaceShip::changedActivity() | 
|---|
| 311 |     { | 
|---|
| 312 |         Model::changedActivity(); | 
|---|
| 313 |  | 
|---|
| 314 |         this->tt1_->setEnabled(this->isVisible()); | 
|---|
| 315 |         this->tt2_->setEnabled(this->isVisible()); | 
|---|
| 316 |         this->redBillboard_.setVisible(this->isVisible()); | 
|---|
| 317 |         this->greenBillboard_.setVisible(this->isVisible()); | 
|---|
| 318 |         this->crosshairNear_.setVisible(this->isVisible()); | 
|---|
| 319 |         this->crosshairFar_.setVisible(this->isVisible()); | 
|---|
| 320 |         this->rightThrusterFlare_.setVisible(this->isVisible()); | 
|---|
| 321 |         this->leftThrusterFlare_.setVisible(this->isVisible()); | 
|---|
| 322 |     } | 
|---|
| 323 |  | 
|---|
| 324 |     void SpaceShip::setCamera(const std::string& camera) | 
|---|
| 325 |     { | 
|---|
| 326 |       myShip_=true; // TODO: this is only a hack | 
|---|
| 327 |       camName_=camera; | 
|---|
| 328 |       // change camera attributes here, if you want to ;) | 
|---|
| 329 |     } | 
|---|
| 330 |  | 
|---|
| 331 |     void SpaceShip::getFocus(){ | 
|---|
| 332 |       COUT(4) << "requesting focus" << std::endl; | 
|---|
| 333 |       if(network::Client::getSingleton()==0 || network::Client::getSingleton()->getShipID()==objectID) | 
|---|
| 334 |         CameraHandler::getInstance()->requestFocus(cam_); | 
|---|
| 335 |  | 
|---|
| 336 |     } | 
|---|
| 337 |  | 
|---|
| 338 |     Camera* SpaceShip::getCamera(){ | 
|---|
| 339 |         return cam_; | 
|---|
| 340 |     } | 
|---|
| 341 |  | 
|---|
| 342 |     void SpaceShip::createCamera(){ | 
|---|
| 343 | //       COUT(4) << "begin camera creation" << std::endl; | 
|---|
| 344 |       this->camNode_ = this->getNode()->createChildSceneNode(camName_); | 
|---|
| 345 |       COUT(4) << "position: (this)" << this->getNode()->getPosition() << std::endl; | 
|---|
| 346 |       this->camNode_->setPosition(Vector3(-25,0,5)); | 
|---|
| 347 | //      Quaternion q1 = Quaternion(Radian(Degree(90)),Vector3(0,-1,0)); | 
|---|
| 348 | //      Quaternion q2 = Quaternion(Radian(Degree(90)),Vector3(0,0,-1)); | 
|---|
| 349 | //      camNode_->setOrientation(q1*q2); | 
|---|
| 350 |       COUT(4) << "position: (cam)" << this->camNode_->getPosition() << std::endl; | 
|---|
| 351 |       cam_ = new Camera(this->camNode_); | 
|---|
| 352 |  | 
|---|
| 353 |       cam_->setTargetNode(this->getNode()); | 
|---|
| 354 | //        cam->setPosition(Vector3(0,-350,0)); | 
|---|
| 355 |       Quaternion q1 = Quaternion(Radian(Degree(90)),Vector3(0,-1,0)); | 
|---|
| 356 |       Quaternion q2 = Quaternion(Radian(Degree(90)),Vector3(1,0,0)); | 
|---|
| 357 |       this->camNode_->setOrientation(q2*q1); | 
|---|
| 358 |       if(network::Client::getSingleton()!=0 && network::Client::getSingleton()->getShipID()==objectID){ | 
|---|
| 359 |         this->setBacksync(true); | 
|---|
| 360 |         CameraHandler::getInstance()->requestFocus(cam_); | 
|---|
| 361 |       } | 
|---|
| 362 |     } | 
|---|
| 363 |  | 
|---|
| 364 |     void SpaceShip::setMaxSpeed(float value) | 
|---|
| 365 |     { this->maxSpeed_ = value; } | 
|---|
| 366 |     void SpaceShip::setMaxSideAndBackSpeed(float value) | 
|---|
| 367 |     { this->maxSideAndBackSpeed_ = value; } | 
|---|
| 368 |     void SpaceShip::setMaxRotation(float value) | 
|---|
| 369 |     { this->maxRotation_ = value; this->maxRotationRadian_ = Radian(value); } | 
|---|
| 370 |     void SpaceShip::setTransAcc(float value) | 
|---|
| 371 |     { this->translationAcceleration_ = value; } | 
|---|
| 372 |     void SpaceShip::setRotAcc(float value) | 
|---|
| 373 |     { this->rotationAcceleration_ = value; this->rotationAccelerationRadian_ = Radian(value); } | 
|---|
| 374 |     void SpaceShip::setTransDamp(float value) | 
|---|
| 375 |     { this->translationDamping_ = value; } | 
|---|
| 376 |     void SpaceShip::setRotDamp(float value) | 
|---|
| 377 |     { this->rotationDamping_ = value; this->rotationDampingRadian_ = Radian(value); } | 
|---|
| 378 |  | 
|---|
| 379 |     /** | 
|---|
| 380 |         @brief XML loading and saving. | 
|---|
| 381 |         @param xmlelement The XML-element | 
|---|
| 382 |         @param loading Loading (true) or saving (false) | 
|---|
| 383 |         @return The XML-element | 
|---|
| 384 |     */ | 
|---|
| 385 |     void SpaceShip::XMLPort(Element& xmlelement, XMLPort::Mode mode) | 
|---|
| 386 |     { | 
|---|
| 387 |         Model::XMLPort(xmlelement, mode); | 
|---|
| 388 |  | 
|---|
| 389 |         XMLPortParamLoadOnly(SpaceShip, "camera", setCamera, xmlelement, mode); | 
|---|
| 390 |         XMLPortParamLoadOnly(SpaceShip, "maxSpeed", setMaxSpeed, xmlelement, mode); | 
|---|
| 391 |         XMLPortParamLoadOnly(SpaceShip, "maxSideAndBackSpeed", setMaxSideAndBackSpeed, xmlelement, mode); | 
|---|
| 392 |         XMLPortParamLoadOnly(SpaceShip, "maxRotation", setMaxRotation, xmlelement, mode); | 
|---|
| 393 |         XMLPortParamLoadOnly(SpaceShip, "transAcc", setTransAcc, xmlelement, mode); | 
|---|
| 394 |         XMLPortParamLoadOnly(SpaceShip, "rotAcc", setRotAcc, xmlelement, mode); | 
|---|
| 395 |         XMLPortParamLoadOnly(SpaceShip, "transDamp", setTransDamp, xmlelement, mode); | 
|---|
| 396 |         XMLPortParamLoadOnly(SpaceShip, "rotDamp", setRotDamp, xmlelement, mode); | 
|---|
| 397 |  | 
|---|
| 398 |         SpaceShip::create(); | 
|---|
| 399 |         if (this->isExactlyA(Class(SpaceShip))) | 
|---|
| 400 |             getFocus(); | 
|---|
| 401 |     } | 
|---|
| 402 |  | 
|---|
| 403 |     std::string SpaceShip::whereAmI() { | 
|---|
| 404 |         return getConvertedValue<float, std::string>(SpaceShip::getLocalShip()->getPosition().x) | 
|---|
| 405 |         + "  " + getConvertedValue<float, std::string>(SpaceShip::getLocalShip()->getPosition().y) | 
|---|
| 406 |         + "  " + getConvertedValue<float, std::string>(SpaceShip::getLocalShip()->getPosition().z); | 
|---|
| 407 |     } | 
|---|
| 408 |  | 
|---|
| 409 |     void SpaceShip::tick(float dt) | 
|---|
| 410 |     { | 
|---|
| 411 |         if (!this->isActive()) | 
|---|
| 412 |             return; | 
|---|
| 413 |  | 
|---|
| 414 |         currentDir_ = getOrientation()*initialDir_; | 
|---|
| 415 |         currentOrth_ = getOrientation()*initialOrth_; | 
|---|
| 416 |  | 
|---|
| 417 |         if (this->cam_) | 
|---|
| 418 |             this->cam_->tick(dt); | 
|---|
| 419 |  | 
|---|
| 420 |         if (Settings::showsGraphics()) | 
|---|
| 421 |         { | 
|---|
| 422 |             if (this->smoke_) | 
|---|
| 423 |                 this->smoke_->setVisible(this->isVisible() && this->health_ < 40); | 
|---|
| 424 |             if (this->fire_) | 
|---|
| 425 |                 this->fire_->setVisible(this->isVisible() && this->health_ < 20); | 
|---|
| 426 |  | 
|---|
| 427 |             if (this->backlight_) | 
|---|
| 428 |             {   // (there's already fire ||                 we're to slow                 ||                  we're moving backwards                  ) | 
|---|
| 429 |                 if (this->health_ < 20   || this->getVelocity().squaredLength() < 150*150 || this->getVelocity().dotProduct(this->getInitialDir()) < 0) | 
|---|
| 430 |                     this->backlight_->setActive(false); | 
|---|
| 431 |                 else | 
|---|
| 432 |                     this->backlight_->setActive(true); | 
|---|
| 433 |             } | 
|---|
| 434 |  | 
|---|
| 435 |             if (this->redNode_ && this->greenNode_) | 
|---|
| 436 |             { | 
|---|
| 437 |                 this->blinkTime_ += dt; | 
|---|
| 438 |                 float redScale = 0.15 + 0.15 * sin(this->blinkTime_ * 10.0); | 
|---|
| 439 |                 float greenScale = 0.15 - 0.15 * sin(this->blinkTime_ * 10.0); | 
|---|
| 440 |                 this->redNode_->setScale(redScale, redScale, redScale); | 
|---|
| 441 |                 this->greenNode_->setScale(greenScale, greenScale, greenScale); | 
|---|
| 442 |             } | 
|---|
| 443 |         } | 
|---|
| 444 |  | 
|---|
| 445 |         if (this->timeToReload_ > 0) | 
|---|
| 446 |             this->timeToReload_ -= dt; | 
|---|
| 447 |         else | 
|---|
| 448 |             this->timeToReload_ = 0; | 
|---|
| 449 |  | 
|---|
| 450 |         if (this->bLMousePressed_ && this->timeToReload_ <= 0) | 
|---|
| 451 |         { | 
|---|
| 452 |  | 
|---|
| 453 |             BillboardProjectile* projectile = new ParticleProjectile(this); | 
|---|
| 454 |             projectile->setColour(this->getProjectileColour()); | 
|---|
| 455 |             projectile->create(); | 
|---|
| 456 |             if (projectile->classID == 0) | 
|---|
| 457 |             { | 
|---|
| 458 |               COUT(3) << "generated projectile with classid 0" <<  std::endl; // TODO: remove this output | 
|---|
| 459 |             } | 
|---|
| 460 |  | 
|---|
| 461 |             projectile->setBacksync(true); | 
|---|
| 462 |             this->timeToReload_ = this->reloadTime_; | 
|---|
| 463 |         } | 
|---|
| 464 |  | 
|---|
| 465 |  | 
|---|
| 466 |         // ##################################### | 
|---|
| 467 |         // ############# STEERING ############## | 
|---|
| 468 |         // ##################################### | 
|---|
| 469 |  | 
|---|
| 470 |         if (this->velocity_.x > this->maxSpeed_) | 
|---|
| 471 |             this->velocity_.x = this->maxSpeed_; | 
|---|
| 472 |         if (this->velocity_.x < -this->maxSideAndBackSpeed_) | 
|---|
| 473 |             this->velocity_.x = -this->maxSideAndBackSpeed_; | 
|---|
| 474 |         if (this->velocity_.y > this->maxSideAndBackSpeed_) | 
|---|
| 475 |             this->velocity_.y = this->maxSideAndBackSpeed_; | 
|---|
| 476 |         if (this->velocity_.y < -this->maxSideAndBackSpeed_) | 
|---|
| 477 |             this->velocity_.y = -this->maxSideAndBackSpeed_; | 
|---|
| 478 |         if (this->rotationRate_ > this->maxRotationRadian_) | 
|---|
| 479 |             this->rotationRate_ = this->maxRotationRadian_; | 
|---|
| 480 |         if (this->rotationRate_ < -this->maxRotationRadian_) | 
|---|
| 481 |             this->rotationRate_ = -this->maxRotationRadian_; | 
|---|
| 482 |  | 
|---|
| 483 |         if (this->acceleration_.x == 0) | 
|---|
| 484 |         { | 
|---|
| 485 |             if (this->velocity_.x > 0) | 
|---|
| 486 |             { | 
|---|
| 487 |                 this->velocity_.x -= (this->translationDamping_ * dt); | 
|---|
| 488 |                 if (this->velocity_.x < 0) | 
|---|
| 489 |                     this->velocity_.x = 0; | 
|---|
| 490 |             } | 
|---|
| 491 |             else if (this->velocity_.x < 0) | 
|---|
| 492 |             { | 
|---|
| 493 |                 this->velocity_.x += (this->translationDamping_ * dt); | 
|---|
| 494 |                 if (this->velocity_.x > 0) | 
|---|
| 495 |                     this->velocity_.x = 0; | 
|---|
| 496 |             } | 
|---|
| 497 |         } | 
|---|
| 498 |  | 
|---|
| 499 |         if (this->acceleration_.y == 0) | 
|---|
| 500 |         { | 
|---|
| 501 |             if (this->velocity_.y > 0) | 
|---|
| 502 |             { | 
|---|
| 503 |                 this->velocity_.y -= (this->translationDamping_ * dt); | 
|---|
| 504 |                 if (this->velocity_.y < 0) | 
|---|
| 505 |                     this->velocity_.y = 0; | 
|---|
| 506 |             } | 
|---|
| 507 |             else if (this->velocity_.y < 0) | 
|---|
| 508 |             { | 
|---|
| 509 |                 this->velocity_.y += (this->translationDamping_ * dt); | 
|---|
| 510 |                 if (this->velocity_.y > 0) | 
|---|
| 511 |                     this->velocity_.y = 0; | 
|---|
| 512 |             } | 
|---|
| 513 |         } | 
|---|
| 514 |  | 
|---|
| 515 |         if (this->momentum_ == this->zeroRadian_) | 
|---|
| 516 |         { | 
|---|
| 517 |             if (this->rotationRate_ > this->zeroRadian_) | 
|---|
| 518 |             { | 
|---|
| 519 |                 this->rotationRate_ -= (this->rotationDampingRadian_ * dt); | 
|---|
| 520 |                 if (this->rotationRate_ < this->zeroRadian_) | 
|---|
| 521 |                     this->rotationRate_ = 0; | 
|---|
| 522 |             } | 
|---|
| 523 |             else if (this->rotationRate_ < this->zeroRadian_) | 
|---|
| 524 |             { | 
|---|
| 525 |                 this->rotationRate_ += (this->rotationDampingRadian_ * dt); | 
|---|
| 526 |                 if (this->rotationRate_ > this->zeroRadian_) | 
|---|
| 527 |                     this->rotationRate_ = 0; | 
|---|
| 528 |             } | 
|---|
| 529 |         } | 
|---|
| 530 |  | 
|---|
| 531 |  | 
|---|
| 532 |         WorldEntity::tick(dt); | 
|---|
| 533 |  | 
|---|
| 534 |         this->roll(this->mouseXRotation_ * dt); | 
|---|
| 535 |         if (this->bInvertYAxis_) | 
|---|
| 536 |             this->yaw(Radian(-this->mouseYRotation_ * dt)); | 
|---|
| 537 |         else | 
|---|
| 538 |             this->yaw(Radian(this->mouseYRotation_ * dt)); | 
|---|
| 539 |  | 
|---|
| 540 |         if (this->acceleration_.x > 0) | 
|---|
| 541 |         { | 
|---|
| 542 |             this->tt1_->setEnabled(true); | 
|---|
| 543 |             this->tt2_->setEnabled(true); | 
|---|
| 544 |         } | 
|---|
| 545 |         else | 
|---|
| 546 |         { | 
|---|
| 547 |             this->tt1_->setEnabled(false); | 
|---|
| 548 |             this->tt2_->setEnabled(false); | 
|---|
| 549 |         } | 
|---|
| 550 |  | 
|---|
| 551 |         COUT(5) << "steering our ship: " << objectID << std::endl; | 
|---|
| 552 |         this->acceleration_.x = 0; | 
|---|
| 553 |         this->acceleration_.y = 0; | 
|---|
| 554 |         this->momentum_ = 0; | 
|---|
| 555 |         this->mouseXRotation_ = Radian(0); | 
|---|
| 556 |         this->mouseYRotation_ = Radian(0); | 
|---|
| 557 |         this->bLMousePressed_ = false; | 
|---|
| 558 |     } | 
|---|
| 559 |  | 
|---|
| 560 |     void SpaceShip::movePitch(float val) | 
|---|
| 561 |     {   getLocalShip()->setMovePitch(val);   } | 
|---|
| 562 |     void SpaceShip::moveYaw(float val) | 
|---|
| 563 |     {   getLocalShip()->setMoveYaw(val);   } | 
|---|
| 564 |     void SpaceShip::moveRoll(float val) | 
|---|
| 565 |     {   getLocalShip()->setMoveRoll(val);   } | 
|---|
| 566 |     void SpaceShip::moveLongitudinal(float val) | 
|---|
| 567 |     {   getLocalShip()->setMoveLongitudinal(val);   } | 
|---|
| 568 |     void SpaceShip::moveLateral(float val) | 
|---|
| 569 |     {   getLocalShip()->setMoveLateral(val);   } | 
|---|
| 570 |     void SpaceShip::fire() | 
|---|
| 571 |     {   getLocalShip()->doFire();   } | 
|---|
| 572 |  | 
|---|
| 573 |     void SpaceShip::setMovePitch(float val) | 
|---|
| 574 |     { | 
|---|
| 575 |         val = -val * val * sgn(val) * this->rotationAcceleration_; | 
|---|
| 576 |         if (val > this->maxRotation_) | 
|---|
| 577 |             val = this->maxRotation_; | 
|---|
| 578 |         if (val < -this->maxRotation_) | 
|---|
| 579 |             val = -this->maxRotation_; | 
|---|
| 580 |         this->mouseYRotation_ = Radian(val); | 
|---|
| 581 |     } | 
|---|
| 582 |  | 
|---|
| 583 |     void SpaceShip::setMoveYaw(float val) | 
|---|
| 584 |     { | 
|---|
| 585 |         val = -val * val * sgn(val) * this->rotationAcceleration_; | 
|---|
| 586 |         if (val > this->maxRotation_) | 
|---|
| 587 |             val = this->maxRotation_; | 
|---|
| 588 |         if (val < -this->maxRotation_) | 
|---|
| 589 |             val = -this->maxRotation_; | 
|---|
| 590 |         this->mouseXRotation_ = Radian(val); | 
|---|
| 591 |     } | 
|---|
| 592 |  | 
|---|
| 593 |     void SpaceShip::setMoveRoll(float val) | 
|---|
| 594 |     { | 
|---|
| 595 |         this->momentum_ = Radian(-this->rotationAccelerationRadian_ * val); | 
|---|
| 596 |         //COUT(3) << "rotating val: " << val << " acceleration: " << this->rotationAccelerationRadian_.valueDegrees() << std::endl; | 
|---|
| 597 |     } | 
|---|
| 598 |  | 
|---|
| 599 |     void SpaceShip::setMoveLongitudinal(float val) | 
|---|
| 600 |     { | 
|---|
| 601 |         this->acceleration_.x = this->translationAcceleration_ * val; | 
|---|
| 602 |     } | 
|---|
| 603 |  | 
|---|
| 604 |     void SpaceShip::setMoveLateral(float val) | 
|---|
| 605 |     { | 
|---|
| 606 |         this->acceleration_.y = -this->translationAcceleration_ * val; | 
|---|
| 607 |     } | 
|---|
| 608 |  | 
|---|
| 609 |     void SpaceShip::doFire() | 
|---|
| 610 |     { | 
|---|
| 611 |         this->bLMousePressed_ = true; | 
|---|
| 612 |     } | 
|---|
| 613 | } | 
|---|