TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Position Struct Reference

#include <Position.h>

Classes

struct  PositionXYStreamer
 
struct  PositionXYZOStreamer
 
struct  PositionXYZStreamer
 

Public Member Functions

 Position (float x=0, float y=0, float z=0, float o=0)
 
 Position (Position const &loc)
 
bool operator== (Position const &a)
 
bool operator!= (Position const &a)
 
void Relocate (float x, float y)
 
void Relocate (float x, float y, float z)
 
void Relocate (float x, float y, float z, float orientation)
 
void Relocate (Position const &pos)
 
void Relocate (Position const *pos)
 
void Relocate (G3D::Vector3 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
 
Position::PositionXYStreamer PositionXYStream ()
 
Position::PositionXYZStreamer PositionXYZStream ()
 
Position::PositionXYZOStreamer PositionXYZOStream ()
 
bool IsPositionValid () const
 
float GetExactDist2dSq (float x, float y) const
 
float GetExactDist2d (const float x, const float y) const
 
float GetExactDist2dSq (Position const *pos) const
 
float GetExactDist2d (Position const *pos) const
 
float GetExactDistSq (float x, float y, float z) const
 
float GetExactDist (float x, float y, float z) const
 
float GetExactDistSq (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 GetAngle (Position const *pos) const
 
float GetAngle (float x, float y) const
 
float GetRelativeAngle (Position const *pos) const
 
float GetRelativeAngle (float x, float y) const
 
void GetSinCos (float x, float y, float &vsin, float &vcos) 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 IsWithinBox (const Position &center, float xradius, float yradius, float zradius) const
 
bool HasInArc (float arcangle, Position const *pos, float border=2.0f) const
 
bool HasInLine (Position const *pos, 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 ( float  x = 0,
float  y = 0,
float  z = 0,
float  o = 0 
)
inline
float m_positionY
Definition: Position.h:53
float m_positionX
Definition: Position.h:52
static float NormalizeOrientation(float o)
Definition: Position.h:211
G3D::int16 z
Definition: Vector3int16.h:46
G3D::int16 y
Definition: Vector2int16.h:38
float m_positionZ
Definition: Position.h:54
G3D::int16 x
Definition: Vector2int16.h:37
float m_orientation
Definition: Position.h:57

+ Here is the caller graph for this function:

Position::Position ( Position const loc)
inline
32 { Relocate(loc); }
void Relocate(float x, float y)
Definition: Position.h:67

Member Function Documentation

float Position::GetAngle ( Position const pos) const
64 {
65  if (!obj)
66  return 0;
67 
68  return GetAngle(obj->GetPositionX(), obj->GetPositionY());
69 }
float GetAngle(Position const *pos) const
Definition: Position.cpp:63

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

float Position::GetAngle ( float  x,
float  y 
) const
73 {
74  float dx = x - GetPositionX();
75  float dy = y - GetPositionY();
76 
77  float ang = std::atan2(dy, dx);
78  ang = (ang >= 0) ? ang : 2 * float(M_PI) + ang;
79  return ang;
80 }
#define M_PI
Definition: Common.h:163
float GetPositionY() const
Definition: Position.h:105
G3D::int16 y
Definition: Vector2int16.h:38
G3D::int16 x
Definition: Vector2int16.h:37
float GetPositionX() const
Definition: Position.h:104

+ Here is the call graph for this function:

float Position::GetExactDist ( float  x,
float  y,
float  z 
) const
inline
158  {
159  return std::sqrt(GetExactDistSq(x, y, z));
160  }
G3D::int16 z
Definition: Vector3int16.h:46
float GetExactDistSq(float x, float y, float z) const
Definition: Position.h:152
G3D::int16 y
Definition: Vector2int16.h:38
G3D::int16 x
Definition: Vector2int16.h:37

+ Here is the caller graph for this function:

float Position::GetExactDist ( Position const pos) const
inline
168  {
169  return std::sqrt(GetExactDistSq(pos));
170  }
float GetExactDistSq(float x, float y, float z) const
Definition: Position.h:152
float Position::GetExactDist2d ( const float  x,
const float  y 
) const
inline
138  {
139  return std::sqrt(GetExactDist2dSq(x, y));
140  }
float GetExactDist2dSq(float x, float y) const
Definition: Position.h:132
G3D::int16 y
Definition: Vector2int16.h:38
G3D::int16 x
Definition: Vector2int16.h:37

+ Here is the caller graph for this function:

float Position::GetExactDist2d ( Position const pos) const
inline
148  {
149  return std::sqrt(GetExactDist2dSq(pos));
150  }
float GetExactDist2dSq(float x, float y) const
Definition: Position.h:132
float Position::GetExactDist2dSq ( float  x,
float  y 
) const
inline
133  {
134  float dx = m_positionX - x; float dy = m_positionY - y; return dx*dx + dy*dy;
135  }
float m_positionY
Definition: Position.h:53
float m_positionX
Definition: Position.h:52
G3D::int16 y
Definition: Vector2int16.h:38
G3D::int16 x
Definition: Vector2int16.h:37

+ Here is the caller graph for this function:

float Position::GetExactDist2dSq ( Position const pos) const
inline
143  {
144  float dx = m_positionX - pos->m_positionX; float dy = m_positionY - pos->m_positionY; return dx*dx + dy*dy;
145  }
float m_positionY
Definition: Position.h:53
float m_positionX
Definition: Position.h:52
float Position::GetExactDistSq ( float  x,
float  y,
float  z 
) const
inline
153  {
154  float dz = m_positionZ - z; return GetExactDist2dSq(x, y) + dz*dz;
155  }
float GetExactDist2dSq(float x, float y) const
Definition: Position.h:132
G3D::int16 z
Definition: Vector3int16.h:46
G3D::int16 y
Definition: Vector2int16.h:38
float m_positionZ
Definition: Position.h:54
G3D::int16 x
Definition: Vector2int16.h:37

+ Here is the caller graph for this function:

float Position::GetExactDistSq ( Position const pos) const
inline
163  {
164  float dx = m_positionX - pos->m_positionX; float dy = m_positionY - pos->m_positionY; float dz = m_positionZ - pos->m_positionZ; return dx*dx + dy*dy + dz*dz;
165  }
float m_positionY
Definition: Position.h:53
float m_positionX
Definition: Position.h:52
float m_positionZ
Definition: Position.h:54
float Position::GetOrientation ( ) const
inline
107 { return m_orientation; }
float m_orientation
Definition: Position.h:57
void Position::GetPosition ( float &  x,
float &  y 
) const
inline
110  {
111  x = m_positionX; y = m_positionY;
112  }
float m_positionY
Definition: Position.h:53
float m_positionX
Definition: Position.h:52
G3D::int16 y
Definition: Vector2int16.h:38
G3D::int16 x
Definition: Vector2int16.h:37
void Position::GetPosition ( float &  x,
float &  y,
float &  z 
) const
inline
115  {
117  }
float m_positionY
Definition: Position.h:53
float m_positionX
Definition: Position.h:52
G3D::int16 z
Definition: Vector3int16.h:46
G3D::int16 y
Definition: Vector2int16.h:38
float m_positionZ
Definition: Position.h:54
G3D::int16 x
Definition: Vector2int16.h:37
void Position::GetPosition ( float &  x,
float &  y,
float &  z,
float &  o 
) const
inline
120  {
122  }
float m_positionY
Definition: Position.h:53
float m_positionX
Definition: Position.h:52
G3D::int16 z
Definition: Vector3int16.h:46
G3D::int16 y
Definition: Vector2int16.h:38
float m_positionZ
Definition: Position.h:54
G3D::int16 x
Definition: Vector2int16.h:37
float m_orientation
Definition: Position.h:57
Position Position::GetPosition ( ) const
inline
124 { return *this; }

+ Here is the caller graph for this function:

void Position::GetPositionOffsetTo ( Position const endPos,
Position retOffset 
) const
46 {
47  float dx = endPos.GetPositionX() - GetPositionX();
48  float dy = endPos.GetPositionY() - GetPositionY();
49 
50  retOffset.m_positionX = dx * std::cos(GetOrientation()) + dy * std::sin(GetOrientation());
51  retOffset.m_positionY = dy * std::cos(GetOrientation()) - dx * std::sin(GetOrientation());
52  retOffset.m_positionZ = endPos.GetPositionZ() - GetPositionZ();
53  retOffset.SetOrientation(endPos.GetOrientation() - GetOrientation());
54 }
float m_positionY
Definition: Position.h:53
void SetOrientation(float orientation)
Definition: Position.h:99
float m_positionX
Definition: Position.h:52
float GetOrientation() const
Definition: Position.h:107
float GetPositionY() const
Definition: Position.h:105
float GetPositionZ() const
Definition: Position.h:106
float m_positionZ
Definition: Position.h:54
float GetPositionX() const
Definition: Position.h:104

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Position Position::GetPositionWithOffset ( Position const offset) const
57 {
58  Position ret(*this);
59  ret.RelocateOffset(offset);
60  return ret;
61 }
Definition: Position.h:27

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

float Position::GetPositionX ( ) const
inline
104 { return m_positionX; }
float m_positionX
Definition: Position.h:52
float Position::GetPositionY ( ) const
inline
105 { return m_positionY; }
float m_positionY
Definition: Position.h:53
float Position::GetPositionZ ( ) const
inline
106 { return m_positionZ; }
float m_positionZ
Definition: Position.h:54
float Position::GetRelativeAngle ( Position const pos) const
inline
178  {
179  return GetAngle(pos) - m_orientation;
180  }
float GetAngle(Position const *pos) const
Definition: Position.cpp:63
float m_orientation
Definition: Position.h:57

+ Here is the caller graph for this function:

float Position::GetRelativeAngle ( float  x,
float  y 
) const
inline
182 { return GetAngle(x, y) - m_orientation; }
float GetAngle(Position const *pos) const
Definition: Position.cpp:63
G3D::int16 y
Definition: Vector2int16.h:38
G3D::int16 x
Definition: Vector2int16.h:37
float m_orientation
Definition: Position.h:57
void Position::GetSinCos ( float  x,
float  y,
float &  vsin,
float &  vcos 
) const
83 {
84  float dx = GetPositionX() - x;
85  float dy = GetPositionY() - y;
86 
87  if (std::fabs(dx) < 0.001f && std::fabs(dy) < 0.001f)
88  {
89  float angle = (float)rand_norm()*static_cast<float>(2 * M_PI);
90  vcos = std::cos(angle);
91  vsin = std::sin(angle);
92  }
93  else
94  {
95  float dist = std::sqrt((dx*dx) + (dy*dy));
96  vcos = dx / dist;
97  vsin = dy / dist;
98  }
99 }
#define M_PI
Definition: Common.h:163
float GetPositionY() const
Definition: Position.h:105
G3D::int16 y
Definition: Vector2int16.h:38
double rand_norm()
Definition: Random.cpp:69
G3D::int16 x
Definition: Vector2int16.h:37
float GetPositionX() const
Definition: Position.h:104

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool Position::HasInArc ( float  arcangle,
Position const pos,
float  border = 2.0f 
) const
130 {
131  // always have self in arc
132  if (obj == this)
133  return true;
134 
135  // move arc to range 0.. 2*pi
136  arc = NormalizeOrientation(arc);
137 
138  float angle = GetAngle(obj);
139  angle -= m_orientation;
140 
141  // move angle to range -pi ... +pi
142  angle = NormalizeOrientation(angle);
143  if (angle > float(M_PI))
144  angle -= 2.0f * float(M_PI);
145 
146  float lborder = -1 * (arc / border); // in range -pi..0
147  float rborder = (arc / border); // in range 0..pi
148  return ((angle >= lborder) && (angle <= rborder));
149 }
#define M_PI
Definition: Common.h:163
static float NormalizeOrientation(float o)
Definition: Position.h:211
float GetAngle(Position const *pos) const
Definition: Position.cpp:63
float m_orientation
Definition: Position.h:57

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool Position::HasInLine ( Position const pos,
float  width 
) const
152 {
153  if (!HasInArc(float(M_PI), pos))
154  return false;
155 
156  float angle = GetRelativeAngle(pos);
157  return std::fabs(std::sin(angle)) * GetExactDist2d(pos->GetPositionX(), pos->GetPositionY()) < width;
158 }
#define M_PI
Definition: Common.h:163
float GetExactDist2d(const float x, const float y) const
Definition: Position.h:137
float GetRelativeAngle(Position const *pos) const
Definition: Position.h:177
bool HasInArc(float arcangle, Position const *pos, float border=2.0f) const
Definition: Position.cpp:129

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool Position::IsInDist ( float  x,
float  y,
float  z,
float  dist 
) const
inline
196  {
197  return GetExactDistSq(x, y, z) < dist * dist;
198  }
G3D::int16 z
Definition: Vector3int16.h:46
float GetExactDistSq(float x, float y, float z) const
Definition: Position.h:152
G3D::int16 y
Definition: Vector2int16.h:38
G3D::int16 x
Definition: Vector2int16.h:37

+ Here is the caller graph for this function:

bool Position::IsInDist ( Position const pos,
float  dist 
) const
inline
201  {
202  return GetExactDistSq(pos) < dist * dist;
203  }
float GetExactDistSq(float x, float y, float z) const
Definition: Position.h:152
bool Position::IsInDist2d ( float  x,
float  y,
float  dist 
) const
inline
186  {
187  return GetExactDist2dSq(x, y) < dist * dist;
188  }
float GetExactDist2dSq(float x, float y) const
Definition: Position.h:132
G3D::int16 y
Definition: Vector2int16.h:38
G3D::int16 x
Definition: Vector2int16.h:37

+ Here is the caller graph for this function:

bool Position::IsInDist2d ( Position const pos,
float  dist 
) const
inline
191  {
192  return GetExactDist2dSq(pos) < dist * dist;
193  }
float GetExactDist2dSq(float x, float y) const
Definition: Position.h:132
bool Position::IsPositionValid ( ) const
41 {
43 }
float m_positionY
Definition: Position.h:53
float m_positionX
Definition: Position.h:52
bool IsValidMapCoord(float c)
Definition: GridDefines.h:218
float m_positionZ
Definition: Position.h:54
float m_orientation
Definition: Position.h:57

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool Position::IsWithinBox ( const Position center,
float  xradius,
float  yradius,
float  zradius 
) const
102 {
103  // rotate the WorldObject position instead of rotating the whole cube, that way we can make a simplified
104  // is-in-cube check and we have to calculate only one point instead of 4
105 
106  // 2PI = 360*, keep in mind that ingame orientation is counter-clockwise
107  double rotation = 2 * M_PI - center.GetOrientation();
108  double sinVal = std::sin(rotation);
109  double cosVal = std::cos(rotation);
110 
111  float BoxDistX = GetPositionX() - center.GetPositionX();
112  float BoxDistY = GetPositionY() - center.GetPositionY();
113 
114  float rotX = float(center.GetPositionX() + BoxDistX * cosVal - BoxDistY*sinVal);
115  float rotY = float(center.GetPositionY() + BoxDistY * cosVal + BoxDistX*sinVal);
116 
117  // box edges are parallel to coordiante axis, so we can treat every dimension independently :D
118  float dz = GetPositionZ() - center.GetPositionZ();
119  float dx = rotX - center.GetPositionX();
120  float dy = rotY - center.GetPositionY();
121  if ((std::fabs(dx) > xradius) ||
122  (std::fabs(dy) > yradius) ||
123  (std::fabs(dz) > zradius))
124  return false;
125 
126  return true;
127 }
#define M_PI
Definition: Common.h:163
float GetOrientation() const
Definition: Position.h:107
float GetPositionY() const
Definition: Position.h:105
float GetPositionZ() const
Definition: Position.h:106
float GetPositionX() const
Definition: Position.h:104

+ Here is the call graph for this function:

static float Position::NormalizeOrientation ( float  o)
inlinestatic
212  {
213  // fmod only supports positive numbers. Thus we have
214  // to emulate negative numbers
215  if (o < 0)
216  {
217  float mod = o *-1;
218  mod = std::fmod(mod, 2.0f * static_cast<float>(M_PI));
219  mod = -mod + 2.0f * static_cast<float>(M_PI);
220  return mod;
221  }
222  return std::fmod(o, 2.0f * static_cast<float>(M_PI));
223  }
#define M_PI
Definition: Common.h:163

+ Here is the caller graph for this function:

bool Position::operator!= ( Position const a)
inline
63  {
64  return !(operator==(a));
65  }
bool operator==(Position const &a)
Definition: Position.cpp:24

+ Here is the call graph for this function:

bool Position::operator== ( Position const a)
25 {
26  return (G3D::fuzzyEq(a.m_positionX, m_positionX) &&
27  G3D::fuzzyEq(a.m_positionY, m_positionY) &&
28  G3D::fuzzyEq(a.m_positionZ, m_positionZ) &&
29  G3D::fuzzyEq(a.m_orientation, m_orientation));
30 }
float m_positionY
Definition: Position.h:53
float m_positionX
Definition: Position.h:52
float m_positionZ
Definition: Position.h:54
bool fuzzyEq(double a, double b)
Definition: g3dmath.h:857
float m_orientation
Definition: Position.h:57

+ Here is the call graph for this function:

Position::PositionXYStreamer Position::PositionXYStream ( )
inline
126 { return PositionXYStreamer(*this); }
Position::PositionXYZOStreamer Position::PositionXYZOStream ( )
inline
128 { return PositionXYZOStreamer(*this); }

+ Here is the caller graph for this function:

Position::PositionXYZStreamer Position::PositionXYZStream ( )
inline
127 { return PositionXYZStreamer(*this); }

+ Here is the caller graph for this function:

void Position::Relocate ( float  x,
float  y 
)
inline
68  {
70  }
float m_positionY
Definition: Position.h:53
float m_positionX
Definition: Position.h:52
G3D::int16 y
Definition: Vector2int16.h:38
G3D::int16 x
Definition: Vector2int16.h:37
void Position::Relocate ( float  x,
float  y,
float  z 
)
inline
73  {
75  }
float m_positionY
Definition: Position.h:53
float m_positionX
Definition: Position.h:52
G3D::int16 z
Definition: Vector3int16.h:46
G3D::int16 y
Definition: Vector2int16.h:38
float m_positionZ
Definition: Position.h:54
G3D::int16 x
Definition: Vector2int16.h:37
void Position::Relocate ( float  x,
float  y,
float  z,
float  orientation 
)
inline
78  {
79  m_positionX = x; m_positionY = y; m_positionZ = z; SetOrientation(orientation);
80  }
float m_positionY
Definition: Position.h:53
void SetOrientation(float orientation)
Definition: Position.h:99
float m_positionX
Definition: Position.h:52
G3D::int16 z
Definition: Vector3int16.h:46
G3D::int16 y
Definition: Vector2int16.h:38
float m_positionZ
Definition: Position.h:54
G3D::int16 x
Definition: Vector2int16.h:37
void Position::Relocate ( Position const pos)
inline
83  {
84  m_positionX = pos.m_positionX; m_positionY = pos.m_positionY; m_positionZ = pos.m_positionZ; SetOrientation(pos.m_orientation);
85  }
float m_positionY
Definition: Position.h:53
void SetOrientation(float orientation)
Definition: Position.h:99
float m_positionX
Definition: Position.h:52
float m_positionZ
Definition: Position.h:54
void Position::Relocate ( Position const pos)
inline
88  {
89  m_positionX = pos->m_positionX; m_positionY = pos->m_positionY; m_positionZ = pos->m_positionZ; SetOrientation(pos->m_orientation);
90  }
float m_positionY
Definition: Position.h:53
void SetOrientation(float orientation)
Definition: Position.h:99
float m_positionX
Definition: Position.h:52
float m_positionZ
Definition: Position.h:54
void Position::Relocate ( G3D::Vector3 const pos)
inline
93  {
94  m_positionX = pos.x; m_positionY = pos.y; m_positionZ = pos.z;
95  }
float m_positionY
Definition: Position.h:53
float m_positionX
Definition: Position.h:52
float m_positionZ
Definition: Position.h:54
void Position::RelocateOffset ( Position const offset)
33 {
34  m_positionX = GetPositionX() + (offset.GetPositionX() * std::cos(GetOrientation()) + offset.GetPositionY() * std::sin(GetOrientation() + float(M_PI)));
35  m_positionY = GetPositionY() + (offset.GetPositionY() * std::cos(GetOrientation()) + offset.GetPositionX() * std::sin(GetOrientation()));
36  m_positionZ = GetPositionZ() + offset.GetPositionZ();
37  SetOrientation(GetOrientation() + offset.GetOrientation());
38 }
#define M_PI
Definition: Common.h:163
float m_positionY
Definition: Position.h:53
void SetOrientation(float orientation)
Definition: Position.h:99
float m_positionX
Definition: Position.h:52
float GetOrientation() const
Definition: Position.h:107
float GetPositionY() const
Definition: Position.h:105
float GetPositionZ() const
Definition: Position.h:106
float m_positionZ
Definition: Position.h:54
float GetPositionX() const
Definition: Position.h:104

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void Position::SetOrientation ( float  orientation)
inline
100  {
101  m_orientation = NormalizeOrientation(orientation);
102  }
static float NormalizeOrientation(float o)
Definition: Position.h:211
float m_orientation
Definition: Position.h:57

+ Here is the caller graph for this function:

std::string Position::ToString ( ) const
161 {
162  std::stringstream sstr;
163  sstr << "X: " << m_positionX << " Y: " << m_positionY << " Z: " << m_positionZ << " O: " << m_orientation;
164  return sstr.str();
165 }
float m_positionY
Definition: Position.h:53
float m_positionX
Definition: Position.h:52
float m_positionZ
Definition: Position.h:54
float m_orientation
Definition: Position.h:57

+ Here is the caller graph for this function:

Member Data Documentation

float Position::m_orientation
private
float Position::m_positionX
float Position::m_positionY
float Position::m_positionZ

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