Skip to content

Commit

Permalink
[10104] Cleaned up WorldObject::HasInArc
Browse files Browse the repository at this point in the history
  • Loading branch information
arrai committed Jun 24, 2010
1 parent dcf996b commit fff8f98
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 10 deletions.
15 changes: 15 additions & 0 deletions src/game/MapManager.h
Expand Up @@ -112,6 +112,21 @@ class MANGOS_DLL_DECL MapManager : public MaNGOS::Singleton<MapManager, MaNGOS::
return IsValidMapCoord(loc.mapid,loc.coord_x,loc.coord_y,loc.coord_z,loc.orientation);
}

// modulos a radian orientation to the range of 0..2PI
static float NormalizeOrientation(float o)
{
// fmod only supports positive numbers. Thus we have
// to emulate negative numbers
if(o < 0)
{
float mod = o *-1;
mod = fmod(mod, 2.0f*M_PI_F);
mod = -mod+2.0f*M_PI_F;
return mod;
}
return fmod(o, 2.0f*M_PI_F);
}

void RemoveAllObjectsInRemoveList();

void LoadTransports();
Expand Down
15 changes: 6 additions & 9 deletions src/game/Object.cpp
Expand Up @@ -1361,19 +1361,15 @@ bool WorldObject::HasInArc(const float arcangle, const WorldObject* obj) const
float arc = arcangle;

// move arc to range 0.. 2*pi
while( arc >= 2.0f * M_PI_F )
arc -= 2.0f * M_PI_F;
while( arc < 0 )
arc += 2.0f * M_PI_F;
arc = MapManager::NormalizeOrientation(arc);

float angle = GetAngle( obj );
angle -= m_orientation;

// move angle to range -pi ... +pi
while( angle > M_PI_F)
angle -= 2.0f * M_PI_F;
while(angle < -M_PI_F)
angle += 2.0f * M_PI_F;
angle = MapManager::NormalizeOrientation(angle);
if(angle > M_PI_F)
angle -= 2.0f*M_PI_F;

float lborder = -1 * (arc/2.0f); // in range -pi..0
float rborder = (arc/2.0f); // in range 0..pi
Expand Down Expand Up @@ -1958,4 +1954,5 @@ bool WorldObject::IsControlledByPlayer() const
default:
return false;
}
}
}

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 "10103"
#define REVISION_NR "10104"
#endif // __REVISION_NR_H__

2 comments on commit fff8f98

@teyrnon
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is the sense to make it(function) visible globally?
and how this math normalization related to map manager..

@alexrp
Copy link

@alexrp alexrp commented on fff8f98 Jun 24, 2010

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feel free to suggest a better place to put it. ;)

Please sign in to comment.