- Timestamp:
- Apr 17, 2014, 4:05:06 PM (11 years ago)
- Location:
- code/branches/turretFS14/src/modules/objects/controllers
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/turretFS14/src/modules/objects/controllers/TurretController.cc
r10031 r10039 38 38 { 39 39 RegisterObject(TurretController); 40 this->startOrient_ = Quaternion::IDENTITY; 41 this->startDir_ = Vector3::ZERO; 42 this->localZ_ = Vector3::UNIT_Z; 43 this->localY_ = Vector3::UNIT_Y; 44 this->localX_ = Vector3::UNIT_X; 45 this->attackRadius_ = 200; 46 this->maxPitch_ = 90; 47 this->maxYaw_ = 90; 48 this->gotOrient_ = false; 49 orxout() << "Constructor " << this << endl; 40 50 } 41 51 … … 48 58 { 49 59 Turret* turret = orxonox_cast<Turret*>(this->getControllableEntity()); 50 if(target_ && t urret->isInRange(target_->getPosition()))60 if(target_ && this->isInRange(target_->getWorldPosition())) 51 61 { 52 62 return; … … 62 72 { 63 73 Pawn* parenttarget = orxonox_cast<Pawn*>(parent->getTarget()); 64 if(parenttarget && t urret->isInRange(parenttarget->getPosition()))74 if(parenttarget && this->isInRange(parenttarget->getWorldPosition())) 65 75 { 66 76 this->setTarget(parenttarget); … … 76 86 continue; 77 87 78 if(t urret->isInRange(entity->getPosition()))88 if(this->isInRange(entity->getWorldPosition())) 79 89 { 80 90 this->setTarget(entity); … … 85 95 } 86 96 97 bool TurretController::isInRange(Vector3 position) 98 { 99 Vector3 distance = position - this->getControllableEntity()->getWorldPosition(); 100 if(distance.squaredLength() > (this->attackRadius_ * this->attackRadius_)) 101 { 102 return false; 103 } 104 105 Vector3 dir = getTransformedVector(distance, this->localX_, this->localY_, this->localZ_); 106 Vector3 dirProjected = dir; 107 dirProjected.x = 0; 108 Vector3 startDirProjected = this->startDir_; 109 startDirProjected.x = 0; 110 Ogre::Real angle = startDirProjected.angleBetween(dirProjected).valueDegrees(); 111 if(angle > this->maxPitch_) 112 { 113 return false; 114 } 115 116 dirProjected = dir; 117 dirProjected.y = 0; 118 startDirProjected = this->startDir_; 119 startDirProjected.y = 0; 120 angle = startDirProjected.angleBetween(dirProjected).valueDegrees(); 121 if(angle > this->maxYaw_) 122 { 123 return false; 124 } 125 return true; 126 } 127 87 128 void TurretController::tick(float dt) 88 129 { 130 131 132 if(!gotOrient_) 133 { 134 this->startOrient_ = this->getControllableEntity()->getOrientation(); 135 this->localXStart_ = this->startOrient_ * this->localX_; 136 this->localXStart_.normalise(); 137 this->localX_ = this->localXStart_; 138 this->localYStart_ = this->startOrient_ * this->localY_; 139 this->localYStart_.normalise(); 140 this->localY_ = this->localYStart_; 141 this->localZStart_ = this->startOrient_ * this->localZ_; 142 this->localZStart_.normalise(); 143 this->localZ_ = this->localZStart_; 144 145 //startDir should always be (0,0,-1) 146 this->startDir_ = getTransformedVector(this->startOrient_ * WorldEntity::FRONT, this->localX_, this->localY_, this->localZ_); 147 148 this->gotOrient_ = true; 149 } 150 151 //orxout() << "Controller " << this; 152 //orxout() << "\tControllable Entity " << this->getControllableEntity() << endl; 153 WorldEntity* parent = this->getControllableEntity()->getParent(); 154 if(parent) 155 { 156 Quaternion parentrot = parent->getOrientation(); 157 this->localX_ = parentrot * this->localXStart_; 158 this->localY_ = parentrot * this->localYStart_; 159 this->localZ_ = parentrot * this->localZStart_; 160 } 161 162 orxout() << this->getControllableEntity()->getWorldPosition() << endl; 163 164 89 165 if (!this->isActive() || !this->getControllableEntity()) 90 166 return; 91 167 this->searchTarget(); 92 this->getControllableEntity()->rotatePitch(0.2); 93 /*if(target_) 168 if(target_) 94 169 { 95 170 this->aimAtTarget(); 171 //this->getControllableEntity()->lookAt(this->targetPosition_); 96 172 //It says move, but really it only turns 97 173 this->moveToTargetPosition(); … … 100 176 orxout() << 42 << endl; 101 177 } 102 } */178 } 103 179 } 104 180 } -
code/branches/turretFS14/src/modules/objects/controllers/TurretController.h
r10031 r10039 44 44 45 45 private: 46 bool gotOrient_; 47 float attackRadius_; 48 Ogre::Real maxPitch_; 49 Ogre::Real maxYaw_; 50 Quaternion startOrient_; 51 Vector3 startDir_; 52 Vector3 localZ_; 53 Vector3 localZStart_; 54 Vector3 localY_; 55 Vector3 localYStart_; 56 Vector3 localX_; 57 Vector3 localXStart_; 46 58 void searchTarget(); 59 bool isInRange(Vector3 position); 47 60 }; 48 61 }
Note: See TracChangeset
for help on using the changeset viewer.