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.
Type: FUNCTION post multiply scale
Parameters
m (Matrix4) - the matrixv (Vector3) - the scale vectorReturns
r (Matrix4) - the scaled vectorType: FUNCTION cross product between two vectors
Parameters
a (Vector3) - the operandb (Vector3) - the dividendReturns
v (Vector3) - the result vectorType: FUNCTION Divide two vectors per element: Vector3(a.x/b.x, a.y/b.y, a.z/b.z)
Parameters
a (Vector3) - the operandb (Vector3) - the dividendReturns
v (Vector3) - the result vectorType: FUNCTION Divide two vectors per element: Vector3(a.x/b.x, a.y/b.y, a.z/b.z, a.w/b.w)
Parameters
a (Vector4) - the operandb (Vector4) - the dividendReturns
v (Vector4) - the result vectorType: FUNCTION dot product between two vectors
Parameters
a (Vector3) - the first vectorb (Vector3) - the second vectorReturns
dot_product (float) - the dot productType: FUNCTION dot product between two vectors
Parameters
a (Vector4) - the first vectorb (Vector4) - the second vectorReturns
dot_product (float) - the dot productType: FUNCTION Converts euler angles (x, y, z) in degrees into a quaternion The error is guaranteed to be less than 0.001.
Parameters
xyz (Vector3) - rotation (deg)Type: FUNCTION inverse matrix
Parameters
m (Matrix3) - the rotationReturns
r (Matrix3) - the transposed matrixType: FUNCTION inverse matrix
Parameters
m (Matrix4) - the rotationReturns
r (Matrix4) - the transposed matrixType: FUNCTION calculate length of a vector
Parameters
v (Vector3) - the vectorReturns
length (float) - the lengthType: FUNCTION calculate length of a vector
Parameters
v (Vector3) - the vectorReturns
length (float) - the lengthType: FUNCTION calculate length of a quaternion
Parameters
v (Quat) - the quaternionReturns
length (float) - the lengthType: FUNCTION calculate squared length of a vector
Parameters
v (Vector3) - the vectorReturns
length (float) - the squared lengthType: FUNCTION calculate squared length of a vector
Parameters
v (Vector4) - the vectorReturns
length (float) - the squared lengthType: FUNCTION calculate squared length of a quaternion
Parameters
v (Quat) - the vectorReturns
length (float) - the squared lengthType: FUNCTION linear interpolate between two vectors
Notes
Parameters
t (float) - the unit timea (Vector3) - the start vector (t == 0)b (Vector3) - the end vector (t == 1)Returns
v (Vector3) - the result vector v = a + (b - a) * tExamples
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
Type: FUNCTION linear interpolate between two vectors
Notes
Parameters
t (float) - the unit timea (Vector4) - the start vector (t == 0)b (Vector4) - the end vector (t == 1)Returns
v (Vector4) - the result vector v = a + (b - a) * tExamples
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
Type: TYPEDEF A 3x3 matrix
Notes
Type: TYPEDEF A 4x4 matrix
Notes
Type: FUNCTION Multiply two vectors per element: Vector3(a.x * b.x, a.y * b.y, a.z * b.z)
Parameters
a (Vector3) - the first vectorb (Vector3) - the second vectorReturns
v (Vector3) - the result vectorType: FUNCTION Multiply two vectors per element: Vector3(a.x * b.x, a.y * b.y, a.z * b.z, a.w * b.w)
Parameters
a (Vector4) - the first vectorb (Vector4) - the second vectorReturns
v (Vector4) - the result vectorType: FUNCTION Return absolute value per element: Vector3(abs(v.x), abs(v.y), abs(v.z))
Parameters
v (Vector3) - the vectorReturns
r (Vector3) - the result vectorType: FUNCTION Returns the conjugate of the quaternion: conj = -q
Parameters
q (Quat) - the quaternionsReturns
r (Quat) - the resultType: FUNCTION normalize a vector to length 1
Parameters
v (Vector3) - the vectorReturns
n (Vector3) - the normalized vectorType: FUNCTION normalize a vector to length 1
Parameters
v (Vector4) - the vectorReturns
n (Vector4) - the normalized vectorType: FUNCTION normalize a quaternion to length 1
Parameters
v (Quat) - the quaternionReturns
n (Quat) - the normalized quaternionType: FUNCTION Compute the inverse of a 4x4 matrix, which is expected to be an affine matrix with an orthogonal upper-left 3x3 submatrix
Parameters
m (Matrix4) - the rotationReturns
r (Matrix4) - the transposed matrixType: 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();
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
Type: FUNCTION construct a quaternion from an axis index and angle
Parameters
axis_index (uint32_t) - index of the rotation axisradians (float) - angle of rotation in radiansReturns
q (Quat) - quaternion describing the rotationType: 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
q0 (float) - first imaginary axisq1 (float) - second imaginary axisq2 (float) - third imaginary axisq3 (float) - real partReturns
euler (Vector3) - euler angles in degreesType: FUNCTION rotate vector using quaternion
Parameters
q (Quat) - the rotationv (Vector3) - the vectorReturns
r (Vector3) - the rotated vectorType: FUNCTION spherical linear interpolate between two vectors
Notes
Parameters
t (float) - the unit timea (Vector3) - the start vector (t == 0)b (Vector3) - the end vector (t == 1)Returns
v (Vector3) - the result vectorType: FUNCTION spherical linear interpolate between two vectors
Notes
Parameters
t (float) - the unit timea (Vector4) - the start vector (t == 0)b (Vector4) - the end vector (t == 1)Returns
v (Vector4) - the result vectorType: FUNCTION Interpolates along the shortest path between two quaternions
Notes
Parameters
t (float) - the unit timea (Quat) - the start vector (t == 0)b (Quat) - the end vector (t == 1)Returns
v (Quat) - the result vectorType: FUNCTION transpose matrix
Parameters
m (Matrix3) - the rotationReturns
r (Matrix3) - the transposed matrixType: FUNCTION transpose matrix
Parameters
m (Matrix4) - the rotationReturns
r (Matrix4) - the transposed matrixType: 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();
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();