Hey all,

Plunging ever further into the depths of matrices and the fun math issues one may need to solve while building some tools for the studio.

I'm trying to figure out how the SI Matrix3's are derived / set and am hitting some walls. I have some Euler angles that I need to convert to Matrix3's then set a Transform from the result.

Basically a Euler angle to Matrix3 operation. I need to solve this without the built in methods as I need to convert data from external sources to align with Softimage without the SDK available.

I've referenced many of web sites (wikipedia, educational institutions, etc.) and all of the equations for multiplying the 3 matrices (x,y,z) end up with results that are not consistent with Softimage's methods. The only source that has proven to give me valid results is the 3D Math Primer for Graphics and Game Dev book (Chapter 8.7). However it only shows the solution for XYZ rotation order and even that I'm unsure how they got the order in which they multiply the rows / columns.

If any of you smart people out there (Raf, Matt?) have a few free minutes to review my below code and show me the error of my ways I'd appreciate it. Maybe others could benefit too.

Create 2 nulls. Set one rotation to x = -45, y=45
Select 2nd null and run script.
Swap the commented "result" line and run again.

# Python
import math

si = Application
log = si.LogMessage
sel = si.Selection

def degToRad(value):
    return value * (math.pi / 180)

x = -45
y = 45
z = 0


cx = math.cos(degToRad(x))
sx = math.sin(degToRad(x))
cy = math.cos(degToRad(y))
sy = math.sin(degToRad(y))
cz = math.cos(degToRad(z))
sz = math.sin(degToRad(z))


matX = XSIMath.CreateMatrix3()
matX.Set(0,1,0,0,cx,sx,0,-sx,cx)

matY = XSIMath.CreateMatrix3()
matY.Set(cy,0,-sy,0,1,0,sy,0,cy)

matZ = XSIMath.CreateMatrix3()
matZ.Set(cz,sz,0,-sz,cz,0,0,0,1)

result = XSIMath.CreateMatrix3()
# From most sites I referenced-ish
#result.Set(cz*cy, sz*cx + cz*sy*sx, sz*sx - cz*sy*cx, -sz*cy, cz*cx - sz*sy*sx, cz*sx + sz*sy*cx, sy, -cy*sx, cy*cx)

result.Set(cy*cz + sy*sx*sz, sz*cx, -sy*cz + cy*sx*sz, -cy*sz + sy*sx*cz, cz*cx, sz*sy + cy*sx*cz, sy*cx, -sx, cy*cx) # From Book

log(result.Get2())

xfo = XSIMath.CreateTransform()
xfo.SetRotationFromMatrix3(result)

sel(0).Kinematics.Global.PutTransform2(None, xfo)

# End Python

--
Eric Thivierge
===============
Character TD / RnD
Hybride Technologies

Reply via email to