Hello everybody! There is a way to access to the transformation matrix? Something like GetMatElement but where you can change the values of the matrix?
Thanks
Thanks
Global Quat_W# Global Quat_X# Global Quat_Y# Global Quat_Z# Function Mat2Quat(entity) m00#=GetMatElement#(entity,0,0) m01#=GetMatElement#(entity,0,1) m02#=GetMatElement#(entity,0,2) m10#=GetMatElement#(entity,1,0) m11#=GetMatElement#(entity,1,1) m12#=GetMatElement#(entity,1,2) m20#=GetMatElement#(entity,2,0) m21#=GetMatElement#(entity,2,1) m22#=GetMatElement#(entity,2,2) Quat_W#= Sqr (1 + m00 + m11 + m22) /2 Quat_X# = (m21 - m12)/( 4 *Quat_W#) Quat_Y#= (m02 - m20)/( 4 *Quat_W#) Quat_Z# = (m10 - m01)/( 4 *Quat_W#) End Function
yaw=-asin(R(2,0)) pitch=atan2(R(2,1) / cos(yaw),R(2,2) / cos(yaw)) roll=atan2(R(1,0) / cos(yaw),R(0,0) / cos(yaw))
Global QuatLib_X# Global QuatLib_Y# Global QuatLib_Z# Global QuatLib_W# Global QuatLib_Pitch# Global QuatLib_Yaw# Global QuatLib_Roll# Function QuatToEuler(Qxx#, Qyy#, Qzz#, Qw#) Qx#=Qzz#*-1 Qy#=Qxx#*-1 Qz#=Qyy# Qx2# = Qx# * 2.0 Qy2# = Qy# * 2.0 Qz2# = Qz# * 2.0 Sin_T# = (Qy2# * Qw#) - (Qx2# * Qz#) Cos_T# = 1.0 - (Sin_T# * Sin_T#) If Abs(Cos_T#) > QuatToEuler_Epsilon# Cos_T# = Sqr(Cos_T#) Else Cos_T# = 0 EndIf If Abs(Cos_T#) > QuatToEuler_Epsilon# Sin_V# = ( (Qy2# * Qz#) + (Qx2# * Qw#)) / Cos_T# Cos_V# = (1.0 - (Qx2# * Qx#) - (Qy2# * Qy#)) / Cos_T# Sin_F# = ( (Qx2# * Qy#) + (Qz2# * Qw#)) / Cos_T# Cos_F# = (1.0 - (Qy2# * Qy#) - (Qz2# * Qz#)) / Cos_T# Else Sin_V# = (Qx2# * Qw#) - (Qy2# * Qz#) Cos_V# = 1.0 - (Qx2# * Qx#) - (Qz2# * Qz#) Sin_F# = 0 Cos_F# = 1.0 EndIf QuatLib_Pitch# = ATan2(Sin_T#, Cos_T#) QuatLib_Yaw# = ATan2(Sin_F#, Cos_F#) QuatLib_Roll# = ATan2(Sin_V#, Cos_V#) End Function Function EulerToQuat(Pitch#, Yaw#, Roll#) Pitch# = Pitch# / 2.0 Yaw# = Yaw# / 2.0 Roll# = Roll# / 2.0 Cos_Pitch# = Cos(Pitch#) Cos_Yaw# = Cos(Yaw#) Cos_Roll# = Cos(Roll#); Sin_Pitch# = Sin(Pitch#) Sin_Yaw# = Sin(Yaw#) Sin_Roll# = Sin(Roll#); CpCy# = Cos_Pitch# * Cos_Yaw# SpSy# = Sin_Pitch# * Sin_Yaw# SpCy# = Sin_Pitch# * Cos_Yaw# CpSy# = Cos_Pitch# * Sin_Yaw# QuatLib_Z# = ((Sin_Roll# * CpCy#) - (Cos_Roll# * SpSy#))*-1 QuatLib_X# = ((Cos_Roll# * SpCy#) + (Sin_Roll# * CpSy#))*-1 QuatLib_Y# = (Cos_Roll# * CpSy#) - (Sin_Roll# * SpCy#) QuatLib_W# = (Cos_Roll# * CpCy#) + (Sin_Roll# * SpSy#) End Function
Global QuatLib_X# Global QuatLib_Y# Global QuatLib_Z# Global QuatLib_W# Global QuatLib_Pitch# Global QuatLib_Yaw# Global QuatLib_Roll# Function QuatToEuler(Qxx#, Qyy#, Qzz#, Qw#) Qx#=Qzz#*-1 Qy#=Qxx#*-1 Qz#=Qyy# Qx2# = Qx# * 2.0 Qy2# = Qy# * 2.0 Qz2# = Qz# * 2.0 Sin_T# = (Qy2# * Qw#) - (Qx2# * Qz#) Cos_T# = 1.0 - (Sin_T# * Sin_T#) If Abs(Cos_T#) > QuatToEuler_Epsilon# Cos_T# = Sqr(Cos_T#) Else Cos_T# = 0 EndIf If Abs(Cos_T#) > QuatToEuler_Epsilon# Sin_V# = ( (Qy2# * Qz#) + (Qx2# * Qw#)) / Cos_T# Cos_V# = (1.0 - (Qx2# * Qx#) - (Qy2# * Qy#)) / Cos_T# Sin_F# = ( (Qx2# * Qy#) + (Qz2# * Qw#)) / Cos_T# Cos_F# = (1.0 - (Qy2# * Qy#) - (Qz2# * Qz#)) / Cos_T# Else Sin_V# = (Qx2# * Qw#) - (Qy2# * Qz#) Cos_V# = 1.0 - (Qx2# * Qx#) - (Qz2# * Qz#) Sin_F# = 0 Cos_F# = 1.0 EndIf QuatLib_Pitch# = ATan2(Sin_T#, Cos_T#) QuatLib_Yaw# = ATan2(Sin_F#, Cos_F#) QuatLib_Roll# = ATan2(Sin_V#, Cos_V#) End Function Function EulerToQuat(Pitch#, Yaw#, Roll#) Pitch# = Pitch# / 2.0 Yaw# = Yaw# / 2.0 Roll# = Roll# / 2.0 Cos_Pitch# = Cos(Pitch#) Cos_Yaw# = Cos(Yaw#) Cos_Roll# = Cos(Roll#); Sin_Pitch# = Sin(Pitch#) Sin_Yaw# = Sin(Yaw#) Sin_Roll# = Sin(Roll#); CpCy# = Cos_Pitch# * Cos_Yaw# SpSy# = Sin_Pitch# * Sin_Yaw# SpCy# = Sin_Pitch# * Cos_Yaw# CpSy# = Cos_Pitch# * Sin_Yaw# QuatLib_Z# = ((Sin_Roll# * CpCy#) - (Cos_Roll# * SpSy#))*-1 QuatLib_X# = ((Cos_Roll# * SpCy#) + (Sin_Roll# * CpSy#))*-1 QuatLib_Y# = (Cos_Roll# * CpSy#) - (Sin_Roll# * SpCy#) QuatLib_W# = (Cos_Roll# * CpCy#) + (Sin_Roll# * SpSy#) End Function