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