本文整理汇总了C++中Coordinates::distance方法的典型用法代码示例。如果您正苦于以下问题:C++ Coordinates::distance方法的具体用法?C++ Coordinates::distance怎么用?C++ Coordinates::distance使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Coordinates
的用法示例。
在下文中一共展示了Coordinates::distance方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Coordinates
Rectangle::Rectangle(Coordinates v1, Coordinates v2) {
my_vertex[0] = v1;
my_vertex[1] = Coordinates(v1.getAbs() , v2.getOrd());
my_vertex[2] = Coordinates(v2.getAbs() , v1.getOrd());
my_vertex[3] = v2;
my_length = v1.distance(my_vertex[1]); //determining edge length
my_width = v2.distance(my_vertex[2]); //determining edge length
if(my_length<my_width ){
float temp;
temp=my_length;
my_length= my_width;
my_width = temp;
}
pos = (v2+v1)/2;
}
示例2: validateTactic
int AttackNearestEnemy::validateTactic(list<Action*> &newActions, Unit* squad, const vector<Unit*>& enemyUnits,
const vector<Unit*>& alliedUnits)
{
if (enemyUnits.size() == 0 || squad->getNShipsAlive() == 0)
return 0;
squad->setTarget(-1);
int Ret = 0;
Coordinates myPos = squad->getAveragePos();
float minDist = 99999;
Unit *nearestUnit = NULL;
for (unsigned int i = 0; i < enemyUnits.size(); ++i)
{
Coordinates enemyAvrg = enemyUnits[i]->getAveragePos();
if (enemyUnits[i]->getNShipsAlive() > 0)
{
float dist = myPos.distance(enemyAvrg);
if (dist < minDist)
{
minDist = dist;
nearestUnit = enemyUnits[i];
squad->setTarget(i);
}
}
}
if (nearestUnit && minDist < squad->getSquadBaseStats().range)
{
for (unsigned int i = 0; i < squad->nShips(); ++i)
{
Ship *iShip = squad->getShip(i);
if (iShip->isAlive() && iShip->getStats().currentAtkCD == 0)
{
while (1)
{
int s = rand() % nearestUnit->nShips();
if (nearestUnit->getShip(s)->isAlive())
{
iShip->getStats().currentAtkCD = iShip->getBaseStats().maxAtkCD;
newActions.push_back(new AttackAction(iShip, nearestUnit->getShip(s), squad->getUnitInfo(), nearestUnit->getUnitInfo()));
++Ret;
break;
}
}
}
}
}
// TODO: Se eu nao conseguir atacar, devo desconsiderar o target?
// if (Ret == 0)
// squad->setTarget(-1);
return Ret;
}
示例3: source
MoveAction::MoveAction(Ship *Source, Ship* Target)
: source(Source), target(Target)
{
Coordinates tc = target->getPosition();
float dist = tc.distance(source->getPosition());
if (dist > source->getBaseStats().range)
{
float direction = atan2(source->getY() - target->getY(), source->getX() - target->getX());
dist -= (source->getBaseStats().range-30);
coord.x = source->getX() - dist * cos(direction);
coord.y = source->getY() - dist * sin(direction);
}
else
{
coord = source->getPosition();
}
// printf("Move To: %lf, %lf\n", coord.x, coord.y);
}