23 Vec3f() : x(0.0f), y(0.0f), z(0.0f) {}
26 explicit Vec3f(
const Vec2f& v) : x(v.x), y(v.y), z(0.0f) {}
30 void Set(
const KyFloat32* coords) { x = coords[0]; y = coords[1]; z = coords[2]; }
31 void Set(
const Vec2f& v) { x = v.x; y = v.y; z = 0.0f; }
34 void Clear() { x = 0.0f; y = 0.0f; z = 0.0f; }
41 bool operator==(
const Vec3f& v)
const {
return x == v.x && y == v.y && z == v.z; }
42 bool operator!=(
const Vec3f& v)
const {
return x != v.x || y != v.y || z != v.z; }
45 bool operator>(
const Vec3f& v)
const;
46 bool operator<=(
const Vec3f& v)
const {
return !operator>(v); }
49 Vec3f& operator*=(
KyFloat32 s) { x *= s; y *= s; z *= s;
return *
this; }
51 Vec3f& operator+=(
const Vec3f& v) { x += v.x; y += v.y; z += v.z;
return *
this; }
52 Vec3f& operator-=(
const Vec3f& v) { x -= v.x; y -= v.y; z -= v.z;
return *
this; }
56 Vec3f operator+(
const Vec3f& v)
const {
return Vec3f(x + v.x, y + v.y, z + v.z); }
57 Vec3f operator-(
const Vec3f& v)
const {
return Vec3f(x - v.x, y - v.y, z - v.z); }
58 Vec3f operator-()
const {
return Vec3f(-x, -y, -z); }
62 Vec3f& operator+=(
const Vec2f& v) { x += v.x; y += v.y;
return *
this; }
63 Vec3f& operator-=(
const Vec2f& v) { x -= v.x; y -= v.y;
return *
this; }
64 Vec3f operator+(
const Vec2f& v)
const {
return Vec3f(x + v.x, y + v.y, z); }
65 Vec3f operator-(
const Vec2f& v)
const {
return Vec3f(x - v.x, y - v.y, z); }
67 Vec2f Get2d()
const {
return Vec2f(x, y); }
75 KyFloat32 GetSquareLength()
const {
return x * x + y * y + z * z; }
76 KyFloat32 GetLength()
const {
return Sqrtf(x * x + y * y + z * z); }
80 bool IsNormalized()
const {
return IsEpsilonEqual(GetSquareLength(), 1.0f); }
84 KyFloat32 SqLength()
const {
return GetSquareLength(); }
85 KyFloat32 Length()
const {
return GetLength(); }
100 bool IsZero()
const {
return x == 0.0f && y == 0.0f && z == 0.0f; }
117 SwapEndianness(e,
self.x);
118 SwapEndianness(e,
self.y);
119 SwapEndianness(e,
self.z);
122 template <
class OSTREAM>
123 inline OSTREAM& operator<<(OSTREAM& os,
const Vec3f& v)
125 os <<
"{" << v.x <<
", " << v.y <<
", " << v.z <<
"}";
131 inline Vec3f
operator*(
KyFloat32 s,
const Vec3f& v) {
return Vec3f(v.x * s, v.y * s, v.z * s); }
132 inline KyFloat32 DotProduct(
const Vec3f& v1,
const Vec3f& v2) {
return v1.x * v2.x + v1.y * v2.y + v1.z * v2.z; }
134 inline KyFloat32 CrossProduct_x(
const Vec3f& v1,
const Vec3f& v2) {
return v1.y * v2.z - v1.z * v2.y; }
135 inline KyFloat32 CrossProduct_y(
const Vec3f& v1,
const Vec3f& v2) {
return v1.z * v2.x - v1.x * v2.z; }
137 inline KyFloat32 CrossProduct2d(
const Vec3f& v1,
const Vec3f& v2) {
return v1.x * v2.y - v1.y * v2.x; }
138 inline Vec3f CrossProduct(
const Vec3f& v1,
const Vec3f& v2) {
return Vec3f(CrossProduct_x(v1, v2), CrossProduct_y(v1, v2),
CrossProduct_z(v1, v2)); }
140 inline Vec3f Seg(
const Vec3f& A,
const Vec3f& B) {
return B - A; }
146 inline KyFloat32 SquareDistance2d(
const Vec3f& A,
const Vec3f& B) {
return Seg(A, B).GetSquareLength2d(); }
149 inline KyFloat32 Distance2d(
const Vec3f& A,
const Vec3f& B) {
return Sqrtf(SquareDistance2d(A, B)); }
153 inline bool IsEpsilonEqual(
const Vec3f& A,
const Vec3f& B) {
return IsEpsilonEqual(A.x, B.x) && IsEpsilonEqual(A.y, B.y) && IsEpsilonEqual(A.z, B.z); }
154 inline bool IsEpsilonEqual2d(
const Vec3f& A,
const Vec3f& B) {
return IsEpsilonEqual(A.x, B.x) && IsEpsilonEqual(A.y, B.y); }
155 inline bool IsEpsilonDifferent(
const Vec3f& A,
const Vec3f& B) {
return !IsEpsilonEqual(A, B); }
156 inline bool IsEpsilonDifferent2d(
const Vec3f& A,
const Vec3f& B) {
return !IsEpsilonEqual2d(A, B); }
160 inline KyFloat32 Dot(
const Vec3f& v1,
const Vec3f& v2) {
return DotProduct(v1, v2); }
162 inline KyFloat32 Cross_x(
const Vec3f& v1,
const Vec3f& v2) {
return CrossProduct_x(v1, v2); }
163 inline KyFloat32 Cross_y(
const Vec3f& v1,
const Vec3f& v2) {
return CrossProduct_y(v1, v2); }
165 inline KyFloat32 Cross2d(
const Vec3f& v1,
const Vec3f& v2) {
return CrossProduct2d(v1, v2); }
166 inline Vec3f Cross(
const Vec3f& v1,
const Vec3f& v2) {
return CrossProduct(v1, v2); }
168 inline KyFloat32 SqDist2d(
const Vec3f& A,
const Vec3f& B) {
return SquareDistance2d(A, B); }
170 inline KyFloat32 Dist2d(
const Vec3f& A,
const Vec3f& B) {
return Distance2d(A, B); }
176 if (x < v.x)
return true;
177 if (x > v.x)
return false;
178 if (y < v.y)
return true;
179 if (y > v.y)
return false;
183 inline bool Vec3f::operator>(
const Vec3f& v)
const
185 if (x > v.x)
return true;
186 if (x < v.x)
return false;
187 if (y > v.y)
return true;
188 if (y < v.y)
return false;
206 const KyFloat32 invLength = 1.0f / length;
207 normalized.
Set(x * invLength, y * invLength, z * invLength);
212 normalized.
Set(0.0f, 0.0f, 0.0f);
217 inline Vec3f Vec3f::GetNormalized()
const
220 GetNormalized(normalized);
230 const KyFloat32 invLength = 1.0f / length;
231 normalized2d.Set(x * invLength, y * invLength);
236 normalized2d.Set(0.0f, 0.0f);
246 const KyFloat32 invLength = 1.0f / length;
247 return Vec2f(x * invLength, y * invLength);
251 return Vec2f(0.0f, 0.0f);
Vec3f OffsetY(KyFloat32 dy) const
Returns {x, y + dy, z}.
Definition: vec3f.h:92
KyFloat32 GetNormalized(Vec3f &normalized) const
Normalizes normalized. Returns the length of this vector before normalization.
Definition: vec3f.h:200
Vec3f OffsetX(KyFloat32 dx) const
Returns {x + dx, y, z}.
Definition: vec3f.h:91
KyFloat32 Distance(const Vec2f &A, const Vec2f &B)
Returns the distance between A and B.
Definition: vec2f.h:138
Vec2f GetNormalized2d() const
as Get2d().GetNormalized()
Definition: vec3f.h:241
void Set(KyFloat32 _x, KyFloat32 _y, KyFloat32 _z)
Sets {_x, _y, _z}.
Definition: vec3f.h:29
void Set(const Vec2f &v)
Sets {v.x, v.y, 0.0f}.
Definition: vec3f.h:31
bool operator<(const Vec3f &v) const
x is compared first. ex: {1, 5, 0} < {2,="" 0,="" 0}.="" />
Definition: vec3f.h:174
static Vec3f Zero()
Returns {0.0f, 0.0f, 0.0f}.
Definition: vec3f.h:99
Vec3f()
Sets {0.0f, 0.0f, 0.0f}.
Definition: vec3f.h:23
KyFloat32 SquareDistance(const Vec2f &A, const Vec2f &B)
Returns the square of the distance between A and B.
Definition: vec2f.h:130
Vec3f(KyFloat32 _x, KyFloat32 _y, KyFloat32 _z)
Sets {_x, _y, _z}.
Definition: vec3f.h:24
#define KY_DEFINE_NEW_DELETE_OPERATORS(MemStat)
This macro defines new and delete operators.
Definition: memory.h:132
Vec2f Dir2d(const Vec3f &A, const Vec3f &B)
Returns the normalized direction AB in 2d.
Definition: vec3f.h:151
KyFloat32 DotProduct2d(const Vec3f &v1, const Vec3f &v2)
Returns DotProduct(v1.Get2d(), v1.Get2d())
Definition: vec3f.h:133
Vec3f Offset2d(KyFloat32 dx, KyFloat32 dy) const
Returns {x + dx, y + dy, z}.
Definition: vec3f.h:95
Vec2f Dir(const Vec2f &A, const Vec2f &B)
Returns the normalized direction AB, returns zero if A == B.
Definition: vec2f.h:150
void Set(const KyFloat32 *coords)
Sets {coords[0], coords[1], coords[2]}.
Definition: vec3f.h:30
static Vec3f UnitZ()
Returns {0.0f, 0.0f, 1.0f}.
Definition: vec3f.h:106
Target
Enumerates the possible endianness types relative to the current platform.
Definition: endianness.h:27
Vec3f RightDir(const Vec3f &v)
Returns the normalized horizontal vector on the right of v. If v is vertical, this return Vec3f::Zero...
Definition: vec3f.h:143
void Set(const Vec2f &v, KyFloat32 _z)
Sets {v.x, v.y, _z}.
Definition: vec3f.h:32
2d vector using KyFloat32.
Definition: vec2f.h:18
KyFloat32 GetLength2d() const
as Get2d().GetLength()
Definition: vec3f.h:69
The Autodesk Navigation namespace.
Definition: gamekitcrowddispersion.cpp:17
KyFloat32 Normalize()
Normalizes this vector. Returns the length of this vector before normalization.
Definition: vec3f.h:192
Vec2f operator*(KyFloat32 s, const Vec2f &v)
scalar * vec operator
Definition: vec2f.h:120
std::int32_t KyInt32
int32_t
Definition: types.h:24
static Vec3f UnitY()
Returns {0.0f, 1.0f, 0.0f}.
Definition: vec3f.h:105
Vec3f(const KyFloat32 *coords)
Sets {coords[0], coords[1], coords[2]}.
Definition: vec3f.h:25
void Clear()
Sets x=0.0f, y=0.0f and z=0.0f.
Definition: vec3f.h:34
KyFloat32 CrossProduct_z(const Vec2f &v1, const Vec2f &v2)
alias for CrossProduct, useful in some template functions
Definition: vec2f.h:123
Vec3f OffsetZ(KyFloat32 dz) const
Returns {x, y, z + dz}.
Definition: vec3f.h:93
Vec3f(const Vec2f &v, KyFloat32 _z)
Sets {v.x, v.y, _z}.
Definition: vec3f.h:27
static Vec3f UnitX()
Returns {1.0f, 0.0f, 0.0f}.
Definition: vec3f.h:104
Vec3f(const Vec2f &v)
Sets {v.x, v.y, 0.0f}.
Definition: vec3f.h:26
float KyFloat32
float
Definition: types.h:32
3d vector using 32bits floating points.
Definition: vec3f.h:16
KyFloat32 GetSquareLength2d() const
as Get2d().GetSquareLength()
Definition: vec3f.h:68