Skip to content

tes3matrix33⚓︎

A 3 by 3 matrix.

Properties⚓︎

x⚓︎

The first row of the matrix.

Returns:


y⚓︎

The second row of the matrix.

Returns:


z⚓︎

The third row of the matrix.

Returns:


Methods⚓︎

__tostring⚓︎

Converts the matrix to a string with 2 decimal places.

local result = myObject:__tostring()

Returns:

  • result (string)

copy⚓︎

Creates a copy of the matrix.

local result = myObject:copy()

Returns:


fromEulerXYZ⚓︎

Fills the matrix with values from euler angles in radians.

myObject:fromEulerXYZ(x, y, z)

Parameters:

  • x (number)
  • y (number)
  • z (number)

fromQuaternion⚓︎

Fill the matrix by converting a quaternion.

myObject:fromQuaternion(quaternion)

Parameters:


getForwardVector⚓︎

Returns a copy of the forward vector component. This is the second column of the matrix.

local result = myObject:getForwardVector()

Returns:


getRightVector⚓︎

Returns a copy of the right vector component. This is the first column of the matrix.

local result = myObject:getRightVector()

Returns:


getUpVector⚓︎

Returns a copy of the up vector component. This is the third column of the matrix.

local result = myObject:getUpVector()

Returns:


invert⚓︎

Inverts the matrix.

local matrix, valid = myObject:invert()

Returns:


lookAt⚓︎

Updates the matrix so that its forward and up vectors point toward the given directions.

myObject:lookAt(forward, up)

Parameters:

Example: Using the lookAt method to rotate a scene graph line along the view direction
---@type niSwitchNode, niCamera
local line, camera
local verticalOffset = tes3vector3.new(0, 0, -5)

local function onLoaded()
    -- MWSE ships with a mesh which contains a few useful widgets.
    -- These can be used during debugging.
    local mesh = tes3.loadMesh("mwse\\widgets.nif") --[[@as niNode]]
    local widgets = {
        -- 3D coordinate axes
        arrows = mesh:getObjectByName("unitArrows") --[[@as niTriShape]],
        -- A common switch node that has three almost infinite lines
        -- along each coordinate exis
        axes = mesh:getObjectByName("axisLines") --[[@as niSwitchNode]],
        plane = mesh:getObjectByName("unitPlane") --[[@as niTriShape]],
        sphere = mesh:getObjectByName("unitSphere") --[[@as niTriShape]]
    }

    local root = tes3.worldController.vfxManager.worldVFXRoot
    ---@cast root niNode

    line = widgets.axes:clone() --[[@as niSwitchNode]]
    root:attachChild(line)
    root:update()

    -- switchIndex = 0 - x axis (red)
    -- switchIndex = 1 - y axis (green)
    -- switchIndex = 2 - z axis (blue)
    line.switchIndex = 1

    camera = tes3.worldController.worldCamera.cameraData.camera
end
event.register(tes3.event.loaded, onLoaded)

local function simulateCallback()
    -- Let's make the line's origin at the eye position.
    -- The position is offset -5 along the Z axis, so that
    -- that we can actually see the line (the line isn't
    -- visible if looking directly along the line).
    line.translation = tes3.getPlayerEyePosition() + verticalOffset

    local rotation = tes3matrix33.new()

    -- Make the line point in the look direction.
    -- We'll get the direction vector from the world camera.
    rotation:lookAt(camera.worldDirection, camera.worldUp)
    line.rotation = rotation
    line:update()
end
event.register(tes3.event.simulate, simulateCallback)

reorthogonalize⚓︎

Reorthogonalizes the matrix.

local result = myObject:reorthogonalize()

Returns:

  • result (boolean)

toEulerXYZ⚓︎

Converts the matrix to series of rotations along each axis in radians.

local vector3, isUnique = myObject:toEulerXYZ()

Returns:


toEulerZYX⚓︎

Converts the matrix to series of rotations along each axis in radians.

local vector3, isUnique = myObject:toEulerZYX()

Returns:


toIdentity⚓︎

Converts the matrix to the identity matrix's values.

myObject:toIdentity()

toQuaternion⚓︎

Convert the matrix into a quaternion.

local result = myObject:toQuaternion()

Returns:


toRotation⚓︎

Makes this matrix a rotation matrix with provided axis-angle rotation parameters.

myObject:toRotation(angle, x, y, z)

Parameters:

  • angle (number)
  • x (number)
  • y (number)
  • z (number)

toRotationX⚓︎

Fills this matrix with the values needed to rotate a 3-by-1 vector or 3-by-N matrix of vectors around the X axis by x radians. For the rotation matrix A and vector v, the rotated vector is given by A * v.

myObject:toRotationX(x)

Parameters:

  • x (number): In radians.

toRotationY⚓︎

Fills this matrix with the values needed to rotate a 3-by-1 vector or 3-by-N matrix of vectors around the Y axis by y radians. For the rotation matrix A and vector v, the rotated vector is given by A * v.

myObject:toRotationY(y)

Parameters:

  • y (number): In radians.

toRotationZ⚓︎

Fills this matrix with the values needed to rotate a 3-by-1 vector or 3-by-N matrix of vectors around the Z axis by z radians. For the rotation matrix A and vector v, the rotated vector is given by A * v.

myObject:toRotationZ(z)

Parameters:

  • z (number): In radians.

toZero⚓︎

Zeroes out all values in the matrix.

myObject:toZero()

transpose⚓︎

No description yet available.

local result = myObject:transpose()

Returns:


Functions⚓︎

new⚓︎

Creates a new 3 by 3 matrix from 3 provided vectors or 9 numbers. Creates an empty matrix if nothing is provided.

local matrix = tes3matrix33.new(x0, y0, z0, x1, y1, z1, x2, y2, z2)

Parameters:

  • x0 (number, tes3vector3): Default: 0.
  • y0 (number, tes3vector3): Default: 0.
  • z0 (number, tes3vector3): Default: 0.
  • x1 (number): Default: 0.
  • y1 (number): Default: 0.
  • z1 (number): Default: 0.
  • x2 (number): Default: 0.
  • y2 (number): Default: 0.
  • z2 (number): Default: 0.

Returns:


Math Operations⚓︎

Addition (+)⚓︎

Left operand type Right operand type Result type Description
tes3matrix33 tes3matrix33 tes3matrix33 The matrix addition.

Equality (==)⚓︎

Left operand type Right operand type Result type Description
tes3matrix33 tes3matrix33 boolean True if both matrices point to the same data.

Multiplication (*)⚓︎

Left operand type Right operand type Result type Description
tes3matrix33 tes3matrix33 tes3matrix33 The matrix multiplication. Geometrically, this will concatenate the transformations of both matrices in the resulting matrix.
tes3matrix33 tes3vector3 tes3vector3 Multiplies the matrix by a vector. The resulting vector is starting vector with the matrix' transformations applied.
tes3matrix33 number tes3matrix33 Multiplies the matrix by a scalar.

Subtraction (-)⚓︎

Left operand type Right operand type Result type Description
tes3matrix33 tes3matrix33 tes3matrix33 The matrix subtraction.