gwnavruntime/math/vec3i.h Source File

vec3i.h
Go to the documentation of this file.
1 /*
2 * Copyright 2016 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 #pragma once
8 
10 
11 namespace Kaim
12 {
13 
15 class Vec3i
16 {
17  KY_DEFINE_NEW_DELETE_OPERATORS(Stat_Default_Mem)
18 
19 public:
20  // ---------------------------------- Init ----------------------------------
21 
22  Vec3i() : x(0), y(0), z(0) {}
23  Vec3i(KyInt32 _x, KyInt32 _y, KyInt32 _z) : x(_x), y(_y), z(_z) {}
24  explicit Vec3i(KyInt32* coords) { Set(coords); }
25 
26  void Set(KyInt32 _x, KyInt32 _y, KyInt32 _z) { x = _x; y = _y; z = _z; }
27  void Set(const Vec2i& v, KyInt32 _z) { x = v.x; y = v.y; z = _z; }
28  void Set(KyInt32* coords) { x = coords[0]; y = coords[1]; z = coords[2]; }
29 
30  // -------------------------- Operators --------------------------------
31 
32  KyInt32& operator[](KyInt32 i) { return (&x)[i]; }
33  KyInt32 operator[](KyInt32 i) const { return (&x)[i]; }
34 
35  bool operator==(const Vec3i& v) const { return x == v.x && y == v.y && z == v.z; }
36  bool operator!=(const Vec3i& v) const { return x != v.x || y != v.y || z != v.z; }
37 
38  bool operator<(const Vec3i& v) const;
39  bool operator>(const Vec3i& v) const;
40  bool operator<=(const Vec3i& v) const { return !operator>(v); }
41  bool operator>=(const Vec3i& v) const { return !operator<(v); }
42 
43  Vec3i& operator*=(KyInt32 s) { x *= s; y *= s; z *= s; return *this; }
44  Vec3i& operator/=(KyInt32 d) { x /= d; y /= d; z /= d; return *this; }
45  Vec3i& operator+=(const Vec3i& v) { x += v.x; y += v.y; z += v.z; return *this; }
46  Vec3i& operator-=(const Vec3i& v) { x -= v.x; y -= v.y; z -= v.z; return *this; }
47  Vec3i operator*(KyInt32 s) const { return Vec3i(x * s, y * s, z * s); }
48  Vec3i operator/(KyInt32 d) const { return Vec3i(x / d, y / d, z / d); }
49 
50  Vec3i operator+(const Vec3i& v) const { return Vec3i(x + v.x, y + v.y, z + v.z); }
51  Vec3i operator-(const Vec3i& v) const { return Vec3i(x - v.x, y - v.y, z - v.z); }
52  Vec3i operator-() const { return Vec3i(-x, -y, -z); }
53 
54  // ------------------------------ SquareLength -----------------------------
55 
56  KyInt32 GetSquareLength() const { return x * x + y * y + z * z; }
57 
58  // ------------------------------ Side -----------------------------
59 
61  KyInt32 Orient2d(const Vec3i& A, const Vec3i& B) const { return (A.x - x) * (B.y - y) - (B.x - x) * (A.y - y); }
62  bool IsOnLeftSide(const Vec3i& A, const Vec3i& B) const { return Orient2d(A, B) >= 0; }
63  bool IsStrictlyOnLeftSide(const Vec3i& A, const Vec3i& B) const { return Orient2d(A, B) > 0; }
64 
65  // -------------------------- Unit --------------------------------
66 
67  static Vec3i UnitX() { return Vec3i(1, 0, 0); }
68  static Vec3i UnitY() { return Vec3i(0, 1, 0); }
69  static Vec3i UnitZ() { return Vec3i(0, 0, 1); }
70 
71  // ---------------------------------- Data ----------------------------------
72 
73  KyInt32 x;
74  KyInt32 y;
75  KyInt32 z;
76 };
77 
78 inline bool Vec3i::operator<(const Vec3i& v) const
79 {
80  if (x < v.x) return true;
81  if (x > v.x) return false;
82  if (y < v.y) return true;
83  if (y > v.y) return false;
84  return (z < v.z);
85 }
86 
87 inline bool Vec3i::operator>(const Vec3i& v) const
88 {
89  if (x > v.x) return true;
90  if (x < v.x) return false;
91  if (y > v.y) return true;
92  if (y < v.y) return false;
93  return (z > v.z);
94 }
95 
96 inline void SwapEndianness(Endianness::Target e, Vec3i& self)
97 {
98  SwapEndianness(e, self.x);
99  SwapEndianness(e, self.y);
100  SwapEndianness(e, self.z);
101 }
102 
103 }
104 
105 
106 
3d vector using 32bits integer
Definition: vec3i.h:15
bool operator<(const Vec3i &v) const
x is compared first. ex: {1, 5, 0} < {2,="" 0,="" 0}.="" />
Definition: vec3i.h:78
KyInt32 Orient2d(const Vec3i &A, const Vec3i &B) const
CrossProduct(MA, MB) where M=*this.
Definition: vec3i.h:61
#define KY_DEFINE_NEW_DELETE_OPERATORS(MemStat)
This macro defines new and delete operators.
Definition: memory.h:132
Target
Enumerates the possible endianness types relative to the current platform.
Definition: endianness.h:27
2d vector using KyInt32
Definition: vec2i.h:18
The Autodesk Navigation namespace.
Definition: gamekitcrowddispersion.cpp:17
std::int32_t KyInt32
int32_t
Definition: types.h:24