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