Changeset 10060 for code/branches/turretFS14/src/modules/objects/Turret.cc
- Timestamp:
- May 15, 2014, 5:10:55 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/turretFS14/src/modules/objects/Turret.cc
r10049 r10060 30 30 #include "core/CoreIncludes.h" 31 31 #include "core/XMLPort.h" 32 #include "Scene.h" 33 #include <OgreSceneQuery.h> 34 32 35 33 36 namespace orxonox … … 73 76 /** 74 77 @brief 75 Checks, if a (world)positionis inside the turret's range.78 Checks, if a WorldEntity is inside the turret's range. 76 79 77 80 This function is safe to use on turrets that are attached, rotated, etc. 78 The turret's range is determined with the maxPitch, maxYaw, and the two attackRadius'. 79 80 @param position 81 The position to check 82 */ 83 bool Turret::isInRange(const Vector3 &position) 81 The turret's range is determined with the maxPitch, maxYaw, and the two attackRadius. 82 83 @param target 84 The WorldEntity to check 85 86 @return 87 The squared distance to the position. -1, if it's ouside of range 88 */ 89 float Turret::isInRange(const WorldEntity* target ) const 84 90 { 85 91 //Check distance 86 Vector3 distance = position- this->getWorldPosition();92 Vector3 distance = target->getWorldPosition() - this->getWorldPosition(); 87 93 float distanceVal = distance.squaredLength(); 88 94 if(distanceVal > (this->maxAttackRadius_ * this->maxAttackRadius_) || distanceVal < (this->minAttackRadius_ * this->minAttackRadius_)) 89 95 { 90 return false;96 return -1.f; 91 97 } 92 98 … … 100 106 if(angle > this->maxPitch_) 101 107 { 102 return false;108 return -1.f; 103 109 } 104 110 … … 111 117 if(angle > this->maxYaw_) 112 118 { 113 return false; 114 } 115 return true; 119 return -1.f; 120 } 121 122 Ogre::SceneManager* scenemanager = this->getScene()->getSceneManager(); 123 Ogre::Ray ray = Ogre::Ray(this->getWorldPosition(), distance); 124 Ogre::DefaultRaySceneQuery rayscenequery = Ogre::DefaultRaySceneQuery(scenemanager); 125 rayscenequery.setRay(ray); 126 127 return distanceVal; 116 128 } 117 129 … … 215 227 216 228 Every tick, the turret gets rotated if it should, and the local axes get updated with the parent's rotation. 229 230 @param dt 231 Duration of the tick 217 232 */ 218 233 void Turret::tick(float dt) … … 220 235 SUPER(Turret, tick, dt); 221 236 222 237 //Stuff isn't properly initialized in the c'tor, so we have to do it like this 223 238 if(!this->once_) 224 239 { … … 256 271 { 257 272 //Don't make the rotation instantaneous. Use an arbitrary interpolation, not that great... 273 //TODO: make the rotation better (constant velocity etc.). At the moment, the turret rotates 274 // slower the closer it is to the destination 258 275 Quaternion drot = Quaternion::nlerp(dt*this->rotationThrust_/20.f, Quaternion::IDENTITY, this->rotation_); 259 276 this->rotate(drot, WorldEntity::World);
Note: See TracChangeset
for help on using the changeset viewer.