mirror of
https://github.com/mangosfour/server.git
synced 2025-12-15 01:37:00 +00:00
[11882] Improve a few functions related to Angle calculation
Signed-off-by: Schmoozerd <schmoozerd@scriptdev2.com>
This commit is contained in:
parent
de3bdc0ed0
commit
2c175f6d82
3 changed files with 17 additions and 13 deletions
|
|
@ -119,7 +119,7 @@ class MANGOS_DLL_DECL MapManager : public MaNGOS::Singleton<MapManager, MaNGOS::
|
||||||
{
|
{
|
||||||
// fmod only supports positive numbers. Thus we have
|
// fmod only supports positive numbers. Thus we have
|
||||||
// to emulate negative numbers
|
// to emulate negative numbers
|
||||||
if(o < 0)
|
if (o < 0)
|
||||||
{
|
{
|
||||||
float mod = o *-1;
|
float mod = o *-1;
|
||||||
mod = fmod(mod, 2.0f*M_PI_F);
|
mod = fmod(mod, 2.0f*M_PI_F);
|
||||||
|
|
|
||||||
|
|
@ -1187,17 +1187,21 @@ bool WorldObject::IsInRange3d(float x, float y, float z, float minRange, float m
|
||||||
|
|
||||||
float WorldObject::GetAngle(const WorldObject* obj) const
|
float WorldObject::GetAngle(const WorldObject* obj) const
|
||||||
{
|
{
|
||||||
if(!obj) return 0;
|
if (!obj)
|
||||||
return GetAngle( obj->GetPositionX(), obj->GetPositionY() );
|
return 0.0f;
|
||||||
|
|
||||||
|
MANGOS_ASSERT(obj != this);
|
||||||
|
|
||||||
|
return GetAngle(obj->GetPositionX(), obj->GetPositionY());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return angle in range 0..2*pi
|
// Return angle in range 0..2*pi
|
||||||
float WorldObject::GetAngle( const float x, const float y ) const
|
float WorldObject::GetAngle(const float x, const float y) const
|
||||||
{
|
{
|
||||||
float dx = x - GetPositionX();
|
float dx = x - GetPositionX();
|
||||||
float dy = y - GetPositionY();
|
float dy = y - GetPositionY();
|
||||||
|
|
||||||
float ang = atan2(dy, dx);
|
float ang = atan2(dy, dx); // returns value between -Pi..Pi
|
||||||
ang = (ang >= 0) ? ang : 2 * M_PI_F + ang;
|
ang = (ang >= 0) ? ang : 2 * M_PI_F + ang;
|
||||||
return ang;
|
return ang;
|
||||||
}
|
}
|
||||||
|
|
@ -1205,7 +1209,7 @@ float WorldObject::GetAngle( const float x, const float y ) const
|
||||||
bool WorldObject::HasInArc(const float arcangle, const WorldObject* obj) const
|
bool WorldObject::HasInArc(const float arcangle, const WorldObject* obj) const
|
||||||
{
|
{
|
||||||
// always have self in arc
|
// always have self in arc
|
||||||
if(obj == this)
|
if (obj == this)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
float arc = arcangle;
|
float arc = arcangle;
|
||||||
|
|
@ -1213,12 +1217,12 @@ bool WorldObject::HasInArc(const float arcangle, const WorldObject* obj) const
|
||||||
// move arc to range 0.. 2*pi
|
// move arc to range 0.. 2*pi
|
||||||
arc = MapManager::NormalizeOrientation(arc);
|
arc = MapManager::NormalizeOrientation(arc);
|
||||||
|
|
||||||
float angle = GetAngle( obj );
|
float angle = GetAngle(obj);
|
||||||
angle -= m_position.o;
|
angle -= m_position.o;
|
||||||
|
|
||||||
// move angle to range -pi ... +pi
|
// move angle to range -pi ... +pi
|
||||||
angle = MapManager::NormalizeOrientation(angle);
|
angle = MapManager::NormalizeOrientation(angle);
|
||||||
if(angle > M_PI_F)
|
if (angle > M_PI_F)
|
||||||
angle -= 2.0f*M_PI_F;
|
angle -= 2.0f*M_PI_F;
|
||||||
|
|
||||||
float lborder = -1 * (arc/2.0f); // in range -pi..0
|
float lborder = -1 * (arc/2.0f); // in range -pi..0
|
||||||
|
|
@ -1581,7 +1585,7 @@ namespace MaNGOS
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
NearUsedPosDo(WorldObject const& obj, WorldObject const* searcher, float absAngle, ObjectPosSelector& selector)
|
NearUsedPosDo(WorldObject const& obj, WorldObject const* searcher, float absAngle, ObjectPosSelector& selector)
|
||||||
: i_object(obj), i_searcher(searcher), i_absAngle(absAngle), i_selector(selector) {}
|
: i_object(obj), i_searcher(searcher), i_absAngle(MapManager::NormalizeOrientation(absAngle)), i_selector(selector) {}
|
||||||
|
|
||||||
void operator()(Corpse*) const {}
|
void operator()(Corpse*) const {}
|
||||||
void operator()(DynamicObject*) const {}
|
void operator()(DynamicObject*) const {}
|
||||||
|
|
@ -1635,10 +1639,10 @@ namespace MaNGOS
|
||||||
|
|
||||||
float angle = i_object.GetAngle(u) - i_absAngle;
|
float angle = i_object.GetAngle(u) - i_absAngle;
|
||||||
|
|
||||||
// move angle to range -pi ... +pi
|
// move angle to range -pi ... +pi, range before is -2Pi..2Pi
|
||||||
while (angle > M_PI_F)
|
if (angle > M_PI_F)
|
||||||
angle -= 2.0f * M_PI_F;
|
angle -= 2.0f * M_PI_F;
|
||||||
while (angle < -M_PI_F)
|
else if (angle < -M_PI_F)
|
||||||
angle += 2.0f * M_PI_F;
|
angle += 2.0f * M_PI_F;
|
||||||
|
|
||||||
i_selector.AddUsedArea(u->GetObjectBoundingRadius(), angle, dist2d);
|
i_selector.AddUsedArea(u->GetObjectBoundingRadius(), angle, dist2d);
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
#ifndef __REVISION_NR_H__
|
#ifndef __REVISION_NR_H__
|
||||||
#define __REVISION_NR_H__
|
#define __REVISION_NR_H__
|
||||||
#define REVISION_NR "11881"
|
#define REVISION_NR "11882"
|
||||||
#endif // __REVISION_NR_H__
|
#endif // __REVISION_NR_H__
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue