本文整理汇总了C++中Point2d::SquareDistance方法的典型用法代码示例。如果您正苦于以下问题:C++ Point2d::SquareDistance方法的具体用法?C++ Point2d::SquareDistance怎么用?C++ Point2d::SquareDistance使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Point2d
的用法示例。
在下文中一共展示了Point2d::SquareDistance方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: NotifyMove
// Move to a point with collision test
collision_t PhysicalObj::NotifyMove(Point2d oldPos, Point2d newPos)
{
if (IsGhost())
return NO_COLLISION;
Point2d contactPos;
Double contactAngle;
Point2d pos, offset;
PhysicalObj* collided_obj = NULL;
collision_t collision = NO_COLLISION;
// Convert meters to pixels.
oldPos *= PIXEL_PER_METER;
newPos *= PIXEL_PER_METER;
// Compute distance between old and new position.
Double lg = oldPos.SquareDistance(newPos);
MSG_DEBUG("physic.move", "%s moves (%s, %s) -> (%s, %s), square distance: %s",
GetName().c_str(),
Double2str(oldPos.x).c_str(), Double2str(oldPos.y).c_str(),
Double2str(newPos.x).c_str(), Double2str(newPos.y).c_str(),
Double2str(lg).c_str());
if (!lg.IsNotZero())
return NO_COLLISION;
// Compute increments to move the object step by step from the old
// to the new position.
lg = sqrt(lg);
offset = (newPos - oldPos) / lg;
// First iteration position.
pos = oldPos + offset;
if (!m_collides_with_ground || IsInWater()) {
MSG_DEBUG("physic.move", "%s moves (%s, %s) -> (%s, %s), collides ground:%d, water:%d",
GetName().c_str(),
Double2str(oldPos.x).c_str(), Double2str(oldPos.y).c_str(),
Double2str(newPos.x).c_str(), Double2str(newPos.y).c_str(),
m_collides_with_ground, IsInWater());
SetXY(newPos);
return NO_COLLISION;
}
do {
Point2i tmpPos(uround(pos.x), uround(pos.y));
// Check if we exit the GetWorld(). If so, we stop moving and return.
if (IsOutsideWorldXY(tmpPos)) {
if (!GetWorld().IsOpen()) {
tmpPos.x = InRange_Long(tmpPos.x, 0, GetWorld().GetWidth() - GetWidth() - 1);
tmpPos.y = InRange_Long(tmpPos.y, 0, GetWorld().GetHeight() - GetHeight() - 1);
MSG_DEBUG("physic.state", "%s - DeplaceTestCollision touche un bord : %d, %d",
GetName().c_str(), tmpPos.x, tmpPos.y);
collision = COLLISION_ON_GROUND;
break;
}
SetXY(pos);
MSG_DEBUG("physic.move", "%s moves (%f, %f) -> (%f, %f) : OUTSIDE WORLD",
GetName().c_str(), oldPos.x.tofloat(), oldPos.y.tofloat(),
newPos.x.tofloat(), newPos.y.tofloat());
return NO_COLLISION;
}
// Test if we collide...
collided_obj = CollidedObjectXY(tmpPos);
if (collided_obj) {
if (!m_go_through_objects || m_last_collided_object != collided_obj) {
MSG_DEBUG("physic.state", "%s collide on %s", GetName().c_str(), collided_obj->GetName().c_str());
if (m_go_through_objects) {
SignalObjectCollision(GetSpeed(), collided_obj, collided_obj->GetSpeed());
collision = NO_COLLISION;
} else {
collision = COLLISION_ON_OBJECT;
}
m_last_collided_object = collided_obj;
} else {
collided_obj = NULL;
collision = NO_COLLISION;
}
} else if (!IsInVacuumXY(tmpPos, false)) {
collision = COLLISION_ON_GROUND;
m_last_collided_object = NULL;
}
if (collision != NO_COLLISION) {
// Nothing more to do!
MSG_DEBUG("physic.state", "%s - Collision at %d,%d : on %s",
GetName().c_str(), tmpPos.x, tmpPos.y,
collision == COLLISION_ON_GROUND ? "ground" : "an object");
// Set the object position to the current position.
//.........这里部分代码省略.........