Vector Math functions.
Namespace: | dmVMath |
Include: | #include <dmsdk/dlib/vmath.h> |
TYPES | |
---|---|
Matrix3 | 3x3 matrix |
Matrix4 | 4x4 matrix |
Point3 | 3-tuple |
Quat | 4-tuple representing a rotation |
Vector3 | 3-tuple |
Vector4 | 4-tuple |
FUNCTIONS | |
---|---|
Matrix4 AppendScale(Matrix4 m, vector3 v) | post multiply scale |
vector3 Cross(vector3 a, vector3 b) | cross product between two vectors |
vector3 DivPerElem(vector3 a, vector3 b) | divide two vectors per element |
vector4 DivPerElem(vector4 a, vector4 b) | divide two vectors per element |
float Dot(vector3 a, vector3 b) | dot product between two vectors |
float Dot(vector4 a, vector4 b) | dot product between two vectors |
Matrix3 Inverse(Matrix3 m) | inverse matrix |
Matrix4 Inverse(Matrix4 m) | inverse matrix |
float Length(vector3 v) | calculate length of a vector |
float Length(vector3 v) | calculate length of a vector |
float Length(quaternion v) | calculate length of a quaternion |
float Length(vector3 v) | calculate squared length of a vector |
float Length(vector4 v) | calculate squared length of a vector |
float Length(quaternion v) | calculate squared length of a quaternion |
vector3 Lerp(float t, vector3 a, vector3 b) | linear interpolate between two vectors |
vector4 Lerp(float t, vector4 a, vector4 b) | linear interpolate between two vectors |
vector3 MulPerElem(vector3 a, vector3 b) | multiply two vectors per element |
vector4 MulPerElem(vector4 a, vector4 b) | multiply two vectors per element |
vector3 MulPerElem(vector3 v) | abs value per element |
quaternion MulPerElem(quaternion q) | conjugate of quaternion |
vector3 Normalize(vector3 v) | normalize a vector to length 1 |
vector4 Normalize(vector4 v) | normalize a vector to length 1 |
quaternion Normalize(quaternion v) | normalize a quaternion to length 1 |
Matrix4 OrthoInverse(Matrix4 m) | Compute the inverse of a 4x4 matrix, which is expe... |
vector3 Rotate(quaternion q, vector3 v) | rotate vector using quaternion |
vector3 Slerp(float t, vector3 a, vector3 b) | spherical linear interpolate between two vectors |
vector4 Slerp(float t, vector4 a, vector4 b) | spherical linear interpolate between two vectors |
quaternion Slerp(float t, quaternion a, quaternion b) | spherical linear interpolate between two vectors |
Matrix3 Transpose(Matrix3 m) | transpose matrix |
Matrix4 Transpose(Matrix4 m) | transpose matrix |
Matrix4 AppendScale(Matrix4 m, vector3 v)
post multiply scale
PARAMETERS
Matrix4 |
m |
the matrix |
vector3 |
v |
the scale vector |
RETURNS
Matrix4 |
the scaled vector |
vector3 Cross(vector3 a, vector3 b)
cross product between two vectors
PARAMETERS
vector3 |
a |
the operand |
vector3 |
b |
the dividend |
RETURNS
vector3 |
the result vector |
vector3 DivPerElem(vector3 a, vector3 b)
Divide two vectors per element: Vector3(a.x/b.x, a.y/b.y, a.z/b.z)
PARAMETERS
vector3 |
a |
the operand |
vector3 |
b |
the dividend |
RETURNS
vector3 |
the result vector |
vector4 DivPerElem(vector4 a, vector4 b)
Divide two vectors per element: Vector3(a.x/b.x, a.y/b.y, a.z/b.z, a.w/b.w)
PARAMETERS
vector4 |
a |
the operand |
vector4 |
b |
the dividend |
RETURNS
vector4 |
the result vector |
float Dot(vector3 a, vector3 b)
dot product between two vectors
PARAMETERS
vector3 |
a |
the first vector |
vector3 |
b |
the second vector |
RETURNS
float |
the dot product |
float Dot(vector4 a, vector4 b)
dot product between two vectors
PARAMETERS
vector4 |
a |
the first vector |
vector4 |
b |
the second vector |
RETURNS
float |
the dot product |
Matrix3 Inverse(Matrix3 m)
inverse matrix
PARAMETERS
Matrix3 |
m |
the rotation |
RETURNS
Matrix3 |
the transposed matrix |
Matrix4 Inverse(Matrix4 m)
inverse matrix
PARAMETERS
Matrix4 |
m |
the rotation |
RETURNS
Matrix4 |
the transposed matrix |
float Length(vector3 v)
calculate length of a vector
PARAMETERS
vector3 |
v |
the vector |
RETURNS
float |
the length |
float Length(vector3 v)
calculate length of a vector
PARAMETERS
vector3 |
v |
the vector |
RETURNS
float |
the length |
float Length(quaternion v)
calculate length of a quaternion
PARAMETERS
quaternion |
v |
the quaternion |
RETURNS
float |
the length |
float Length(vector3 v)
calculate squared length of a vector
PARAMETERS
vector3 |
v |
the vector |
RETURNS
float |
the squared length |
float Length(vector4 v)
calculate squared length of a vector
PARAMETERS
vector4 |
v |
the vector |
RETURNS
float |
the squared length |
float Length(quaternion v)
calculate squared length of a quaternion
PARAMETERS
quaternion |
v |
the vector |
RETURNS
float |
the squared length |
vector3 Lerp(float t, vector3 a, vector3 b)
linear interpolate between two vectors
PARAMETERS
float |
t |
the unit time |
vector3 |
a |
the start vector (t == 0) |
vector3 |
b |
the end vector (t == 1) |
RETURNS
vector3 |
the result vector v = a + (b - a) * t |
EXAMPLES
dmVMath::Vector3 v0 = dmVMath::Lerp(0.0f, a, b); // v0 == a
dmVMath::Vector3 v1 = dmVMath::Lerp(1.0f, a, b); // v1 == b
dmVMath::Vector3 v2 = dmVMath::Lerp(2.0f, a, b); // v2 == a + (b-a) * 2.0f
vector4 Lerp(float t, vector4 a, vector4 b)
linear interpolate between two vectors
PARAMETERS
float |
t |
the unit time |
vector4 |
a |
the start vector (t == 0) |
vector4 |
b |
the end vector (t == 1) |
RETURNS
vector4 |
the result vector v = a + (b - a) * t |
EXAMPLES
dmVMath::Vector4 v0 = dmVMath::Lerp(0.0f, a, b); // v0 == a
dmVMath::Vector4 v1 = dmVMath::Lerp(1.0f, a, b); // v1 == b
dmVMath::Vector4 v2 = dmVMath::Lerp(2.0f, a, b); // v2 == a + (b-a) * 2.0f
vector3 MulPerElem(vector3 a, vector3 b)
Multiply two vectors per element: Vector3(a.x * b.x, a.y * b.y, a.z * b.z)
PARAMETERS
vector3 |
a |
the first vector |
vector3 |
b |
the second vector |
RETURNS
vector3 |
the result vector |
vector4 MulPerElem(vector4 a, vector4 b)
Multiply two vectors per element: Vector3(a.x * b.x, a.y * b.y, a.z * b.z, a.w * b.w)
PARAMETERS
vector4 |
a |
the first vector |
vector4 |
b |
the second vector |
RETURNS
vector4 |
the result vector |
vector3 MulPerElem(vector3 v)
Return absolute value per element: Vector3(abs(v.x), abs(v.y), abs(v.z))
PARAMETERS
vector3 |
v |
the vector |
RETURNS
vector3 |
the result vector |
quaternion MulPerElem(quaternion q)
Returns the conjugate of the quaternion: conj = -q
PARAMETERS
quaternion |
q |
the quaternions |
RETURNS
quaternion |
the result |
vector3 Normalize(vector3 v)
normalize a vector to length 1
PARAMETERS
vector3 |
v |
the vector |
RETURNS
vector3 |
the normalized vector |
vector4 Normalize(vector4 v)
normalize a vector to length 1
PARAMETERS
vector4 |
v |
the vector |
RETURNS
vector4 |
the normalized vector |
quaternion Normalize(quaternion v)
normalize a quaternion to length 1
PARAMETERS
quaternion |
v |
the quaternion |
RETURNS
quaternion |
the normalized quaternion |
Matrix4 OrthoInverse(Matrix4 m)
Compute the inverse of a 4x4 matrix, which is expected to be an affine matrix with an orthogonal upper-left 3x3 submatrix
PARAMETERS
Matrix4 |
m |
the rotation |
RETURNS
Matrix4 |
the transposed matrix |
vector3 Rotate(quaternion q, vector3 v)
rotate vector using quaternion
PARAMETERS
quaternion |
q |
the rotation |
vector3 |
v |
the vector |
RETURNS
vector3 |
the rotated vector |
vector3 Slerp(float t, vector3 a, vector3 b)
spherical linear interpolate between two vectors
PARAMETERS
float |
t |
the unit time |
vector3 |
a |
the start vector (t == 0) |
vector3 |
b |
the end vector (t == 1) |
RETURNS
vector3 |
the result vector |
vector4 Slerp(float t, vector4 a, vector4 b)
spherical linear interpolate between two vectors
PARAMETERS
float |
t |
the unit time |
vector4 |
a |
the start vector (t == 0) |
vector4 |
b |
the end vector (t == 1) |
RETURNS
vector4 |
the result vector |
quaternion Slerp(float t, quaternion a, quaternion b)
Interpolates along the shortest path between two quaternions
PARAMETERS
float |
t |
the unit time |
quaternion |
a |
the start vector (t == 0) |
quaternion |
b |
the end vector (t == 1) |
RETURNS
quaternion |
the result vector |
Matrix3 Transpose(Matrix3 m)
transpose matrix
PARAMETERS
Matrix3 |
m |
the rotation |
RETURNS
Matrix3 |
the transposed matrix |
Matrix4 Transpose(Matrix4 m)
transpose matrix
PARAMETERS
Matrix4 |
m |
the rotation |
RETURNS
Matrix4 |
the transposed matrix |
A 3x3 matrix
A 4x4 matrix
A 3-tuple (with 4-th element always set to 1)
A 4-tuple representing a rotation rotation. The xyz
represents the axis, and the w
represents the angle.
A 3-tuple (with 4-th element always set to 0)
A 4-tuple