Vector Math

Namespace: dmVMath Language: C++ Type: Defold C++ File: vmath.h Source: engine/dlib/src/dmsdk/dlib/vmath.h Include: dmsdk/dlib/vmath.h

Vector Math functions.

API

AppendScale

Type: FUNCTION post multiply scale

Parameters

Returns

Cross

Type: FUNCTION cross product between two vectors

Parameters

Returns

DivPerElem

Type: FUNCTION Divide two vectors per element: Vector3(a.x/b.x, a.y/b.y, a.z/b.z)

Parameters

Returns

DivPerElem

Type: FUNCTION Divide two vectors per element: Vector3(a.x/b.x, a.y/b.y, a.z/b.z, a.w/b.w)

Parameters

Returns

Dot

Type: FUNCTION dot product between two vectors

Parameters

Returns

Dot

Type: FUNCTION dot product between two vectors

Parameters

Returns

EulerToQuat

Type: FUNCTION Converts euler angles (x, y, z) in degrees into a quaternion The error is guaranteed to be less than 0.001.

Parameters

Inverse

Type: FUNCTION inverse matrix

Parameters

Returns

Inverse

Type: FUNCTION inverse matrix

Parameters

Returns

Length

Type: FUNCTION calculate length of a vector

Parameters

Returns

Length

Type: FUNCTION calculate length of a vector

Parameters

Returns

Length

Type: FUNCTION calculate length of a quaternion

Parameters

Returns

Length

Type: FUNCTION calculate squared length of a vector

Parameters

Returns

Length

Type: FUNCTION calculate squared length of a vector

Parameters

Returns

Length

Type: FUNCTION calculate squared length of a quaternion

Parameters

Returns

Lerp

Type: FUNCTION linear interpolate between two vectors

Notes

Parameters

Returns

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

Type: FUNCTION linear interpolate between two vectors

Notes

Parameters

Returns

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

Matrix3

Type: TYPEDEF A 3x3 matrix

Notes

Matrix4

Type: TYPEDEF A 4x4 matrix

Notes

MulPerElem

Type: FUNCTION Multiply two vectors per element: Vector3(a.x * b.x, a.y * b.y, a.z * b.z)

Parameters

Returns

MulPerElem

Type: FUNCTION Multiply two vectors per element: Vector3(a.x * b.x, a.y * b.y, a.z * b.z, a.w * b.w)

Parameters

Returns

MulPerElem

Type: FUNCTION Return absolute value per element: Vector3(abs(v.x), abs(v.y), abs(v.z))

Parameters

Returns

MulPerElem

Type: FUNCTION Returns the conjugate of the quaternion: conj = -q

Parameters

Returns

Normalize

Type: FUNCTION normalize a vector to length 1

Parameters

Returns

Normalize

Type: FUNCTION normalize a vector to length 1

Parameters

Returns

Normalize

Type: FUNCTION normalize a quaternion to length 1

Parameters

Returns

OrthoInverse

Type: FUNCTION Compute the inverse of a 4x4 matrix, which is expected to be an affine matrix with an orthogonal upper-left 3x3 submatrix

Parameters

Returns

Point3

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

Notes

Examples

dmVMath::Point3 p = dmVMath::Point3(x, y, z); // Create new point
float length_squared = p.getX() * p.getX() + p.getY() * p.getY() + p.getZ() * p.getZ();

Quat

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

Notes

Examples

dmVMath::Quat p = dmVMath::Quat(x, y, z, w); // Create new rotation. W is the angle

QuatFromAngle

Type: FUNCTION construct a quaternion from an axis index and angle

Parameters

Returns

QuatToEuler

Type: FUNCTION Converts a quaternion into euler angles (r0, r1, r2), based on YZX rotation order. To handle gimbal lock (singularity at r1 ~ +/- 90 degrees), the cut off is at r0 = +/- 88.85 degrees, which snaps to +/- 90. The provided quaternion is expected to be normalized. The error is guaranteed to be less than +/- 0.02 degrees

Parameters

Returns

Rotate

Type: FUNCTION rotate vector using quaternion

Parameters

Returns

Slerp

Type: FUNCTION spherical linear interpolate between two vectors

Notes

Parameters

Returns

Slerp

Type: FUNCTION spherical linear interpolate between two vectors

Notes

Parameters

Returns

Slerp

Type: FUNCTION Interpolates along the shortest path between two quaternions

Notes

Parameters

Returns

Transpose

Type: FUNCTION transpose matrix

Parameters

Returns

Transpose

Type: FUNCTION transpose matrix

Parameters

Returns

Vector3

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

Notes

Examples

dmVMath::Vector3 p = dmVMath::Vector3(x, y, z); // Create new vector
float length_squared = p.getX() * p.getX() + p.getY() * p.getY() + p.getZ() * p.getZ();

Vector4

Type: TYPEDEF A 4-tuple

Notes

Examples

dmVMath::Vector4 p = dmVMath::Vector4(x, y, z, w); // Create new vector
float length_squared = p.getX() * p.getX() + p.getY() * p.getY() + p.getZ() * p.getZ() + p.getW() * p.getW();