Changeset 1608 for code/trunk/src/orxonox/objects
- Timestamp:
- Jun 17, 2008, 3:33:03 PM (17 years ago)
- Location:
- code/trunk/src/orxonox/objects
- Files:
-
- 2 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk/src/orxonox/objects/ParticleSpawner.cc
r1602 r1608 33 33 #include "core/Executor.h" 34 34 #include "tools/ParticleInterface.h" 35 #include "GraphicsEngine.h" 35 36 36 37 namespace orxonox … … 44 45 } 45 46 46 ParticleSpawner::ParticleSpawner(const std::string& templateName, LODParticle::LOD detaillevel, float lifetime, float delay, const Vector3& direction)47 ParticleSpawner::ParticleSpawner(const std::string& templateName, LODParticle::LOD detaillevel, float lifetime, float startdelay, float destroydelay, const Vector3& direction) 47 48 { 48 49 RegisterObject(ParticleSpawner); 49 this->setParticle(templateName, detaillevel, lifetime, delay, direction);50 this->setParticle(templateName, detaillevel, lifetime, startdelay, destroydelay, direction); 50 51 } 51 52 52 void ParticleSpawner::setParticle(const std::string& templateName, LODParticle::LOD detaillevel, float lifetime, float delay, const Vector3& direction)53 void ParticleSpawner::setParticle(const std::string& templateName, LODParticle::LOD detaillevel, float lifetime, float startdelay, float destroydelay, const Vector3& direction) 53 54 { 54 55 ExecutorMember<ParticleSpawner>* executor = createExecutor(createFunctor(&ParticleSpawner::createParticleSpawner)); 56 this->destroydelay_ = destroydelay; 55 57 executor->setDefaultValues(lifetime); 56 this->timer_.setTimer( delay, false, this, executor);58 this->timer_.setTimer(startdelay, false, this, executor); 57 59 this->particle_ = new ParticleInterface(templateName, detaillevel); 58 60 this->particle_->addToSceneNode(this->getNode()); … … 72 74 } 73 75 }; 76 77 void ParticleSpawner::destroy() 78 { 79 this->setPosition(this->getNode()->getParent()->getPosition()); 80 this->getNode()->getParent()->removeChild(this->getNode()); 81 GraphicsEngine::getSingleton().getSceneManager()->getRootSceneNode()->addChild(this->getNode()); 82 if (this->particle_) 83 this->particle_->setEnabled(false); 84 if (!this->timer_.isActive() || this->timer_.getRemainingTime() > this->destroydelay_) 85 this->timer_.setTimer(this->destroydelay_, false, this, createExecutor(createFunctor(&ParticleSpawner::destroyParticleSpawner))); 86 } 74 87 75 88 void ParticleSpawner::createParticleSpawner(float lifetime) -
code/trunk/src/orxonox/objects/ParticleSpawner.h
r1602 r1608 41 41 public: 42 42 ParticleSpawner(); 43 ParticleSpawner(const std::string& templateName, LODParticle::LOD detaillevel, float lifetime = 0, float delay = 0, const Vector3& direction = Vector3::ZERO);43 ParticleSpawner(const std::string& templateName, LODParticle::LOD detaillevel, float lifetime = 0, float startdelay = 0, float destroydelay = 0, const Vector3& direction = Vector3::ZERO); 44 44 virtual ~ParticleSpawner(); 45 void destroy(); 45 46 46 void setParticle(const std::string& templateName, LODParticle::LOD detaillevel, float lifetime = 0, float delay = 0, const Vector3& direction = Vector3::ZERO);47 void setParticle(const std::string& templateName, LODParticle::LOD detaillevel, float lifetime = 0, float startdelay = 0, float destroydelay = 0, const Vector3& direction = Vector3::ZERO); 47 48 inline ParticleInterface* getParticleInterface() const 48 49 { return this->particle_; } … … 56 57 Timer<ParticleSpawner> timer_; 57 58 ParticleInterface* particle_; 59 float destroydelay_; 58 60 }; 59 61 } -
code/trunk/src/orxonox/objects/SpaceShip.cc
r1602 r1608 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 "core/XMLPort.h" 44 #include "core/ConsoleCommand.h" 45 #include "core/input/InputManager.h" 46 47 #include "network/Client.h" 48 49 #include "hud/HUD.h" 50 #include "tools/ParticleInterface.h" 51 43 52 #include "GraphicsEngine.h" 44 #include "core/input/InputManager.h"45 #include "tools/ParticleInterface.h"46 53 #include "RotatingProjectile.h" 47 54 #include "ParticleProjectile.h" 48 #include "core/XMLPort.h" 49 #include "core/ConsoleCommand.h" 50 #include "network/Client.h" 51 #include "hud/HUD.h" 55 #include "ParticleSpawner.h" 56 #include "Backlight.h" 57 #include "CameraHandler.h" 52 58 53 59 namespace orxonox … … 101 107 this->tt1_ = 0; 102 108 this->tt2_ = 0; 109 this->smoke_ = 0; 110 this->fire_ = 0; 111 112 this->backlight_ = 0; 103 113 104 114 this->redNode_ = 0; … … 143 153 delete this->tt2_; 144 154 145 if (setMouseEventCallback_) 155 if (this->smoke_) 156 this->smoke_->destroy(); 157 if (this->fire_) 158 this->fire_->destroy(); 159 160 if (this->backlight_) 161 delete this->backlight_; 162 163 if (this->setMouseEventCallback_) 146 164 InputManager::removeMouseHandler("SpaceShip"); 147 165 … … 184 202 void SpaceShip::init() 185 203 { 186 // START CREATING THRUSTER 204 // START CREATING THRUSTERS 187 205 this->tt1_ = new ParticleInterface("Orxonox/thruster1", LODParticle::low); 188 206 this->tt1_->createNewEmitter(); … … 216 234 node2c->attachObject(this->leftThrusterFlare_.getBillboardSet()); 217 235 node2c->attachObject(this->rightThrusterFlare_.getBillboardSet()); 218 // END CREATING THRUSTER 236 // END CREATING THRUSTERS 219 237 220 238 // START CREATING BLINKING LIGHTS … … 234 252 // END CREATING BLINKING LIGHTS 235 253 236 this->smoke_.setParticle("Orxonox/smoke5", LODParticle::normal); 237 this->fire_.setParticle("Orxonox/fire3", LODParticle::normal); 254 // START CREATING ADDITIONAL EFFECTS 255 this->backlight_ = new Backlight(this->maxSpeed_, 0.8); 256 this->attachObject(this->backlight_); 257 this->backlight_->setPosition(-2.35, 0, 0.2); 258 this->backlight_->setColour(this->getProjectileColour()); 259 260 this->smoke_ = new ParticleSpawner(); 261 this->smoke_->setParticle("Orxonox/smoke5", LODParticle::normal, 0, 0, 3); 238 262 this->attachObject(this->smoke_); 263 264 this->fire_ = new ParticleSpawner(); 265 this->fire_->setParticle("Orxonox/fire3", LODParticle::normal, 0, 0, 1); 239 266 this->attachObject(this->fire_); 267 // END CREATING ADDITIONAL EFFECTS 240 268 241 269 if (this->isExactlyA(Class(SpaceShip))) … … 255 283 this->chFarNode_->attachObject(this->crosshairFar_.getBillboardSet()); 256 284 this->chFarNode_->setScale(0.4, 0.4, 0.4); 285 // END of testing crosshair 257 286 } 258 287 259 288 createCamera(); 260 // END of testing crosshair261 289 } 262 290 … … 280 308 this->rightThrusterFlare_.setVisible(this->isVisible()); 281 309 this->leftThrusterFlare_.setVisible(this->isVisible()); 282 this->smoke_.setVisible(this->isVisible()); 283 this->fire_.setVisible(this->isVisible()); 310 this->smoke_->setVisible(this->isVisible()); 311 this->fire_->setVisible(this->isVisible()); 312 this->backlight_->setVisible(this->isVisible()); 284 313 } 285 314 … … 336 365 CameraHandler::getInstance()->requestFocus(cam_); 337 366 } 338 339 367 } 340 368 … … 378 406 } 379 407 380 int sgn(float x)381 {382 if (x >= 0)383 return 1;384 else385 return -1;386 }387 388 408 std::string SpaceShip::whereAmI() { 389 390 391 409 return getConvertedValue<float, std::string>(SpaceShip::getLocalShip()->getPosition().x) 410 + " " + getConvertedValue<float, std::string>(SpaceShip::getLocalShip()->getPosition().y) 411 + " " + getConvertedValue<float, std::string>(SpaceShip::getLocalShip()->getPosition().z); 392 412 } 393 413 … … 403 423 this->cam_->tick(dt); 404 424 405 this->smoke_.setVisible(this->isVisible() && this->health_ < 40); 406 this->fire_.setVisible(this->isVisible() && this->health_ < 20); 425 if (this->smoke_) 426 this->smoke_->setVisible(this->isVisible() && this->health_ < 40); 427 if (this->fire_) 428 this->fire_->setVisible(this->isVisible() && this->health_ < 20); 429 430 if (this->backlight_) 431 { // (there's already fire || we're to slow || we're moving backwards ) 432 if (this->health_ < 20 || this->getVelocity().squaredLength() < 150*150 || this->getVelocity().dotProduct(this->getInitialDir()) < 0) 433 this->backlight_->setActive(false); 434 else 435 this->backlight_->setActive(true); 436 } 407 437 408 438 if (this->redNode_ && this->greenNode_) … … 521 551 } 522 552 523 if( myShip_ ) 524 { 525 COUT(5) << "steering our ship: " << objectID << std::endl; 526 this->acceleration_.x = 0; 527 this->acceleration_.y = 0; 528 this->momentum_ = 0; 529 this->mouseXRotation_ = Radian(0); 530 this->mouseYRotation_ = Radian(0); 531 }/*else 532 COUT(4) << "not steering ship: " << objectID << " our ship: " << network::Client::getSingleton()->getShipID() << std::endl;*/ 533 534 this->bLMousePressed_ = false; 553 COUT(5) << "steering our ship: " << objectID << std::endl; 554 this->acceleration_.x = 0; 555 this->acceleration_.y = 0; 556 this->momentum_ = 0; 557 this->mouseXRotation_ = Radian(0); 558 this->mouseYRotation_ = Radian(0); 559 this->bLMousePressed_ = false; 535 560 } 536 561 -
code/trunk/src/orxonox/objects/SpaceShip.h
r1602 r1608 37 37 #include "Model.h" 38 38 #include "tools/BillboardSet.h" 39 #include "ParticleSpawner.h"40 39 41 40 namespace orxonox … … 145 144 BillboardSet rightThrusterFlare_; 146 145 146 Backlight* backlight_; 147 147 148 BillboardSet redBillboard_; 148 149 BillboardSet greenBillboard_; … … 151 152 float blinkTime_; 152 153 153 ParticleSpawner smoke_;154 ParticleSpawner fire_;154 ParticleSpawner* smoke_; 155 ParticleSpawner* fire_; 155 156 156 157 BillboardSet crosshairNear_; -
code/trunk/src/orxonox/objects/SpaceShipAI.cc
r1566 r1608 102 102 newenemy->XMLPort(xmlelement, XMLPort::LoadObject); 103 103 104 ParticleSpawner* spawneffect = new ParticleSpawner("Orxonox/fairytwirl", LODParticle::normal, 2.0, 0 .0, newenemy->getOrth());104 ParticleSpawner* spawneffect = new ParticleSpawner("Orxonox/fairytwirl", LODParticle::normal, 2.0, 0, 0, newenemy->getOrth()); 105 105 spawneffect->setPosition(newenemy->getPosition() - newenemy->getOrth() * 50); 106 106 spawneffect->create(); … … 131 131 // search enemy 132 132 random = rnd(maxrand); 133 if (random < 20&& (!this->target_))133 if (random < 15 && (!this->target_)) 134 134 this->searchNewTarget(); 135 135 … … 146 146 // fly somewhere 147 147 random = rnd(maxrand); 148 if (random < 40 && (!this->bHasTargetPosition_ && !this->target_))148 if (random < 50 && (!this->bHasTargetPosition_ && !this->target_)) 149 149 this->searchNewTargetPosition(); 150 150 … … 201 201 Vector3 ringdirection = Vector3(rnd(), rnd(), rnd()); 202 202 ringdirection.normalise(); 203 explosion = new ParticleSpawner("Orxonox/BigExplosion1part3", LODParticle::normal, 3.0, 0.5, ringdirection);204 explosion->setPosition(this->getPosition()); 205 explosion->getParticleInterface()->setKeepParticlesInLocalSpace(true); 206 explosion->setScale(4); 207 explosion->create(); 208 explosion = new ParticleSpawner("Orxonox/BigExplosion1part3", LODParticle::high, 3.0, 0.5, ringdirection);203 explosion = new ParticleSpawner("Orxonox/BigExplosion1part3", LODParticle::normal, 3.0, 0.5, 0, ringdirection); 204 explosion->setPosition(this->getPosition()); 205 explosion->getParticleInterface()->setKeepParticlesInLocalSpace(true); 206 explosion->setScale(4); 207 explosion->create(); 208 explosion = new ParticleSpawner("Orxonox/BigExplosion1part3", LODParticle::high, 3.0, 0.5, 0, ringdirection); 209 209 explosion->setPosition(this->getPosition()); 210 210 explosion->getParticleInterface()->setKeepParticlesInLocalSpace(true); … … 235 235 { 236 236 Vector2 coord = get2DViewdirection(this->getPosition(), this->getDir(), this->getOrth(), this->targetPosition_); 237 this->setMoveYaw(0.8 * sgn(coord.x)); 238 this->setMovePitch(0.8 * sgn(coord.y)); 239 240 if ((this->targetPosition_ - this->getPosition()).length() > 500) 237 238 float distance = (this->targetPosition_ - this->getPosition()).length(); 239 if (this->target_ || distance > 50) 240 { 241 // Multiply with 0.8 to make them a bit slower 242 this->setMoveYaw(0.8 * sgn(coord.x) * coord.x*coord.x); 243 this->setMovePitch(0.8 * sgn(coord.y) * coord.y*coord.y); 244 } 245 246 if (this->target_ && distance < 1000 && this->getVelocity().squaredLength() > this->target_->getVelocity().squaredLength()) 247 this->setMoveLongitudinal(-0.5); // They don't brake with full power to give the player a chance 248 else if (!this->target_ && distance <= this->getVelocity().length() / (2 * this->getTransAcc())) 249 this->setMoveLongitudinal(-1.0); 250 else 241 251 this->setMoveLongitudinal(0.8); 242 243 if (this->isCloseAtTarget(300) && this->target_)244 {245 if (this->getVelocity().length() > this->target_->getVelocity().length())246 this->setMoveLongitudinal(-0.5);247 }248 252 } 249 253 … … 306 310 void SpaceShipAI::shipDied(SpaceShipAI* ship) 307 311 { 308 this->forgetTarget(); 309 this->searchNewTargetPosition(); 312 if (ship == this->target_) 313 { 314 this->forgetTarget(); 315 this->searchNewTargetPosition(); 316 } 310 317 } 311 318 }
Note: See TracChangeset
for help on using the changeset viewer.