TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Vector3int32.h
Go to the documentation of this file.
1 
12 #ifndef G3D_Vector3int32_h
13 #define G3D_Vector3int32_h
14 
15 #include "G3D/platform.h"
16 #include "G3D/g3dmath.h"
17 #include "G3D/HashTrait.h"
18 #include "G3D/Crypto.h"
19 
20 namespace G3D {
21 
22  class Any;
23 
30 private:
31  // Hidden operators
32  bool operator<(const Vector3int32&) const;
33  bool operator>(const Vector3int32&) const;
34  bool operator<=(const Vector3int32&) const;
35  bool operator>=(const Vector3int32&) const;
36 
37 public:
38  G3D::int32 x;
39  G3D::int32 y;
40  G3D::int32 z;
41 
42  Vector3int32() : x(0), y(0), z(0) {}
43  Vector3int32(int _x, int _y, int _z) : x(_x), y(_y), z(_z) {}
44  Vector3int32(const class Vector2int32& v, int _z);
45  Vector3int32(const class Vector2int16& v, int _z);
46  Vector3int32(const class Vector3int16& v);
47  Vector3int32(const Any& any);
48  Any toAny() const;
49 
51  explicit Vector3int32(const class Vector3& v);
52  explicit Vector3int32(class BinaryInput& bi);
53 
54  static Vector3int32 truncate(const class Vector3& v);
55 
56  bool nonZero() const {
57  return (x != 0) || (y != 0) || (z != 0);
58  }
59 
60  void serialize(class BinaryOutput& bo) const;
61  void deserialize(class BinaryInput& bi);
62 
63  inline G3D::int32& operator[] (int i) {
64  debugAssert(i <= 2);
65  return ((G3D::int32*)this)[i];
66  }
67 
68  inline const G3D::int32& operator[] (int i) const {
69  debugAssert(i <= 2);
70  return ((G3D::int32*)this)[i];
71  }
72 
73  inline Vector3int32 operator+(const Vector3int32& other) const {
74  return Vector3int32(x + other.x, y + other.y, z + other.z);
75  }
76 
77  inline Vector3int32 operator-(const Vector3int32& other) const {
78  return Vector3int32(x - other.x, y - other.y, z - other.z);
79  }
80 
81  inline Vector3int32 operator*(const Vector3int32& other) const {
82  return Vector3int32(x * other.x, y * other.y, z * other.z);
83  }
84 
85  inline Vector3int32 operator*(const int s) const {
86  return Vector3int32(x * s, y * s, z * s);
87  }
88 
90  inline Vector3int32 operator/(const Vector3int32& other) const {
91  return Vector3int32(x / other.x, y / other.y, z / other.z);
92  }
93 
95  inline Vector3int32 operator/(const int s) const {
96  return Vector3int32(x / s, y / s, z / s);
97  }
98 
100  x += other.x;
101  y += other.y;
102  z += other.z;
103  return *this;
104  }
105 
107  x -= other.x;
108  y -= other.y;
109  z -= other.z;
110  return *this;
111  }
112 
114  x *= other.x;
115  y *= other.y;
116  z *= other.z;
117  return *this;
118  }
119 
120  bool operator== (const Vector3int32& rkVector) const {
121  return ( x == rkVector.x && y == rkVector.y && z == rkVector.z );
122  }
123 
124  bool operator!= (const Vector3int32& rkVector) const {
125  return ( x != rkVector.x || y != rkVector.y || z != rkVector.z );
126  }
127 
128  Vector3int32 max(const Vector3int32& v) const {
129  return Vector3int32(iMax(x, v.x), iMax(y, v.y), iMax(z, v.z));
130  }
131 
132  Vector3int32 min(const Vector3int32& v) const {
133  return Vector3int32(iMin(x, v.x), iMin(y, v.y), iMin(z, v.z));
134  }
135 
136  Vector3int32 operator-() const {
137  return Vector3int32(-x, -y, -z);
138  }
139 
140  std::string toString() const;
141 
142  Vector3int32 operator<<(int i) const {
143  return Vector3int32(x << i, y << i, z << i);
144  }
145 
146  Vector3int32 operator>>(int i) const {
147  return Vector3int32(x >> i, y >> i, z >> i);
148  }
149 
151  return Vector3int32(x >> v.x, y >> v.y, z >> v.z);
152  }
153 
155  return Vector3int32(x << v.x, y << v.y, z << v.z);
156  }
157 
158  Vector3int32 operator&(int16 i) const {
159  return Vector3int32(x & i, y & i, z & i);
160  }
161 
162  // 2-char swizzles
163 
164  Vector2int32 xx() const;
165  Vector2int32 yx() const;
166  Vector2int32 zx() const;
167  Vector2int32 xy() const;
168  Vector2int32 yy() const;
169  Vector2int32 zy() const;
170  Vector2int32 xz() const;
171  Vector2int32 yz() const;
172  Vector2int32 zz() const;
173 }
175 
177 
179 
180 } // namespace G3D
181 
182 template <> struct HashTrait<G3D::Vector3int32> {
183  static size_t hashCode(const G3D::Vector3int32& key) {
184  return G3D::superFastHash(&key, sizeof(key));
185  //return G3D::Crypto::crc32(&key, sizeof(key));
186  /*
187  // Mask for the top bit of a uint32
188  const G3D::uint32 top = (1UL << 31);
189  // Mask for the bottom 10 bits of a uint32
190  const G3D::uint32 bot = 0x000003FF;
191  return static_cast<size_t>(((key.x & top) | ((key.y & top) >> 1) | ((key.z & top) >> 2)) |
192  (((key.x & bot) << 19) ^ ((key.y & bot) << 10) ^ (key.z & bot)));
193  */
194  }
195 };
196 
197 #endif
Vector2int32 zz() const
Vector3int32
Definition: Vector3int32.h:29
unorm16 operator-(const unorm16 other) const
Definition: unorm16.h:131
class Any toAny() const
unorm16 & operator+=(const unorm16 other)
Definition: unorm16.h:126
bool operator!=(const NetAddress &a, const NetAddress &b)
Definition: NetAddress.h:128
uint32_t superFastHash(const void *_data, size_t numBytes)
A hash function that is faster than CRC32 for arbitrary long strings http://www.azillionmonkeys.com/qed/hash.html by Paul Hsieh.
Definition: HashTrait.h:35
bool operator<=(const unorm16 other) const
Definition: unorm16.h:110
Definition: HashTrait.h:105
Definition: AABox.h:25
bool any(float x)
Definition: g3dmath.h:424
unorm16 operator+(const unorm16 other) const
Definition: unorm16.h:122
int iFloor(double fValue)
Definition: g3dmath.h:603
bool operator<(const unorm16 other) const
Definition: unorm16.h:102
Vector3int32 Point3int32
Definition: Vector3int32.h:176
void deserialize(std::string &s, BinaryInput &b)
Definition: serialize.h:16
Vector2int32 yy() const
G3D::Color3 operator/(float s, const G3D::Color3 &c)
Definition: Color3.h:287
bool operator==(const NetAddress &a, const NetAddress &b)
Definition: NetAddress.h:123
T max(const T &x, const T &y)
Definition: g3dmath.h:320
Vector2int32 xy() const
Definition: Vector3.h:58
static size_t hashCode(const G3D::Vector3int32 &key)
Definition: Vector3int32.h:183
T min(const T &x, const T &y)
Definition: g3dmath.h:305
unorm16 & operator-=(const unorm16 other)
Definition: unorm16.h:135
#define G3D_END_PACKED_CLASS(byteAlign)
Definition: platform.h:357
void serialize(const std::string &s, BinaryOutput &b)
Definition: serialize.h:12
Vector2int32 yx() const
Vector2int32 zx() const
#define debugAssert(exp)
Definition: debugAssert.h:160
G3D::int16 z
Definition: Vector3int16.h:46
std::string toString() const
Vector2int32 zy() const
Vector3int16 operator&(int16 i) const
Definition: Vector3int16.h:149
unorm16 & operator*=(const int i)
Definition: unorm16.h:144
G3D::int16 y
Definition: Vector2int16.h:38
G3D::int16 & operator[](int i)
Definition: Vector2int16.h:51
bool operator>=(const unorm16 other) const
Definition: unorm16.h:106
static Vector3int32 truncate(const class Vector3 &v)
Definition: Vector3int32.cpp:86
bool nonZero() const
Definition: Vector3int32.h:56
bool operator>(const unorm16 other) const
Definition: unorm16.h:98
#define G3D_BEGIN_PACKED_CLASS(byteAlign)
Definition: platform.h:345
Vector2int32 yz() const
std::ostream & operator<<(std::ostream &os, const NetAddress &)
Definition: NetworkDevice.cpp:26
unorm16 operator>>(const int i) const
Definition: unorm16.h:167
int32_t int32
Definition: g3dmath.h:167
Vector2int32 xz() const
int16_t int16
Definition: Define.h:147
#define const
Definition: zconf.h:217
G3D::int16 x
Definition: Vector2int16.h:37
int iMax(int x, int y)
Definition: g3dmath.h:759
Vector2int32 xx() const
Definition: Vector2int16.h:22
G3D::Color3 operator*(float s, const G3D::Color3 &c)
Definition: Color3.h:275
int iMin(int x, int y)
Definition: g3dmath.h:753