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