66 inline explicit Vector(
float _x,
float _y,
float _z)
81 return reinterpret_cast<float*
>(
this);
85 inline const float*
Array()
const
87 return reinterpret_cast<const float*
>(
this);
93 return sqrtf(
x*
x +
y*
y +
z*
z);
115 float px =
y * right.
z -
z * right.
y;
116 float py =
z * right.
x -
x * right.
z;
117 float pz =
x * right.
y -
y * right.
x;
118 return Vector(px, py, pz);
128 return x * right.
x +
y * right.
y +
z * right.
z;
164 return Vector(left.
x + right.
x, left.
y + right.
y, left.
z + right.
z);
179 return Vector(left.
x - right.
x, left.
y - right.
y, left.
z - right.
z);
194 return Vector(left * right.
x, left * right.
y, left * right.
z);
200 return Vector(left.
x * right, left.
y * right, left.
z * right);
215 return Vector(left.
x / right, left.
y / right, left.
z / right);
224 s <<
"[" <<
x <<
", " <<
y <<
", " <<
z <<
"]";
267 return sqrtf( (a.
x-b.
x)*(a.
x-b.
x) +
268 (a.
y-b.
y)*(a.
y-b.
y) +
269 (a.
z-b.
z)*(a.
z-b.
z) );
Vector CrossMultiply(const Vector &right) const
Calculates the cross product with another vector.
Definition: vector.h:113
const float TOLERANCE
Tolerance level – minimum accepted float value.
Definition: const.h:33
friend const Vector operator/(const Vector &left, const float &right)
Divides vector by scalar.
Definition: vector.h:213
bool IsZero(float a, float tolerance=Math::TOLERANCE)
Compares a to zero within tolerance.
Definition: func.h:44
friend const Vector operator*(const float &left, const Vector &right)
Multiplies vector by scalar.
Definition: vector.h:192
float Angle(const Math::Vector &a, const Math::Vector &b)
Convenience function for calculating angle (in radians) between two vectors.
Definition: vector.h:259
friend const Vector operator-(const Vector &left, const Vector &right)
Subtracts two vectors.
Definition: vector.h:177
float * Array()
Returns the struct cast to float* array; use with care!
Definition: vector.h:79
float Max(float a, float b)
Maximum.
Definition: func.h:72
float CosAngle(const Vector &right) const
Returns the cosine of angle between this and another vector.
Definition: vector.h:132
float Distance(const Point &a, const Point &b)
Returns the distance between two points.
Definition: point.h:186
const Vector & operator+=(const Vector &right)
Adds the given vector.
Definition: vector.h:153
Vector Normalize(const Math::Vector &v)
Convenience function for getting normalized vector.
Definition: vector.h:239
void Normalize()
Normalizes the vector.
Definition: vector.h:97
float x
X - 1st coord.
Definition: vector.h:52
Vector(float _x, float _y, float _z)
Creates a vector from given values.
Definition: vector.h:66
float DotProduct(const Math::Vector &left, const Math::Vector &right)
Convenience function for calculating dot product.
Definition: vector.h:247
Vector operator-() const
Returns the inverted vector.
Definition: vector.h:147
float Angle(const Vector &right) const
Returns angle (in radians) between this and another vector.
Definition: vector.h:138
std::string ToString() const
Returns a string "[x, y, z]".
Definition: vector.h:220
const float * Array() const
Returns the struct cast to const float* array; use with care!
Definition: vector.h:85
Vector Clamp(const Vector &vec, const Vector &min, const Vector &max)
Clamps the vector vec to range between min and max.
Definition: vector.h:273
bool IsEqual(float a, float b, float tolerance=Math::TOLERANCE)
Compares a and b within tolerance.
Definition: func.h:38
friend const Vector operator*(const Vector &left, const float &right)
Multiplies vector by scalar.
Definition: vector.h:198
float DotMultiply(const Vector &right) const
Calculates the dot product with another vector.
Definition: vector.h:126
float Min(float a, float b)
Minimum.
Definition: func.h:50
const Vector & operator/=(const float &right)
Divides by given scalar.
Definition: vector.h:204
bool VectorsEqual(const Math::Vector &a, const Math::Vector &b, float tolerance=TOLERANCE)
Checks if two vectors are equal within given tolerance.
Definition: vector.h:231
float z
Z - 3rd coord.
Definition: vector.h:56
float Length() const
Returns the vector length.
Definition: vector.h:91
Constants used in math functions.
Vector()
Creates a zero vector (0, 0, 0)
Definition: vector.h:59
friend const Vector operator+(const Vector &left, const Vector &right)
Adds two vectors.
Definition: vector.h:162
const Vector & operator-=(const Vector &right)
Subtracts the given vector.
Definition: vector.h:168
void LoadZero()
Loads the zero vector (0, 0, 0)
Definition: vector.h:73
Vector CrossProduct(const Math::Vector &left, const Math::Vector &right)
Convenience function for calculating cross product.
Definition: vector.h:253
3D (3x1) vector
Definition: vector.h:49
const Vector & operator*=(const float &right)
Multiplies by given scalar.
Definition: vector.h:183
float y
Y - 2nd coord.
Definition: vector.h:54