MathFu
An open source project by
FPL.
|
Vector of d elements with type T. More...
#include "mathfu/vector.h"
Vector of d elements with type T.
Vector stores d elements of type T and provides a set functions to perform operations on the set of elements.
Public Types | |
typedef T | Scalar |
Element type to enable reference by other classes. | |
Public Member Functions | |
Vector () | |
Create an uninitialized Vector. | |
Vector (const Vector< T, d > &v) | |
Create a vector from another vector copying each element. More... | |
template<typename U > | |
Vector (const Vector< U, d > &v) | |
Create a vector from another vector of a different type. More... | |
Vector (const T &s) | |
Create a vector from a single float. More... | |
Vector (const T *a) | |
Create a vector form the first d elements of an array. More... | |
Vector (const T &s1, const T &s2) | |
Create a vector from two values. More... | |
Vector (const T &s1, const T &s2, const T &s3) | |
Create a vector from three values. More... | |
Vector (const Vector< T, 2 > &v12, const T &s3) | |
Create a vector from a 2 component vector and a third value. More... | |
Vector (const T &s1, const T &s2, const T &s3, const T &s4) | |
Create a vector from four values. More... | |
Vector (const Vector< T, 3 > &vector3, const T &value) | |
Create a 4-dimensional vector from a Vector<T, 3>. More... | |
Vector (const Vector< T, 2 > &v12, const Vector< T, 2 > &v34) | |
Create a vector from two 2 component vectors. More... | |
Vector (const VectorPacked< T, d > &vector) | |
Create a vector from packed vector (VectorPacked). More... | |
T & | operator() (const int i) |
Access an element of the vector. More... | |
const T & | operator() (const int i) const |
Access an element of the vector. More... | |
T & | operator[] (const int i) |
Access an element of the vector. More... | |
const T & | operator[] (const int i) const |
Access an element of the vector. More... | |
Vector< T, 3 > | xyz () |
GLSL style 3 element accessor. More... | |
const Vector< T, 3 > | xyz () const |
GLSL style 3 element accessor. More... | |
Vector< T, 2 > | xy () |
GLSL style 2 element accessor. More... | |
const Vector< T, 2 > | xy () const |
GLSL style 2 element accessor. More... | |
Vector< T, 2 > | zw () |
GLSL style 2 element accessor. More... | |
const Vector< T, 2 > | zw () const |
GLSL style 2 element accessor. More... | |
void | Pack (VectorPacked< T, d > *const vector) const |
Pack a Vector to a packed "d" element vector structure. More... | |
T | LengthSquared () const |
Calculate the squared length of this vector. More... | |
T | Length () const |
Calculate the length of this vector. More... | |
T | Normalize () |
Normalize this vector in-place. More... | |
Vector< T, d > | Normalized () const |
Calculate the normalized version of this vector. More... | |
Static Public Member Functions | |
template<typename CompatibleT > | |
static Vector< T, d > | FromType (const CompatibleT &compatible) |
Load from any type that is some formulation of a length d array of type T. More... | |
template<typename CompatibleT > | |
static CompatibleT | ToType (const Vector< T, d > &v) |
Load into any type that is some formulation of a length d array of type T. More... | |
static T | DotProduct (const Vector< T, d > &v1, const Vector< T, d > &v2) |
Calculate the dot product of two vectors. More... | |
static Vector< T, d > | HadamardProduct (const Vector< T, d > &v1, const Vector< T, d > &v2) |
Calculate the hadamard or componentwise product of two vectors. More... | |
static Vector< T, 3 > | CrossProduct (const Vector< T, 3 > &v1, const Vector< T, 3 > &v2) |
Calculate the cross product of two vectors. More... | |
static Vector< T, d > | Lerp (const Vector< T, d > &v1, const Vector< T, d > &v2, const T percent) |
Linearly interpolate two vectors. More... | |
static Vector< T, d > | RandomInRange (const Vector< T, d > &min, const Vector< T, d > &max) |
Generates a random vector. More... | |
static Vector< T, d > | Max (const Vector< T, d > &v1, const Vector< T, d > &v2) |
Compare each component and returns max values. More... | |
static Vector< T, d > | Min (const Vector< T, d > &v1, const Vector< T, d > &v2) |
Compare each component and returns min values. More... | |
Public Attributes | |
MATHFU_DEFINE_CLASS_SIMD_AWARE_NEW_DELETE T | data_ [d] |
Elements of the vector. | |
Related Functions | |
(Note that these are not member functions.) | |
template<class T , int d> | |
Vector< T, d > | operator* (const T &s, const Vector< T, d > &v) |
Multiply a Vector by a scalar. More... | |
template<class T , int d> | |
Vector< T, d > | operator/ (const Vector< T, d > &v, const T &s) |
Divide a Vector by a scalar. More... | |
template<class T , int d> | |
Vector< T, d > | operator+ (const T &s, const Vector< T, d > &v) |
Add a scalar to each element of a Vector. More... | |
template<class T , int d> | |
Vector< T, d > | operator- (const T &s, const Vector< T, d > &v) |
Subtract a scalar from each element of a Vector. More... | |
|
inline |
Create a vector from another vector copying each element.
v | Vector that the data will be copied from. |
|
inlineexplicit |
Create a vector from another vector of a different type.
This copies each element of a Vector which makes it possible to between vectors of different types, for example float/double/int
vectors.
v | Vector that the data will be copied from. |
U | type of Vector elements to copy. |
|
inlineexplicit |
Create a vector from a single float.
Each elements is set to be equal to the value given.
s | Scalar value that the vector will be initialized to. |
|
inlineexplicit |
Create a vector form the first d elements of an array.
a | Array of values that the vector will be iniitlized to. |
|
inline |
Create a vector from two values.
s1 | Scalar value for the first element of the vector. |
s2 | Scalar value for the second element of the vector. |
|
inline |
Create a vector from three values.
s1 | Scalar value for the first element of the vector. |
s2 | Scalar value for the second element of the vector. |
s3 | Scalar value for the third element of the vector. |
|
inline |
Create a vector from a 2 component vector and a third value.
v12 | Vector containing the first 2 values. |
s3 | Scalar value for the third element of the vector. |
|
inline |
Create a vector from four values.
s1 | Scalar value for the first element of the vector. |
s2 | Scalar value for the second element of the vector. |
s3 | Scalar value for the third element of the vector. |
s4 | Scalar value for the forth element of the vector. |
|
inline |
Create a 4-dimensional vector from a Vector<T, 3>.
The last element is initialized to the specified value.
vector3 | Vector used to initialize the first 3 elements. |
value | Value used to set the last element of the vector. |
|
inline |
|
inlineexplicit |
Create a vector from packed vector (VectorPacked).
vector | Packed vector used to initialize an unpacked. |
|
inlinestatic |
Calculate the cross product of two vectors.
Note that this function is only defined for 3-dimensional Vectors.
v1 | First vector. |
v2 | Second vector. |
|
inlinestatic |
Calculate the dot product of two vectors.
v1 | First vector. |
v2 | Second vector. |
|
inlinestatic |
Load from any type that is some formulation of a length d array of type T.
Essentially this is just a type cast and a load, but it happens safely so that we avoid aliasing bugs.
compatible
cast to Vector<T,d>
and dereferenced.
|
inlinestatic |
Calculate the hadamard or componentwise product of two vectors.
v1 | First vector. |
v2 | Second vector. |
|
inline |
Calculate the length of this vector.
|
inline |
Calculate the squared length of this vector.
|
inlinestatic |
Linearly interpolate two vectors.
v1 | First vector. |
v2 | Second vector. |
percent | Percentage from v1 to v2 in range 0.0...1.0. |
|
inlinestatic |
Compare each component and returns max values.
v1 | First vector. |
v2 | Second vector. |
|
inlinestatic |
Compare each component and returns min values.
v1 | First vector. |
v2 | Second vector. |
|
inline |
Normalize this vector in-place.
|
inline |
Calculate the normalized version of this vector.
|
inline |
Access an element of the vector.
i | Index of the element to access. |
|
inline |
Access an element of the vector.
i | Index of the element to access. |
|
inline |
Access an element of the vector.
i | Index of the element to access. |
|
inline |
Access an element of the vector.
i | Index of the element to access. |
|
inline |
Pack a Vector to a packed "d" element vector structure.
vector | Packed "d" element vector to write to. |
|
inlinestatic |
Generates a random vector.
The range of each component is bounded by min and max.
min | Minimum value of the vector. |
max | Maximum value of the vector. |
|
inlinestatic |
Load into any type that is some formulation of a length d array of type T.
Essentially this is just a type cast and a load, but it happens safely so that we avoid aliasing bugs.
v
cast to CompatibleT
and dereferenced.
|
inline |
|
inline |
|
inline |
GLSL style 3 element accessor.
This only works with vectors that contain more than 3 elements.
|
inline |
GLSL style 3 element accessor.
This only works with vectors that contain more than 3 elements.
|
inline |
|
inline |