Skip to content

Commit

Permalink
[7828] Add 2d/3d versions for WorldObject::IsInRange(x,y,... and Worl…
Browse files Browse the repository at this point in the history
…dObject::IsWithinDist(x,y,...
  • Loading branch information
VladimirMangos committed May 14, 2009
1 parent 81206d5 commit ebb0030
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 12 deletions.
48 changes: 39 additions & 9 deletions src/game/Object.cpp
Expand Up @@ -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;

Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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;
Expand Down
6 changes: 4 additions & 2 deletions src/game/Object.h
Expand Up @@ -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
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/shared/revision_nr.h
@@ -1,4 +1,4 @@
#ifndef __REVISION_NR_H__
#define __REVISION_NR_H__
#define REVISION_NR "7827"
#define REVISION_NR "7828"
#endif // __REVISION_NR_H__

0 comments on commit ebb0030

Please sign in to comment.