Entities/Object: Add some Position const& overloads to distance/angle methods for usability.

This commit is contained in:
treeston authored and Aokromes committed 2016-09-10 14:27:00 +02:00
1 parent 9b89458cc8
commit 74c4c208c9
4 files changed
+35 -13

No files matched your search

+5 -8
View File
@@ -1559,24 +1559,21 @@ bool WorldObject::IsInRange3d(float x, float y, float z, float minRange, float m
return distsq < maxdist * maxdist;
}
bool WorldObject::IsInBetween(const WorldObject* obj1, const WorldObject* obj2, float size) const
bool WorldObject::IsInBetween(Position const& pos1, Position const& pos2, float size) const
{
if (!obj1 || !obj2)
return false;
float dist = GetExactDist2d(obj1->GetPositionX(), obj1->GetPositionY());
float dist = GetExactDist2d(pos1);
// not using sqrt() for performance
if ((dist * dist) >= obj1->GetExactDist2dSq(obj2->GetPositionX(), obj2->GetPositionY()))
if ((dist * dist) >= pos1.GetExactDist2dSq(pos2))
return false;
if (!size)
size = GetObjectSize() / 2;
float angle = obj1->GetAngle(obj2);
float angle = pos1.GetAngle(pos2);
// not using sqrt() for performance
return (size * size) >= GetExactDist2dSq(obj1->GetPositionX() + std::cos(angle) * dist, obj1->GetPositionY() + std::sin(angle) * dist);
return (size * size) >= GetExactDist2dSq(pos1.GetPositionX() + std::cos(angle) * dist, pos1.GetPositionY() + std::sin(angle) * dist);
}
bool WorldObject::isInFront(WorldObject const* target, float arc) const