en:vci:sample:mat4

Movement using matrix4x4

In this example, we will be using matrix4x4 the transformation matrix to move a SubItem object.
The example script turns the object by 1 degree per frame around the Z-axis.

Example data

Unitypackage

tutorial_matrix4x4.unitypackage

main.lua
local m = Matrix4x4.zero
 
local sub = vci.assets.GetTransform("sub")
local baseposition
local baserotation
local basescale
local rotq
 
 
local rotation = Quaternion.Euler(0, 0, 1)--Local rotation
local translation = Vector3.__new(0,0,0)--Local transpose
local scale = Vector3.__new(1,1,1)--Local scale
 
 
function updateAll()
    baseposition = sub.GetLocalPosition()--Vector3
    baserotation = sub.GetLocalRotation()--Quaternion
    basescale = sub.GetLocalScale()--Vector3
 
    m.setTRS(translation,rotation,scale)--Set a transformation matrix on m
    rotq = m.rotation --Quaternion solved by the transformation matrix
 
    baserotation = rotq*baserotation
    baseposition = m.MultiplyPoint3x4(baseposition)--Can be used for parallel translation
    basescale = Vector3.__new(scale.x*basescale.x,scale.y*basescale.y,scale.z*basescale.z)
 
    sub.SetLocalRotation(baserotation)--Apply the rotation
    sub.SetLocalPosition(baseposition)--Apply the position
    sub.SetLocalScale(basescale)--Apply the scale
 
end
en/vci/sample/mat4.txt · Last modified: 2023/09/29 17:16 by pastatto

Page Tools