本文整理汇总了C++中Vector2::LengthSqr方法的典型用法代码示例。如果您正苦于以下问题:C++ Vector2::LengthSqr方法的具体用法?C++ Vector2::LengthSqr怎么用?C++ Vector2::LengthSqr使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Vector2
的用法示例。
在下文中一共展示了Vector2::LengthSqr方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: GetDistanceSqr
float AIController::GetDistanceSqr(const Vector3 &pos1,const Vector3 &pos2)const
{
Vector2 distance ;//since the board gemeotry is mostly flat,we can use 2D vector
distance.x = pos1.x - pos2.x;
distance.y = pos1.z - pos2.z;
return distance.LengthSqr();
}
示例2: Control
void AIController::Control(const Board *board,const MovableObject *player,bool playerInv)
{
const Vector3 & pos1 = object->GetPosition();//ghost position in world space
float velocity = object->GetVelocity();
//get ghost location in board
board->GetTileInfo(pos1,currentTile.row,currentTile.col);
float diff;
switch (object->GetDirection())
{
case LEFT:
diff = pos1.x - destination.x;
if(diff <= FLOAT_DELTA && diff >=- FLOAT_DELTA)
break;
if (diff > velocity + FLOAT_DELTA)
{
this->object->Update();
return;
}
else
{
posOffset = velocity - diff;
this->object->SetPosition(destination);
return;
}
break;
case RIGHT:
diff = destination.x - pos1.x;
if(diff <= FLOAT_DELTA && diff >=- FLOAT_DELTA)
break;
if (diff > velocity + FLOAT_DELTA)
{
this->object->Update();
return;
}
else
{
posOffset = velocity - diff;
this->object->SetPosition(destination);
return;
}
break;
case UP:
diff = pos1.z - destination.y;
if(diff <= FLOAT_DELTA && diff >=- FLOAT_DELTA)
break;
if (diff > velocity + FLOAT_DELTA)
{
this->object->Update();
return;
}
else
{
posOffset = velocity - diff;
this->object->SetPosition(destination);
return;
}
break;
case DOWN:
diff = destination.y - pos1.z;
if(diff <= FLOAT_DELTA && diff >=- FLOAT_DELTA)
break;
if (diff > velocity + FLOAT_DELTA)
{
this->object->Update();
return;
}
else
{
posOffset = velocity - diff;
this->object->SetPosition(destination);
return;
}
break;
}
if(playerInv)//player is invisible
{
Wandering(board);
return;
}
Vector2 distance ;//since the board gemeotry is mostly flat,we can use 2D vector
float distSqr;
const Vector3 & pos2 = player->GetPosition();
distance.x = pos1.x - pos2.x;
distance.y = pos1.z - pos2.z;
distSqr = distance.LengthSqr();
if (distSqr <= rosSqr)//player is in ghost's range of sight
Chasing(board,player);
else
{
Wandering(board);
}
}