bool EnemyController::withinReach(void) { EnemyPlane* enemy = static_cast<EnemyPlane*>(IDManager::getPointer(_enemyName, ACTOR)); double distance = enemy->getPosition().distance(FCKnowledge::getSingleton().getPlayerPosition()); return distance < 100.0; }
void EnemyController::approach(void) { EnemyPlane* enemy = static_cast<EnemyPlane*>(IDManager::getPointer(_enemyName, ACTOR)); Ogre::Vector3 temp = FCKnowledge::getSingleton().getPlayerPosition() - enemy->getPosition(); Ogre::Vector3 direction = temp * enemy->getAxis(); //std::cout<<direction.x<<" "<<direction.y<<" "<<direction.z<<std::endl; if(direction.angleBetween(Ogre::Vector3::NEGATIVE_UNIT_Z) >= Ogre::Radian(Ogre::Degree(1))) { Ogre::Quaternion test = direction.getRotationTo(Ogre::Vector3::NEGATIVE_UNIT_Z); Ogre::Degree angle = enemy->getRotateLimit(); double yawNum = test.getYaw().valueDegrees()/(angle*WORLD_UPDATE_INTERVAL).valueDegrees(); yawNum = Ogre::Math::Clamp(yawNum, -1.0, 1.0); enemy->yaw(yawNum); double pitchNum = test.getPitch().valueDegrees()/(angle*WORLD_UPDATE_INTERVAL).valueDegrees(); pitchNum = Ogre::Math::Clamp(pitchNum, -1.0, 1.0); enemy->pitch(pitchNum); double rollNum = test.getRoll().valueDegrees()/(angle*WORLD_UPDATE_INTERVAL).valueDegrees(); rollNum = Ogre::Math::Clamp(rollNum, -1.0, 1.0); enemy->roll(rollNum); } else { enemy->yaw(0); enemy->pitch(0); enemy->roll(0); } }