Table of Contents

Class Mat4d

Namespace
Vintagestory.API.MathTools
Assembly
VintagestoryAPI.dll

4x4 Matrix Math

public class Mat4d
Inheritance
Mat4d
Inherited Members

Methods

Adjoint(double[], double[])

Calculates the adjugate of a mat4

public static double[] Adjoint(double[] output, double[] a)

Parameters

output double[]

{mat4} out the receiving matrix

a double[]

{mat4} a the source matrix

Returns

double[]

{mat4} out

CloneIt(double[])

Creates a new mat4 initialized with values from an existing matrix

public static double[] CloneIt(double[] a)

Parameters

a double[]

a matrix to clone

Returns

double[]

{mat4} a new 4x4 matrix

Copy(double[], double[])

Copy the values from one mat4 to another

public static double[] Copy(double[] output, double[] a)

Parameters

output double[]

{mat4} out the receiving matrix

a double[]

{mat4} a the source matrix

Returns

double[]

{mat4} out

Create()

Creates a new identity mat4 0 4 8 12 1 5 9 13 2 6 10 14 3 7 11 15

public static double[] Create()

Returns

double[]

{mat4} a new 4x4 matrix

Determinant(double[])

Calculates the determinant of a mat4

public static double Determinant(double[] a)

Parameters

a double[]

{mat4} a the source matrix

Returns

double

{Number} determinant of a

FromQuat(double[], double[])

Calculates a 4x4 matrix from the given quaternion

public static double[] FromQuat(double[] output, double[] q)

Parameters

output double[]

{mat4} out mat4 receiving operation result

q double[]

{quat} q Quaternion to create matrix from

Returns

double[]

{mat4} out

FromRotationTranslation(double[], double[], double[])

Creates a matrix from a quaternion rotation and vector translation This is equivalent to (but much faster than): mat4.identity(dest); mat4.translate(dest, vec); var quatMat = mat4.create(); quat4.toMat4(quat, quatMat); mat4.multiply(dest, quatMat);

public static double[] FromRotationTranslation(double[] output, double[] q, double[] v)

Parameters

output double[]

{mat4} out mat4 receiving operation result

q double[]

{quat4} q Rotation quaternion

v double[]

{vec3} v Translation vector

Returns

double[]

{mat4} out

Frustum(double[], double, double, double, double, double, double)

Generates a frustum matrix with the given bounds

public static double[] Frustum(double[] output, double left, double right, double bottom, double top, double near, double far)

Parameters

output double[]

{mat4} out mat4 frustum matrix will be written into

left double

{Number} left Left bound of the frustum

right double

{Number} right Right bound of the frustum

bottom double

{Number} bottom Bottom bound of the frustum

top double

{Number} top Top bound of the frustum

near double

{Number} near Near bound of the frustum

far double

{Number} far Far bound of the frustum

Returns

double[]

{mat4} out

Identity(double[])

Set a mat4 to the identity matrix

public static double[] Identity(double[] output)

Parameters

output double[]

{mat4} out the receiving matrix

Returns

double[]

{mat4} out

Invert(double[], double[])

Inverts a mat4

public static double[] Invert(double[] output, double[] a)

Parameters

output double[]

{mat4} out the receiving matrix

a double[]

{mat4} a the source matrix

Returns

double[]

{mat4} out

IsTranslationOnly(double[])

If we have a translation-only matrix - one with no rotation or scaling - return true. If the matrix includes some scaling or rotation components, return false.
The identity matrix returns true here because there is no scaling or rotation, even though the translation is zero in that special case.

public static bool IsTranslationOnly(double[] matrix)

Parameters

matrix double[]

Returns

bool

true if a simple translation matrix was found, otherwise false

LookAt(double[], double[], double[], double[])

Generates a look-at matrix with the given eye position, focal point, and up axis

public static double[] LookAt(double[] output, double[] eye, double[] center, double[] up)

Parameters

output double[]

{mat4} out mat4 frustum matrix will be written into

eye double[]

{vec3} eye Position of the viewer

center double[]

{vec3} center Point the viewer is looking at

up double[]

{vec3} up vec3 pointing up

Returns

double[]

{mat4} out

Mul(double[], double[], double[])

mat4.multiply

public static double[] Mul(double[] output, double[] a, double[] b)

Parameters

output double[]
a double[]
b double[]

Returns

double[]

Mul(double[], float[], double[])

mat4.multiply

public static double[] Mul(double[] output, float[] a, double[] b)

Parameters

output double[]
a float[]
b double[]

Returns

double[]

MulWithVec4(double[], double[])

Multiply the matrix with a vec4. Reference: http://mathinsight.org/matrix_vector_multiplication Returns a new vec4 vector

public static double[] MulWithVec4(double[] matrix, double[] vec4)

Parameters

matrix double[]
vec4 double[]

Returns

double[]

MulWithVec4(double[], double[], Vec4d)

Multiply the matrix with a vec4. Reference: http://mathinsight.org/matrix_vector_multiplication

public static void MulWithVec4(double[] matrix, double[] vec4, Vec4d outVal)

Parameters

matrix double[]
vec4 double[]
outVal Vec4d

MulWithVec4(double[], Vec4d, Vec4d)

Multiply the matrix with a vec4. Reference: http://mathinsight.org/matrix_vector_multiplication

public static void MulWithVec4(double[] matrix, Vec4d inVal, Vec4d outVal)

Parameters

matrix double[]
inVal Vec4d
outVal Vec4d

Multiply(double[], double[], double[])

Multiplies two mat4's

public static double[] Multiply(double[] output, double[] a, double[] b)

Parameters

output double[]

{mat4} out the receiving matrix

a double[]

{mat4} a the first operand

b double[]

{mat4} b the second operand

Returns

double[]

{mat4} out

Multiply(double[], float[], double[])

Multiplies two mat4's

public static double[] Multiply(double[] output, float[] a, double[] b)

Parameters

output double[]

{mat4} out the receiving matrix

a float[]

{mat4} a the first operand

b double[]

{mat4} b the second operand

Returns

double[]

{mat4} out

Ortho(double[], double, double, double, double, double, double)

Generates a orthogonal projection matrix with the given bounds

public static double[] Ortho(double[] output, double left, double right, double bottom, double top, double near, double far)

Parameters

output double[]

{mat4} out mat4 frustum matrix will be written into

left double

{number} left Left bound of the frustum

right double

{number} right Right bound of the frustum

bottom double

{number} bottom Bottom bound of the frustum

top double

{number} top Top bound of the frustum

near double

{number} near Near bound of the frustum

far double

{number} far Far bound of the frustum

Returns

double[]

{mat4} out

Perspective(double[], double, double, double, double)

Generates a perspective projection matrix with the given bounds

public static double[] Perspective(double[] output, double fovy, double aspect, double near, double far)

Parameters

output double[]

{mat4} out mat4 frustum matrix will be written into

fovy double

{number} fovy Vertical field of view in radians

aspect double

{number} aspect Aspect ratio. typically viewport width/height

near double

{number} near Near bound of the frustum

far double

{number} far Far bound of the frustum

Returns

double[]

{mat4} out

Rotate(double[], double[], double, double, double, double)

Rotates a mat4 by the given angle

public static double[] Rotate(double[] output, double[] a, double rad, double x, double y, double z)

Parameters

output double[]
a double[]
rad double
x double
y double
z double

Returns

double[]

Rotate(double[], double[], double, double[])

Rotates a mat4 by the given angle

public static double[] Rotate(double[] output, double[] a, double rad, double[] axis)

Parameters

output double[]

{mat4} out the receiving matrix

a double[]

{mat4} a the matrix to rotate

rad double

{Number} rad the angle to rotate the matrix by

axis double[]

{vec3} axis the axis to rotate around

Returns

double[]

{mat4} out

RotateX(double[], double[], double)

Rotates a matrix by the given angle around the X axis

public static double[] RotateX(double[] output, double[] a, double rad)

Parameters

output double[]

{mat4} out the receiving matrix

a double[]

{mat4} a the matrix to rotate

rad double

{Number} rad the angle to rotate the matrix by

Returns

double[]

{mat4} out

RotateY(double[], double[], double)

Rotates a matrix by the given angle around the Y axis

public static double[] RotateY(double[] output, double[] a, double rad)

Parameters

output double[]

{mat4} out the receiving matrix

a double[]

{mat4} a the matrix to rotate

rad double

{Number} rad the angle to rotate the matrix by

Returns

double[]

{mat4} out

RotateZ(double[], double[], double)

Rotates a matrix by the given angle around the Z axis

public static double[] RotateZ(double[] output, double[] a, double rad)

Parameters

output double[]

{mat4} out the receiving matrix

a double[]

{mat4} a the matrix to rotate

rad double

{Number} rad the angle to rotate the matrix by

Returns

double[]

{mat4} out

Scale(double[], double, double, double)

public static void Scale(double[] matrix, double x, double y, double z)

Parameters

matrix double[]
x double
y double
z double

Scale(double[], double[], double[])

Scales the mat4 by the dimensions in the given vec3

public static double[] Scale(double[] output, double[] a, double[] v)

Parameters

output double[]

{mat4} out the receiving matrix

a double[]

{mat4} a the matrix to scale

v double[]

{vec3} v the vec3 to scale the matrix by

Returns

double[]

{mat4} out

ToMat4f(float[], double[])

public static float[] ToMat4f(float[] output, double[] input)

Parameters

output float[]
input double[]

Returns

float[]

Translate(double[], double[], double, double, double)

Translate a mat4 by the given vector

public static double[] Translate(double[] output, double[] input, double x, double y, double z)

Parameters

output double[]

{mat4} out the receiving matrix

input double[]

{mat4} a the matrix to translate

x double

{vec3} v vector to translate by

y double
z double

Returns

double[]

{mat4} out

Translate(double[], double[], double[])

Translate a mat4 by the given vector

public static double[] Translate(double[] output, double[] input, double[] translate)

Parameters

output double[]

{mat4} out the receiving matrix

input double[]

{mat4} a the matrix to translate

translate double[]

{vec3} v vector to translate by

Returns

double[]

{mat4} out

Transpose(double[], double[])

Transpose the values of a mat4

public static double[] Transpose(double[] output, double[] a)

Parameters

output double[]

{mat4} out the receiving matrix

a double[]

{mat4} a the source matrix

Returns

double[]

{mat4} out