TrinityCore
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
 
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
 

Detailed Description

Definition at line 27 of file Position.h.

Constructor & Destructor Documentation

◆ Position()

Position::Position ( float  x = 0,
float  y = 0,
float  z = 0,
float  o = 0 
)
inline

Definition at line 29 of file Position.h.

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
+ Here is the caller graph for this function:

Member Function Documentation

◆ GetAbsoluteAngle() [1/3]

float Position::GetAbsoluteAngle ( float  x,
float  y 
) const
inline

Definition at line 125 of file Position.h.

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

◆ GetAbsoluteAngle() [2/3]

float Position::GetAbsoluteAngle ( Position const &  pos) const
inline

Definition at line 131 of file Position.h.

131{ return GetAbsoluteAngle(pos.m_positionX, pos.m_positionY); }
float GetAbsoluteAngle(float x, float y) const
Definition: Position.h:125
+ 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

Definition at line 132 of file Position.h.

132{ 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

Definition at line 118 of file Position.h.

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

◆ GetExactDist() [2/3]

float Position::GetExactDist ( Position const &  pos) const
inline

Definition at line 119 of file Position.h.

119{ return GetExactDist(pos.m_positionX, pos.m_positionY, pos.m_positionZ); }
float GetExactDist(float x, float y, float z) const
Definition: Position.h:118
+ 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

Definition at line 120 of file Position.h.

120{ 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

Definition at line 106 of file Position.h.

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

◆ GetExactDist2d() [2/3]

float Position::GetExactDist2d ( Position const &  pos) const
inline

Definition at line 107 of file Position.h.

107{ return GetExactDist2d(pos.m_positionX, pos.m_positionY); }
float GetExactDist2d(const float x, const float y) const
Definition: Position.h:106
+ 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

Definition at line 108 of file Position.h.

108{ 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

Definition at line 97 of file Position.h.

98 {
99 float dx = x - m_positionX;
100 float dy = y - m_positionY;
101 return dx*dx + dy*dy;
102 }
+ Here is the caller graph for this function:

◆ GetExactDist2dSq() [2/3]

float Position::GetExactDist2dSq ( Position const &  pos) const
inline

Definition at line 103 of file Position.h.

103{ 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

Definition at line 104 of file Position.h.

104{ 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

Definition at line 110 of file Position.h.

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

◆ GetExactDistSq() [2/3]

float Position::GetExactDistSq ( Position const &  pos) const
inline

Definition at line 115 of file Position.h.

115{ 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

Definition at line 116 of file Position.h.

116{ 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

Definition at line 79 of file Position.h.

79{ return m_orientation; }

◆ GetPosition() [1/4]

Position Position::GetPosition ( ) const
inline

Definition at line 84 of file Position.h.

84{ return *this; }
+ Here is the caller graph for this function:

◆ GetPosition() [2/4]

void Position::GetPosition ( float &  x,
float &  y 
) const
inline

Definition at line 81 of file Position.h.

81{ x = m_positionX; y = m_positionY; }

◆ GetPosition() [3/4]

void Position::GetPosition ( float &  x,
float &  y,
float &  z 
) const
inline

Definition at line 82 of file Position.h.

82{ GetPosition(x, y); z = m_positionZ; }
Position GetPosition() const
Definition: Position.h:84
+ 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

Definition at line 83 of file Position.h.

83{ 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

Definition at line 47 of file Position.cpp.

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:78
float GetOrientation() const
Definition: Position.h:79
void SetOrientation(float orientation)
Definition: Position.h:71
float GetPositionX() const
Definition: Position.h:76
float GetPositionY() const
Definition: Position.h:77
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ GetPositionWithOffset()

Position Position::GetPositionWithOffset ( Position const &  offset) const

Definition at line 58 of file Position.cpp.

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

◆ GetPositionX()

float Position::GetPositionX ( ) const
inline

Definition at line 76 of file Position.h.

76{ return m_positionX; }

◆ GetPositionY()

float Position::GetPositionY ( ) const
inline

Definition at line 77 of file Position.h.

77{ return m_positionY; }

◆ GetPositionZ()

float Position::GetPositionZ ( ) const
inline

Definition at line 78 of file Position.h.

78{ return m_positionZ; }

◆ GetRelativeAngle() [1/3]

float Position::GetRelativeAngle ( float  x,
float  y 
) const
inline

Definition at line 136 of file Position.h.

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

◆ GetRelativeAngle() [2/3]

float Position::GetRelativeAngle ( Position const &  pos) const
inline

Definition at line 137 of file Position.h.

137{ return ToRelativeAngle(GetAbsoluteAngle(pos)); }

◆ GetRelativeAngle() [3/3]

float Position::GetRelativeAngle ( Position const *  pos) const
inline

Definition at line 138 of file Position.h.

138{ return ToRelativeAngle(GetAbsoluteAngle(pos)); }

◆ HasInArc()

bool Position::HasInArc ( float  arcangle,
Position const *  pos,
float  border = 2.0f 
) const

Definition at line 99 of file Position.cpp.

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:115
float GetRelativeAngle(float x, float y) const
Definition: Position.h:136
+ 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

Definition at line 118 of file Position.cpp.

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

Definition at line 143 of file Position.h.

143{ 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

Definition at line 144 of file Position.h.

144{ return GetExactDistSq(pos) < dist * dist; }

◆ IsInDist() [3/3]

bool Position::IsInDist ( Position const *  pos,
float  dist 
) const
inline

Definition at line 145 of file Position.h.

145{ return GetExactDistSq(pos) < dist * dist; }

◆ IsInDist2d() [1/2]

bool Position::IsInDist2d ( float  x,
float  y,
float  dist 
) const
inline

Definition at line 140 of file Position.h.

140{ 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

Definition at line 141 of file Position.h.

141{ return GetExactDist2dSq(pos) < dist * dist; }

◆ IsPositionValid()

bool Position::IsPositionValid ( ) const

Definition at line 42 of file Position.cpp.

+ 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

Definition at line 65 of file Position.cpp.

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

Definition at line 93 of file Position.cpp.

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:140
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ NormalizeOrientation()

float Position::NormalizeOrientation ( float  o)
static

Definition at line 135 of file Position.cpp.

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

Definition at line 26 of file Position.cpp.

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

Definition at line 92 of file Position.h.

92{ return Streamer<PackedXYZ>(*this); }

◆ PositionPackedXYZStream() [2/2]

ConstStreamer< PackedXYZ > Position::PositionPackedXYZStream ( ) const
inline

Definition at line 93 of file Position.h.

93{ return ConstStreamer<PackedXYZ>(*this); }

◆ PositionXYStream() [1/2]

Streamer< XY > Position::PositionXYStream ( )
inline

Definition at line 86 of file Position.h.

86{ return Streamer<XY>(*this); }

◆ PositionXYStream() [2/2]

ConstStreamer< XY > Position::PositionXYStream ( ) const
inline

Definition at line 87 of file Position.h.

87{ return ConstStreamer<XY>(*this); }

◆ PositionXYZOStream() [1/2]

Streamer< XYZO > Position::PositionXYZOStream ( )
inline

Definition at line 90 of file Position.h.

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

◆ PositionXYZOStream() [2/2]

ConstStreamer< XYZO > Position::PositionXYZOStream ( ) const
inline

Definition at line 91 of file Position.h.

91{ return ConstStreamer<XYZO>(*this); }

◆ PositionXYZStream() [1/2]

Streamer< XYZ > Position::PositionXYZStream ( )
inline

Definition at line 88 of file Position.h.

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

◆ PositionXYZStream() [2/2]

ConstStreamer< XYZ > Position::PositionXYZStream ( ) const
inline

Definition at line 89 of file Position.h.

89{ return ConstStreamer<XYZ>(*this); }

◆ Relocate() [1/5]

void Position::Relocate ( float  x,
float  y 
)
inline

Definition at line 63 of file Position.h.

63{ 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

Definition at line 64 of file Position.h.

64{ Relocate(x, y); m_positionZ = z; }
void Relocate(float x, float y)
Definition: Position.h:63
+ 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

Definition at line 65 of file Position.h.

65{ 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

Definition at line 66 of file Position.h.

66{ *this = pos; }

◆ Relocate() [5/5]

void Position::Relocate ( Position const *  pos)
inline

Definition at line 67 of file Position.h.

67{ *this = *pos; }

◆ RelocateOffset()

void Position::RelocateOffset ( Position const &  offset)

Definition at line 34 of file Position.cpp.

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

Definition at line 71 of file Position.h.

72 {
74 }
+ Here is the caller graph for this function:

◆ ToAbsoluteAngle()

float Position::ToAbsoluteAngle ( float  relAngle) const
inline

Definition at line 133 of file Position.h.

133{ return NormalizeOrientation(relAngle + m_orientation); }
+ Here is the caller graph for this function:

◆ ToRelativeAngle()

float Position::ToRelativeAngle ( float  absAngle) const
inline

Definition at line 135 of file Position.h.

135{ return NormalizeOrientation(absAngle - m_orientation); }

◆ ToString()

std::string Position::ToString ( ) const

Definition at line 128 of file Position.cpp.

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

Definition at line 58 of file Position.h.

◆ m_positionX

float Position::m_positionX

Definition at line 53 of file Position.h.

◆ m_positionY

float Position::m_positionY

Definition at line 54 of file Position.h.

◆ m_positionZ

float Position::m_positionZ

Definition at line 55 of file Position.h.


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