'
' This illustrates how to convert a position from local coordinates
' to global coordinates
'
set oRoot = Application.ActiveProject.ActiveScene.Root
if Selection.Count = 0 then
' create a sample scene
set oModel = oRoot.AddModel
oModel.posx.value = 5
set oObject = oModel.AddNull
oObject.posx.value = 5
else
set oObject = Selection(0)
end if
'
' Create transformation matrix4 from global transform
'
set oGlobalParameters = oObject.kinematics.global.parameters
Set globalScl = XSIMath.CreateVector3
call globalScl.Set( _
oGlobalParameters("sclx").value, _
oGlobalParameters("scly").value, _
oGlobalParameters("sclz").value )
Set globalRot = XSIMath.CreateVector3
call globalRot.Set( _
oGlobalParameters("rotx").value, _
oGlobalParameters("roty").value, _
oGlobalParameters("rotz").value )
Set globalTrs = XSIMath.CreateVector3
call globalTrs.Set( _
oGlobalParameters("posx").value, _
oGlobalParameters("posy").value, _
oGlobalParameters("posz").value )
set m4Global = CreateMatrix4(globalScl,globalRot,globalTrs)
'
' get local position
'
Set v3Pos = XSIMath.CreateVector3
call v3Pos.Set( oObject.posx.value, oObject.posy.value, oObject.posz.value )
Application.LogMessage "local position = " & v3Pos.x & ", " & v3Pos.y & ", " & v3Pos.z
'
' transform local to global position
'
Set v3Pos = XSIMath.CreateVector3
call v3Pos.MulByMatrix4( v3Pos, m4Global )
Application.LogMessage "global position = " & v3Pos.x & ", " & v3Pos.y & ", " & v3Pos.z
'
' Create and initialize SIMatrix4 using from the scaling, rotation and
' translation values (SIVector3)
'
Function CreateMatrix4( inv3Scl, inv3Rot, inv3Pos )
Dim l_Rot, l_Trs, l_Matrix, l_RadToDeg, l_DegToRad
Set l_Rot = XSIMath.CreateVector3
Set l_Trs = XSIMath.CreateTransform
Set l_Matrix = XSIMath.CreateMatrix4
l_RadToDeg = 180.0 / 3.1415926535897932
l_DegToRad = 3.1415926535897932 / 180.0
'Conversion of the rotation angles into radians
l_Rot.Copy inv3Rot
l_Rot.ScaleInPlace l_DegToRad
'Create an SI Transform first.
l_Trs.SetScaling inv3Scl
l_Trs.SetTranslation inv3Pos
l_Trs.SetRotationFromXYZAngles l_Rot
'Extract a Matrix from that transform.
l_Trs.GetMatrix4 l_Matrix
Set CreateMatrix4 = l_Matrix
End Function |