1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
|
/**
@file G3D/Vector3int32.h
@maintainer Morgan McGuire, matrix@brown.edu
@created 2008-07-01
@edited 2011-01-01
Copyright 2000-2012, Morgan McGuire.
All rights reserved.
*/
#ifndef G3D_Vector3int32_h
#define G3D_Vector3int32_h
#include "G3D/platform.h"
#include "G3D/g3dmath.h"
#include "G3D/HashTrait.h"
#include "G3D/Crypto.h"
namespace G3D {
class Any;
/**
\ Vector3int32
A Vector3 that packs its fields into uint32s.
*/
G3D_BEGIN_PACKED_CLASS(4)
Vector3int32 {
private:
// Hidden operators
bool operator<(const Vector3int32&) const;
bool operator>(const Vector3int32&) const;
bool operator<=(const Vector3int32&) const;
bool operator>=(const Vector3int32&) const;
public:
G3D::int32 x;
G3D::int32 y;
G3D::int32 z;
Vector3int32() : x(0), y(0), z(0) {}
Vector3int32(int _x, int _y, int _z) : x(_x), y(_y), z(_z) {}
Vector3int32(const class Vector2int32& v, int _z);
Vector3int32(const class Vector2int16& v, int _z);
Vector3int32(const class Vector3int16& v);
Vector3int32(const Any& any);
Any toAny() const;
/** Rounds to the nearest int */
explicit Vector3int32(const class Vector3& v);
explicit Vector3int32(class BinaryInput& bi);
static Vector3int32 truncate(const class Vector3& v);
bool nonZero() const {
return (x != 0) || (y != 0) || (z != 0);
}
void serialize(class BinaryOutput& bo) const;
void deserialize(class BinaryInput& bi);
inline G3D::int32& operator[] (int i) {
debugAssert(i <= 2);
return ((G3D::int32*)this)[i];
}
inline const G3D::int32& operator[] (int i) const {
debugAssert(i <= 2);
return ((G3D::int32*)this)[i];
}
inline Vector3int32 operator+(const Vector3int32& other) const {
return Vector3int32(x + other.x, y + other.y, z + other.z);
}
inline Vector3int32 operator-(const Vector3int32& other) const {
return Vector3int32(x - other.x, y - other.y, z - other.z);
}
inline Vector3int32 operator*(const Vector3int32& other) const {
return Vector3int32(x * other.x, y * other.y, z * other.z);
}
inline Vector3int32 operator*(const int s) const {
return Vector3int32(x * s, y * s, z * s);
}
/** Integer division */
inline Vector3int32 operator/(const Vector3int32& other) const {
return Vector3int32(x / other.x, y / other.y, z / other.z);
}
/** Integer division */
inline Vector3int32 operator/(const int s) const {
return Vector3int32(x / s, y / s, z / s);
}
Vector3int32& operator+=(const Vector3int32& other) {
x += other.x;
y += other.y;
z += other.z;
return *this;
}
Vector3int32& operator-=(const Vector3int32& other) {
x -= other.x;
y -= other.y;
z -= other.z;
return *this;
}
Vector3int32& operator*=(const Vector3int32& other) {
x *= other.x;
y *= other.y;
z *= other.z;
return *this;
}
bool operator== (const Vector3int32& rkVector) const {
return ( x == rkVector.x && y == rkVector.y && z == rkVector.z );
}
bool operator!= (const Vector3int32& rkVector) const {
return ( x != rkVector.x || y != rkVector.y || z != rkVector.z );
}
Vector3int32 max(const Vector3int32& v) const {
return Vector3int32(iMax(x, v.x), iMax(y, v.y), iMax(z, v.z));
}
Vector3int32 min(const Vector3int32& v) const {
return Vector3int32(iMin(x, v.x), iMin(y, v.y), iMin(z, v.z));
}
Vector3int32 operator-() const {
return Vector3int32(-x, -y, -z);
}
std::string toString() const;
Vector3int32 operator<<(int i) const {
return Vector3int32(x << i, y << i, z << i);
}
Vector3int32 operator>>(int i) const {
return Vector3int32(x >> i, y >> i, z >> i);
}
Vector3int32 operator>>(const Vector3int32& v) const {
return Vector3int32(x >> v.x, y >> v.y, z >> v.z);
}
Vector3int32 operator<<(const Vector3int32& v) const {
return Vector3int32(x << v.x, y << v.y, z << v.z);
}
Vector3int32 operator&(int16 i) const {
return Vector3int32(x & i, y & i, z & i);
}
// 2-char swizzles
Vector2int32 xx() const;
Vector2int32 yx() const;
Vector2int32 zx() const;
Vector2int32 xy() const;
Vector2int32 yy() const;
Vector2int32 zy() const;
Vector2int32 xz() const;
Vector2int32 yz() const;
Vector2int32 zz() const;
}
G3D_END_PACKED_CLASS(4)
typedef Vector3int32 Point3int32;
Vector3int32 iFloor(const Vector3&);
} // namespace G3D
template <> struct HashTrait<G3D::Vector3int32> {
static size_t hashCode(const G3D::Vector3int32& key) {
return G3D::superFastHash(&key, sizeof(key));
//return G3D::Crypto::crc32(&key, sizeof(key));
/*
// Mask for the top bit of a uint32
const G3D::uint32 top = (1UL << 31);
// Mask for the bottom 10 bits of a uint32
const G3D::uint32 bot = 0x000003FF;
return static_cast<size_t>(((key.x & top) | ((key.y & top) >> 1) | ((key.z & top) >> 2)) |
(((key.x & bot) << 19) ^ ((key.y & bot) << 10) ^ (key.z & bot)));
*/
}
};
#endif
|