70 inline explicit Vector(
float _x,
float _y,
float _z)
85 return reinterpret_cast<float*
>(
this);
89 inline const float*
Array()
const 91 return reinterpret_cast<const float*
>(
this);
97 return sqrtf(x*x + y*y + z*z);
119 float px = y * right.
z - z * right.
y;
120 float py = z * right.
x - x * right.
z;
121 float pz = x * right.
y - y * right.
x;
122 return Vector(px, py, pz);
132 return x * right.
x + y * right.
y + z * right.
z;
153 return Vector(-x, -y, -z);
168 return Vector(left.
x + right.
x, left.
y + right.
y, left.
z + right.
z);
183 return Vector(left.
x - right.
x, left.
y - right.
y, left.
z - right.
z);
198 return Vector(left * right.
x, left * right.
y, left * right.
z);
204 return Vector(left.
x * right, left.
y * right, left.
z * right);
219 return Vector(left.
x / right, left.
y / right, left.
z / right);
228 s <<
"[" << x <<
", " << y <<
", " << z <<
"]";
271 return sqrtf( (a.
x-b.
x)*(a.
x-b.
x) +
272 (a.
y-b.
y)*(a.
y-b.
y) +
273 (a.
z-b.
z)*(a.
z-b.
z) );
Vector CrossMultiply(const Vector &right) const
Calculates the cross product with another vector.
Definition: vector.h:117
const float TOLERANCE
Tolerance level – minimum accepted float value.
Definition: const.h:37
friend const Vector operator/(const Vector &left, const float &right)
Divides vector by scalar.
Definition: vector.h:217
bool IsZero(float a, float tolerance=Math::TOLERANCE)
Compares a to zero within tolerance.
Definition: func.h:47
friend const Vector operator*(const float &left, const Vector &right)
Multiplies vector by scalar.
Definition: vector.h:196
friend const Vector operator-(const Vector &left, const Vector &right)
Subtracts two vectors.
Definition: vector.h:181
float * Array()
Returns the struct cast to float* array; use with care!
Definition: vector.h:83
float Max(float a, float b)
Maximum.
Definition: func.h:75
float CosAngle(const Vector &right) const
Returns the cosine of angle between this and another vector.
Definition: vector.h:136
float Distance(const Point &a, const Point &b)
Returns the distance between two points.
Definition: point.h:190
const Vector & operator+=(const Vector &right)
Adds the given vector.
Definition: vector.h:157
void Normalize()
Normalizes the vector.
Definition: vector.h:101
float x
X - 1st coord.
Definition: vector.h:56
Vector(float _x, float _y, float _z)
Creates a vector from given values.
Definition: vector.h:70
float DotProduct(const Math::Vector &left, const Math::Vector &right)
Convenience function for calculating dot product.
Definition: vector.h:251
Vector operator-() const
Returns the inverted vector.
Definition: vector.h:151
float Angle(const Vector &right) const
Returns angle (in radians) between this and another vector.
Definition: vector.h:142
std::string ToString() const
Returns a string "[x, y, z]".
Definition: vector.h:224
const float * Array() const
Returns the struct cast to const float* array; use with care!
Definition: vector.h:89
bool IsEqual(float a, float b, float tolerance=Math::TOLERANCE)
Compares a and b within tolerance.
Definition: func.h:41
friend const Vector operator*(const Vector &left, const float &right)
Multiplies vector by scalar.
Definition: vector.h:202
float DotMultiply(const Vector &right) const
Calculates the dot product with another vector.
Definition: vector.h:130
Namespace for (new) math code.
Definition: device.h:39
float Min(float a, float b)
Minimum.
Definition: func.h:53
const Vector & operator/=(const float &right)
Divides by given scalar.
Definition: vector.h:208
T Clamp(T value, T min, T max)
Clamps the value to a range specified by min and max.
Definition: func.h:98
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:235
float z
Z - 3rd coord.
Definition: vector.h:60
float Length() const
Returns the vector length.
Definition: vector.h:95
Constants used in math functions.
Vector()
Creates a zero vector (0, 0, 0)
Definition: vector.h:63
friend const Vector operator+(const Vector &left, const Vector &right)
Adds two vectors.
Definition: vector.h:166
const Vector & operator-=(const Vector &right)
Subtracts the given vector.
Definition: vector.h:172
void LoadZero()
Loads the zero vector (0, 0, 0)
Definition: vector.h:77
Vector CrossProduct(const Math::Vector &left, const Math::Vector &right)
Convenience function for calculating cross product.
Definition: vector.h:257
3D (3x1) vector
Definition: vector.h:53
const Vector & operator*=(const float &right)
Multiplies by given scalar.
Definition: vector.h:187
float y
Y - 2nd coord.
Definition: vector.h:58