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