TrinityCore
Loading...
Searching...
No Matches
Position Struct Reference

#include <Position.h>

Classes

struct  ConstStreamer
 
struct  Streamer
 

Public Member Functions

 Position (float x=0, float y=0, float z=0, float o=0)
 
bool operator== (Position const &a) const
 
bool operator!= (Position const &a) const
 
void Relocate (float x, float y)
 
void Relocate (float x, float y, float z)
 
void Relocate (float x, float y, float z, float o)
 
void Relocate (Position const &pos)
 
void Relocate (Position const *pos)
 
void RelocateOffset (Position const &offset)
 
void SetOrientation (float orientation)
 
float GetPositionX () const
 
float GetPositionY () const
 
float GetPositionZ () const
 
float GetOrientation () const
 
void GetPosition (float &x, float &y) const
 
void GetPosition (float &x, float &y, float &z) const
 
void GetPosition (float &x, float &y, float &z, float &o) const
 
Position GetPosition () const
 
Streamer< XY > PositionXYStream ()
 
ConstStreamer< XY > PositionXYStream () const
 
Streamer< XYZ > PositionXYZStream ()
 
ConstStreamer< XYZ > PositionXYZStream () const
 
Streamer< XYZO > PositionXYZOStream ()
 
ConstStreamer< XYZO > PositionXYZOStream () const
 
Streamer< PackedXYZ > PositionPackedXYZStream ()
 
ConstStreamer< PackedXYZ > PositionPackedXYZStream () const
 
bool IsPositionValid () const
 
float GetExactDist2dSq (const float x, const float y) const
 
float GetExactDist2dSq (Position const &pos) const
 
float GetExactDist2dSq (Position const *pos) const
 
float GetExactDist2d (const float x, const float y) const
 
float GetExactDist2d (Position const &pos) const
 
float GetExactDist2d (Position const *pos) const
 
float GetExactDistSq (float x, float y, float z) const
 
float GetExactDistSq (Position const &pos) const
 
float GetExactDistSq (Position const *pos) const
 
float GetExactDist (float x, float y, float z) const
 
float GetExactDist (Position const &pos) const
 
float GetExactDist (Position const *pos) const
 
void GetPositionOffsetTo (Position const &endPos, Position &retOffset) const
 
Position GetPositionWithOffset (Position const &offset) const
 
float GetAbsoluteAngle (float x, float y) const
 
float GetAbsoluteAngle (Position const &pos) const
 
float GetAbsoluteAngle (Position const *pos) const
 
float ToAbsoluteAngle (float relAngle) const
 
float ToRelativeAngle (float absAngle) const
 
float GetRelativeAngle (float x, float y) const
 
float GetRelativeAngle (Position const &pos) const
 
float GetRelativeAngle (Position const *pos) const
 
bool IsInDist2d (float x, float y, float dist) const
 
bool IsInDist2d (Position const *pos, float dist) const
 
bool IsInDist (float x, float y, float z, float dist) const
 
bool IsInDist (Position const &pos, float dist) const
 
bool IsInDist (Position const *pos, float dist) const
 
bool IsWithinBox (Position const &center, float xradius, float yradius, float zradius) const
 
bool IsWithinDoubleVerticalCylinder (Position const *center, float radius, float height) const
 
bool HasInArc (float arcangle, Position const *pos, float border=2.0f) const
 
bool HasInLine (Position const *pos, float objSize, float width) const
 
std::string ToString () const
 

Static Public Member Functions

static float NormalizeOrientation (float o)
 

Public Attributes

float m_positionX
 
float m_positionY
 
float m_positionZ
 

Private Attributes

float m_orientation
 

Constructor & Destructor Documentation

◆ Position()

Position::Position ( float  x = 0,
float  y = 0,
float  z = 0,
float  o = 0 
)
inline
float m_positionZ
Definition: Position.h:55
static float NormalizeOrientation(float o)
Definition: Position.cpp:135
float m_positionX
Definition: Position.h:53
float m_positionY
Definition: Position.h:54
float m_orientation
Definition: Position.h:58

Member Function Documentation

◆ GetAbsoluteAngle() [1/3]

float Position::GetAbsoluteAngle ( float  x,
float  y 
) const
inline
127 {
128 float dx = x - m_positionX;
129 float dy = y - m_positionY;
130 return NormalizeOrientation(std::atan2(dy, dx));
131 }
+ Here is the caller graph for this function:

◆ GetAbsoluteAngle() [2/3]

float Position::GetAbsoluteAngle ( Position const &  pos) const
inline
132{ return GetAbsoluteAngle(pos.m_positionX, pos.m_positionY); }
float GetAbsoluteAngle(float x, float y) const
Definition: Position.h:126
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ GetAbsoluteAngle() [3/3]

float Position::GetAbsoluteAngle ( Position const *  pos) const
inline
133{ return GetAbsoluteAngle(*pos); }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ GetExactDist() [1/3]

float Position::GetExactDist ( float  x,
float  y,
float  z 
) const
inline
119{ return std::sqrt(GetExactDistSq(x, y, z)); }
float GetExactDistSq(float x, float y, float z) const
Definition: Position.h:111
+ Here is the caller graph for this function:

◆ GetExactDist() [2/3]

float Position::GetExactDist ( Position const &  pos) const
inline
120{ return GetExactDist(pos.m_positionX, pos.m_positionY, pos.m_positionZ); }
float GetExactDist(float x, float y, float z) const
Definition: Position.h:119
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ GetExactDist() [3/3]

float Position::GetExactDist ( Position const *  pos) const
inline
121{ return GetExactDist(*pos); }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ GetExactDist2d() [1/3]

float Position::GetExactDist2d ( const float  x,
const float  y 
) const
inline
107{ return std::sqrt(GetExactDist2dSq(x, y)); }
float GetExactDist2dSq(const float x, const float y) const
Definition: Position.h:98
+ Here is the caller graph for this function:

◆ GetExactDist2d() [2/3]

float Position::GetExactDist2d ( Position const &  pos) const
inline
108{ return GetExactDist2d(pos.m_positionX, pos.m_positionY); }
float GetExactDist2d(const float x, const float y) const
Definition: Position.h:107
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ GetExactDist2d() [3/3]

float Position::GetExactDist2d ( Position const *  pos) const
inline
109{ return GetExactDist2d(*pos); }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ GetExactDist2dSq() [1/3]

float Position::GetExactDist2dSq ( const float  x,
const float  y 
) const
inline
99 {
100 float dx = x - m_positionX;
101 float dy = y - m_positionY;
102 return dx*dx + dy*dy;
103 }
+ Here is the caller graph for this function:

◆ GetExactDist2dSq() [2/3]

float Position::GetExactDist2dSq ( Position const &  pos) const
inline
104{ return GetExactDist2dSq(pos.m_positionX, pos.m_positionY); }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ GetExactDist2dSq() [3/3]

float Position::GetExactDist2dSq ( Position const *  pos) const
inline
105{ return GetExactDist2dSq(*pos); }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ GetExactDistSq() [1/3]

float Position::GetExactDistSq ( float  x,
float  y,
float  z 
) const
inline
112 {
113 float dz = z - m_positionZ;
114 return GetExactDist2dSq(x, y) + dz*dz;
115 }
+ Here is the caller graph for this function:

◆ GetExactDistSq() [2/3]

float Position::GetExactDistSq ( Position const &  pos) const
inline
116{ return GetExactDistSq(pos.m_positionX, pos.m_positionY, pos.m_positionZ); }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ GetExactDistSq() [3/3]

float Position::GetExactDistSq ( Position const *  pos) const
inline
117{ return GetExactDistSq(*pos); }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ GetOrientation()

float Position::GetOrientation ( ) const
inline
80{ return m_orientation; }

◆ GetPosition() [1/4]

Position Position::GetPosition ( ) const
inline
85{ return *this; }
+ Here is the caller graph for this function:

◆ GetPosition() [2/4]

void Position::GetPosition ( float &  x,
float &  y 
) const
inline
82{ x = m_positionX; y = m_positionY; }

◆ GetPosition() [3/4]

void Position::GetPosition ( float &  x,
float &  y,
float &  z 
) const
inline
83{ GetPosition(x, y); z = m_positionZ; }
Position GetPosition() const
Definition: Position.h:85
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ GetPosition() [4/4]

void Position::GetPosition ( float &  x,
float &  y,
float &  z,
float &  o 
) const
inline
84{ GetPosition(x, y, z); o = m_orientation; }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ GetPositionOffsetTo()

void Position::GetPositionOffsetTo ( Position const &  endPos,
Position retOffset 
) const
48{
49 float dx = endPos.GetPositionX() - GetPositionX();
50 float dy = endPos.GetPositionY() - GetPositionY();
51
52 retOffset.m_positionX = dx * std::cos(GetOrientation()) + dy * std::sin(GetOrientation());
53 retOffset.m_positionY = dy * std::cos(GetOrientation()) - dx * std::sin(GetOrientation());
54 retOffset.m_positionZ = endPos.GetPositionZ() - GetPositionZ();
55 retOffset.SetOrientation(endPos.GetOrientation() - GetOrientation());
56}
float GetPositionZ() const
Definition: Position.h:79
float GetOrientation() const
Definition: Position.h:80
void SetOrientation(float orientation)
Definition: Position.h:72
float GetPositionX() const
Definition: Position.h:77
float GetPositionY() const
Definition: Position.h:78
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ GetPositionWithOffset()

Position Position::GetPositionWithOffset ( Position const &  offset) const
59{
60 Position ret(*this);
61 ret.RelocateOffset(offset);
62 return ret;
63}
Definition: Position.h:28
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ GetPositionX()

float Position::GetPositionX ( ) const
inline
77{ return m_positionX; }

◆ GetPositionY()

float Position::GetPositionY ( ) const
inline
78{ return m_positionY; }

◆ GetPositionZ()

float Position::GetPositionZ ( ) const
inline
79{ return m_positionZ; }

◆ GetRelativeAngle() [1/3]

float Position::GetRelativeAngle ( float  x,
float  y 
) const
inline
137{ return ToRelativeAngle(GetAbsoluteAngle(x, y)); }
float ToRelativeAngle(float absAngle) const
Definition: Position.h:136
+ Here is the caller graph for this function:

◆ GetRelativeAngle() [2/3]

float Position::GetRelativeAngle ( Position const &  pos) const
inline
138{ return ToRelativeAngle(GetAbsoluteAngle(pos)); }

◆ GetRelativeAngle() [3/3]

float Position::GetRelativeAngle ( Position const *  pos) const
inline
139{ return ToRelativeAngle(GetAbsoluteAngle(pos)); }

◆ HasInArc()

bool Position::HasInArc ( float  arcangle,
Position const *  pos,
float  border = 2.0f 
) const
100{
101 // always have self in arc
102 if (obj == this)
103 return true;
104
105 // move arc to range 0.. 2*pi
106 arc = NormalizeOrientation(arc);
107
108 // move angle to range -pi ... +pi
109 float angle = GetRelativeAngle(obj);
110 if (angle > float(M_PI))
111 angle -= 2.0f * float(M_PI);
112
113 float lborder = -1 * (arc / border); // in range -pi..0
114 float rborder = (arc / border); // in range 0..pi
115 return ((angle >= lborder) && (angle <= rborder));
116}
#define M_PI
Definition: Common.h:140
float GetRelativeAngle(float x, float y) const
Definition: Position.h:137
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ HasInLine()

bool Position::HasInLine ( Position const *  pos,
float  objSize,
float  width 
) const
119{
120 if (!HasInArc(float(M_PI), pos, 2.0f))
121 return false;
122
123 width += objSize;
124 float angle = GetRelativeAngle(pos);
125 return std::fabs(std::sin(angle)) * GetExactDist2d(pos->GetPositionX(), pos->GetPositionY()) < width;
126}
bool HasInArc(float arcangle, Position const *pos, float border=2.0f) const
Definition: Position.cpp:99
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ IsInDist() [1/3]

bool Position::IsInDist ( float  x,
float  y,
float  z,
float  dist 
) const
inline
144{ return GetExactDistSq(x, y, z) < dist * dist; }
+ Here is the caller graph for this function:

◆ IsInDist() [2/3]

bool Position::IsInDist ( Position const &  pos,
float  dist 
) const
inline
145{ return GetExactDistSq(pos) < dist * dist; }

◆ IsInDist() [3/3]

bool Position::IsInDist ( Position const *  pos,
float  dist 
) const
inline
146{ return GetExactDistSq(pos) < dist * dist; }

◆ IsInDist2d() [1/2]

bool Position::IsInDist2d ( float  x,
float  y,
float  dist 
) const
inline
141{ return GetExactDist2dSq(x, y) < dist * dist; }
+ Here is the caller graph for this function:

◆ IsInDist2d() [2/2]

bool Position::IsInDist2d ( Position const *  pos,
float  dist 
) const
inline
142{ return GetExactDist2dSq(pos) < dist * dist; }

◆ IsPositionValid()

bool Position::IsPositionValid ( ) const
43{
45}
bool IsValidMapCoord(float c)
Definition: GridDefines.h:241
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ IsWithinBox()

bool Position::IsWithinBox ( Position const &  center,
float  xradius,
float  yradius,
float  zradius 
) const
66{
67 // rotate the WorldObject position instead of rotating the whole cube, that way we can make a simplified
68 // is-in-cube check and we have to calculate only one point instead of 4
69
70 // 2PI = 360*, keep in mind that ingame orientation is counter-clockwise
71 double rotation = 2 * M_PI - center.GetOrientation();
72 double sinVal = std::sin(rotation);
73 double cosVal = std::cos(rotation);
74
75 float BoxDistX = GetPositionX() - center.GetPositionX();
76 float BoxDistY = GetPositionY() - center.GetPositionY();
77
78 float rotX = float(center.GetPositionX() + BoxDistX * cosVal - BoxDistY*sinVal);
79 float rotY = float(center.GetPositionY() + BoxDistY * cosVal + BoxDistX*sinVal);
80
81 // box edges are parallel to coordiante axis, so we can treat every dimension independently :D
82 float dz = GetPositionZ() - center.GetPositionZ();
83 float dx = rotX - center.GetPositionX();
84 float dy = rotY - center.GetPositionY();
85 if ((std::fabs(dx) > xradius) ||
86 (std::fabs(dy) > yradius) ||
87 (std::fabs(dz) > zradius))
88 return false;
89
90 return true;
91}
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ IsWithinDoubleVerticalCylinder()

bool Position::IsWithinDoubleVerticalCylinder ( Position const *  center,
float  radius,
float  height 
) const
94{
95 float verticalDelta = GetPositionZ() - center->GetPositionZ();
96 return IsInDist2d(center, radius) && std::abs(verticalDelta) <= height;
97}
bool IsInDist2d(float x, float y, float dist) const
Definition: Position.h:141
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ NormalizeOrientation()

float Position::NormalizeOrientation ( float  o)
static
136{
137 // fmod only supports positive numbers. Thus we have
138 // to emulate negative numbers
139 if (o < 0)
140 {
141 float mod = o *-1;
142 mod = std::fmod(mod, 2.0f * static_cast<float>(M_PI));
143 mod = -mod + 2.0f * static_cast<float>(M_PI);
144 return mod;
145 }
146 return std::fmod(o, 2.0f * static_cast<float>(M_PI));
147}
+ Here is the caller graph for this function:

◆ operator!=()

bool Position::operator!= ( Position const &  a) const
inline
62{ return !(operator==(a)); }
bool operator==(Position const &a) const
Definition: Position.cpp:26
+ Here is the call graph for this function:

◆ operator==()

bool Position::operator== ( Position const &  a) const
27{
28 return (G3D::fuzzyEq(a.m_positionX, m_positionX) &&
29 G3D::fuzzyEq(a.m_positionY, m_positionY) &&
30 G3D::fuzzyEq(a.m_positionZ, m_positionZ) &&
31 G3D::fuzzyEq(a.m_orientation, m_orientation));
32}

◆ PositionPackedXYZStream() [1/2]

Streamer< PackedXYZ > Position::PositionPackedXYZStream ( )
inline
93{ return Streamer<PackedXYZ>(*this); }

◆ PositionPackedXYZStream() [2/2]

ConstStreamer< PackedXYZ > Position::PositionPackedXYZStream ( ) const
inline
94{ return ConstStreamer<PackedXYZ>(*this); }

◆ PositionXYStream() [1/2]

Streamer< XY > Position::PositionXYStream ( )
inline
87{ return Streamer<XY>(*this); }

◆ PositionXYStream() [2/2]

ConstStreamer< XY > Position::PositionXYStream ( ) const
inline
88{ return ConstStreamer<XY>(*this); }

◆ PositionXYZOStream() [1/2]

Streamer< XYZO > Position::PositionXYZOStream ( )
inline
91{ return Streamer<XYZO>(*this); }
+ Here is the caller graph for this function:

◆ PositionXYZOStream() [2/2]

ConstStreamer< XYZO > Position::PositionXYZOStream ( ) const
inline
92{ return ConstStreamer<XYZO>(*this); }

◆ PositionXYZStream() [1/2]

Streamer< XYZ > Position::PositionXYZStream ( )
inline
89{ return Streamer<XYZ>(*this); }
+ Here is the caller graph for this function:

◆ PositionXYZStream() [2/2]

ConstStreamer< XYZ > Position::PositionXYZStream ( ) const
inline
90{ return ConstStreamer<XYZ>(*this); }

◆ Relocate() [1/5]

void Position::Relocate ( float  x,
float  y 
)
inline
64{ m_positionX = x; m_positionY = y; }
+ Here is the caller graph for this function:

◆ Relocate() [2/5]

void Position::Relocate ( float  x,
float  y,
float  z 
)
inline
65{ Relocate(x, y); m_positionZ = z; }
void Relocate(float x, float y)
Definition: Position.h:64
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Relocate() [3/5]

void Position::Relocate ( float  x,
float  y,
float  z,
float  o 
)
inline
66{ Relocate(x, y, z); SetOrientation(o); }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Relocate() [4/5]

void Position::Relocate ( Position const &  pos)
inline
67{ *this = pos; }

◆ Relocate() [5/5]

void Position::Relocate ( Position const *  pos)
inline
68{ *this = *pos; }

◆ RelocateOffset()

void Position::RelocateOffset ( Position const &  offset)
35{
36 m_positionX = GetPositionX() + (offset.GetPositionX() * std::cos(GetOrientation()) + offset.GetPositionY() * std::sin(GetOrientation() + float(M_PI)));
37 m_positionY = GetPositionY() + (offset.GetPositionY() * std::cos(GetOrientation()) + offset.GetPositionX() * std::sin(GetOrientation()));
38 m_positionZ = GetPositionZ() + offset.GetPositionZ();
39 SetOrientation(GetOrientation() + offset.GetOrientation());
40}
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ SetOrientation()

void Position::SetOrientation ( float  orientation)
inline
73 {
75 }
+ Here is the caller graph for this function:

◆ ToAbsoluteAngle()

float Position::ToAbsoluteAngle ( float  relAngle) const
inline
134{ return NormalizeOrientation(relAngle + m_orientation); }
+ Here is the caller graph for this function:

◆ ToRelativeAngle()

float Position::ToRelativeAngle ( float  absAngle) const
inline
136{ return NormalizeOrientation(absAngle - m_orientation); }

◆ ToString()

std::string Position::ToString ( ) const
129{
130 std::stringstream sstr;
131 sstr << "X: " << m_positionX << " Y: " << m_positionY << " Z: " << m_positionZ << " O: " << m_orientation;
132 return sstr.str();
133}
+ Here is the caller graph for this function:

Member Data Documentation

◆ m_orientation

float Position::m_orientation
private

◆ m_positionX

float Position::m_positionX

◆ m_positionY

float Position::m_positionY

◆ m_positionZ

float Position::m_positionZ

The documentation for this struct was generated from the following files: