gwnavruntime/math/vec3i.h Source File

vec3i.h
Go to the documentation of this file.
1 /*
2 * Copyright 2015 Autodesk, Inc. All rights reserved.
3 * Use of this software is subject to the terms of the Autodesk license agreement and any attachments or Appendices thereto provided at the time of installation or download,
4 * or which otherwise accompanies this software in either electronic or hard copy form, or which is signed by you and accepted by Autodesk.
5 */
6 
7 
8 // primary contact: GUAL - secondary contact: NOBODY
9 #ifndef Navigation_Vec3i_H
10 #define Navigation_Vec3i_H
11 
13 
14 
15 namespace Kaim
16 {
17 
18 
21 class Vec3i
22 {
23  KY_DEFINE_NEW_DELETE_OPERATORS(Stat_Default_Mem)
24 
25 public:
26  // ---------------------------------- Creation & Initialization ----------------------------------
27 
29  Vec3i() : x(0), y(0), z(0) {}
30 
35  Vec3i(KyInt32 _x, KyInt32 _y, KyInt32 _z) : x(_x), y(_y), z(_z) {}
36 
40  explicit Vec3i(KyInt32* coords) { Set(coords); }
41 
46  KY_INLINE void Set(KyInt32 _x, KyInt32 _y, KyInt32 _z) { x = _x; y = _y; z = _z; }
47 
51  KY_INLINE void Set(const Vec2i& v, KyInt32 _z) { x = v.x; y = v.y; z = _z; }
52 
56  KY_INLINE void Set(KyInt32* coords) { x = coords[0]; y = coords[1]; z = coords[2]; }
57 
58 
59  // -------------------------- Operators --------------------------------
60 
63  KY_INLINE KyInt32& operator[](KyInt32 i) { return (&x)[i]; }
64 
67  KY_INLINE KyInt32 operator[](KyInt32 i) const { return (&x)[i]; }
68 
70  KY_INLINE bool operator==(const Vec3i& v) const { return x == v.x && y == v.y && z == v.z; }
71 
73  KY_INLINE bool operator!=(const Vec3i& v) const { return x != v.x || y != v.y || z != v.z; }
74 
76  bool operator<(const Vec3i& v) const
77  {
78  if (x < v.x) return true;
79  if (x > v.x) return false;
80  if (y < v.y) return true;
81  if (y > v.y) return false;
82  return (z < v.z);
83  }
84 
86  KY_INLINE Vec3i& operator*=(KyInt32 s) { x *= s; y *= s; z *= s; return *this; }
87 
89  KY_INLINE Vec3i& operator/=(KyInt32 d) { x /= d; y /= d; z /= d; return *this; }
90 
93  KY_INLINE Vec3i& operator+=(const Vec3i& v) { x += v.x; y += v.y; z += v.z; return *this; }
94 
97  KY_INLINE Vec3i& operator-=(const Vec3i& v) { x -= v.x; y -= v.y; z -= v.z; return *this; }
98 
100  KY_INLINE Vec3i operator*(KyInt32 s) const { return Vec3i(x * s, y * s, z * s); }
101 
103  KY_INLINE Vec3i operator/(KyInt32 d) const { return Vec3i(x / d, y / d, z / d); }
104 
107  KY_INLINE Vec3i operator+(const Vec3i& v) const { return Vec3i(x + v.x, y + v.y, z + v.z); }
108 
111  KY_INLINE Vec3i operator-(const Vec3i& v) const { return Vec3i(x - v.x, y - v.y, z - v.z); }
112 
114  KY_INLINE Vec3i operator-() const { return Vec3i(-x, -y, -z); }
115 
117  KY_INLINE KyInt32 operator*(const Vec3i& v) const { return x * v.x + y * v.y + z * v.z; } // DOT PRODUCT
118 
120  KY_INLINE Vec3i operator^(const Vec3i& v) const { return Vec3i( (y * v.z - z * v.y), (z * v.x - x * v.z), (x * v.y - y * v.x) ); } // CROSS PRODUCT
121 
122 
123  // -------------------------- Main interface --------------------------------
124 
131  KY_INLINE KyInt32 Orient2d(const Vec3i& A, const Vec3i& B) const { return (A.x - x) * (B.y - y) - (B.x - x) * (A.y - y); }
132 
135  KY_INLINE bool IsOnLeftSide(const Vec3i& A, const Vec3i& B) const { return Orient2d(A, B) >= 0; }
136 
139  KY_INLINE bool IsStrictlyOnLeftSide(const Vec3i& A, const Vec3i& B) const { return Orient2d(A, B) > 0; }
140 
142  KY_INLINE KyInt32 GetSquareLength() const { return x * x + y * y + z * z; }
143 
145  // -------------------------- Static methods --------------------------------
146 
148  static KY_INLINE Vec3i UnitX() { return Vec3i(1, 0, 0); }
149 
151  static KY_INLINE Vec3i UnitY() { return Vec3i(0, 1, 0); }
154  static KY_INLINE Vec3i UnitZ() { return Vec3i(0, 0, 1); }
156 
157  // ---------------------------------- Public Data Members ----------------------------------
158 
159  KyInt32 x;
160  KyInt32 y;
161  KyInt32 z;
162 };
163 
166 KY_INLINE void SwapEndianness(Endianness::Target e, Vec3i& self)
167 {
168  SwapEndianness(e, self.x);
169  SwapEndianness(e, self.y);
170  SwapEndianness(e, self.z);
171 }
172 
173 
174 }
175 
176 
177 #endif
178 
KyInt32 z
The size of the vector along the Z axis.
Definition: vec3i.h:182
Vec3i()
Creates a vector with coordinates (0,0,0).
Definition: vec3i.h:34
Vec3i operator-() const
Negates the X, Y and Z coordinates of this vector, effectively flipping it around the origin...
Definition: vec3i.h:123
This class defines a three-dimensional vector whose coordinates are stored using 32-bit integers...
Definition: vec3i.h:21
Vec3i & operator+=(const Vec3i &v)
Adds the X coordinate of v to the X coordinate of this vector, adds the Y coordinate of v to the Y co...
Definition: vec3i.h:102
Vec3i operator+(const Vec3i &v) const
Adds the X coordinate of v to the X coordinate of this vector, adds the Y coordinate of v to the Y co...
Definition: vec3i.h:116
void Set(const Vec2i &v, KyInt32 _z)
Sets the coordinates of the vector to match the specified values.
Definition: vec3i.h:56
bool operator<(const Vec3i &v) const
Returns true if the size of this vector along all three of the X, Y and Z axes is less than that of v...
Definition: vec3i.h:85
KyInt32 Orient2d(const Vec3i &A, const Vec3i &B) const
Indicates whether or not the polyline formed by (A to B to this vector ) outlines a triangle in count...
Definition: vec3i.h:144
bool operator==(const Vec3i &v) const
Returns true if this object contains the same coordinates as v.
Definition: vec3i.h:79
Vec3i operator^(const Vec3i &v) const
Returns the cross product of this vector and v.
Definition: vec3i.h:129
Vec3i & operator*=(KyInt32 s)
Multiplies the X, Y and Z coordinates of this vector by the specified value.
Definition: vec3i.h:95
int KyInt32
Type used internally to represent a 32-bit integer.
Definition: types.h:35
KyInt32 x
The size of the vector along the X axis.
Definition: vec2i.h:283
KyInt32 x
The size of the vector along the X axis.
Definition: vec3i.h:180
Vec3i operator/(KyInt32 d) const
Divides the X, Y and Z coordinates of this vector by the specified value.
Definition: vec3i.h:112
Vec3i & operator-=(const Vec3i &v)
Subtracts the X coordinate of v from the X coordinate of this vector, subtracts the Y coordinate of v...
Definition: vec3i.h:106
static Vec3i UnitZ()
Returns the normalized orientation of the Y axis.
Definition: vec3i.h:171
KyInt32 GetSquareLength() const
Returns the square of the magnitude of the vector.
Definition: vec3i.h:155
KyInt32 y
The size of the vector along the Y axis.
Definition: vec2i.h:284
Target
Enumerates the possible endianness types relative to the current platform.
Definition: endianness.h:35
static Vec3i UnitX()
Returns the normalized orientation of the X axis.
Definition: vec3i.h:165
Vec3i & operator/=(KyInt32 d)
Divides the X, Y and Z coordinates of this vector by the specified value.
Definition: vec3i.h:98
bool IsStrictlyOnLeftSide(const Vec3i &A, const Vec3i &B) const
Returns true if this vector is on the left side when moving from A to B, but not if this vector is on...
Definition: vec3i.h:152
KyInt32 y
The size of the vector along the Y axis.
Definition: vec3i.h:181
This class defines a two-dimensional vector whose coordinates are stored using 32-bit integers...
Definition: vec2i.h:26
Definition: gamekitcrowddispersion.h:20
static Vec3i UnitY()
Returns the normalized orientation of the Y axis.
Definition: vec3i.h:168
#define KY_DEFINE_NEW_DELETE_OPERATORS(MemStat)
This macro defines new and delete operators.
Definition: memory.h:137
Vec3i(KyInt32 _x, KyInt32 _y, KyInt32 _z)
Creates a vector with the specified coordinates.
Definition: vec3i.h:40
void Set(KyInt32 _x, KyInt32 _y, KyInt32 _z)
Sets the coordinates of the vector to match the specified values.
Definition: vec3i.h:51
bool operator!=(const Vec3i &v) const
Returns true if this object contains at least one different coordinate from v.
Definition: vec3i.h:82
Vec3i operator*(KyInt32 s) const
Multiplies the X, Y and Z coordinates of this vector by the specified value.
Definition: vec3i.h:109
KyInt32 & operator[](KyInt32 i)
Retrieves the size of the vector around one of its axes.
Definition: vec3i.h:72
bool IsOnLeftSide(const Vec3i &A, const Vec3i &B) const
Returns true if this vector is on the left side when moving from A to B, or if this vector is on the ...
Definition: vec3i.h:148