Translations of this page:

Sidebar

en:vci:sample:mat4

Movement using matrix4x4

Example data:
https://seed.online/items/9f1ff8f354b294e0ae6b3d5b49ccd2388f86694e238ecf3cb38fc29f5386291a

UnityPackage: tutorial_matrix4x4.zip

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.

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: 2022/03/06 23:15 by Ramen

Page Tools