- Timestamp:
- Oct 31, 2015, 4:07:29 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/AI_HS15/src/orxonox/controllers/CommonController.cc
r10729 r10731 35 35 static const float ROTATEFACTOR = 0.2f; 36 36 37 /*static const float SPEED_FREE = 0.8f; 38 static const float ROTATEFACTOR_FREE = 0.8f;*/ 39 37 CommonController::CommonController(Context* context) : Controller(context) 38 { 39 40 RegisterObject(CommonController); 41 } 42 43 44 CommonController::~CommonController() 45 { 46 } 47 48 49 50 40 51 bool CommonController::setWingman (CommonController* wingman) 41 52 { 42 53 return false; 43 54 } 44 bool CommonController::isLeader () 45 { 46 return false; 47 } 55 48 56 bool CommonController::hasWingman() 49 57 { … … 51 59 } 52 60 53 CommonController::CommonController(Context* context) : Controller(context) 54 { 55 56 RegisterObject(CommonController); 57 } 58 59 60 CommonController::~CommonController() 61 { 62 } 61 62 63 64 void CommonController::setTargetPosition(const Vector3& target) 65 { 66 this->targetPosition_ = target; 67 this->bHasTargetPosition_ = true; 68 } 69 70 void CommonController::setTargetOrientation(const Quaternion& orient) 71 { 72 this->targetOrientation_=orient; 73 this->bHasTargetOrientation_=true; 74 } 75 76 void CommonController::setTargetOrientation(ControllableEntity* target) 77 { 78 if (target) 79 setTargetOrientation(target->getOrientation()); 80 } 81 82 /*void CommonController::spin() 83 { 84 this->moveToTargetPosition(); 85 this->getControllableEntity()->rotateRoll(8.0f); 86 } 87 void CommonController::turn180() 88 { 89 Vector2 coord = get2DViewdirection(this->getControllableEntity()->getPosition(), this->getControllableEntity()->getOrientation() * WorldEntity::FRONT, this->getControllableEntity()->getOrientation() * WorldEntity::UP, this->targetPosition_); 90 91 this->getControllableEntity()->rotateYaw(-2.0f * sgn(coord.x) * coord.x*coord.x); 92 this->getControllableEntity()->rotatePitch(2.0f * sgn(coord.y) * coord.y*coord.y); 93 94 this->getControllableEntity()->moveFrontBack(SPEED); 95 }*/ 96 97 98 63 99 //copy the Roll orientation of given Quaternion. 64 100 void CommonController::copyOrientation(const Quaternion& orient) … … 69 105 while(diff<-math::twoPi) diff+=math::twoPi; 70 106 this->getControllableEntity()->rotateRoll(-diff); 71 72 73 74 } 75 void CommonController::setTargetPosition(const Vector3& target) 76 { 77 this->targetPosition_ = target; 78 this->bHasTargetPosition_ = true; 79 } 80 107 } 81 108 void CommonController::copyTargetOrientation() 82 109 { … … 86 113 } 87 114 } 88 void CommonController::setTargetOrientation(const Quaternion& orient) 89 { 90 this->targetOrientation_=orient; 91 this->bHasTargetOrientation_=true; 92 } 93 void CommonController::setTargetOrientation(ControllableEntity* target) 94 { 95 if (target) 96 setTargetOrientation(target->getOrientation()); 97 } 98 99 115 116 117 118 119 void CommonController::moveToTargetPosition() 120 { 121 this->moveToPosition(this->targetPosition_); 122 } 100 123 void CommonController::moveToPosition(const Vector3& target) 101 124 { … … 146 169 bHasTargetOrientation_ = false; 147 170 } 148 149 150 } 151 void CommonController::moveToTargetPosition() 152 { 153 this->moveToPosition(this->targetPosition_); 154 } 171 } 172 void CommonController::doFire() 173 { 174 if (this->isLookingAtTarget(math::pi / 20.0f)) 175 this->getControllableEntity()->fire(0); //ai uses lens flare if they're close enough to the target 176 } 177 bool CommonController::isLookingAtTarget(float angle) const 178 { 179 if (!this->getControllableEntity()) 180 return false; 181 182 return (getAngle(this->getControllableEntity()->getPosition(), this->getControllableEntity()->getOrientation() * WorldEntity::FRONT, this->targetPosition_) < angle); 183 } 184 185 void CommonController::aimAtTarget() 186 { 187 if (!this->target_ || !this->getControllableEntity()) 188 return; 189 190 static const float hardcoded_projectile_speed = 750; 191 192 Vector3 aimPosition = getPredictedPosition(this->getControllableEntity()->getWorldPosition(), 193 hardcoded_projectile_speed, this->target_->getWorldPosition(), this->target_->getVelocity()); 194 195 Pawn* pawn = orxonox_cast<Pawn*>(this->getControllableEntity()); 196 if (pawn) 197 pawn->setAimPosition(aimPosition); 198 } 199 155 200 156 201
Note: See TracChangeset
for help on using the changeset viewer.