32 return ((
X *
X) + (
Y *
Y));
37 return sqrtf(
X *
X +
Y *
Y);
52 return (
X * vector.
X) + (
Y * vector.
Y);
57 return (
X * vector.
Y) - (
Y * vector.
X);
62 return sqrtf(pow((vector2.
X - vector1.
X), 2) + pow((vector2.
Y - vector1.
Y), 2));
67 return pow((vector2.
X - vector1.
X), 2) + pow((vector2.
Y - vector1.
Y), 2);
72 if (value < 0)
return start;
73 if (value > 1)
return end;
75 return start + (end - start) * value;
91 std::ostringstream ss;
92 ss <<
"{ " <<
X <<
", " <<
Y <<
" }";
141 return Vector2(*
this) += vector;
146 return Vector2(*
this) -= vector;
151 return Vector2(*
this) *= scalar;
156 return Vector2(*
this) /= scalar;
161 return ((
X == vector.
X) && (
Y == vector.
Y));
166 return !((
X == vector.
X) && (
Y == vector.
Y));
static float GetRandomFloat()
Get a random number between zero and one.
Defines a point in 2D space.
Defines a vector with 2 components (x and y).
float Y
The y-coordinate of the vector.
const Vector2 operator*(const float scalar) const
Multiplies a vector by a scalar.
static const Vector2 UNIT_X
A unit vector on the x-axis.
const Point ToPoint() const
Converts the vector into a point.
float DotProduct(const Vector2 &vector) const
Calculates the dot product of two vectors.
Vector2 & operator/=(const float scalar)
Divides by a scalar.
static float Distance(const Vector2 &vector1, const Vector2 &vector2)
Calculates the distance between two vectors.
float CrossProduct(const Vector2 &vector) const
Calculates the cross product between two vectors.
const Vector2 operator-() const
Negates the vector.
void Normalize()
Resize a vector to a length of one unit. If the starting vector is the zero vector,...
static const Vector2 UNIT_Y
A unit vector on the y-axis.
static Vector2 GetRandom(bool normalize=false)
Creates a random vector.
const Vector2 operator+(const Vector2 &vector) const
Adds two vectors.
float LengthSquared() const
Calculates the length of the vector squared.
static const Vector2 ZERO
A vector with both of its components set to zero.
Vector2 & operator+=(const Vector2 &vector)
Adds a vector.
bool IsZero() const
Determines if the vector is the zero vector.
const Vector2 operator/(const float scalar) const
Divides a vector by a scalar.
static Vector2 Lerp(const Vector2 &start, const Vector2 &end, const float value)
Linearly interpolate between two vectors.
Vector2(const float x=0, const float y=0)
Instantiates a new Vector2 object.
static float DistanceSquared(const Vector2 &vector1, const Vector2 &vector2)
Calculates the distance squared between two vectors.
Vector2 & operator*=(const float scalar)
Multiplies by a scalar.
bool operator==(const Vector2 &vector) const
Determines if two vectors are equal.
Vector2 & operator-=(const Vector2 &vector)
Subtracts a vector.
std::string ToString() const
Gets a string representation of the vector.
float Length() const
Calculates the length of the vector.
bool operator!=(const Vector2 &vector) const
Determines if two vectors are not equal.
static const Vector2 ONE
A vector with both of its components set to one.
Vector2 & operator=(const Vector2 &vector)
Assigns the reference of a vector.
float X
The x-coordinate of the vector.
Katana Engine is a library of classes, interfaces, and value types that provides a foundation for dev...