Sdk vector math api documentation

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

Functions

AppendScale

Matrix4 AppendScale(Matrix4 m, vector3 v)

post multiply scale

PARAMETERS

Matrix4 m the matrix
vector3 v the scale vector

RETURNS

Matrix4 the scaled vector

Cross

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

DivPerElem

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

DivPerElem

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

Dot

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

Dot

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

Inverse

Matrix3 Inverse(Matrix3 m)

inverse matrix

PARAMETERS

Matrix3 m the rotation

RETURNS

Matrix3 the transposed matrix

Inverse

Matrix4 Inverse(Matrix4 m)

inverse matrix

PARAMETERS

Matrix4 m the rotation

RETURNS

Matrix4 the transposed matrix

Length

float Length(vector3 v)

calculate length of a vector

PARAMETERS

vector3 v the vector

RETURNS

float the length

Length

float Length(vector3 v)

calculate length of a vector

PARAMETERS

vector3 v the vector

RETURNS

float the length

Length

float Length(quaternion v)

calculate length of a quaternion

PARAMETERS

quaternion v the quaternion

RETURNS

float the length

Length

float Length(vector3 v)

calculate squared length of a vector

PARAMETERS

vector3 v the vector

RETURNS

float the squared length

Length

float Length(vector4 v)

calculate squared length of a vector

PARAMETERS

vector4 v the vector

RETURNS

float the squared length

Length

float Length(quaternion v)

calculate squared length of a quaternion

PARAMETERS

quaternion v the vector

RETURNS

float the squared length

Lerp

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

Lerp

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

MulPerElem

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

MulPerElem

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

MulPerElem

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

MulPerElem

quaternion MulPerElem(quaternion q)

Returns the conjugate of the quaternion: conj = -q

PARAMETERS

quaternion q the quaternions

RETURNS

quaternion the result

Normalize

vector3 Normalize(vector3 v)

normalize a vector to length 1

PARAMETERS

vector3 v the vector

RETURNS

vector3 the normalized vector

Normalize

vector4 Normalize(vector4 v)

normalize a vector to length 1

PARAMETERS

vector4 v the vector

RETURNS

vector4 the normalized vector

Normalize

quaternion Normalize(quaternion v)

normalize a quaternion to length 1

PARAMETERS

quaternion v the quaternion

RETURNS

quaternion the normalized quaternion

OrthoInverse

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

Rotate

vector3 Rotate(quaternion q, vector3 v)

rotate vector using quaternion

PARAMETERS

quaternion q the rotation
vector3 v the vector

RETURNS

vector3 the rotated vector

Slerp

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

Slerp

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

Slerp

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

Transpose

Matrix3 Transpose(Matrix3 m)

transpose matrix

PARAMETERS

Matrix3 m the rotation

RETURNS

Matrix3 the transposed matrix

Transpose

Matrix4 Transpose(Matrix4 m)

transpose matrix

PARAMETERS

Matrix4 m the rotation

RETURNS

Matrix4 the transposed matrix

Types

Matrix3

A 3x3 matrix


Matrix4

A 4x4 matrix


Point3

A 3-tuple (with 4-th element always set to 1)


Quat

A 4-tuple representing a rotation rotation. The xyz represents the axis, and the w represents the angle.


Vector3

A 3-tuple (with 4-th element always set to 0)


Vector4

A 4-tuple