9 #ifndef Navigation_Vec2f_H
10 #define Navigation_Vec2f_H
46 KY_INLINE
void Set(
KyFloat32* coords) {
x = coords[0];
y = coords[1]; }
65 KY_INLINE
bool operator>(
const Vec2f& v)
const;
66 KY_INLINE
bool operator<=(
const Vec2f& v)
const;
67 KY_INLINE
bool operator>=(
const Vec2f& v)
const;
155 SwapEndianness(e,
self.x);
156 SwapEndianness(e,
self.y);
164 KY_INLINE
KyFloat32 DotProduct(
const Vec2f& v1,
const Vec2f& v2) {
return (v1.x * v2.x + v1.y * v2.y); }
175 return dx * dx + dy * dy;
185 KY_INLINE Vec2f
GetDir2d(
const Vec2f& v1,
const Vec2f& v2)
198 const KyFloat32 sqLengthProd = sqLengthV1 * sqLengthV2;
200 if (sqLengthProd > 0.0f)
202 const KyFloat32 lengthProd = (sqLengthProd == 1.0f) ? 1.0f : Sqrtf(sqLengthProd);
205 KyFloat32 angleRad = Kaim::Acosf(dotProd / lengthProd);
208 return ((crossProd >= 0.0f) ? angleRad : (
KY_2_PI - angleRad));
217 const KyFloat32 formerDirX = direction.x;
218 direction.x = cosAngle * formerDirX - sinAngle * direction.y;
219 direction.y = sinAngle * formerDirX + cosAngle * direction.y;
227 if (
x < v.x)
return true;
228 if (
x > v.x)
return false;
232 KY_INLINE
bool Vec2f::operator>(
const Vec2f& v)
const
234 if (
x > v.x)
return true;
235 if (
x < v.x)
return false;
239 KY_INLINE
bool Vec2f::operator<=(
const Vec2f& v)
const {
return !operator>(v); }
240 KY_INLINE
bool Vec2f::operator>=(
const Vec2f& v)
const {
return !
operator<(v); }
258 const KyFloat32 invLength = 1.f / length;
259 normalized.
Set(
x * invLength,
y * invLength);
264 normalized.
Set(0.0f, 0.0f);
271 template <
class OSTREAM>
272 inline OSTREAM& operator<<(OSTREAM& os,
const Vec2f& v)
274 os <<
"{" << v.
x <<
";" << v.
y <<
"}";
Vec2f()
Creates a vector with coordinates (0,0)
Definition: vec2f.h:37
bool operator<(const Vec2f &v) const
x is compared first. ex: (1,5) < (2,0).="" />
Definition: vec2f.h:249
KyFloat32 GetSquareLength() const
Returns the square of the magnitude of the vector.
Definition: vec2f.h:123
KyFloat32 & operator[](KyInt32 i)
Retrieves the coordinates of the vector. Use [0] for the X axis, or [1] for the Y axis...
Definition: vec2f.h:61
KyFloat32 operator^(const Vec2f &v) const
Returns the magnitude on the Z axis of the cross product between this vector and v.
Definition: vec2f.h:113
KyFloat32 Normalize()
Normalizes the vector, making it one unit in length without changing its orientation.
Definition: vec2f.h:267
Vec2f GetDir2d(const Vec2f &v1, const Vec2f &v2)
Returns the normalized direction between v1 and v2.
Definition: vec2f.h:208
Vec2f & operator+=(const Vec2f &v)
Adds the X coordinate of v to the X coordinate of this vector, and adds the Y coordinate of v to the ...
Definition: vec2f.h:86
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
static Vec2f UnitX()
Returns the normalized orientation of the X axis.
Definition: vec2f.h:157
KyFloat32 x
The size of the vector along the X axis.
Definition: vec2f.h:169
Vec2f operator*(KyFloat32 s) const
Multiplies both the X and Y coordinates of the vector by the specified value.
Definition: vec2f.h:93
Vec2f & operator*=(KyFloat32 s)
Multiplies both the X and Y coordinates by s.
Definition: vec2f.h:79
void Set(KyFloat32 _x, KyFloat32 _y)
Sets the coordinates of the vector.
Definition: vec2f.h:47
int KyInt32
Type used internally to represent a 32-bit integer.
Definition: types.h:35
KyFloat32 GetNormalized(Vec2f &normalized) const
Normalizes the vector, making it one unit in length without changing its orientation.
Definition: vec2f.h:276
Vec2f operator-() const
Negates the X and Y coordinates of this vector, effectively flipping it around the origin...
Definition: vec2f.h:107
Vec2f operator+(const Vec2f &v) const
Adds the X coordinate of v to the X coordinate of this vector, and adds the Y coordinate of v to the ...
Definition: vec2f.h:100
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
Vec2f PerpCCW() const
Rotates this vector 90 degrees counter-clockwise (negating the Y coordinate).
Definition: vec2f.h:144
This class defines a two-dimensional vector whose coordinates are stored using floating-point numbers...
Definition: vec2f.h:24
KyFloat32 GetAngleRad(const Vec2f &v1, const Vec2f &v2)
Returns the angle in radians between v1 and v2 (CounterClockwise).
Definition: vec2f.h:218
bool operator!=(const Vec2f &v) const
Returns true if this object contains at least one different coordinate from v.
Definition: vec2f.h:70
KyFloat32 Distance(const Vec2f &v1, const Vec2f &v2)
Returns the distance between v1 and v2.
Definition: vec2f.h:202
Definition: gamekitcrowddispersion.h:20
void Rotate(Vec2f &direction, KyFloat32 cosAngle, KyFloat32 sinAngle)
Turns direction accordingly to provided sine & cosine. Positive angles rotate CCW.
Definition: vec2f.h:239
KyFloat32 DotProduct(const Vec2f &v1, const Vec2f &v2)
Returns the dot product of v1 and v2.
Definition: vec2f.h:187
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
Vec2f & operator-=(const Vec2f &v)
Subtracts the X coordinate of v from the X coordinate of this vector, and subtracts the Y coordinate ...
Definition: vec2f.h:90
Vec2f operator/(KyFloat32 d) const
Divides both the X and Y coordinates of the vector by the specified value.
Definition: vec2f.h:96
static Vec2f Zero()
Returns a vector of zero size: (0,0).
Definition: vec2f.h:154
KyFloat32 GetLength() const
Returns the magnitude of the vector.
Definition: vec2f.h:126
Vec2f PerpCW() const
Rotates this vector 90 degrees clockwise (negating the X coordinate).
Definition: vec2f.h:141
static const KyFloat32 KY_2_PI
Stores the value of twice pi.
Definition: types.h:373
bool operator==(const Vec2f &v) const
Returns true if this object contains the same coordinates as v.
Definition: vec2f.h:67
static Vec2f UnitY()
Returns the normalized orientation of the Y axis.
Definition: vec2f.h:160
Vec2f & operator/=(KyFloat32 d)
Divides both the X and Y coordinates ny d .
Definition: vec2f.h:82
float KyFloat32
Type used internally to represent a 32-bit floating-point number.
Definition: types.h:43
KyFloat32 y
The size of the vector along the Y axis.
Definition: vec2f.h:170