Clutter Engine 0.0.1
|
A 3D vector structure. More...
#include <Vector3.h>
Public Member Functions | |
Vector3 () | |
Default constructor. Initializes all components to zero. | |
Vector3 (float pXYZ) | |
Constructs a vector with all components set to the same value. | |
Vector3 (Vector2 pXY) | |
Constructs a vector from a Vector2, z is set to 0. | |
Vector3 (float xP, float yP, float zP) | |
Constructs a vector with specified x, y, and z values. | |
void | Set (float xP, float yP, float zP) |
Sets the vector components. | |
float | LengthSq () const |
Returns the squared length of the vector. | |
float | Length () const |
Returns the length (magnitude) of the vector. | |
void | Normalize () |
Normalizes the vector in place. | |
const float * | GetAsFloatPtr () const |
Returns a pointer to the vector's data as a float array. | |
float & | operator[] (int index) |
Accesses a component by index. | |
const float & | operator[] (int index) const |
Accesses a component by index (const). | |
Vector3 & | operator/= (float scalar) |
Divides the vector by a scalar in place. | |
Vector3 | operator- () const |
Negates the vector. | |
Vector3 & | operator*= (float scalar) |
Multiplies the vector by a scalar in place. | |
Vector3 & | operator+= (const Vector3 &right) |
Adds another vector to this vector in place. | |
Vector3 & | operator-= (const Vector3 &right) |
Subtracts another vector from this vector in place. | |
Vector3 | Normalized () const |
Returns a normalized copy of this vector. | |
Vector3 | Abs () const |
Returns a vector with the absolute values of each component. | |
std::string | ToString () |
Returns a string representation of the vector. | |
Vector2 | xy () |
Returns the x and y components as a Vector2. | |
Vector2 | xz () |
Returns the x and z components as a Vector2. | |
Vector2 | yz () |
Returns the y and z components as a Vector2. | |
void | Clamp (float minValue, float maxValue) |
Clamps the vector components to the given range in place. | |
Static Public Member Functions | |
static Vector3 | Normalize (const Vector3 &vec) |
Returns a normalized copy of the provided vector. | |
static float | Dot (const Vector3 &a, const Vector3 &b) |
Computes the dot product of two vectors. | |
static Vector3 | Cross (const Vector3 &a, const Vector3 &b) |
Computes the cross product of two vectors. | |
static Vector3 | Lerp (const Vector3 &a, const Vector3 &b, float f) |
Linearly interpolates between two vectors. | |
static Vector3 | VInterp (const Vector3 ¤t, const Vector3 &target, float interpSpeed, float deltaTime=-1) |
Linearly interpolates between two vectors with speed and delta time. | |
static Vector3 | Reflect (const Vector3 &v, const Vector3 &n) |
Reflects a vector about a normal. | |
static Vector3 | Transform (Vector3 &vec, class Matrix4 &mat, float w=1.0f) |
Transforms a vector by a matrix. | |
static Vector3 | TransformWithPerspDiv (Vector3 &vec, class Matrix4 &mat, float w=1.0f) |
Transforms the vector by a matrix and applies perspective division. | |
static Vector3 | Transform (const Vector3 &v, const class Quaternion &q) |
Transforms a vector by a quaternion. | |
static Vector3 | Clamp (const Vector3 &vec, float minValue, float maxValue) |
Clamps the vector components to the given range. | |
Public Attributes | |
float | x = 0 |
The x component of the vector. | |
float | y = 0 |
The y component of the vector. | |
float | z = 0 |
The z component of the vector. | |
Static Public Attributes | |
static const Vector3 | Zero |
A vector with all components set to zero. | |
static const Vector3 | One |
A vector with all components set to one. | |
static const Vector3 | Up |
A vector pointing up (0, 1, 0). | |
static const Vector3 | Down |
A vector pointing down (0, -1, 0). | |
static const Vector3 | Left |
A vector pointing left (-1, 0, 0). | |
static const Vector3 | Right |
A vector pointing right (1, 0, 0). | |
static const Vector3 | Forward |
A vector pointing forward (0, 0, 1). | |
static const Vector3 | Backward |
A vector pointing backward (0, 0, -1). | |
static const Vector3 | Infinity |
A vector with all components set to positive infinity. | |
static const Vector3 | NegInfinity |
A vector with all components set to negative infinity. | |
Friends | |
Vector3 | operator+ (const Vector3 &a, const Vector3 &b) |
Adds two vectors. | |
Vector3 | operator/ (const Vector3 &vec, float scalar) |
Divides a vector by a scalar. | |
Vector3 | operator/ (const Vector3 &a, const Vector3 &b) |
Divides two vectors component-wise. | |
Vector3 | operator- (const Vector3 &a, const Vector3 &b) |
Subtracts two vectors. | |
Vector3 | operator* (const Vector3 &left, const Vector3 &right) |
Multiplies two vectors component-wise. | |
Vector3 | operator* (const Vector3 &vec, float scalar) |
Multiplies a vector by a scalar. | |
Vector3 | operator* (float scalar, const Vector3 &vec) |
Multiplies a scalar by a vector. | |
Vector3 | Clamp (Vector3 temp, float minValue, float maxValue) |
Clamps the vector components to the given range. | |
A 3D vector structure.
|
inline |
Constructs a vector with all components set to the same value.
pXYZ | The value to set for x, y, and z. |
|
inline |
|
inline |
Constructs a vector with specified x, y, and z values.
xP | The x component. |
yP | The y component. |
zP | The z component. |
|
inline |
Returns a vector with the absolute values of each component.
Clamps the vector components to the given range.
vec | The vector to clamp. |
minValue | The minimum value. |
maxValue | The maximum value. |
|
inline |
Clamps the vector components to the given range in place.
minValue | The minimum value. |
maxValue | The maximum value. |
Computes the cross product of two vectors.
a | The first vector. |
b | The second vector. |
Computes the dot product of two vectors.
a | The first vector. |
b | The second vector. |
|
inline |
Returns a pointer to the vector's data as a float array.
float Vector3::Length | ( | ) | const |
Returns the length (magnitude) of the vector.
float Vector3::LengthSq | ( | ) | const |
Returns the squared length of the vector.
Linearly interpolates between two vectors.
a | The start vector. |
b | The end vector. |
f | The interpolation factor (0-1). |
Returns a normalized copy of the provided vector.
vec | The vector to normalize. |
|
inline |
Returns a normalized copy of this vector.
|
inline |
Multiplies the vector by a scalar in place.
scalar | The scalar value. |
Adds another vector to this vector in place.
right | The vector to add. |
|
inline |
Negates the vector.
Subtracts another vector from this vector in place.
right | The vector to subtract. |
|
inline |
Divides the vector by a scalar in place.
scalar | The scalar value. |
|
inline |
Accesses a component by index.
index | The index (0=x, 1=y, 2=z). |
std::out_of_range | if index is not 0, 1, or 2. |
|
inline |
Accesses a component by index (const).
index | The index (0=x, 1=y, 2=z). |
std::out_of_range | if index is not 0, 1, or 2. |
Reflects a vector about a normal.
v | The vector to reflect. |
n | The normal vector (should be normalized). |
void Vector3::Set | ( | float | xP, |
float | yP, | ||
float | zP ) |
Sets the vector components.
xP | The x component. |
yP | The y component. |
zP | The z component. |
|
inline |
Returns a string representation of the vector.
|
static |
Transforms a vector by a quaternion.
v | The vector to transform. |
q | The quaternion. |
Transforms a vector by a matrix.
vec | The vector to transform. |
mat | The transformation matrix. |
w | The w component (default 1.0f). |
|
static |
Transforms the vector by a matrix and applies perspective division.
vec | The vector to transform. |
mat | The transformation matrix. |
w | The w component (default 1.0f). |
|
inlinestatic |
Linearly interpolates between two vectors with speed and delta time.
current | The current vector. |
target | The target vector. |
interpSpeed | The interpolation speed. |
deltaTime | The time step (optional). |
|
inline |
|
inline |
|
inline |
Clamps the vector components to the given range.
temp | The vector to clamp. |
minValue | The minimum value. |
maxValue | The maximum value. |
Multiplies two vectors component-wise.
left | The first vector. |
right | The second vector. |
Multiplies a vector by a scalar.
vec | The vector. |
scalar | The scalar value. |
Multiplies a scalar by a vector.
scalar | The scalar value. |
vec | The vector. |
Adds two vectors.
a | The first vector. |
b | The second vector. |
Subtracts two vectors.
a | The first vector. |
b | The second vector. |
Divides two vectors component-wise.
a | The numerator vector. |
b | The denominator vector. |
Divides a vector by a scalar.
vec | The vector. |
scalar | The scalar value. |