[7828] Add 2d/3d versions for WorldObject::IsInRange(x,y,... and WorldObject::IsWithinDist(x,y,...

This commit is contained in:
VladimirMangos 2009-05-14 20:37:02 +04:00
parent 592db69c0c
commit 42d74d811f
3 changed files with 44 additions and 12 deletions

View file

@ -1114,16 +1114,25 @@ float WorldObject::GetDistanceZ(const WorldObject* obj) const
return ( dist > 0 ? dist : 0);
}
bool WorldObject::IsWithinDist(float x, float y, float z, float dist2compare, bool is3D) const
bool WorldObject::IsWithinDist(float x, float y, float z, float dist2compare) const
{
float dx = GetPositionX() - x;
float dy = GetPositionY() - y;
float dz = GetPositionZ() - z;
float distsq = dx*dx + dy*dy + dz*dz;
float sizefactor = GetObjectSize();
float maxdist = dist2compare + sizefactor;
return distsq < maxdist * maxdist;
}
bool WorldObject::IsWithinDist2d(float x, float y, float dist2compare) const
{
float dx = GetPositionX() - x;
float dy = GetPositionY() - y;
float distsq = dx*dx + dy*dy;
if(is3D)
{
float dz = GetPositionZ() - z;
distsq += dz*dz;
}
float sizefactor = GetObjectSize();
float maxdist = dist2compare + sizefactor;
@ -1185,12 +1194,16 @@ bool WorldObject::GetDistanceOrder(WorldObject const* obj1, WorldObject const* o
return distsq1 < distsq2;
}
bool WorldObject::IsInRange(WorldObject const* obj, float minRange, float maxRange) const
bool WorldObject::IsInRange(WorldObject const* obj, float minRange, float maxRange, bool is3D /* = true */) const
{
float dx = GetPositionX() - obj->GetPositionX();
float dy = GetPositionY() - obj->GetPositionY();
float dz = GetPositionZ() - obj->GetPositionZ();
float distsq = dx*dx + dy*dy + dz*dz;
float distsq = dx*dx + dy*dy;
if(is3D)
{
float dz = GetPositionZ() - obj->GetPositionZ();
distsq += dz*dz;
}
float sizefactor = GetObjectSize() + obj->GetObjectSize();
@ -1218,6 +1231,23 @@ bool WorldObject::IsInRange2d(float x, float y, float minRange, float maxRange)
return distsq < maxdist * maxdist;
}
bool WorldObject::IsInRange(float x, float y, float z, float minRange, float maxRange) const
{
float dx = GetPositionX() - x;
float dy = GetPositionY() - y;
float dz = GetPositionZ() - z;
float distsq = dx*dx + dy*dy + dz*dz;
float sizefactor = GetObjectSize();
float mindist = minRange + sizefactor;
if(distsq < mindist * mindist)
return false;
float maxdist = maxRange + sizefactor;
return distsq < maxdist * maxdist;
}
float WorldObject::GetAngle(const WorldObject* obj) const
{
if(!obj) return 0;

View file

@ -433,7 +433,8 @@ class MANGOS_DLL_SPEC WorldObject : public Object
return IsInWorld() && obj->IsInWorld() && GetMapId()==obj->GetMapId() &&
GetInstanceId()==obj->GetInstanceId() && InSamePhase(obj);
}
bool IsWithinDist(float x, float y, float z, float dist2compare, bool is3D = true) const;
bool IsWithinDist(float x, float y, float z, float dist2compare) const;
bool IsWithinDist2d(float x, float y, float dist2compare) const;
bool _IsWithinDist(WorldObject const* obj, float dist2compare, bool is3D) const;
bool IsWithinDist(WorldObject const* obj, float dist2compare, bool is3D = true) const
// use only if you will sure about placing both object at same map
@ -447,8 +448,9 @@ class MANGOS_DLL_SPEC WorldObject : public Object
bool IsWithinLOS(float x, float y, float z) const;
bool IsWithinLOSInMap(const WorldObject* obj) const;
bool GetDistanceOrder(WorldObject const* obj1, WorldObject const* obj2, bool is3D = true) const;
bool IsInRange(WorldObject const* obj, float minRange, float maxRange) const;
bool IsInRange(WorldObject const* obj, float minRange, float maxRange, bool is3D = true) const;
bool IsInRange2d(float x, float y, float minRange, float maxRange) const;
bool IsInRange(float x, float y, float z, float minRange, float maxRange) const;
float GetAngle( const WorldObject* obj ) const;
float GetAngle( const float x, const float y ) const;

View file

@ -1,4 +1,4 @@
#ifndef __REVISION_NR_H__
#define __REVISION_NR_H__
#define REVISION_NR "7827"
#define REVISION_NR "7828"
#endif // __REVISION_NR_H__