Changeset 1552 for code/trunk/src/orxonox/objects
- Timestamp:
- Jun 6, 2008, 5:31:58 PM (17 years ago)
- Location:
- code/trunk/src/orxonox/objects
- Files:
-
- 6 added
- 2 deleted
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
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 }
Note: See TracChangeset
for help on using the changeset viewer.