69 inline explicit Vector(
float _x,
float _y,
float _z)
84 return reinterpret_cast<float*
>(
this);
88 inline const float*
Array()
const
90 return reinterpret_cast<const float*
>(
this);
96 return sqrtf(x*x + y*y + z*z);
118 float px = y * right.
z - z * right.
y;
119 float py = z * right.
x - x * right.
z;
120 float pz = x * right.
y - y * right.
x;
121 return Vector(px, py, pz);
131 return x * right.
x + y * right.
y + z * right.
z;
152 return Vector(-x, -y, -z);
167 return Vector(left.
x + right.
x, left.
y + right.
y, left.
z + right.
z);
182 return Vector(left.
x - right.
x, left.
y - right.
y, left.
z - right.
z);
197 return Vector(left * right.
x, left * right.
y, left * right.
z);
203 return Vector(left.
x * right, left.
y * right, left.
z * right);
218 return Vector(left.
x / right, left.
y / right, left.
z / right);
227 s <<
"[" << x <<
", " << y <<
", " << z <<
"]";
270 return sqrtf( (a.
x-b.
x)*(a.
x-b.
x) +
271 (a.
y-b.
y)*(a.
y-b.
y) +
272 (a.
z-b.
z)*(a.
z-b.
z) );
Vector CrossMultiply(const Vector &right) const
Calculates the cross product with another vector.
Definition: vector.h:116
const float TOLERANCE
Tolerance level – minimum accepted float value.
Definition: const.h:36
friend const Vector operator/(const Vector &left, const float &right)
Divides vector by scalar.
Definition: vector.h:216
bool IsZero(float a, float tolerance=Math::TOLERANCE)
Compares a to zero within tolerance.
Definition: func.h:46
friend const Vector operator*(const float &left, const Vector &right)
Multiplies vector by scalar.
Definition: vector.h:195
float Angle(const Math::Vector &a, const Math::Vector &b)
Convenience function for calculating angle (in radians) between two vectors.
Definition: vector.h:262
friend const Vector operator-(const Vector &left, const Vector &right)
Subtracts two vectors.
Definition: vector.h:180
float * Array()
Returns the struct cast to float* array; use with care!
Definition: vector.h:82
float Max(float a, float b)
Maximum.
Definition: func.h:74
float CosAngle(const Vector &right) const
Returns the cosine of angle between this and another vector.
Definition: vector.h:135
float Distance(const Point &a, const Point &b)
Returns the distance between two points.
Definition: point.h:189
const Vector & operator+=(const Vector &right)
Adds the given vector.
Definition: vector.h:156
Vector Normalize(const Math::Vector &v)
Convenience function for getting normalized vector.
Definition: vector.h:242
void Normalize()
Normalizes the vector.
Definition: vector.h:100
float x
X - 1st coord.
Definition: vector.h:55
Vector(float _x, float _y, float _z)
Creates a vector from given values.
Definition: vector.h:69
float DotProduct(const Math::Vector &left, const Math::Vector &right)
Convenience function for calculating dot product.
Definition: vector.h:250
Vector operator-() const
Returns the inverted vector.
Definition: vector.h:150
float Angle(const Vector &right) const
Returns angle (in radians) between this and another vector.
Definition: vector.h:141
std::string ToString() const
Returns a string "[x, y, z]".
Definition: vector.h:223
const float * Array() const
Returns the struct cast to const float* array; use with care!
Definition: vector.h:88
Vector Clamp(const Vector &vec, const Vector &min, const Vector &max)
Clamps the vector vec to range between min and max.
Definition: vector.h:276
bool IsEqual(float a, float b, float tolerance=Math::TOLERANCE)
Compares a and b within tolerance.
Definition: func.h:40
friend const Vector operator*(const Vector &left, const float &right)
Multiplies vector by scalar.
Definition: vector.h:201
float DotMultiply(const Vector &right) const
Calculates the dot product with another vector.
Definition: vector.h:129
Namespace for (new) math code.
Definition: const.h:32
float Min(float a, float b)
Minimum.
Definition: func.h:52
const Vector & operator/=(const float &right)
Divides by given scalar.
Definition: vector.h:207
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:234
float z
Z - 3rd coord.
Definition: vector.h:59
float Length() const
Returns the vector length.
Definition: vector.h:94
Constants used in math functions.
Vector()
Creates a zero vector (0, 0, 0)
Definition: vector.h:62
friend const Vector operator+(const Vector &left, const Vector &right)
Adds two vectors.
Definition: vector.h:165
const Vector & operator-=(const Vector &right)
Subtracts the given vector.
Definition: vector.h:171
void LoadZero()
Loads the zero vector (0, 0, 0)
Definition: vector.h:76
Vector CrossProduct(const Math::Vector &left, const Math::Vector &right)
Convenience function for calculating cross product.
Definition: vector.h:256
3D (3x1) vector
Definition: vector.h:52
const Vector & operator*=(const float &right)
Multiplies by given scalar.
Definition: vector.h:186
float y
Y - 2nd coord.
Definition: vector.h:57