Changeset 1552 for code/trunk/src
- Timestamp:
- Jun 6, 2008, 5:31:58 PM (16 years ago)
- Location:
- code/trunk/src
- Files:
-
- 6 added
- 2 deleted
- 17 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk/src/asylum/orxonox/objects/Fighter.cc
r1505 r1552 132 132 #if 0 133 133 w = new particle::ParticleInterface(GraphicsEngine::getSingleton().getSceneManager(),"schuss" + this->getName(),"Orxonox/schuss"); 134 w->getParticleSystem()->setParameter("local_space","true");135 134 w->newEmitter(); 136 135 /* … … 151 150 152 151 tt = new ParticleInterface(GraphicsEngine::getSingleton().getSceneManager(),"twinthruster" + this->getName(),"Orxonox/engineglow"); 153 tt->getParticleSystem()->setParameter("local_space","true");154 152 tt->newEmitter(); 155 153 /* -
code/trunk/src/orxonox/CMakeLists.txt
r1535 r1552 22 22 objects/Camera.cc 23 23 objects/CameraHandler.cc 24 objects/Explosion.cc25 24 objects/Model.cc 26 25 objects/NPC.cc 27 objects/Projectile.cc 28 objects/RotatingProjectile.cc 26 objects/ParticleSpawner.cc 29 27 objects/Skybox.cc 30 28 objects/SpaceShip.cc … … 32 30 objects/Tickable.cc 33 31 objects/WorldEntity.cc 32 33 objects/Projectile.cc 34 objects/BillboardProjectile.cc 35 objects/RotatingProjectile.cc 36 objects/ParticleProjectile.cc 34 37 35 38 # objects/weapon/AmmunitionDump.cc -
code/trunk/src/orxonox/OrxonoxPrereqs.h
r1505 r1552 67 67 class Ambient; 68 68 class Camera; 69 class Explosion;70 69 class Fighter; 71 70 class Model; 72 71 class NPC; 73 class P rojectile;72 class ParticleSpawner; 74 73 class Skybox; 75 74 class SpaceShip; 76 75 class SpaceShipAI; 77 76 class WorldEntity; 77 78 class Projectile; 79 class BillboardProjectile; 80 class RotatingProjectile; 81 class ParticleProjectile; 78 82 79 83 class AmmunitionDump; -
code/trunk/src/orxonox/objects/Model.cc
r1511 r1552 45 45 CreateFactory(Model); 46 46 47 Model::Model() 47 Model::Model() : meshSrc_("") 48 48 { 49 49 RegisterObject(Model); … … 53 53 Model::~Model() 54 54 { 55 if ((this->meshSrc_ != "") && (this->meshSrc_.size() > 0)) 56 this->detachObject(this->mesh_.getEntity()); 55 57 } 56 58 -
code/trunk/src/orxonox/objects/Projectile.cc
r1505 r1552 35 35 #include "core/Executor.h" 36 36 #include "core/ConfigValueIncludes.h" 37 #include "particle/ParticleInterface.h" 37 38 38 #include "SpaceShip .h"39 #include " Explosion.h"39 #include "SpaceShipAI.h" 40 #include "ParticleSpawner.h" 40 41 #include "Model.h" 41 42 42 43 namespace orxonox 43 44 { 44 CreateFactory(Projectile);45 float Projectile::speed_ = 2000; 45 46 46 float Projectile::speed_ = 0; 47 48 Projectile::Projectile(SpaceShip* owner) : 49 owner_(owner) 47 Projectile::Projectile(SpaceShip* owner) : owner_(owner) 50 48 { 51 49 RegisterObject(Projectile); 52 50 53 51 this->setConfigValues(); 54 55 this->billboard_.setBillboardSet("Examples/Flare", ColourValue(1.0, 1.0, 0.5), 1); 56 this->attachObject(this->billboard_.getBillboardSet()); 57 this->scale(0.5); 52 this->explosionTemplateName_ = "Orxonox/explosion1"; 53 this->smokeTemplateName_ = "Orxonox/smoke3"; 58 54 59 55 if (this->owner_) … … 63 59 this->setPosition(this->owner_->getPosition()); 64 60 this->translate(Vector3(55, 0, 0), Ogre::Node::TS_LOCAL); 65 this->setVelocity( Vector3(1, 0, 0) * this->speed_);61 this->setVelocity(this->owner_->getInitialDir() * this->speed_); 66 62 } 67 63 68 64 this->destroyTimer_.setTimer(this->lifetime_, false, this, createExecutor(createFunctor(&Projectile::destroyObject))); 69 // COUT(3) << this->classID << std::endl;70 65 } 71 66 … … 76 71 void Projectile::setConfigValues() 77 72 { 78 SetConfigValue(lifetime_, 10.0).description("The time in seconds a projectile stays alive"); 73 SetConfigValue(damage_, 15.0).description("The damage caused by the projectile"); 74 SetConfigValue(lifetime_, 5.0).description("The time in seconds a projectile stays alive"); 79 75 SetConfigValue(speed_, 2000.0).description("The speed of a projectile in units per second"); 80 76 81 this->setVelocity( Vector3(1, 0, 0) * this->speed_);77 this->setVelocity(this->owner_->getInitialDir() * this->speed_); 82 78 } 83 79 … … 95 91 if (this->getPosition().squaredDistance(it->getPosition()) <= (radius*radius)) 96 92 { 97 Explosion *exp = new Explosion(this); 98 exp->create(); 93 // hit 94 if (it->isA(Class(SpaceShipAI))) 95 ((SpaceShipAI*)(*it))->damage(this->damage_); 96 ParticleSpawner* explosion = new ParticleSpawner(this->explosionTemplateName_, 2.0); 97 explosion->setPosition(this->getPosition()); 98 explosion->create(); 99 ParticleSpawner* smoke = new ParticleSpawner(this->smokeTemplateName_, 6.0, 0.0); 100 smoke->setPosition(this->getPosition()); 101 smoke->getParticleInterface()->setSpeedFactor(3.0); 102 smoke->create(); 99 103 delete this; 100 104 return; … … 108 112 delete this; 109 113 } 110 111 void Projectile::setColour(const ColourValue& colour)112 {113 this->billboard_.getBillboardSet()->getBillboard(0)->setColour(colour);114 }115 114 } -
code/trunk/src/orxonox/objects/Projectile.h
r1505 r1552 33 33 34 34 #include "WorldEntity.h" 35 #include "../tools/BillboardSet.h" 36 #include "../tools/Timer.h" 37 #include "util/Math.h" 35 #include "tools/Timer.h" 38 36 39 37 namespace orxonox … … 42 40 { 43 41 public: 44 Projectile(SpaceShip* owner = 0);45 42 virtual ~Projectile(); 46 43 void setConfigValues(); 47 44 void destroyObject(); 48 45 virtual void tick(float dt); 49 virtual bool create(){return WorldEntity::create();}50 void setColour(const ColourValue& colour);51 46 52 47 static float getSpeed() … … 54 49 55 50 protected: 51 Projectile(SpaceShip* owner = 0); 56 52 SpaceShip* owner_; 57 53 58 54 private: 59 BillboardSet billboard_; 55 std::string explosionTemplateName_; 56 std::string smokeTemplateName_; 60 57 static float speed_; 61 58 float lifetime_; 59 float damage_; 62 60 Timer<Projectile> destroyTimer_; 63 61 }; -
code/trunk/src/orxonox/objects/RotatingProjectile.cc
r1505 r1552 37 37 CreateFactory(RotatingProjectile); 38 38 39 RotatingProjectile::RotatingProjectile(SpaceShip* owner) : Projectile(owner)39 RotatingProjectile::RotatingProjectile(SpaceShip* owner) : BillboardProjectile(owner) 40 40 { 41 41 RegisterObject(RotatingProjectile); -
code/trunk/src/orxonox/objects/RotatingProjectile.h
r1505 r1552 2 2 #define _RotatingProjectile_H__ 3 3 4 #include " ../OrxonoxPrereqs.h"4 #include "OrxonoxPrereqs.h" 5 5 #include "util/Math.h" 6 #include " Projectile.h"6 #include "BillboardProjectile.h" 7 7 8 8 namespace orxonox 9 9 { 10 class _OrxonoxExport RotatingProjectile : public Projectile/*, public network::Synchronisable*/10 class _OrxonoxExport RotatingProjectile : public BillboardProjectile 11 11 { 12 12 public: … … 15 15 void setConfigValues(); 16 16 virtual void tick(float dt); 17 virtual bool create(){return Projectile::create();}18 17 19 18 private: -
code/trunk/src/orxonox/objects/SpaceShip.cc
r1535 r1552 44 44 #include "core/input/InputManager.h" 45 45 #include "particle/ParticleInterface.h" 46 #include "Projectile.h"47 46 #include "RotatingProjectile.h" 47 #include "ParticleProjectile.h" 48 48 #include "core/XMLPort.h" 49 49 #include "core/ConsoleCommand.h" … … 69 69 SpaceShip* SpaceShip::instance_s; 70 70 71 71 72 72 SpaceShip *SpaceShip::getLocalShip(){ 73 73 Iterator<SpaceShip> it; … … 88 88 cam_(0), 89 89 camName_("CamNode"), 90 tt_(0), 90 tt1_(0), 91 tt2_(0), 91 92 redNode_(0), 92 93 greenNode_(0), … … 111 112 mouseX_(0.0f), 112 113 mouseY_(0.0f), 113 emitterRate_(0.0f),114 114 myShip_(false), 115 115 teamNr_(0), … … 138 138 SpaceShip::~SpaceShip() 139 139 { 140 if (this->tt_) 141 delete this->tt_; 140 if (this->tt1_) 141 delete this->tt1_; 142 if (this->tt2_) 143 delete this->tt2_; 142 144 if(setMouseEventCallback_) 143 145 InputManager::removeMouseHandler("SpaceShip"); … … 180 182 { 181 183 // 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); 184 this->tt1_ = new ParticleInterface("Orxonox/thruster1"); 185 this->tt1_->createNewEmitter(); 186 this->tt1_->getAllEmitters()->setDirection(-this->getInitialDir()); 187 this->tt1_->getEmitter(0)->setPosition(Vector3(-15, 20, -1)); 188 this->tt1_->getEmitter(1)->setPosition(Vector3(-15, -20, -1)); 189 this->tt1_->setSpeedFactor(3.0); 190 191 Ogre::SceneNode* node2a = this->getNode()->createChildSceneNode(this->getName() + "particle2a"); 192 node2a->setInheritScale(false); 193 node2a->setScale(1, 1, 1); 194 tt1_->addToSceneNode(node2a); 195 196 this->tt2_ = new ParticleInterface("Orxonox/thruster2"); 197 this->tt2_->createNewEmitter(); 198 this->tt2_->getAllEmitters()->setDirection(Vector3(-1, 0, 0)); 199 this->tt2_->getEmitter(0)->setPosition(Vector3(-30, 40, -2)); 200 this->tt2_->getEmitter(1)->setPosition(Vector3(-30, -40, -2)); 201 202 Ogre::SceneNode* node2b = this->getNode()->createChildSceneNode(this->getName() + "particle2b"); 203 node2b->setInheritScale(false); 204 node2b->setScale(0.5, 0.5, 0.5); 205 tt2_->addToSceneNode(node2b); 200 206 // END CREATING THRUSTER 201 207 … … 266 272 this->camNode_ = this->getNode()->createChildSceneNode(camName_); 267 273 COUT(4) << "position: (this)" << this->getNode()->getPosition() << std::endl; 268 this->camNode_->setPosition(Vector3(- 50,0,10));274 this->camNode_->setPosition(Vector3(-25,0,5)); 269 275 // Quaternion q1 = Quaternion(Radian(Degree(90)),Vector3(0,-1,0)); 270 276 // Quaternion q2 = Quaternion(Radian(Degree(90)),Vector3(0,0,-1)); … … 339 345 } 340 346 341 Vector3 SpaceShip::getDir() {342 return currentDir_;343 }344 345 Vector3 SpaceShip::getOrth(){346 return currentOrth_;347 }348 349 float SpaceShip::getMaxSpeed() { return maxSpeed_; }350 351 347 void SpaceShip::tick(float dt) 352 348 { … … 374 370 { 375 371 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) 372 BillboardProjectile* projectile = new ParticleProjectile(this); 373 projectile->setColour(this->getProjectileColour()); 374 projectile->create(); 375 if (projectile->classID == 0) 376 { 384 377 COUT(3) << "generated projectile with classid 0" << std::endl; // TODO: remove this output 385 386 p->setBacksync(true); 378 } 379 380 projectile->setBacksync(true); 387 381 this->timeToReload_ = this->reloadTime_; 388 382 } … … 464 458 465 459 if (this->acceleration_.x > 0) 466 this->tt_->setRate(emitterRate_); 460 { 461 this->tt1_->setEnabled(true); 462 this->tt2_->setEnabled(true); 463 } 467 464 else 468 this->tt_->setRate(0); 465 { 466 this->tt1_->setEnabled(false); 467 this->tt2_->setEnabled(false); 468 } 469 469 470 470 if( myShip_ ) -
code/trunk/src/orxonox/objects/SpaceShip.h
r1535 r1552 43 43 { 44 44 public: 45 46 47 45 static SpaceShip *getLocalShip(); 48 46 … … 66 64 void getFocus(); 67 65 66 inline float getMaxSpeed() const 67 { return this->maxSpeed_; } 68 inline float getMaxSideAndBackSpeed() const 69 { return this->maxSideAndBackSpeed_; } 70 inline float getMaxRotation() const 71 { return this->maxRotation_; } 72 inline float getTransAcc() const 73 { return this->translationAcceleration_; } 74 inline float getRotAcc() const 75 { return this->rotationAcceleration_; } 76 inline float getTransDamp() const 77 { return this->translationDamping_; } 78 inline float getRotDamp() const 79 { return this->rotationDamping_; } 80 68 81 static std::string whereAmI(); 69 82 static void setMaxSpeedTest(float value) … … 83 96 void doFire(); 84 97 85 float getMaxSpeed(); 86 Vector3 getDir(); 87 Vector3 getOrth(); 98 inline const Vector3& getDir() const 99 { return this->currentDir_; } 100 inline const Vector3& getInitialDir() const 101 { return this->initialDir_; } 102 inline const Vector3& getOrth() const 103 { return this->currentOrth_; } 104 inline const Vector3& getInitialOrth() const 105 { return this->initialOrth_; } 106 88 107 Camera* getCamera(); 89 108 90 109 int getTeamNr() const 91 110 { return this->teamNr_; } 92 int getHealth() const111 float getHealth() const 93 112 { return this->health_; } 94 113 … … 118 137 std::string camName_; 119 138 120 121 ParticleInterface* tt _;139 ParticleInterface* tt1_; 140 ParticleInterface* tt2_; 122 141 123 142 BillboardSet redBillboard_; … … 153 172 float mouseY_; 154 173 155 float emitterRate_;156 157 174 protected: 158 175 bool myShip_; 159 176 160 177 int teamNr_; 161 int health_;178 float health_; 162 179 163 180 static SpaceShip* instance_s; -
code/trunk/src/orxonox/objects/SpaceShipAI.cc
r1505 r1552 32 32 #include <OgreMath.h> 33 33 #include "Projectile.h" 34 #include "ParticleSpawner.h" 34 35 #include "core/CoreIncludes.h" 35 36 #include "core/Iterator.h" … … 37 38 #include "core/ConsoleCommand.h" 38 39 #include "core/XMLPort.h" 40 #include "particle/ParticleInterface.h" 39 41 40 42 #define ACTION_INTERVAL 1.0f … … 51 53 RegisterObject(SpaceShipAI); 52 54 53 this->alive_ = true;54 this->setPosition(Vector3(rnd(-1000, 1000), rnd(-1000, 1000), rnd(-1000, 0000)));55 55 this->target_ = 0; 56 56 this->bShooting_ = 0; … … 70 70 } 71 71 72 SpaceShipAI::~SpaceShipAI() 73 { 74 for (Iterator<SpaceShipAI> it = ObjectList<SpaceShipAI>::begin(); it; ++it) 75 it->shipDied(this); 76 } 77 72 78 void SpaceShipAI::XMLPort(Element& xmlelement, XMLPort::Mode mode) 73 79 { 74 80 SpaceShip::XMLPort(xmlelement, mode); 75 myShip_=true; 76 81 82 this->myShip_=true; 77 83 this->actionTimer_.setTimer(ACTION_INTERVAL, true, this, createExecutor(createFunctor(&SpaceShipAI::action))); 78 84 } … … 85 91 newenemy->setMesh("assff.mesh"); 86 92 // newenemy->setPosition(0, 0, 0); 93 newenemy->setPosition(Vector3(rnd(-3000, 3000), rnd(-3000, 3000), rnd(-3000, 3000))); 87 94 newenemy->setScale(10); 88 95 newenemy->setMaxSpeed(500); … … 95 102 Element xmlelement; 96 103 newenemy->XMLPort(xmlelement, XMLPort::LoadObject); 104 105 ParticleSpawner* spawneffect = new ParticleSpawner("Orxonox/fairytwirl", 2.0, 0.0, newenemy->getOrth()); 106 spawneffect->setPosition(newenemy->getPosition() - newenemy->getOrth() * 50); 107 spawneffect->create(); 97 108 } 98 109 } … … 103 114 for (Iterator<SpaceShipAI> it = ObjectList<SpaceShipAI>::begin(); it; ) 104 115 { 105 delete *(it++); 106 ++i; 116 (it++)->kill(); 107 117 if (num && i >= num) 108 118 break; … … 122 132 // search enemy 123 133 random = rnd(maxrand); 124 //std::cout << "search enemy: " << random << std::endl;125 134 if (random < 20 && (!this->target_)) 126 {127 135 this->searchNewTarget(); 128 }129 136 130 137 // forget enemy 131 138 random = rnd(maxrand); 132 //std::cout << "forget enemy: " << random << std::endl;133 139 if (random < 5 && (this->target_)) 134 {135 140 this->forgetTarget(); 136 }137 141 138 142 // next enemy 139 143 random = rnd(maxrand); 140 //std::cout << "next enemy: " << random << std::endl;141 144 if (random < 10 && (this->target_)) 142 {143 145 this->searchNewTarget(); 144 }145 146 146 147 // fly somewhere 147 148 random = rnd(maxrand); 148 //std::cout << "fly somewhere: " << random << std::endl;149 149 if (random < 40 && (!this->bHasTargetPosition_ && !this->target_)) 150 {151 150 this->searchNewTargetPosition(); 152 }153 151 154 152 // stop flying 155 153 random = rnd(maxrand); 156 //std::cout << "stop flying: " << random << std::endl;157 154 if (random < 10 && (this->bHasTargetPosition_ && !this->target_)) 158 {159 155 this->bHasTargetPosition_ = false; 160 }161 156 162 157 // fly somewhere else 163 158 random = rnd(maxrand); 164 //std::cout << "fly somewhere else: " << random << std::endl;165 159 if (random < 30 && (this->bHasTargetPosition_ && !this->target_)) 166 {167 160 this->searchNewTargetPosition(); 168 }169 161 170 162 // shoot 171 163 random = rnd(maxrand); 172 //std::cout << "shoot: " << random << std::endl;173 164 if (random < 75 && (this->target_ && !this->bShooting_)) 174 {175 165 this->bShooting_ = true; 176 }177 166 178 167 // stop shooting 179 168 random = rnd(maxrand); 180 //std::cout << "stop shooting: " << random << std::endl;181 169 if (random < 25 && (this->bShooting_)) 182 {183 170 this->bShooting_ = false; 184 } 171 } 172 173 void SpaceShipAI::damage(float damage) 174 { 175 this->health_ -= damage; 176 if (this->health_ <= 0) 177 { 178 this->kill(); 179 SpaceShipAI::createEnemy(1); 180 } 181 } 182 183 void SpaceShipAI::kill() 184 { 185 ParticleSpawner* explosion = new ParticleSpawner("Orxonox/BigExplosion1part1", 3.0); 186 explosion->setPosition(this->getPosition()); 187 explosion->getParticleInterface()->setKeepParticlesInLocalSpace(true); 188 explosion->setScale(4); 189 explosion->create(); 190 191 explosion = new ParticleSpawner("Orxonox/BigExplosion1part2", 3.0); 192 explosion->setPosition(this->getPosition()); 193 explosion->getParticleInterface()->setKeepParticlesInLocalSpace(true); 194 explosion->setScale(4); 195 explosion->create(); 196 197 Vector3 ringdirection = Vector3(rnd(), rnd(), rnd()); 198 ringdirection.normalise(); 199 explosion = new ParticleSpawner("Orxonox/BigExplosion1part3", 3.0, 0.5, ringdirection); 200 explosion->setPosition(this->getPosition()); 201 explosion->getParticleInterface()->setKeepParticlesInLocalSpace(true); 202 explosion->setScale(4); 203 explosion->create(); 204 205 delete this; 185 206 } 186 207 … … 193 214 this->moveToTargetPosition(dt); 194 215 195 if (this->bShooting_ && this->isCloseAtTarget(2 000) && this->isLookingAtTarget(Ogre::Math::PI / 10.0f))216 if (this->bShooting_ && this->isCloseAtTarget(2500) && this->isLookingAtTarget(Ogre::Math::PI / 10)) 196 217 this->doFire(); 197 218 … … 201 222 void SpaceShipAI::moveToTargetPosition(float dt) 202 223 { 203 static Radian RadianZERO(0); 204 205 // float dotprod = (this->getOrientation() * Ogre::Vector3::UNIT_X).dotProduct(this->targetPosition_ - this->getPosition()); 206 Quaternion rotation = (this->getOrientation() * Ogre::Vector3::UNIT_X).getRotationTo(this->targetPosition_ - this->getPosition()); 207 /* 208 std::cout << "scalprod: " << dotprod << std::endl; 209 std::cout << "dist: " << this->targetPosition_ - this->getPosition() << std::endl; 210 std::cout << "yaw: " << rotation.getYaw().valueRadians() << std::endl; 211 std::cout << "pitch: " << rotation.getPitch().valueRadians() << std::endl; 212 std::cout << "roll: " << rotation.getRoll().valueRadians() << std::endl; 213 */ 214 this->setMoveYaw(-rotation.getRoll().valueRadians()); 215 this->setMovePitch(rotation.getYaw().valueRadians()); 216 217 if ((this->targetPosition_ - this->getPosition()).length() > 100) 218 { 224 Vector3 proj = Ogre::Plane(this->getDir(), this->getPosition()).projectVector(this->targetPosition_ - this->getPosition()); 225 float angle = acos((this->getOrth().dotProduct(proj)) / (this->getOrth().length()*proj.length())); 226 227 if ((this->getDir().crossProduct(this->getOrth())).dotProduct(this->targetPosition_ - this->getPosition()) > 0) 228 this->setMoveYaw(sgn(sin(angle))); 229 else 230 this->setMoveYaw(-sgn(sin(angle))); 231 this->setMovePitch(sgn(cos(angle))); 232 233 if ((this->targetPosition_ - this->getPosition()).length() > 300) 219 234 this->setMoveLongitudinal(1); 220 } 221 235 236 if (this->isCloseAtTarget(300) && this->target_) 237 { 238 if (this->getVelocity().length() > this->target_->getVelocity().length()) 239 this->setMoveLongitudinal(-1); 240 } 222 241 } 223 242 … … 241 260 Vector3 distanceNew = it->getPosition() - this->getPosition(); 242 261 if (!this->target_ || it->getPosition().squaredDistance(this->getPosition()) * (1.5f + acos((this->getOrientation() * Ogre::Vector3::UNIT_X).dotProduct(distanceNew) / speed / distanceNew.length()) / (2 * Ogre::Math::PI)) 243 < this->targetPosition_.squaredDistance(this->getPosition()) * (1.5f + acos((this->getOrientation() * Ogre::Vector3::UNIT_X).dotProduct(distanceCurrent) / speed / distanceCurrent.length()) / (2 * Ogre::Math::PI)) )262 < this->targetPosition_.squaredDistance(this->getPosition()) * (1.5f + acos((this->getOrientation() * Ogre::Vector3::UNIT_X).dotProduct(distanceCurrent) / speed / distanceCurrent.length()) / (2 * Ogre::Math::PI)) + rnd(-250, 250)) 244 263 { 245 264 this->target_ = (*it); … … 248 267 } 249 268 } 250 }269 } 251 270 252 271 void SpaceShipAI::forgetTarget() … … 260 279 if (!this->target_) 261 280 return; 262 /* 281 263 282 Vector3 enemymovement = this->target_->getVelocity(); 264 283 Vector3 distance_normalised = this->target_->getPosition() - this->getPosition(); … … 267 286 float scalarprod = enemymovement.dotProduct(distance_normalised); 268 287 float aimoffset = scalarprod*scalarprod + Projectile::getSpeed() * Projectile::getSpeed() - this->target_->getVelocity().squaredLength(); 288 269 289 if (aimoffset < 0) 270 290 { … … 273 293 } 274 294 aimoffset = -scalarprod + sqrt(aimoffset); 275 this->targetPosition_ = enemymovement + distance_normalised * aimoffset;295 this->targetPosition_ = this->getPosition() + enemymovement + distance_normalised * aimoffset; 276 296 this->bHasTargetPosition_ = true; 277 278 std::cout << "targetpos: " << this->targetPosition_ << std::endl;279 */280 this->targetPosition_ = this->target_->getPosition();281 this->bHasTargetPosition_ = true;282 297 } 283 298 284 299 bool SpaceShipAI::isCloseAtTarget(float distance) 285 300 { 286 return (this->getPosition().squaredDistance(this->targetPosition_) < distance*distance); 301 if (!this->target_) 302 return (this->getPosition().squaredDistance(this->targetPosition_) < distance*distance); 303 else 304 return (this->getPosition().squaredDistance(this->target_->getPosition()) < distance*distance); 287 305 } 288 306 289 307 bool SpaceShipAI::isLookingAtTarget(float angle) 290 308 { 291 return (this->getOrientation() * Ogre::Vector3::UNIT_X).directionEquals(this->targetPosition_ - this->getPosition(), Radian(angle)); 309 Vector3 dist = this->targetPosition_ - this->getPosition(); 310 return (acos((this->getDir().dotProduct(dist)) / (dist.length() * this->getDir().length())) < angle); 311 } 312 313 void SpaceShipAI::shipDied(SpaceShipAI* ship) 314 { 315 this->forgetTarget(); 316 this->searchNewTargetPosition(); 292 317 } 293 318 } -
code/trunk/src/orxonox/objects/SpaceShipAI.h
r1505 r1552 44 44 public: 45 45 SpaceShipAI(); 46 virtual ~SpaceShipAI(); 47 46 48 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 47 49 static void createEnemy(int num); 48 50 static void killEnemies(int num); 51 void shipDied(SpaceShipAI* ship); 52 void damage(float damage); 53 void kill(); 49 54 50 55 private: … … 64 69 Timer<SpaceShipAI> actionTimer_; 65 70 66 bool alive_;67 71 bool bHasTargetPosition_; 68 72 Vector3 targetPosition_; -
code/trunk/src/orxonox/objects/WorldEntity.cc
r1505 r1552 66 66 } 67 67 } 68 68 69 69 70 70 WorldEntity::~WorldEntity() 71 71 { 72 // just to make sure we clean out all scene nodes 73 if(this->getNode()) 74 this->getNode()->removeAndDestroyAllChildren(); 72 // just to make sure we clean out all scene nodes 73 if(this->getNode()) 74 { 75 this->getNode()->removeAndDestroyAllChildren(); 76 GraphicsEngine::getSingleton().getSceneManager()->destroySceneNode(this->getName()); 77 } 75 78 } 76 79 … … 95 98 create(); 96 99 } 97 100 98 101 99 102 void WorldEntity::setYawPitchRoll(const Degree& yaw, const Degree& pitch, const Degree& roll) … … 122 125 123 126 XMLPortObject(WorldEntity, WorldEntity, "attached", attachWorldEntity, getAttachedWorldEntity, xmlelement, mode, false, true); 124 127 125 128 WorldEntity::create(); 126 129 } -
code/trunk/src/orxonox/particle/ParticleInterface.cc
r1505 r1552 34 34 #include "ParticleInterface.h" 35 35 36 // #include <OgreParticleSystem.h> 37 // #include <Ogre.h> 38 // #include <OIS/OIS.h> 39 // #include <CEGUI/CEGUI.h> 40 // #include <CEGUIRenderer.h> 36 #include <OgreParticleSystem.h> 37 #include <OgreParticleEmitter.h> 38 #include <OgreSceneManager.h> 41 39 40 #include "GraphicsEngine.h" 41 #include "util/Convert.h" 42 42 43 namespace orxonox 44 { 45 unsigned int ParticleInterface::counter_s = 0; 46 ParticleInterface* ParticleInterface::currentParticleInterface_s = 0; 43 47 44 namespace orxonox { 45 using namespace Ogre; 46 47 ParticleInterface::ParticleInterface( SceneManager *sceneManager, std::string name, std::string templateName ) 48 ParticleInterface::ParticleInterface(const std::string& templateName) 48 49 { 49 sceneManager_ = sceneManager; 50 particleSystem_ = sceneManager->createParticleSystem(name, templateName); 51 52 //Variabeln einlesen, Emitter1_ ist Referenz-Emitter 53 velocity_ = particleSystem_->getSpeedFactor(); 54 colour_ = particleSystem_->getEmitter(0)->getColour(); 55 rate_ = particleSystem_->getEmitter(0)->getEmissionRate(); 56 distance_ = particleSystem_->getEmitter(0)->getTimeToLive(); 57 58 //Anzahl der Emitter 59 numberOfEmitters_ = particleSystem_->getNumEmitters(); 60 standardizeEmitters(); 50 this->sceneNode_ = 0; 51 this->particleSystem_ = GraphicsEngine::getSingleton().getSceneManager()->createParticleSystem("particles" + getConvertedValue<unsigned int, std::string>(ParticleInterface::counter_s++), templateName); 61 52 } 62 53 63 ParticleInterface::~ParticleInterface( void)54 ParticleInterface::~ParticleInterface() 64 55 { 65 while(particleSystem_->getNumEmitters()>0) 66 particleSystem_->removeEmitter(particleSystem_->getNumEmitters()-1); 67 sceneManager_->destroyParticleSystem(particleSystem_); 56 this->particleSystem_->removeAllEmitters(); 57 GraphicsEngine::getSingleton().getSceneManager()->destroyParticleSystem(particleSystem_); 68 58 } 69 59 70 void ParticleInterface:: standardizeEmitters(void)60 void ParticleInterface::addToSceneNode(Ogre::SceneNode* sceneNode) 71 61 { 72 //Abgleichen der anderen Emitter an die Variabeln 73 for (int i=0; i < numberOfEmitters_; i++) { 74 particleSystem_->getEmitter(i)->setColour( colour_ ); 75 particleSystem_->getEmitter(i)->setTimeToLive( distance_ ); 76 particleSystem_->getEmitter(i)->setEmissionRate( rate_ ); 77 } 78 62 this->sceneNode_ = sceneNode; 63 this->sceneNode_->attachObject(this->particleSystem_); 79 64 } 80 65 81 void ParticleInterface:: setVelocity(Real v)66 void ParticleInterface::detachFromSceneNode() 82 67 { 83 velocity_ = v; 84 //partikel anpassen 85 particleSystem_->setSpeedFactor(v); 86 } 87 88 void ParticleInterface::setRate(float r) 89 { 90 rate_ = r; 91 //partikel anpassen 92 for (int i=0; i<numberOfEmitters_; i++) { 93 particleSystem_->getEmitter(i)->setEmissionRate(rate_); 68 if (this->sceneNode_) 69 { 70 this->sceneNode_->detachObject(this->particleSystem_); 71 this->sceneNode_ = 0; 94 72 } 95 73 } 96 74 97 void ParticleInterface::setDistance(Real d)75 Ogre::ParticleEmitter* ParticleInterface::createNewEmitter() 98 76 { 99 distance_ = d; 100 //partikel anpassen 101 for (int i=0; i < numberOfEmitters_; i++) { 102 particleSystem_->getEmitter(i)->setTimeToLive(distance_); 77 if (this->particleSystem_->getNumEmitters() > 0) 78 { 79 Ogre::ParticleEmitter* newemitter = this->particleSystem_->addEmitter(this->particleSystem_->getEmitter(0)->getType()); 80 this->particleSystem_->getEmitter(0)->copyParametersTo(newemitter); 81 return newemitter; 103 82 } 83 else 84 return 0; 85 } 86 Ogre::ParticleEmitter* ParticleInterface::getEmitter(unsigned int emitterNr) const 87 { 88 if (emitterNr < this->particleSystem_->getNumEmitters()) 89 return this->particleSystem_->getEmitter(emitterNr); 90 else 91 return 0; 92 } 93 void ParticleInterface::removeEmitter(unsigned int emitterNr) 94 { 95 if (emitterNr < this->particleSystem_->getNumEmitters()) 96 this->particleSystem_->removeEmitter(emitterNr); 97 } 98 void ParticleInterface::removeAllEmitters() 99 { 100 this->particleSystem_->removeAllEmitters(); 101 } 102 unsigned int ParticleInterface::getNumEmitters() const 103 { 104 return this->particleSystem_->getNumEmitters(); 104 105 } 105 106 106 void ParticleInterface::setColour(ColourValue colour)107 Ogre::ParticleAffector* ParticleInterface::addAffector(const std::string& name) 107 108 { 108 colour_ = colour; 109 //partikel anpassen 110 for (int i=0; i < numberOfEmitters_; i++) { 111 particleSystem_->getEmitter(i)->setColour(colour_); 112 } 109 return this->particleSystem_->addAffector(name); 110 } 111 Ogre::ParticleAffector* ParticleInterface::getAffector(unsigned int affectorNr) const 112 { 113 if (affectorNr < this->particleSystem_->getNumAffectors()) 114 return this->particleSystem_->getAffector(affectorNr); 115 else 116 return 0; 117 } 118 void ParticleInterface::removeAffector(unsigned int affectorNr) 119 { 120 if (affectorNr < this->particleSystem_->getNumAffectors()) 121 this->particleSystem_->removeAffector(affectorNr); 122 } 123 void ParticleInterface::removeAllAffectors() 124 { 125 this->particleSystem_->removeAllAffectors(); 126 } 127 unsigned int ParticleInterface::getNumAffectors() const 128 { 129 return this->particleSystem_->getNumAffectors(); 113 130 } 114 131 115 ParticleEmitter* ParticleInterface::getEmitter( int emitterNr)132 void ParticleInterface::setEnabled(bool enable) 116 133 { 117 if ( (emitterNr >= numberOfEmitters_) || (emitterNr < 0) ) return NULL;118 return particleSystem_->getEmitter(emitterNr);134 for (unsigned int i = 0; i < this->particleSystem_->getNumEmitters(); i++) 135 this->particleSystem_->getEmitter(i)->setEnabled(enable); 119 136 } 120 137 121 void ParticleInterface:: newEmitter ()138 void ParticleInterface::setSpeedFactor(float factor) 122 139 { 123 particleSystem_->addEmitter(particleSystem_->getEmitter(0)->getType()); 124 particleSystem_->getEmitter(0)->copyParametersTo( particleSystem_->getEmitter(numberOfEmitters_) ); 125 numberOfEmitters_++; 140 this->particleSystem_->setSpeedFactor(factor); 141 } 142 float ParticleInterface::getSpeedFactor() const 143 { 144 return this->particleSystem_->getSpeedFactor(); 126 145 } 127 146 128 // TODO check if this really works 129 Vector3 ParticleInterface::getPositionOfEmitter ( int emitterNr ) 147 bool ParticleInterface::getKeepParticlesInLocalSpace() const 130 148 { 131 return particleSystem_->getEmitter(emitterNr)->getPosition();149 return this->particleSystem_->getKeepParticlesInLocalSpace(); 132 150 } 133 134 void ParticleInterface::setDirection ( Vector3 direction ) 151 void ParticleInterface::setKeepParticlesInLocalSpace(bool keep) 135 152 { 136 for(int i=0; i < numberOfEmitters_; i++) { 137 particleSystem_->getEmitter(i)->setDirection(direction); 138 } 153 this->particleSystem_->setKeepParticlesInLocalSpace(keep); 139 154 } 140 141 void ParticleInterface::switchEnable(){142 bool enable=(!(particleSystem_->getEmitter(0)->getEnabled()));143 for(int i=0; i < numberOfEmitters_; i++) {144 particleSystem_->getEmitter(i)->setEnabled(enable);145 }146 }147 148 155 } -
code/trunk/src/orxonox/particle/ParticleInterface.h
r1505 r1552 21 21 * 22 22 * Author: 23 * Fabian 'x3n' Landau23 * ... 24 24 * Co-authors: 25 25 * ... … … 33 33 34 34 #include <string> 35 36 // #include "ParticleInterface.h"37 // #include <Ogre.h>38 // #include <OIS/OIS.h>39 // #include <CEGUI/CEGUI.h>40 // #include <CEGUIRenderer.h>41 #include <OgreParticleSystem.h>42 35 #include <OgreParticleEmitter.h> 43 #include <OgreSceneManager.h>44 36 45 37 #include "util/Math.h" 46 38 39 #define getAllEmitters() \ 40 storeThisAsCurrentParticleInterface(); \ 41 for (unsigned int i = 0; i < ParticleInterface::getCurrentParticleInterface()->getNumEmitters(); ++i) \ 42 ParticleInterface::getCurrentParticleInterface()->getEmitter(i) 47 43 48 44 namespace orxonox 49 45 { 50 51 46 class _OrxonoxExport ParticleInterface 52 47 { 53 public: 48 public: 49 ParticleInterface(const std::string& templateName); 50 ~ParticleInterface(); 54 51 55 ParticleInterface( Ogre::SceneManager *sceneManager, std::string name, std::string templateName );56 ~ParticleInterface( void );52 inline Ogre::ParticleSystem* getParticleSystem() const 53 { return this->particleSystem_; } 57 54 58 inline void addToSceneNode( Ogre::SceneNode* sceneNode ) 59 { sceneNode_ = sceneNode; sceneNode_->attachObject(particleSystem_);}; 60 inline void detachFromSceneNode( void ) 61 { sceneNode_->detachObject(particleSystem_); sceneNode_ = NULL;}; 55 void addToSceneNode(Ogre::SceneNode* sceneNode); 56 void detachFromSceneNode(); 62 57 63 Ogre::ParticleEmitter* getEmitter ( int emitterNr ); 64 void newEmitter ( void ); 58 Ogre::ParticleEmitter* createNewEmitter(); 59 Ogre::ParticleEmitter* getEmitter(unsigned int emitterNr) const; 60 void removeEmitter(unsigned int emitterNr); 61 void removeAllEmitters(); 62 unsigned int getNumEmitters() const; 65 63 66 Vector3 getPositionOfEmitter ( int emitterNr ); 67 inline void setPositionOfEmitter ( int emitterNr, Vector3 position ) 68 { particleSystem_->getEmitter(emitterNr)->setPosition(position); }; 64 Ogre::ParticleAffector* addAffector(const std::string& name); 65 Ogre::ParticleAffector* getAffector(unsigned int affectorNr) const; 66 void removeAffector(unsigned int affectorNr); 67 void removeAllAffectors(); 68 unsigned int getNumAffectors() const; 69 69 70 inline Vector3 getDirection ( void ) 71 { return particleSystem_->getEmitter(0)->getDirection(); }; 72 void setDirection ( Vector3 direction ); 70 float getSpeedFactor() const; 71 void setSpeedFactor(float factor); 72 bool getKeepParticlesInLocalSpace() const; 73 void setKeepParticlesInLocalSpace(bool keep); 73 74 74 inline Real getVelocity() 75 {return velocity_; }; 76 void setVelocity( Real v ); 75 void setEnabled(bool enable); 77 76 78 inline float getRate() 79 { return rate_; }; 80 void setRate( float r ); 77 inline void storeThisAsCurrentParticleInterface() 78 { ParticleInterface::currentParticleInterface_s = this; } 79 inline static ParticleInterface* getCurrentParticleInterface() 80 { return ParticleInterface::currentParticleInterface_s; } 81 81 82 inline Real getDistance() 83 { return distance_; }; 84 void setDistance( Real d ); 85 86 inline ColourValue getColour( void ) 87 {return colour_;}; 88 void setColour( ColourValue colour ); 89 90 void switchEnable(); 91 92 inline Ogre::ParticleSystem* getParticleSystem() 93 { return this->particleSystem_; }; 94 95 private: 96 Ogre::SceneNode *sceneNode_; 97 Ogre::SceneManager *sceneManager_; 98 Ogre::ParticleSystem *particleSystem_; 99 Real distance_; 100 Real velocity_; 101 float rate_; 102 ColourValue colour_; 103 int numberOfEmitters_; 104 105 void standardizeEmitters(); 82 private: 83 static ParticleInterface* currentParticleInterface_s; 84 static unsigned int counter_s; 85 Ogre::SceneNode* sceneNode_; 86 Ogre::ParticleSystem* particleSystem_; 106 87 }; 107 108 88 } 109 89 -
code/trunk/src/orxonox/tools/Timer.cc
r1505 r1552 102 102 TimerBase::~TimerBase() 103 103 { 104 if (this->executor_) 105 delete this->executor_; 104 this->deleteExecutor(); 106 105 } 107 106 … … 112 111 { 113 112 (*this->executor_)(); 113 } 114 115 /** 116 @brief Deletes the executor. 117 */ 118 void TimerBase::deleteExecutor() 119 { 120 if (this->executor_) 121 delete this->executor_; 114 122 } 115 123 -
code/trunk/src/orxonox/tools/Timer.h
r1535 r1552 78 78 79 79 void run() const; 80 void deleteExecutor(); 80 81 81 82 /** @brief Starts the Timer: Function-call after 'interval' seconds. */ … … 149 150 void setTimer(float interval, bool bLoop, T* object, ExecutorMember<T>* executor) 150 151 { 152 this->deleteExecutor(); 153 151 154 this->interval_ = interval; 152 155 this->bLoop_ = bLoop; … … 185 188 void setTimer(float interval, bool bLoop, ExecutorStatic* executor) 186 189 { 190 this->deleteExecutor(); 191 187 192 this->interval_ = interval; 188 193 this->bLoop_ = bLoop;
Note: See TracChangeset
for help on using the changeset viewer.