![]() |
Murl Engine API
Version 2018.3
|
A 4-component vector class. More...
#include <murl_math_vector.h>
A 4-component vector class.
Public Types | |
enum | Component { X, Y, Z, W, NUM_COMPONENTS } |
Enumeration of the components raw data index. More... | |
enum | ComponentMask { MASK_NONE, MASK_X, MASK_Y, MASK_Z, MASK_W, MASK_XY, MASK_XZ, MASK_YZ, MASK_XYZ, MASK_ALL } |
Enumeration of the components' bit masks. More... | |
enum | PredefinedType { ZERO_DIRECTION, ZERO_POSITION, UNINITIALIZED } |
Enumeration of the predefined initialization types for constructing a Vector(PredefinedType type). More... | |
typedef DataType | ValueType |
The template parameter value type. More... | |
Public Member Functions | |
Vector () | |
The default constructor. | |
template<class DataType2 > | |
Vector (const Vector< DataType2 > &v) | |
The copy constructor using a vector of different type. More... | |
Vector (DataType vx, DataType vy, DataType vz, DataType vw) | |
Constructor to initialize a vector with given component values. More... | |
Vector (const Quaternion< DataType > &q) | |
Constructor to initialize an axis/angle vector from a quaternion. More... | |
Vector (PredefinedType type) | |
Constructor to create a vector from a predefined type. More... | |
const DataType & | operator[] (UInt32 index) const |
Get a const reference to one of the 4 component values. More... | |
DataType & | operator[] (UInt32 index) |
Get a reference to one of the 4 component values. More... | |
const DataType * | GetPointer () const |
Get a const pointer to the raw data. More... | |
DataType * | GetPointer () |
Get a pointer to the raw data. More... | |
Vector & | operator+= (const Vector &v) |
In-place addition operator. More... | |
Vector & | operator-= (const Vector &v) |
In-place subtraction operator. More... | |
Vector & | operator*= (DataType v) |
In-place multiplication operator (scaling). More... | |
Vector & | operator*= (const Vector &v) |
In-place component-wise multiplication operator. More... | |
Vector & | operator/= (DataType v) |
In-place division operator (inverse scaling). More... | |
Vector & | operator/= (const Vector &v) |
In-place component-wise division operator. More... | |
Vector | operator+ (const Vector &rhs) const |
Addition operator. More... | |
Vector | operator- (const Vector &rhs) const |
Subtraction operator. More... | |
Vector | operator* (DataType rhs) const |
Multiplication (scaling) operator. More... | |
Vector | operator* (const Vector &rhs) const |
Component-wise multiplication operator. More... | |
Vector | operator/ (DataType rhs) const |
Division (inverse scaling) operator. More... | |
Vector | operator/ (const Vector &rhs) const |
Component-wise division operator. More... | |
Vector | operator- () const |
Inversion (negation) operator. More... | |
Quaternion< DataType > | operator* (const Quaternion< DataType > &rhs) const |
Multiplication operator for quaternion. More... | |
void | Clear () |
Clear all components of the vector instance. More... | |
void | Set (PredefinedType type) |
Set all components of the vector instance to the values of a given predefined type. More... | |
void | Set (const Vector &v) |
Copy the content of a source vector to the vector instance. More... | |
void | Set (DataType v) |
Set all components of the vector instance to a given value. More... | |
void | Set (DataType vx, DataType vy, DataType vz, DataType vw) |
Set all components of the vector instance to a set of given component values. More... | |
void | Set (const Quaternion< DataType > &q) |
Convert a given quaternion to an axis/angle vector. More... | |
void | AddSelf (const Vector &v) |
In-place addition. More... | |
void | SubtractSelf (const Vector &v) |
In-place subtraction. More... | |
void | MultiplySelf (DataType v) |
In-place multiplication (scaling). More... | |
void | MultiplySelf (const Vector &v) |
In-place component-wise multiplication. More... | |
void | DivideSelf (DataType v) |
In-place division (inverse scaling). More... | |
void | DivideSelf (const Vector &v) |
In-place component-wise division. More... | |
void | CrossSelf (const Vector &v) |
In-place cross product. More... | |
void | InterpolateSelf (const Vector &v, DataType t) |
In-place linear interpolation. More... | |
void | ProjectSelf (const Vector &v) |
In-place projection of a given second vector. More... | |
void | MinSelf (const Vector &v) |
In-place set each component to the minimum from the vector instance and a given second vector. More... | |
void | MaxSelf (const Vector &v) |
In-place set each component to the maximum from the vector instance and a given second vector. More... | |
void | ClampSelf (const Vector &min, const Vector &max) |
In-place clamp each component to the value range given by the min and max vector parameters. More... | |
void | MinLengthSelf (DataType v) |
Rescale the vector to a length below or equal a given minimum. More... | |
void | MaxLengthSelf (DataType v) |
Rescale the vector to a length above or equal a given maximum. More... | |
void | ClampLengthSelf (DataType min, DataType max) |
Clamp the vector to a length within a given range. More... | |
void | AbsSelf () |
Set all vector components to their absolute value. | |
void | SgnSelf () |
Set all vector components to either -1, 0 or +1 depending on their sign. | |
void | InvertSelf () |
In-place inversion (negation) of the vector instance. | |
void | NormalizeSelf () |
In-place normalization of the vector instance. More... | |
void | NormalizeAxisSelf () |
In-place normalization of the x, y and z components. More... | |
Vector | Add (const Vector &v) const |
Get the addition of a vector. More... | |
Vector | Subtract (const Vector &v) const |
Get the subtraction of a vector. More... | |
Quaternion< DataType > | Multiply (const Quaternion< DataType > &q) const |
Get the multiplication with a quaternion. More... | |
Vector | Multiply (DataType v) const |
Get the multiplication (scaling). More... | |
Vector | Multiply (const Vector &v) const |
Get the component-wise multiplication. More... | |
Vector | Divide (DataType v) const |
Get the division (inverse scaling). More... | |
Vector | Divide (const Vector &v) const |
Get the component-wise division. More... | |
Vector | Cross (const Vector &v) const |
Get the cross product. More... | |
Vector | Interpolate (const Vector &v, DataType t) const |
Get the linear interpolation. More... | |
Vector | Project (const Vector &v) const |
Get the projection of a given second vector. More... | |
Vector | Min (const Vector &v) const |
Get the minimum of each component from the vector instance and a given second vector. More... | |
Vector | Max (const Vector &v) const |
Get the maximum of each component from the vector instance and a given second vector. More... | |
Vector | Clamp (const Vector &min, const Vector &max) const |
Clamp each component to the value range given by the min and max vector parameters. More... | |
Vector | MinLength (DataType v) const |
Get a vector with a length below or equal a given minimum. More... | |
Vector | MaxLength (DataType v) const |
Get a vector with a length above or equal a given maximum. More... | |
Vector | ClampLength (DataType min, DataType max) const |
Get the a vector with clamped length. More... | |
Vector | Abs () const |
Get a vector containing absolute values for each of the instance's components. More... | |
Vector | Sgn () const |
Get a vector containing component values of either -1, 0 or +1, depending on the instance component's signs. More... | |
Vector | Invert () const |
Get the inversion (negation) of the vector instance. More... | |
Vector | Normalize () const |
Get the normalization of the vector instance. More... | |
Vector | NormalizeAxis () const |
Get the normalization of the x, y and z components. More... | |
DataType | Dot (const Vector &v) const |
Get the dot product of the vector instance and a given second vector. More... | |
DataType | GetLength () const |
Get the length of the vector instance. More... | |
DataType | GetSquaredLength () const |
Get the squared length of the vector instance. More... | |
DataType | GetAngle2D () const |
Get the x/y angle of the vector instance. More... | |
Bool | IsZero () const |
Check if the vector instance equals the null vector. More... | |
Bool | IsZero (DataType epsilon) const |
Check if the vector instance equals the null vector. More... | |
Bool | IsZeroPosition () const |
Check if the vector instance equals the zero position. More... | |
Bool | IsZeroPosition (DataType epsilon) const |
Check if the vector instance equals the zero position. More... | |
Bool | IsEqual (const Vector &v) const |
Check if the vector instance is equal to a given second vector. More... | |
Bool | IsEqual (const Vector &v, DataType epsilon) const |
Check if the vector instance is equal to a given second vector. More... | |
Bool | GetBaseNormals (Vector &n1, Vector &n2, Vector &n3) const |
Get base vectors for this vector instance. More... | |
String | ToString () const |
Get the string representation of the object. More... | |
SInt32 | GetCount () const |
Get the number of elements in the object. More... | |
Public Attributes | |
union { | |
DataType mComponents [NUM_COMPONENTS] | |
The components data array. More... | |
struct { | |
DataType x | |
The X component. More... | |
DataType y | |
The Y component. More... | |
DataType z | |
The Z component. More... | |
DataType w | |
The W component. More... | |
} | |
The components member struct. More... | |
}; | |
The components storage union overlaps the raw data array mComponents and the component structure. | |
Friends | |
bool | operator== (const Vector< DataType > &lhs, const Vector< DataType > &rhs) |
Equal to comparison operator. More... | |
bool | operator!= (const Vector< DataType > &lhs, const Vector< DataType > &rhs) |
Not equal to comparison operator. More... | |
typedef DataType Murl::Math::Vector< DataType >::ValueType |
The template parameter value type.
enum Murl::Math::Vector::Component |
enum Murl::Math::Vector::ComponentMask |
Enumeration of the components' bit masks.
enum Murl::Math::Vector::PredefinedType |
Enumeration of the predefined initialization types for constructing a Vector(PredefinedType type).
Enumerator | |
---|---|
ZERO_DIRECTION | Initialize with zero direction {0, 0, 0, 0}. |
ZERO_POSITION | Initialize with zero position {0, 0, 0, 1}. |
UNINITIALIZED | Create an uninitialized instance. |
|
inline |
The copy constructor using a vector of different type.
v | The vector to copy. |
|
inline |
Constructor to initialize a vector with given component values.
vx | The x component. |
vy | The y component. |
vz | The z component. |
vw | The w component. |
|
inline |
Constructor to initialize an axis/angle vector from a quaternion.
q | The quaternion. |
|
inline |
Constructor to create a vector from a predefined type.
type | The predefined type. |
|
inline |
Get a const reference to one of the 4 component values.
index | The component index, see enum Component. |
|
inline |
Get a reference to one of the 4 component values.
index | The component index, see enum Component. |
|
inline |
Get a const pointer to the raw data.
|
inline |
Get a pointer to the raw data.
|
inline |
In-place addition operator.
v | The vector to add. |
|
inline |
In-place subtraction operator.
v | The vector to subtract. |
|
inline |
In-place multiplication operator (scaling).
v | The value to multiply. |
|
inline |
In-place component-wise multiplication operator.
v | The vector to multiply. |
|
inline |
In-place division operator (inverse scaling).
v | The value to divide. |
|
inline |
In-place component-wise division operator.
v | The vector to multiply. |
|
inline |
Addition operator.
rhs | The right hand side vector. |
|
inline |
Subtraction operator.
rhs | The right hand side vector. |
|
inline |
Multiplication (scaling) operator.
rhs | The right hand side value. |
|
inline |
Component-wise multiplication operator.
rhs | The right hand side vector. |
|
inline |
Division (inverse scaling) operator.
rhs | The right hand side value. |
|
inline |
Component-wise division operator.
rhs | The right hand side vector. |
|
inline |
Inversion (negation) operator.
|
inline |
Multiplication operator for quaternion.
rhs | The right hand side quaternion. |
|
inline |
Clear all components of the vector instance.
Set all components to default constructor of data type.
|
inline |
Set all components of the vector instance to the values of a given predefined type.
type | The value to set. |
|
inline |
Copy the content of a source vector to the vector instance.
v | The vector to copy from. |
|
inline |
Set all components of the vector instance to a given value.
v | The value to set. |
|
inline |
Set all components of the vector instance to a set of given component values.
vx | The x-component value to set. |
vy | The y-component value to set. |
vz | The z-component value to set. |
vw | The w-component value to set. |
|
inline |
Convert a given quaternion to an axis/angle vector.
q | The quaternion to convert from. |
|
inline |
In-place addition.
v | The vector to add. |
|
inline |
In-place subtraction.
v | The vector to subtract. |
|
inline |
In-place multiplication (scaling).
v | The value to multiply. |
|
inline |
In-place component-wise multiplication.
v | The vector to multiply. |
|
inline |
In-place division (inverse scaling).
v | The value to divide. |
|
inline |
In-place component-wise division.
v | The vector to divide. |
|
inline |
In-place cross product.
v | The vector to cross. |
|
inline |
In-place linear interpolation.
Interpolation along a straight line between the vector instance (first vector) and a given second vector. For t=0.0, the result equals the first vector and for t=1.0 the second one.
v | The vector to interpolate. |
t | The distance for interplation. |
|
inline |
In-place projection of a given second vector.
Project the given second vector onto the vector instance (first vector). The first vector gets normalized and then multiplied by the length retrieved from a dot-product multiplication between the two vectors (i.e. the vector instance retains its direction, but retrieves the length of the projection).
v | The vector to project from. |
|
inline |
In-place set each component to the minimum from the vector instance and a given second vector.
v | The vector to evaluate the minimum from. |
|
inline |
In-place set each component to the maximum from the vector instance and a given second vector.
v | The vector to evaluate the maximum from. |
|
inline |
In-place clamp each component to the value range given by the min and max vector parameters.
min | The component-wise minimum to clamp to. |
max | The component-wise maximum to clamp to. |
|
inline |
Rescale the vector to a length below or equal a given minimum.
See MinLength().
v | The minimum length. |
|
inline |
Rescale the vector to a length above or equal a given maximum.
See MaxLength().
v | The maximum length. |
|
inline |
Clamp the vector to a length within a given range.
See ClampLength().
min | The minimum length. |
max | The maximum length. |
|
inline |
In-place normalization of the vector instance.
Normalization retains the direction and sets the length to 1.0.
|
inline |
In-place normalization of the x, y and z components.
Calculates the normalization without touching the w component, for normalizing the axis of an axis/angle representation.
|
inline |
Get the addition of a vector.
v | The vector to add. |
|
inline |
Get the subtraction of a vector.
v | The vector to subtract. |
|
inline |
Get the multiplication with a quaternion.
q | The quaternion to multiply. |
|
inline |
Get the multiplication (scaling).
v | The value to multiply. |
|
inline |
Get the component-wise multiplication.
v | The vector to multiply. |
|
inline |
Get the division (inverse scaling).
v | The value to divide. |
|
inline |
Get the component-wise division.
v | The vector to divide. |
|
inline |
Get the cross product.
v | The vector to cross. |
|
inline |
Get the linear interpolation.
Interpolation along a straight line between the vector instance (first vector) and a given second vector. For t=0.0, the result equals the first vector and for t=1.0 the second one.
v | The vector to interpolate. |
t | The interpolation factor. |
|
inline |
Get the projection of a given second vector.
Project the given second vector onto the vector instance (first vector). The first vector gets normalized and then multiplied by the length retrieved from a dot-product multiplication between the two vectors (i.e. the vector instance retains its direction, but retrieves the length of the projection).
v | The vector to project from. |
|
inline |
Get the minimum of each component from the vector instance and a given second vector.
v | The vector to evaluate the minimum from. |
|
inline |
Get the maximum of each component from the vector instance and a given second vector.
v | The vector to evaluate the maximum from. |
|
inline |
Clamp each component to the value range given by the min and max vector parameters.
min | The component-wise minimum to clamp to. |
max | The component-wise maximum to clamp to. |
|
inline |
Get a vector with a length below or equal a given minimum.
If the current vector's length is below or equal the given minimum value, the vector is directly returned. Otherwise a scaled vector is returned, with the original direction and given length.
v | The minimum length. |
|
inline |
Get a vector with a length above or equal a given maximum.
If the current vector's length is above or equal the given maximum value, the vector is directly returned. Otherwise a scaled vector is returned, with the original direction and given length. If the vector has zero length (i.e. undefined direction) a zero vector is returned with its w component set to either 0 or 1, depending on the current vector's w value.
v | The maximum length. |
|
inline |
Get the a vector with clamped length.
This method returns a vector in the direction of the vector instance, but with its length clamped to the given range.
min | The minimum length. |
max | The maximum length. |
|
inline |
Get a vector containing absolute values for each of the instance's components.
|
inline |
Get a vector containing component values of either -1, 0 or +1, depending on the instance component's signs.
|
inline |
Get the inversion (negation) of the vector instance.
|
inline |
Get the normalization of the vector instance.
Normalization retains the direction and sets the length to 1.0.
|
inline |
Get the normalization of the x, y and z components.
Calculates the normalization without touching the w component, for normalizing the axis of an axis/angle representation.
|
inline |
Get the dot product of the vector instance and a given second vector.
v | The second vector. |
|
inline |
Get the length of the vector instance.
|
inline |
Get the squared length of the vector instance.
|
inline |
Get the x/y angle of the vector instance.
|
inline |
Check if the vector instance equals the null vector.
Compares all values within the default epsilon range Limits::Epsilon().
|
inline |
Check if the vector instance equals the null vector.
Compares all values within a given epsilon range.
epsilon | The epsilon to compare. |
|
inline |
Check if the vector instance equals the zero position.
Compares the x, y and z values within the default epsilon range Limits::Epsilon().
|
inline |
Check if the vector instance equals the zero position.
Compares the x, y and z values within a given epsilon range.
epsilon | The epsilon to compare. |
|
inline |
Check if the vector instance is equal to a given second vector.
Compares all values within the default epsilon range Limits::Epsilon().
v | The vector to compare. |
|
inline |
Check if the vector instance is equal to a given second vector.
Compares all values within a given epsilon range.
v | The vector to compare. |
epsilon | The epsilon to compare. |
|
inline |
Get base vectors for this vector instance.
This method tries to calculate three direction vectors from the current instance, so that they form an orthonormal base. If the current vector has zero length, false is returned.
n1 | Base vector 1 |
n2 | Base vector 2 |
n3 | Base vector 3 |
|
inline |
Get the string representation of the object.
|
inline |
Get the number of elements in the object.
|
friend |
Equal to comparison operator.
Performs a test without an epsilon range, which can be used for detecting changes i.e. DoubleBuffer<Vector> class. To compare within an epsilon range use Vector::IsEqual().
lhs | The left hand side vector to compare. |
rhs | The right hand side vector to compare. |
|
friend |
Not equal to comparison operator.
Performs a test without an epsilon range, which can be used for detecting changes i.e. DoubleBuffer<Vector> class. To compare within an epsilon range use Vector::IsEqual().
lhs | The left hand side vector to compare. |
rhs | The right hand side vector to compare. |
DataType Murl::Math::Vector< DataType >::mComponents[NUM_COMPONENTS] |
The components data array.
DataType Murl::Math::Vector< DataType >::x |
The X component.
DataType Murl::Math::Vector< DataType >::y |
The Y component.
DataType Murl::Math::Vector< DataType >::z |
The Z component.
DataType Murl::Math::Vector< DataType >::w |
The W component.