9 #ifndef Navigation_Vec3f_H
10 #define Navigation_Vec3f_H
30 Vec3f() :
x(0.0f),
y(0.0f),
z(0.0f) {}
50 KY_INLINE
void Set(
const KyFloat32* coords) {
x = coords[0];
y = coords[1];
z = coords[2]; }
53 KY_INLINE
void Set(
const Vec2f& v) {
x = v.x;
y = v.y;
z = 0.0f; }
70 KY_INLINE
bool operator==(
const Vec3f& v)
const {
return x == v.x &&
y == v.y &&
z == v.z; }
77 KY_INLINE
bool operator>(
const Vec3f& v)
const;
78 KY_INLINE
bool operator<=(
const Vec3f& v)
const;
79 KY_INLINE
bool operator>=(
const Vec3f& v)
const;
166 KY_INLINE
bool IsNormalized()
const;
179 KY_INLINE
bool IsZero()
const {
return x== 0.0f &&
y == 0.0f &&
z == 0.0f; }
208 SwapEndianness(e,
self.x);
209 SwapEndianness(e,
self.y);
210 SwapEndianness(e,
self.z);
252 return dx * dx + dy * dy;
262 KY_INLINE Vec3f
GetDir(
const Vec3f& A,
const Vec3f& B)
270 KY_INLINE Vec2f
GetDir2d(
const Vec3f& A,
const Vec3f& B)
272 Vec2f AB(B.x - A.x, B.y - A.y);
281 if (
x < v.
x)
return true;
282 if (
x > v.
x)
return false;
283 if (
y < v.
y)
return true;
284 if (
y > v.
y)
return false;
288 KY_INLINE
bool Vec3f::operator>(
const Vec3f& v)
const
290 if (
x > v.
x)
return true;
291 if (
x < v.
x)
return false;
292 if (
y > v.
y)
return true;
293 if (
y < v.
y)
return false;
297 KY_INLINE
bool Vec3f::operator<=(
const Vec3f& v)
const {
return !operator>(v); }
298 KY_INLINE
bool Vec3f::operator>=(
const Vec3f& v)
const {
return !
operator<(v); }
302 x = u.
y * v.
z - u.
z * v.
y;
303 y = u.
z * v.
x - u.
x * v.
z;
304 z = u.
x * v.
y - u.
y * v.
x;
323 const KyFloat32 invLength = 1.f / length;
324 normalized.
Set(
x * invLength,
y * invLength,
z * invLength);
329 normalized.
Set(0.f, 0.f, 0.f);
334 KY_INLINE
bool Vec3f::IsNormalized()
const
337 return (fabsf(sqLength - 1.0f) < 1e-6f);
347 normalized2d.
Set(
x * invLength,
y * invLength);
352 normalized2d.
Set(0.0f, 0.0f);
358 template <
class OSTREAM>
359 inline OSTREAM& operator<<(OSTREAM& os,
const Vec3f& v)
361 os <<
"{" << v.x <<
";" << v.y <<
";" << v.z <<
"}";
KyFloat32 GetSquareLength() const
Returns the square of the magnitude of the vector.
Definition: vec3f.h:162
KyFloat32 GetNormalized(Vec3f &normalized) const
Normalizes the vector, making it one unit in length without changing its orientation.
Definition: vec3f.h:346
Vec3f operator/(KyFloat32 d) const
Divides the X, Y and Z coordinates of this vector by the specified value.
Definition: vec3f.h:109
Vec2f GetDir2d(const Vec2f &v1, const Vec2f &v2)
Returns the normalized direction between v1 and v2.
Definition: vec2f.h:208
KyFloat32 CrossProduct(const Vec2f &v1, const Vec2f &v2)
Returns the magnitude on the Z axis of the cross product between this vector and v.
Definition: vec2f.h:190
KyFloat32 z
The size of the vector along the Z axis.
Definition: vec3f.h:229
Vec3f GetRightDirection(const Vec3f &v)
Returns the normalized horizontal vector on the right of v. If v is vertical, this return Vec3f::Zero...
Definition: vec3f.h:267
Vec3f & operator*=(KyFloat32 s)
Multiplies the X, Y and Z coordinates of this vector by the specified value.
Definition: vec3f.h:92
void Set(KyFloat32 _x, KyFloat32 _y, KyFloat32 _z)
Sets the coordinates.
Definition: vec3f.h:52
KyFloat32 Distance2d(const Vec3f &v1, const Vec3f &v2)
Returns the distance between v1 and v2, ignoring Z coordinates.
Definition: vec3f.h:288
KyFloat32 x
The size of the vector along the X axis.
Definition: vec2f.h:169
Vec3f & operator+=(const Vec3f &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: vec3f.h:99
void Set(KyFloat32 _x, KyFloat32 _y)
Sets the coordinates of the vector.
Definition: vec2f.h:47
bool operator<(const Vec3f &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: vec3f.h:308
static Vec3f Zero()
Returns a vector of zero size: (0,0,0).
Definition: vec3f.h:209
int KyInt32
Type used internally to represent a 32-bit integer.
Definition: types.h:35
Vec3f operator-() const
Negates the X, Y and Z coordinates of this vector, effectively flipping it around the origin...
Definition: vec3f.h:120
KyFloat32 CrossProduct_x(const Vec3f &v1, const Vec3f &v2)
Returns the X component of the cross product of v1 and v2.
Definition: vec3f.h:255
KyFloat32 & operator[](KyInt32 i)
Retrieves the size of the vector around one of its axes.
Definition: vec3f.h:73
Vec3f()
Creates a vector with coordinates (0,0,0).
Definition: vec3f.h:36
KyFloat32 y
The size of the vector along the Y axis.
Definition: vec3f.h:228
Vec3f operator+(const Vec3f &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: vec3f.h:113
KyFloat32 SquareDistance2d(const Vec3f &v1, const Vec3f &v2)
Returns the square of the distance between v1 and v2, ignoring Z coordinates.
Definition: vec3f.h:277
KyFloat32 GetLength() const
Returns the magnitude of the vector.
Definition: vec3f.h:168
KyFloat32 DotProduct2d(const Vec3f &v1, const Vec3f &v2)
Returns the dot product of v1 and v2, ignoring Z coordinates.
Definition: vec3f.h:252
Vec2f Get2d() const
Returns a Vec2f that contains the X and Y coordinates of this vector. The Z coordinate is ignored...
Definition: vec3f.h:188
void Set(const KyFloat32 *coords)
Sets the coordinates.
Definition: vec3f.h:56
static Vec3f UnitZ()
Returns the normalized orientation of the Z axis.
Definition: vec3f.h:218
KyFloat32 CrossProduct_z(const Vec3f &v1, const Vec3f &v2)
Returns the Z component of the cross product of v1 and v2.
Definition: vec3f.h:261
KyFloat32 SquareDistance(const Vec2f &v1, const Vec2f &v2)
Returns the square of the distance between v1 and v2.
Definition: vec2f.h:194
Target
Enumerates the possible endianness types relative to the current platform.
Definition: endianness.h:35
KyFloat32 x
The size of the vector along the X axis.
Definition: vec3f.h:227
This class defines a two-dimensional vector whose coordinates are stored using floating-point numbers...
Definition: vec2f.h:24
Vec3f operator^(const Vec3f &v) const
Returns the cross product of this vector and v.
Definition: vec3f.h:126
void Cross(const Vec3f &u, const Vec3f &v)
Calculates the cross product ofu and v, and stores the result in this vector.
Definition: vec3f.h:329
KyFloat32 GetLength2d() const
Returns the magnitude of the vector on the plane of the (X,Y) axes.
Definition: vec3f.h:171
KyFloat32 Distance(const Vec2f &v1, const Vec2f &v2)
Returns the distance between v1 and v2.
Definition: vec2f.h:202
bool operator!=(const Vec3f &v) const
Returns true if this object contains at least one different coordinate from v.
Definition: vec3f.h:83
Definition: gamekitcrowddispersion.h:20
KyFloat32 DotProduct(const Vec2f &v1, const Vec2f &v2)
Returns the dot product of v1 and v2.
Definition: vec2f.h:187
KyFloat32 Normalize()
Normalizes the vector, making it one unit in length without changing its orientation.
Definition: vec3f.h:337
Vec2f operator*(KyFloat32 s, const Vec2f &v)
Multiplies the X and Y coordinates of v by s.
Definition: vec2f.h:184
#define KY_DEFINE_NEW_DELETE_OPERATORS(MemStat)
This macro defines new and delete operators.
Definition: memory.h:137
bool IsZero() const
Returns true if the X, Y and Z coordinates of this vector are all 0.
Definition: vec3f.h:199
Vec3f operator*(KyFloat32 s) const
Multiplies the X, Y and Z coordinates of this vector by the specified value.
Definition: vec3f.h:106
Vec3f & operator/=(KyFloat32 d)
Divides the X, Y and Z coordinates of this vector by the specified value.
Definition: vec3f.h:95
Vec3f GetDir(const Vec3f &A, const Vec3f &B)
Get Direction.
Definition: vec3f.h:291
static Vec3f UnitY()
Returns the normalized orientation of the Y axis.
Definition: vec3f.h:215
Vec3f(const KyFloat32 *coords)
Creates a vector with the specified coordinates.
Definition: vec3f.h:43
static Vec3f UnitX()
Returns the normalized orientation of the X axis.
Definition: vec3f.h:212
KyFloat32 GetNormalized2d(Vec2f &normalized) const
Normalizes the (X,Y) coordinates of the vector, making it one unit in length without changing its ori...
Definition: vec3f.h:369
Vec3f & operator-=(const Vec3f &v)
Subtracts the X coordinate of v from the X coordinate of this vector, subtracts the Y coordinate of v...
Definition: vec3f.h:103
float KyFloat32
Type used internally to represent a 32-bit floating-point number.
Definition: types.h:43
This class defines a three-dimensional vector whose coordinates are stored using floating-point numbe...
Definition: vec3f.h:23
bool operator==(const Vec3f &v) const
Returns true if this object contains the same coordinates as v.
Definition: vec3f.h:80
KyFloat32 y
The size of the vector along the Y axis.
Definition: vec2f.h:170
KyFloat32 GetSquareLength2d() const
Returns the square of the magnitude of the vector on the plane of the (X,Y) axes. ...
Definition: vec3f.h:165
KyFloat32 CrossProduct_y(const Vec3f &v1, const Vec3f &v2)
Returns the Y component of the cross product of v1 and v2.
Definition: vec3f.h:258