Table of Contents

Class Mat4f

Namespace
Vintagestory.API.MathTools
Assembly
VintagestoryAPI.dll

4x4 Matrix Math

public class Mat4f
Inheritance
Mat4f
Inherited Members
Extension Methods

Methods

Adjoint(float[], float[])

Calculates the adjugate of a mat4

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

Parameters

output float[]

{mat4} out the receiving matrix

a float[]

{mat4} a the source matrix

Returns

float[]

{mat4} out

CloneIt(float[])

Creates a new mat4 initialized with values from an existing matrix

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

Parameters

a float[]

a matrix to clone

Returns

float[]

{mat4} a new 4x4 matrix

Copy(float[], float[])

Copy the values from one mat4 to another

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

Parameters

output float[]

{mat4} out the receiving matrix

a float[]

{mat4} a the source matrix

Returns

float[]

{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 float[] Create()

Returns

float[]

{mat4} a new 4x4 matrix

Determinant(float[])

Calculates the determinant of a mat4

public static float Determinant(float[] a)

Parameters

a float[]

{mat4} a the source matrix

Returns

float

{Number} determinant of a

ExtractEulerAngles(float[], ref float, ref float, ref float)

public static void ExtractEulerAngles(float[] m, ref float thetaX, ref float thetaY, ref float thetaZ)

Parameters

m float[]
thetaX float
thetaY float
thetaZ float

FromQuat(float[], float[])

Calculates a 4x4 matrix from the given quaternion

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

Parameters

output float[]

{mat4} out mat4 receiving operation result

q float[]

{quat} q Quaternion to create matrix from

Returns

float[]

{mat4} out

FromRotationTranslation(float[], float[], float[])

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 float[] FromRotationTranslation(float[] output, float[] q, float[] v)

Parameters

output float[]

{mat4} out mat4 receiving operation result

q float[]

{quat4} q Rotation quaternion

v float[]

{vec3} v Translation vector

Returns

float[]

{mat4} out

Frustum(float[], float, float, float, float, float, float)

Generates a frustum matrix with the given bounds

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

Parameters

output float[]

{mat4} out mat4 frustum matrix will be written into

left float

{Number} left Left bound of the frustum

right float

{Number} right Right bound of the frustum

bottom float

{Number} bottom Bottom bound of the frustum

top float

{Number} top Top bound of the frustum

near float

{Number} near Near bound of the frustum

far float

{Number} far Far bound of the frustum

Returns

float[]

{mat4} out

Identity(float[])

Set a mat4 to the identity matrix

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

Parameters

output float[]

{mat4} out the receiving matrix

Returns

float[]

{mat4} out

Identity_Scaled(float[], float)

Set a mat4 to the identity matrix with a scale applied

public static float[] Identity_Scaled(float[] output, float scale)

Parameters

output float[]

{mat4} out the receiving matrix

scale float

Returns

float[]

{mat4} out

Invert(float[], float[])

Inverts a mat4

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

Parameters

output float[]

{mat4} out the receiving matrix

a float[]

{mat4} a the source matrix

Returns

float[]

{mat4} out

LookAt(float[], float[], float[], float[])

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

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

Parameters

output float[]

{mat4} out mat4 frustum matrix will be written into

eye float[]

{vec3} eye Position of the viewer

center float[]

{vec3} center Point the viewer is looking at

up float[]

{vec3} up vec3 pointing up

Returns

float[]

{mat4} out

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

mat4.multiply

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

Parameters

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

Returns

float[]

MulWithVec3(float[], float, float, float)

Used for x,y,z representing a direction or normal - as a vec4 this would have the 4th element set to 0, so that applying a matrix transform with a translation would have no effect

public static FastVec3f MulWithVec3(float[] matrix, float x, float y, float z)

Parameters

matrix float[]
x float
y float
z float

Returns

FastVec3f

MulWithVec3(float[], float[], float[])

Used for vec3 representing a direction or normal - as a vec4 this would have the 4th element set to 0, so that applying a matrix transform with a translation would have no effect

public static void MulWithVec3(float[] matrix, float[] vec, float[] output)

Parameters

matrix float[]
vec float[]
output float[]

MulWithVec3(float[], Vec3f, Vec3f)

Used for Vec3f representing a direction or normal - as a vec4 this would have the 4th element set to 0, so that applying a matrix transform with a translation would have no effect

public static void MulWithVec3(float[] matrix, Vec3f vec, Vec3f output)

Parameters

matrix float[]
vec Vec3f
output Vec3f

MulWithVec3(Span<float>, float[], float[])

Used for vec3 representing a direction or normal - as a vec4 this would have the 4th element set to 0, so that applying a matrix transform with a translation would have no effect

public static void MulWithVec3(Span<float> matrix, float[] vec, float[] output)

Parameters

matrix Span<float>
vec float[]
output float[]

MulWithVec3_BlockFacing(float[], Vec3f)

public static BlockFacing MulWithVec3_BlockFacing(float[] matrix, Vec3f vec)

Parameters

matrix float[]
vec Vec3f

Returns

BlockFacing

MulWithVec3_BlockFacing(Span<float>, Vec3f)

public static BlockFacing MulWithVec3_BlockFacing(Span<float> matrix, Vec3f vec)

Parameters

matrix Span<float>
vec Vec3f

Returns

BlockFacing

MulWithVec3_Position(float[], float, float, float, Vec3f)

Used for vec3 representing an x,y,z position - as a vec4 this would have the 4th element set to 1, so that applying a matrix transform with a translation would have an effect

public static void MulWithVec3_Position(float[] matrix, float x, float y, float z, Vec3f output)

Parameters

matrix float[]
x float
y float
z float
output Vec3f

MulWithVec3_Position(float[], float[], float[], int)

Used for vec3 representing an x,y,z position - as a vec4 this would have the 4th element set to 1, so that applying a matrix transform with a translation would have an effect The offset is used to index within the original and output arrays - e.g. in MeshData.xyz

public static void MulWithVec3_Position(float[] matrix, float[] vec, float[] output, int offset)

Parameters

matrix float[]
vec float[]
output float[]
offset int

MulWithVec3_Position(Span<float>, float[], float[], int)

public static void MulWithVec3_Position(Span<float> matrix, float[] vec, float[] output, int offset)

Parameters

matrix Span<float>
vec float[]
output float[]
offset int

MulWithVec3_Position_AndScale(float[], float[], float[], int, float)

public static void MulWithVec3_Position_AndScale(float[] matrix, float[] vec, float[] output, int offset, float scaleFactor)

Parameters

matrix float[]
vec float[]
output float[]
offset int
scaleFactor float

MulWithVec3_Position_AndScaleXY(float[], float[], float[], int, float)

public static void MulWithVec3_Position_AndScaleXY(float[] matrix, float[] vec, float[] output, int offset, float scaleFactor)

Parameters

matrix float[]
vec float[]
output float[]
offset int
scaleFactor float

MulWithVec3_Position_WithOrigin(float[], float[], float[], int, Vec3f)

Used for vec3 representing an x,y,z position - as a vec4 this would have the 4th element set to 1, so that applying a matrix transform with a translation would have an effect The offset is used to index within the original and output arrays - e.g. in MeshData.xyz The origin is the origin for the rotation

public static void MulWithVec3_Position_WithOrigin(float[] matrix, float[] vec, float[] output, int offset, Vec3f origin)

Parameters

matrix float[]
vec float[]
output float[]
offset int
origin Vec3f

MulWithVec3_Position_WithOrigin(Span<float>, float[], float[], int, Vec3f)

public static void MulWithVec3_Position_WithOrigin(Span<float> matrix, float[] vec, float[] output, int offset, Vec3f origin)

Parameters

matrix Span<float>
vec float[]
output float[]
offset int
origin Vec3f

MulWithVec4(float[], double[])

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

Parameters

matrix float[]
vec4 double[]

Returns

double[]

MulWithVec4(float[], float, float, float, float)

public static float[] MulWithVec4(float[] matrix, float v1, float v2, float v3, float v4)

Parameters

matrix float[]
v1 float
v2 float
v3 float
v4 float

Returns

float[]

MulWithVec4(float[], float[])

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

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

Parameters

matrix float[]
vec4 float[]

Returns

float[]

MulWithVec4(float[], float[], float[])

public static void MulWithVec4(float[] matrix, float[] vec, float[] output)

Parameters

matrix float[]
vec float[]
output float[]

MulWithVec4(float[], float[], Vec4f)

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

public static void MulWithVec4(float[] matrix, float[] vec4, Vec4f outVal)

Parameters

matrix float[]
vec4 float[]
outVal Vec4f

MulWithVec4(float[], Vec4d, Vec4d)

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

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

Parameters

matrix float[]
inVal Vec4d
outVal Vec4d

MulWithVec4(float[], Vec4f, Vec4f)

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

public static void MulWithVec4(float[] matrix, Vec4f inVal, Vec4f outVal)

Parameters

matrix float[]
inVal Vec4f
outVal Vec4f

MulWithVec4(Span<float>, float[], float[])

public static void MulWithVec4(Span<float> matrix, float[] vec, float[] output)

Parameters

matrix Span<float>
vec float[]
output float[]

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

Multiplies two mat4's

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

Parameters

output float[]

{mat4} out the receiving matrix

a float[]

{mat4} a the first operand

b float[]

{mat4} b the second operand

Returns

float[]

{mat4} out

Ortho(float[], float, float, float, float, float, float)

Generates a orthogonal projection matrix with the given bounds

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

Parameters

output float[]

{mat4} out mat4 frustum matrix will be written into

left float

{number} left Left bound of the frustum

right float

{number} right Right bound of the frustum

bottom float

{number} bottom Bottom bound of the frustum

top float

{number} top Top bound of the frustum

near float

{number} near Near bound of the frustum

far float

{number} far Far bound of the frustum

Returns

float[]

{mat4} out

Perspective(float[], float, float, float, float)

Generates a perspective projection matrix with the given bounds

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

Parameters

output float[]

{mat4} out mat4 frustum matrix will be written into

fovy float

{number} fovy Vertical field of view in radians

aspect float

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

near float

{number} near Near bound of the frustum

far float

{number} far Far bound of the frustum

Returns

float[]

{mat4} out

Rotate(float[], float[], float, float[])

Rotates a mat4 by the given angle

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

Parameters

output float[]

{mat4} out the receiving matrix

a float[]

{mat4} a the matrix to rotate

rad float

{Number} rad the angle to rotate the matrix by

axis float[]

{vec3} axis the axis to rotate around

Returns

float[]

{mat4} out

RotateX(float[], float[], float)

Rotates a matrix by the given angle around the X axis

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

Parameters

output float[]

{mat4} out the receiving matrix

a float[]

{mat4} a the matrix to rotate

rad float

{Number} rad the angle to rotate the matrix by

Returns

float[]

{mat4} out

RotateXYZ(Span<float>, float, float, float)

Provides a composite rotation matrix, equivalent to RotateX followed by RotateY followed by RotateZ
Here we work on a Span (which may be on the stack) for higher performance

public static void RotateXYZ(Span<float> matrix, float radX, float radY, float radZ)

Parameters

matrix Span<float>
radX float
radY float
radZ float

RotateY(float[], float[], float)

Rotates a matrix by the given angle around the Y axis

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

Parameters

output float[]

{mat4} out the receiving matrix

a float[]

{mat4} a the matrix to rotate

rad float

{Number} rad the angle to rotate the matrix by

Returns

float[]

{mat4} out

RotateZ(float[], float[], float)

Rotates a matrix by the given angle around the Z axis

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

Parameters

output float[]

{mat4} out the receiving matrix

a float[]

{mat4} a the matrix to rotate

rad float

{Number} rad the angle to rotate the matrix by

Returns

float[]

{mat4} out

Scale(float[], float[], float, float, float)

Scales the mat4 by the dimensions in the given vec3

public static float[] Scale(float[] output, float[] a, float xScale, float yScale, float zScale)

Parameters

output float[]

{mat4} out the receiving matrix

a float[]

{mat4} a the matrix to scale

xScale float
yScale float
zScale float

Returns

float[]

{mat4} out

Scale(float[], float[], float[])

Scales the mat4 by the dimensions in the given vec3

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

Parameters

output float[]

{mat4} out the receiving matrix

a float[]

{mat4} a the matrix to scale

v float[]

{vec3} v the vec3 to scale the matrix by

Returns

float[]

{mat4} out

SimpleScaleMatrix(Span<float>, float, float, float)

public static void SimpleScaleMatrix(Span<float> matrix, float x, float y, float z)

Parameters

matrix Span<float>
x float
y float
z float

Translate(float[], float[], float, float, float)

Translate a mat4 by the given vector

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

Parameters

output float[]

{mat4} out the receiving matrix

input float[]

{mat4} a the matrix to translate

x float

{vec3} v vector to translate by

y float
z float

Returns

float[]

{mat4} out

Translate(float[], float[], float[])

Translate a mat4 by the given vector

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

Parameters

output float[]

{mat4} out the receiving matrix

input float[]

{mat4} a the matrix to translate

translate float[]

{vec3} v vector to translate by

Returns

float[]

{mat4} out

Transpose(float[], float[])

Transpose the values of a mat4

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

Parameters

output float[]

{mat4} out the receiving matrix

a float[]

{mat4} a the source matrix

Returns

float[]

{mat4} out