Libraries.Compute.Matrix4 Documentation

Matrix4 is a class representing a 4x4 matrix.

Example Code

use Libraries.Compute.Matrix4

Matrix4 matrix

matrix:Set(2, 5, 0, 0, 1, 3, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)
matrix:Inverse()

number row0column0 = matrix:row0column0
number row0column1 = matrix:row0column1
number row0column2 = matrix:row0column2
number row0column3 = matrix:row0column3
number row1column0 = matrix:row1column0
number row1column1 = matrix:row1column1
number row1column2 = matrix:row1column2
number row1column3 = matrix:row1column3
number row2column0 = matrix:row2column0
number row2column1 = matrix:row2column1
number row2column2 = matrix:row2column2
number row2column3 = matrix:row2column3
number row3column0 = matrix:row3column0
number row3column1 = matrix:row3column1
number row3column2 = matrix:row3column2
number row3column3 = matrix:row3column3

output "The new matrix is:"
output "|" + row0column0 + ", " + row0column1 + ", " + row0column2 + ", " + row0column3 + "|"
output "|" + row1column0 + ", " + row1column1 + ", " + row1column2 + ", " + row1column3 + "|"
output "|" + row2column0 + ", " + row2column1 + ", " + row2column2 + ", " + row2column3 + "|"
output "|" + row3column0 + ", " + row3column1 + ", " + row3column2 + ", " + row3column3 + "|"

Inherits from: Libraries.Language.Object

Variables Table

VariablesDescription
number row3column0
number row0column3
number row2column0
number row1column0
number row1column3
number row2column3
number row1column1
number row2column1
number row3column1
number row3column3
number row0column1
number row3column2
number row1column2
number row0column0
number row0column2
number row2column2

Actions Documentation

Average(Libraries.Compute.Matrix4 other, number weight)

This action averages the matrix with the passed matrix. Translations and scales are done via a linear interpolation and rotations are done via a spherical linear interpolation.

Parameters

Return

Libraries.Compute.Matrix4: The matrix after averaging

Example

use Libraries.Compute.Matrix4

Matrix4 matrix
Matrix4 other

matrix:Set(2, 0, 3, 1, 0, 2, 1, 1, 0, 0, 2, 1, 0, 0, 0, 1)
other:Set(4, 0, 6, 2, 0, 4, 2, 2, 0, 0, 4, 2, 0, 0, 0, 2)

matrix:Average(other, 0.5)

number row0column0 = matrix:row0column0
number row0column1 = matrix:row0column1
number row0column2 = matrix:row0column2
number row0column3 = matrix:row0column3
number row1column0 = matrix:row1column0
number row1column1 = matrix:row1column1
number row1column2 = matrix:row1column2
number row1column3 = matrix:row1column3
number row2column0 = matrix:row2column0
number row2column1 = matrix:row2column1
number row2column2 = matrix:row2column2
number row2column3 = matrix:row2column3
number row3column0 = matrix:row3column0
number row3column1 = matrix:row3column1
number row3column2 = matrix:row3column2
number row3column3 = matrix:row3column3

output "The new matrix is:"
output "|" + row0column0 + ", " + row0column1 + ", " + row0column2 + ", " + row0column3 + "|"
output "|" + row1column0 + ", " + row1column1 + ", " + row1column2 + ", " + row1column3 + "|"
output "|" + row2column0 + ", " + row2column1 + ", " + row2column2 + ", " + row2column3 + "|"
output "|" + row3column0 + ", " + row3column1 + ", " + row3column2 + ", " + row3column3 + "|"

Compare(Libraries.Language.Object object)

This action compares two object hash codes and returns an integer. The result is larger if this hash code is larger than the object passed as a parameter, smaller, or equal. In this case, -1 means smaller, 0 means equal, and 1 means larger. This action was changed in Quorum 7 to return an integer, instead of a CompareResult object, because the previous implementation was causing efficiency issues.

Parameters

Return

integer: The Compare result, Smaller, Equal, or Larger.

Example

Object o
Object t
integer result = o:Compare(t) //1 (larger), 0 (equal), or -1 (smaller)

Copy()

This action creates a new matrix that is a copy of this matrix.

Return

Libraries.Compute.Matrix4: A new matrix that is a copy of this matrix

Example

use Libraries.Compute.Matrix4

Matrix4 matrix
Matrix4 copyMatrix

copyMatrix:Set(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15)

matrix = copyMatrix:Copy()

number row0column0 = matrix:row0column0
number row0column1 = matrix:row0column1
number row0column2 = matrix:row0column2
number row0column3 = matrix:row0column3
number row1column0 = matrix:row1column0
number row1column1 = matrix:row1column1
number row1column2 = matrix:row1column2
number row1column3 = matrix:row1column3
number row2column0 = matrix:row2column0
number row2column1 = matrix:row2column1
number row2column2 = matrix:row2column2
number row2column3 = matrix:row2column3
number row3column0 = matrix:row3column0
number row3column1 = matrix:row3column1
number row3column2 = matrix:row3column2
number row3column3 = matrix:row3column3

output "The new matrix is:"
output "|" + row0column0 + ", " + row0column1 + ", " + row0column2 + ", " + row0column3 + "|"
output "|" + row1column0 + ", " + row1column1 + ", " + row1column2 + ", " + row1column3 + "|"
output "|" + row2column0 + ", " + row2column1 + ", " + row2column2 + ", " + row2column3 + "|"
output "|" + row3column0 + ", " + row3column1 + ", " + row3column2 + ", " + row3column3 + "|"

Determinant()

This action computes the determinant of the matrix.

Return

number: The determinant of the matrix

Example

use Libraries.Compute.Matrix4

Matrix4 matrix

matrix:Set(2, 5, 0, 0, 1, 3, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)

number determinant = matrix:Determinant()

output "The determinant is " + determinant

Determinant3x3()

This action computes the determinant of the 3x3 matrix composed of the first three rows and first three columns of the 4x4 matrix.

Return

number: The determinant of the 3x3 upper left matrix

Example

use Libraries.Compute.Matrix4

Matrix4 matrix

matrix:Set(2, 5, 0, 0, 1, 3, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)

number determinant3x3 = matrix:Determinant3x3()

output "The determinant of the 3x3 upper left matrix is " + determinant3x3

Equals(Libraries.Language.Object object)

This action determines if two objects are equal based on their hash code values.

Parameters

Return

boolean: True if the hash codes are equal and false if they are not equal.

Example

use Libraries.Language.Object
use Libraries.Language.Types.Text
Object o
Text t
boolean result = o:Equals(t)

GetElement(integer row, integer column)

This action will multiply the provided vectors by the given Matrix4 (which can be this Matrix4 object or any other Matrix4). The results are stored in the array of Vector3 objects provided.

Parameters

  • integer row
  • integer column

Return

number:

Example

use Libraries.Compute.Matrix4
use Libraries.Compute.Vector3
use Libraries.Containers.Array

Vector3 vectorA
Vector3 vectorB
Array<Vector3> array
Matrix4 matrix

vectorA:Set(3.0, 4.0, 2.0)
vectorB:Set(-0.5, 2.0, 0)
array:Add(vectorA)
array:Add(vectorB)

matrix:row0column0 = 2 * 3 / (100 - 0)
matrix:row0column1 = 0
matrix:row0column2 = (100 + 0) / (100 - 0)
matrix:row0column3 = 0
matrix:row1column0 = 0
matrix:row1column1 = 2 * 3 / (100 - 0)
matrix:row1column2 = (100 + 0) / (100 - 0)
matrix:row1column3 = 0
matrix:row2column0 = 0
matrix:row2column1 = 0
matrix:row2column2 = -1 * (10 + 3) / (10 - 3)
matrix:row2column3 = -2 * 10 * 3 / (10 - 3)
matrix:row3column0 = 0
matrix:row3column1 = 0
matrix:row3column2 = -1
matrix:row3column3 = 0

matrix:Project(matrix, array)

integer counter = 0
repeat array:GetSize() times
    Vector3 vector = array:Get(counter)

    number newX = vector:GetX()
    number newY = vector:GetY()
    number newZ = vector:GetZ()

    output "The vector at array position " + counter + " is: [" + newX + ", " + newY + ", " + newZ + "]"

    counter = counter + 1
end

GetHashCode()

This action gets the hash code for an object.

Return

integer: The integer hash code of the object.

Example

Object o
integer hash = o:GetHashCode()

GetRotation(boolean normalizeAxes)

This action gets the rotation of the matrix and returns it as a Quaternion.

Parameters

  • boolean normalizeAxes: true to normalize the axes, false if not

Return

Libraries.Compute.Quaternion: The quaternion with the rotation of the matrix

Example

use Libraries.Compute.Matrix4
use Libraries.Compute.Quaternion

Matrix4 matrix

matrix:SetToRotation(0, 0, 1, 90)

Quaternion quaternion

quaternion = matrix:GetRotation(true)

number x = quaternion:GetX()
number y = quaternion:GetY()
number z = quaternion:GetZ()
number w = quaternion:GetW()

output "The rotation quaternion is : [" + x + ", " + y + ", " + z + ", " + w + "]"

GetRotation()

This action gets the rotation of the matrix and returns it as a Quaternion.

Return

Libraries.Compute.Quaternion: The quaternion with the rotation of the matrix

Example

use Libraries.Compute.Matrix4
use Libraries.Compute.Quaternion

Matrix4 matrix

matrix:SetToRotation(0, 0, 1, 90)

Quaternion quaternion

quaternion = matrix:GetRotation()

number x = quaternion:GetX()
number y = quaternion:GetY()
number z = quaternion:GetZ()
number w = quaternion:GetW()

output "The rotation quaternion is : [" + x + ", " + y + ", " + z + ", " + w + "]"

GetScale()

This action returns the scale components of each axis of the matrix.

Return

Libraries.Compute.Vector3: the scale vector

Example

use Libraries.Compute.Matrix4
use Libraries.Compute.Vector3

Matrix4 matrix

matrix:SetToScaling(2, 3, 4)

Vector3 scale = matrix:GetScale()

number x = scale:GetX()
number y = scale:GetY()
number z = scale:GetZ()

output "The scale vector is: [ " + x ", " + y + ", " + z + "]"

GetScaleX()

This action gets the x-component of the scale of the matrix.

Return

number: The x-component of the scale of the matrix

Example

use Libraries.Compute.Matrix4

Matrix4 matrix

matrix:SetToScaling(2, 3, 4)

number scaleX = matrix:GetScaleX()

output "The x-component of the scale is " + scaleX

GetScaleXSquared()

This action gets the square of the x-component of the scale of the matrix.

Return

number: The square of the x-component of the scale of the matrix

Example

use Libraries.Compute.Matrix4

Matrix4 matrix

matrix:SetToScaling(2, 3, 4)

number scaleXSquared = matrix:GetScaleXSquared()

output "The square of the x-component of the scale is " + scaleXSquared

GetScaleY()

This action gets the y-component of the scale of the matrix.

Return

number: The y-component of the scale of the matrix

Example

use Libraries.Compute.Matrix4

Matrix4 matrix

matrix:SetToScaling(2, 3, 4)

number scaleY = matrix:GetScaleY()

output "The y-component of the scale is " + scaleY

GetScaleYSquared()

This action gets the square of the y-component of the scale of the matrix.

Return

number: The square of the y-component of the scale of the matrix

Example

use Libraries.Compute.Matrix4

Matrix4 matrix

matrix:SetToScaling(2, 3, 4)

number scaleYSquared = matrix:GetScaleYSquared()

output "The square of the y-component of the scale is " + scaleYSquared

GetScaleZ()

This action gets the z-component of the scale of the matrix.

Return

number: The z-component of the scale of the matrix

Example

use Libraries.Compute.Matrix4

Matrix4 matrix

matrix:SetToScaling(2, 3, 4)

number scaleZ = matrix:GetScaleZ()

output "The z-component of the scale is " + scaleZ

GetScaleZSquared()

This action gets the square of the z-component of the scale of the matrix.

Return

number: The square of the z-component of the scale of the matrix

Example

use Libraries.Compute.Matrix4

Matrix4 matrix

matrix:SetToScaling(2, 3, 4)

number scaleXZSquared = matrix:GetScaleZSquared()

output "The square of the z-component of the scale is " + scaleZSquared

GetTranslation()

This action gets the translational component of the matrix..

Return

Libraries.Compute.Vector3: The translation component of the matrix

Example

use Libraries.Compute.Matrix4
use Libraries.Compute.Vector3

Matrix4 matrix

matrix:SetToTranslationAndScaling(1, 1, 1, 2, 2, 2)

Vector3 translation

translation = matrix:GetTranslation()

number x = translation:GetX()
number y = translation:GetY()
number z = translation:GetZ()

output "The translation vector is: [" + x + ", " + y + ", " + z + "]"

IdentityMatrix()

This action sets the matrix to the 4x4 identity matrix.

Return

Libraries.Compute.Matrix4: The matrix as the 4x4 identity matrix

Example

use Libraries.Compute.Matrix4

Matrix4 matrix

matrix:IdentityMatrix()

number row0column0 = matrix:row0column0
number row0column1 = matrix:row0column1
number row0column2 = matrix:row0column2
number row0column3 = matrix:row0column3
number row1column0 = matrix:row1column0
number row1column1 = matrix:row1column1
number row1column2 = matrix:row1column2
number row1column3 = matrix:row1column3
number row2column0 = matrix:row2column0
number row2column1 = matrix:row2column1
number row2column2 = matrix:row2column2
number row2column3 = matrix:row2column3
number row3column0 = matrix:row3column0
number row3column1 = matrix:row3column1
number row3column2 = matrix:row3column2
number row3column3 = matrix:row3column3

output "The new matrix is:"
output "|" + row0column0 + ", " + row0column1 + ", " + row0column2 + ", " + row0column3 + "|"
output "|" + row1column0 + ", " + row1column1 + ", " + row1column2 + ", " + row1column3 + "|"
output "|" + row2column0 + ", " + row2column1 + ", " + row2column2 + ", " + row2column3 + "|"
output "|" + row3column0 + ", " + row3column1 + ", " + row3column2 + ", " + row3column3 + "|"

Inverse()

This action computes the inverse of the matrix

Return

Libraries.Compute.Matrix4: The inverted matrix

Example

use Libraries.Compute.Matrix4

Matrix4 matrix

matrix:Set(2, 5, 0, 0, 1, 3, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)
matrix:Inverse()

number row0column0 = matrix:row0column0
number row0column1 = matrix:row0column1
number row0column2 = matrix:row0column2
number row0column3 = matrix:row0column3
number row1column0 = matrix:row1column0
number row1column1 = matrix:row1column1
number row1column2 = matrix:row1column2
number row1column3 = matrix:row1column3
number row2column0 = matrix:row2column0
number row2column1 = matrix:row2column1
number row2column2 = matrix:row2column2
number row2column3 = matrix:row2column3
number row3column0 = matrix:row3column0
number row3column1 = matrix:row3column1
number row3column2 = matrix:row3column2
number row3column3 = matrix:row3column3

output "The new matrix is:"
output "|" + row0column0 + ", " + row0column1 + ", " + row0column2 + ", " + row0column3 + "|"
output "|" + row1column0 + ", " + row1column1 + ", " + row1column2 + ", " + row1column3 + "|"
output "|" + row2column0 + ", " + row2column1 + ", " + row2column2 + ", " + row2column3 + "|"
output "|" + row3column0 + ", " + row3column1 + ", " + row3column2 + ", " + row3column3 + "|"

LinearInterpolation(Libraries.Compute.Matrix4 matrix, number alpha)

This action performs a linear interpolation between the matrix and the passed matrix by alpha. The alpha value must be between 0 and 1 inclusive.

Parameters

Return

Libraries.Compute.Matrix4: the linear interpolation of the two matrices

Example

use Libraries.Compute.Matrix3

Matrix3 matrix
Matrix3 otherMatrix

matrix:Set(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15)
otherMatrix:Set(15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0)

matrix:LinearInterpolation(otherMatrix, 0.5)

number row0column0 = matrix:row0column0
number row0column1 = matrix:row0column1
number row0column2 = matrix:row0column2
number row0column3 = matrix:row0column3
number row1column0 = matrix:row1column0
number row1column1 = matrix:row1column1
number row1column2 = matrix:row1column2
number row1column3 = matrix:row1column3
number row2column0 = matrix:row2column0
number row2column1 = matrix:row2column1
number row2column2 = matrix:row2column2
number row2column3 = matrix:row2column3
number row3column0 = matrix:row3column0
number row3column1 = matrix:row3column1
number row3column2 = matrix:row3column2
number row3column3 = matrix:row3column3

output "The new matrix is:"
output "|" + row0column0 + ", " + row0column1 + ", " + row0column2 + ", " + row0column3 + "|"
output "|" + row1column0 + ", " + row1column1 + ", " + row1column2 + ", " + row1column3 + "|"
output "|" + row2column0 + ", " + row2column1 + ", " + row2column2 + ", " + row2column3 + "|"
output "|" + row3column0 + ", " + row3column1 + ", " + row3column2 + ", " + row3column3 + "|"

Multiply(Libraries.Compute.Matrix4 matrix)

This action multiplies the calling matrix by the passed matrix.

Parameters

Return

Libraries.Compute.Matrix4: The matrix after multiplication

Example

use Libraries.Compute.Matrix4

Matrix4 matrix
Matrix4 otherMatrix

matrix:Set(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15)
otherMatrix:Set(15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0)

matrix:Multiply(otherMatrix)

number row0column0 = matrix:row0column0
number row0column1 = matrix:row0column1
number row0column2 = matrix:row0column2
number row0column3 = matrix:row0column3
number row1column0 = matrix:row1column0
number row1column1 = matrix:row1column1
number row1column2 = matrix:row1column2
number row1column3 = matrix:row1column3
number row2column0 = matrix:row2column0
number row2column1 = matrix:row2column1
number row2column2 = matrix:row2column2
number row2column3 = matrix:row2column3
number row3column0 = matrix:row3column0
number row3column1 = matrix:row3column1
number row3column2 = matrix:row3column2
number row3column3 = matrix:row3column3

output "The new matrix is:"
output "|" + row0column0 + ", " + row0column1 + ", " + row0column2 + ", " + row0column3 + "|"
output "|" + row1column0 + ", " + row1column1 + ", " + row1column2 + ", " + row1column3 + "|"
output "|" + row2column0 + ", " + row2column1 + ", " + row2column2 + ", " + row2column3 + "|"
output "|" + row3column0 + ", " + row3column1 + ", " + row3column2 + ", " + row3column3 + "|"

Multiply(Libraries.Compute.Matrix4 matrixA, Libraries.Compute.Matrix4 matrixB)

This action multiplies the two passed matrices.

Parameters

Return

Libraries.Compute.Matrix4: The product of the two matrices

Example

use Libraries.Compute.Matrix4

Matrix4 matrix
Matrix4 matrixA
Matrix4 matrixB

matrixA:Set(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15)
matrixB:Set(15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0)

matrix:Multiply(matrixA, matrixB)

number row0column0 = matrix:row0column0
number row0column1 = matrix:row0column1
number row0column2 = matrix:row0column2
number row0column3 = matrix:row0column3
number row1column0 = matrix:row1column0
number row1column1 = matrix:row1column1
number row1column2 = matrix:row1column2
number row1column3 = matrix:row1column3
number row2column0 = matrix:row2column0
number row2column1 = matrix:row2column1
number row2column2 = matrix:row2column2
number row2column3 = matrix:row2column3
number row3column0 = matrix:row3column0
number row3column1 = matrix:row3column1
number row3column2 = matrix:row3column2
number row3column3 = matrix:row3column3

output "The new matrix is:"
output "|" + row0column0 + ", " + row0column1 + ", " + row0column2 + ", " + row0column3 + "|"
output "|" + row1column0 + ", " + row1column1 + ", " + row1column2 + ", " + row1column3 + "|"
output "|" + row2column0 + ", " + row2column1 + ", " + row2column2 + ", " + row2column3 + "|"
output "|" + row3column0 + ", " + row3column1 + ", " + row3column2 + ", " + row3column3 + "|"

Project(Libraries.Compute.Matrix4 matrix, Libraries.Containers.Array<Libraries.Compute.Vector3> vectors)

This action will multiply the provided vectors by the given Matrix4 (which can be this Matrix4 object or any other Matrix4). The results are stored in the array of Vector3 objects provided.

Parameters

Example

use Libraries.Compute.Matrix4
use Libraries.Compute.Vector3
use Libraries.Containers.Array

Vector3 vectorA
Vector3 vectorB
Array<Vector3> array
Matrix4 matrix

vectorA:Set(3.0, 4.0, 2.0)
vectorB:Set(-0.5, 2.0, 0)
array:Add(vectorA)
array:Add(vectorB)

matrix:row0column0 = 2 * 3 / (100 - 0)
matrix:row0column1 = 0
matrix:row0column2 = (100 + 0) / (100 - 0)
matrix:row0column3 = 0
matrix:row1column0 = 0
matrix:row1column1 = 2 * 3 / (100 - 0)
matrix:row1column2 = (100 + 0) / (100 - 0)
matrix:row1column3 = 0
matrix:row2column0 = 0
matrix:row2column1 = 0
matrix:row2column2 = -1 * (10 + 3) / (10 - 3)
matrix:row2column3 = -2 * 10 * 3 / (10 - 3)
matrix:row3column0 = 0
matrix:row3column1 = 0
matrix:row3column2 = -1
matrix:row3column3 = 0

matrix:Project(matrix, array)

integer counter = 0
repeat array:GetSize() times
    Vector3 vector = array:Get(counter)

    number newX = vector:GetX()
    number newY = vector:GetY()
    number newZ = vector:GetZ()

    output "The vector at array position " + counter + " is: [" + newX