Changeset 1629 for code/branches/input/src/orxonox/objects/SpaceShip.cc
- Timestamp:
- Jun 27, 2008, 8:07:29 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/input/src/orxonox/objects/SpaceShip.cc
r1535 r1629 35 35 #include <OgreSceneNode.h> 36 36 37 #include "CameraHandler.h"38 37 #include "util/Convert.h" 39 38 #include "util/Math.h" 39 40 40 #include "core/CoreIncludes.h" 41 41 #include "core/ConfigValueIncludes.h" 42 42 #include "core/Debug.h" 43 #include "GraphicsEngine.h"44 #include "core/input/InputManager.h"45 #include "particle/ParticleInterface.h"46 #include "Projectile.h"47 #include "RotatingProjectile.h"48 43 #include "core/XMLPort.h" 49 44 #include "core/ConsoleCommand.h" 45 50 46 #include "network/Client.h" 51 #include "hud/HUD.h" 47 48 #include "tools/ParticleInterface.h" 49 50 #include "GraphicsEngine.h" 51 #include "RotatingProjectile.h" 52 #include "ParticleProjectile.h" 53 #include "ParticleSpawner.h" 54 #include "Backlight.h" 55 #include "CameraHandler.h" 52 56 53 57 namespace orxonox … … 69 73 SpaceShip* SpaceShip::instance_s; 70 74 71 75 72 76 SpaceShip *SpaceShip::getLocalShip(){ 73 77 Iterator<SpaceShip> it; … … 79 83 } 80 84 81 SpaceShip::SpaceShip() : 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), 114 myShip_(false), 115 teamNr_(0), 116 health_(100) 85 SpaceShip::SpaceShip() 117 86 { 118 87 RegisterObject(SpaceShip); 119 this->registerAllVariables();120 121 SpaceShip::instance_s = this;122 123 this->setConfigValues();124 125 initialDir_ = Vector3(1.0, 0.0, 0.0);126 currentDir_ = initialDir_;127 initialOrth_ = Vector3(0.0, 0.0, 1.0);128 currentOrth_ = initialOrth_;129 130 this->camName_ = this->getName() + "CamNode";131 88 132 89 this->setRotationAxis(1, 0, 0); 133 90 this->setStatic(false); 134 91 135 COUT(3) << "Info: SpaceShip was loaded" << std::endl; 92 this->zeroRadian_ = 0; 93 this->maxSideAndBackSpeed_ = 0; 94 this->maxSpeed_ = 0; 95 this->maxRotation_ = 0; 96 this->translationAcceleration_ = 0; 97 this->rotationAcceleration_ = 0; 98 this->translationDamping_ = 0; 99 this->rotationDamping_ = 0; 100 this->maxRotationRadian_ = 0; 101 this->rotationAccelerationRadian_ = 0; 102 this->rotationDampingRadian_ = 0; 103 104 this->cam_ = 0; 105 this->tt1_ = 0; 106 this->tt2_ = 0; 107 this->smoke_ = 0; 108 this->fire_ = 0; 109 110 this->backlight_ = 0; 111 112 this->redNode_ = 0; 113 this->greenNode_ = 0; 114 this->blinkTime_ = 0; 115 116 this->timeToReload_ = 0; 117 118 this->bLMousePressed_ = false; 119 this->bRMousePressed_ = false; 120 this->mouseXRotation_ = 0; 121 this->mouseYRotation_ = 0; 122 this->myShip_ = false; 123 124 this->registerAllVariables(); 125 126 SpaceShip::instance_s = this; 127 128 this->setConfigValues(); 129 130 this->initialDir_ = Vector3(1.0, 0.0, 0.0); 131 this->currentDir_ = initialDir_; 132 this->initialOrth_ = Vector3(0.0, 0.0, 1.0); 133 this->currentOrth_ = initialOrth_; 134 135 this->camName_ = this->getName() + "CamNode"; 136 137 this->teamNr_ = 0; 138 this->health_ = 100; 139 140 this->radarObject_ = static_cast<WorldEntity*>(this); 136 141 } 137 142 138 143 SpaceShip::~SpaceShip() 139 144 { 140 if (this->tt_) 141 delete this->tt_; 142 if(setMouseEventCallback_) 143 InputManager::removeMouseHandler("SpaceShip"); 144 if (this->cam_) 145 delete this->cam_; 146 if (!Identifier::isCreatingHierarchy() && !myShip_ && &HUD::getSingleton()!=NULL) 147 //remove the radar object 148 HUD::getSingleton().removeRadarObject(this->getNode()); 145 if (this->isInitialized()) 146 { 147 if (this->tt1_) 148 delete this->tt1_; 149 if (this->tt2_) 150 delete this->tt2_; 151 152 if (this->smoke_) 153 this->smoke_->destroy(); 154 if (this->fire_) 155 this->fire_->destroy(); 156 157 if (this->backlight_) 158 delete this->backlight_; 159 160 if (this->cam_) 161 delete this->cam_; 162 } 149 163 } 150 164 … … 154 168 myShip_=true; 155 169 else 156 HUD::getSingleton().addRadarObject(this->getNode(), 3);170 this->setRadarObjectColour(this->getProjectileColour()); 157 171 } 158 172 if(Model::create()) … … 179 193 void SpaceShip::init() 180 194 { 181 // START CREATING THRUSTER 182 this->tt_ = new ParticleInterface(GraphicsEngine::getSingleton().getSceneManager(),"twinthruster" + this->getName(),"Orxonox/engineglow"); 183 this->tt_->getParticleSystem()->setParameter("local_space","true"); 184 this->tt_->newEmitter(); 185 /* 186 this->tt_->setDirection(Vector3(0,0,1)); 187 this->tt_->setPositionOfEmitter(0, Vector3(20,-1,-15)); 188 this->tt_->setPositionOfEmitter(1, Vector3(-20,-1,-15)); 189 */ 190 this->tt_->setDirection(Vector3(-1,0,0)); 191 this->tt_->setPositionOfEmitter(0, Vector3(-15,20,-1)); 192 this->tt_->setPositionOfEmitter(1, Vector3(-15,-20,-1)); 193 this->tt_->setVelocity(50); 194 195 emitterRate_ = tt_->getRate(); 196 197 Ogre::SceneNode* node2 = this->getNode()->createChildSceneNode(this->getName() + "particle2"); 198 node2->setInheritScale(false); 199 tt_->addToSceneNode(node2); 200 // END CREATING THRUSTER 195 // START CREATING THRUSTERS 196 this->tt1_ = new ParticleInterface("Orxonox/thruster1", LODParticle::low); 197 this->tt1_->createNewEmitter(); 198 this->tt1_->getAllEmitters()->setDirection(-this->getInitialDir()); 199 this->tt1_->getEmitter(0)->setPosition(Vector3(-15, 20, -1)); 200 this->tt1_->getEmitter(1)->setPosition(Vector3(-15, -20, -1)); 201 this->tt1_->setSpeedFactor(3.0); 202 203 Ogre::SceneNode* node2a = this->getNode()->createChildSceneNode(this->getName() + "particle2a"); 204 node2a->setInheritScale(false); 205 node2a->setScale(1, 1, 1); 206 tt1_->addToSceneNode(node2a); 207 208 this->tt2_ = new ParticleInterface("Orxonox/thruster2", LODParticle::normal); 209 this->tt2_->createNewEmitter(); 210 this->tt2_->getAllEmitters()->setDirection(Vector3(-1, 0, 0)); 211 this->tt2_->getEmitter(0)->setPosition(Vector3(-30, 40, -2)); 212 this->tt2_->getEmitter(1)->setPosition(Vector3(-30, -40, -2)); 213 214 Ogre::SceneNode* node2b = this->getNode()->createChildSceneNode(this->getName() + "particle2b"); 215 node2b->setInheritScale(false); 216 node2b->setScale(0.5, 0.5, 0.5); 217 tt2_->addToSceneNode(node2b); 218 219 this->leftThrusterFlare_.setBillboardSet("Flares/ThrusterFlare1", Vector3(-7.5, -10, -0.5)); 220 this->rightThrusterFlare_.setBillboardSet("Flares/ThrusterFlare1", Vector3(-7.5, 10, -0.5)); 221 222 Ogre::SceneNode* node2c = this->getNode()->createChildSceneNode(this->getName() + "particle2c"); 223 node2c->setInheritScale(false); 224 node2c->setScale(2, 2, 2); 225 node2c->attachObject(this->leftThrusterFlare_.getBillboardSet()); 226 node2c->attachObject(this->rightThrusterFlare_.getBillboardSet()); 227 // END CREATING THRUSTERS 201 228 202 229 // START CREATING BLINKING LIGHTS … … 216 243 // END CREATING BLINKING LIGHTS 217 244 245 // START CREATING ADDITIONAL EFFECTS 246 this->backlight_ = new Backlight(this->maxSpeed_, 0.8); 247 this->attachObject(this->backlight_); 248 this->backlight_->setPosition(-2.35, 0, 0.2); 249 this->backlight_->setColour(this->getProjectileColour()); 250 251 this->smoke_ = new ParticleSpawner(); 252 this->smoke_->setParticle("Orxonox/smoke5", LODParticle::normal, 0, 0, 3); 253 this->attachObject(this->smoke_); 254 255 this->fire_ = new ParticleSpawner(); 256 this->fire_->setParticle("Orxonox/fire3", LODParticle::normal, 0, 0, 1); 257 this->attachObject(this->fire_); 258 // END CREATING ADDITIONAL EFFECTS 259 218 260 if (this->isExactlyA(Class(SpaceShip))) 219 261 { … … 232 274 this->chFarNode_->attachObject(this->crosshairFar_.getBillboardSet()); 233 275 this->chFarNode_->setScale(0.4, 0.4, 0.4); 276 // END of testing crosshair 234 277 } 235 278 236 279 createCamera(); 237 // END of testing crosshair238 280 } 239 281 … … 245 287 } 246 288 289 void SpaceShip::changedVisibility() 290 { 291 Model::changedVisibility(); 292 293 this->tt1_->setEnabled(this->isVisible()); 294 this->tt2_->setEnabled(this->isVisible()); 295 this->redBillboard_.setVisible(this->isVisible()); 296 this->greenBillboard_.setVisible(this->isVisible()); 297 this->crosshairNear_.setVisible(this->isVisible()); 298 this->crosshairFar_.setVisible(this->isVisible()); 299 this->rightThrusterFlare_.setVisible(this->isVisible()); 300 this->leftThrusterFlare_.setVisible(this->isVisible()); 301 this->smoke_->setVisible(this->isVisible()); 302 this->fire_->setVisible(this->isVisible()); 303 this->backlight_->setVisible(this->isVisible()); 304 } 305 306 void SpaceShip::changedActivity() 307 { 308 Model::changedActivity(); 309 310 this->tt1_->setEnabled(this->isVisible()); 311 this->tt2_->setEnabled(this->isVisible()); 312 this->redBillboard_.setVisible(this->isVisible()); 313 this->greenBillboard_.setVisible(this->isVisible()); 314 this->crosshairNear_.setVisible(this->isVisible()); 315 this->crosshairFar_.setVisible(this->isVisible()); 316 this->rightThrusterFlare_.setVisible(this->isVisible()); 317 this->leftThrusterFlare_.setVisible(this->isVisible()); 318 } 319 247 320 void SpaceShip::setCamera(const std::string& camera) 248 321 { 322 myShip_=true; // TODO: this is only a hack 249 323 camName_=camera; 250 324 // change camera attributes here, if you want to ;) … … 266 340 this->camNode_ = this->getNode()->createChildSceneNode(camName_); 267 341 COUT(4) << "position: (this)" << this->getNode()->getPosition() << std::endl; 268 this->camNode_->setPosition(Vector3(- 50,0,10));342 this->camNode_->setPosition(Vector3(-25,0,5)); 269 343 // Quaternion q1 = Quaternion(Radian(Degree(90)),Vector3(0,-1,0)); 270 344 // Quaternion q2 = Quaternion(Radian(Degree(90)),Vector3(0,0,-1)); … … 277 351 Quaternion q1 = Quaternion(Radian(Degree(90)),Vector3(0,-1,0)); 278 352 Quaternion q2 = Quaternion(Radian(Degree(90)),Vector3(1,0,0)); 279 camNode_->setOrientation(q2*q1);353 this->camNode_->setOrientation(q2*q1); 280 354 if(network::Client::getSingleton()!=0 && network::Client::getSingleton()->getShipID()==objectID){ 281 355 this->setBacksync(true); 282 356 CameraHandler::getInstance()->requestFocus(cam_); 283 357 } 284 285 358 } 286 359 … … 318 391 XMLPortParamLoadOnly(SpaceShip, "transDamp", setTransDamp, xmlelement, mode); 319 392 XMLPortParamLoadOnly(SpaceShip, "rotDamp", setRotDamp, xmlelement, mode); 320 myShip_=true; // TODO: this is only a hack321 393 322 394 SpaceShip::create(); … … 325 397 } 326 398 327 int sgn(float x)328 {329 if (x >= 0)330 return 1;331 else332 return -1;333 }334 335 399 std::string SpaceShip::whereAmI() { 336 return getConvertedValue<float, std::string>(SpaceShip::getLocalShip()->getPosition().x) 337 + " " + getConvertedValue<float, std::string>(SpaceShip::getLocalShip()->getPosition().y) 338 + " " + getConvertedValue<float, std::string>(SpaceShip::getLocalShip()->getPosition().z); 339 } 340 341 Vector3 SpaceShip::getDir() { 342 return currentDir_; 343 } 344 345 Vector3 SpaceShip::getOrth(){ 346 return currentOrth_; 347 } 348 349 float SpaceShip::getMaxSpeed() { return maxSpeed_; } 400 return getConvertedValue<float, std::string>(SpaceShip::getLocalShip()->getPosition().x) 401 + " " + getConvertedValue<float, std::string>(SpaceShip::getLocalShip()->getPosition().y) 402 + " " + getConvertedValue<float, std::string>(SpaceShip::getLocalShip()->getPosition().z); 403 } 350 404 351 405 void SpaceShip::tick(float dt) 352 406 { 407 if (!this->isActive()) 408 return; 409 353 410 currentDir_ = getOrientation()*initialDir_; 354 411 currentOrth_ = getOrientation()*initialOrth_; 355 412 356 413 if (this->cam_) 357 414 this->cam_->tick(dt); 415 416 if (this->smoke_) 417 this->smoke_->setVisible(this->isVisible() && this->health_ < 40); 418 if (this->fire_) 419 this->fire_->setVisible(this->isVisible() && this->health_ < 20); 420 421 if (this->backlight_) 422 { // (there's already fire || we're to slow || we're moving backwards ) 423 if (this->health_ < 20 || this->getVelocity().squaredLength() < 150*150 || this->getVelocity().dotProduct(this->getInitialDir()) < 0) 424 this->backlight_->setActive(false); 425 else 426 this->backlight_->setActive(true); 427 } 358 428 359 429 if (this->redNode_ && this->greenNode_) … … 374 444 { 375 445 376 Projectile *p; 377 if (this->isExactlyA(Class(SpaceShip))) 378 p = new RotatingProjectile(this); 379 else 380 p = new Projectile(this); 381 p->setColour(this->getProjectileColour()); 382 p->create(); 383 if(p->classID==0) 446 BillboardProjectile* projectile = new ParticleProjectile(this); 447 projectile->setColour(this->getProjectileColour()); 448 projectile->create(); 449 if (projectile->classID == 0) 450 { 384 451 COUT(3) << "generated projectile with classid 0" << std::endl; // TODO: remove this output 385 386 p->setBacksync(true); 452 } 453 454 projectile->setBacksync(true); 387 455 this->timeToReload_ = this->reloadTime_; 388 456 } … … 464 532 465 533 if (this->acceleration_.x > 0) 466 this->tt_->setRate(emitterRate_); 534 { 535 this->tt1_->setEnabled(true); 536 this->tt2_->setEnabled(true); 537 } 467 538 else 468 this->tt_->setRate(0); 469 470 if( myShip_ ) 471 { 472 COUT(5) << "steering our ship: " << objectID << std::endl; 473 this->acceleration_.x = 0; 474 this->acceleration_.y = 0; 475 this->momentum_ = 0; 476 this->mouseXRotation_ = Radian(0); 477 this->mouseYRotation_ = Radian(0); 478 this->bLMousePressed_ = false; 479 }/*else 480 COUT(4) << "not steering ship: " << objectID << " our ship: " << network::Client::getSingleton()->getShipID() << std::endl;*/ 539 { 540 this->tt1_->setEnabled(false); 541 this->tt2_->setEnabled(false); 542 } 543 544 COUT(5) << "steering our ship: " << objectID << std::endl; 545 this->acceleration_.x = 0; 546 this->acceleration_.y = 0; 547 this->momentum_ = 0; 548 this->mouseXRotation_ = Radian(0); 549 this->mouseYRotation_ = Radian(0); 550 this->bLMousePressed_ = false; 481 551 } 482 552
Note: See TracChangeset
for help on using the changeset viewer.