< Previous | Contents | Manuals Home | Boris FX | Next >
SyTrans Reference
The position and orientation of objects in 3-D for computer graphics and robotics are typically represented as a 3x4 transformation matrix; such matrices can be multiplied to represent compound manipulations. SyPy stores a transform matrix as a list of four vectors, each a list of 3 floats. Since lists are built into python and easy to create and display, transform matrices are supplied as lists of lists from SyObj.Get(), for example,
>>> cam = hlev.FindObjByName("Camera01")
>>> cam.trans
[[1.0, 0.0, 0.0], [0.0, 0.0, 1.0], [0.0, -1.0, 0.0], [0.0, -100.0, 10.0]]
IMPORTANT PYTHON 3 GOTCHA : SyPy3 for Python3 has some additional functionality built around the Get function, the implicit SyTrans.attrib form, and .Call(), which makes it easier to do transform operations that match up with SynthEyes without having to duplicate that functionality in Python. (Especially access to the conversions to rotation angles. See also SyLevel.Conform()) As part of that, whenever a transform value is brought back from SynthEyes, it appears in Python3 as a SyTrans, not as a list-of-lists as in Python2 . You must add a ".m" to places where the list-of-lists form is needed for your own explicit operations. You can set attributes using either the list-of-lists or SyTrans formats. To create SyTrans use SyPy3.SyTrans(m_data, hlev).
If you want to create and manipulate transform matrices, the sytrans module is available to help. You can use your favorite other package as long as you convert to the list-of-lists format to supply to SyPy.
The SyTrans class in sytrans is a carrier for the list-of-lists data. Here we fetch the camera position, convert it to a SyTrans using the abbreviated SyT function, and then print its m file, which contains the list-of-lists data.
>>> defpos = SyPy.SyT(cam.trans)
>>> defpos
<SyPy.sytrans.SyTrans instance at 0x000000000214CBC8>
>>> defpos.m
[[1.0, 0.0, 0.0], [0.0, 0.0, 1.0], [0.0, -1.0, 0.0], [0.0, -100.0, 10.0]]
While the Get routine always supplies lists-of-lists(SyPy) or SyTrans(SyPy3) data, the Set routine accepts either lists-of-lists or a SyTrans.
>>> hlev.Begin()
>>> cam.Set("trans", defpos)
>>> cam.trans = defpos
>>> cam.trans = defpos.m
>>> cam.Set("trans", defpos.m)
>>> hlev.Accept('Four different ways to do the same nothing')
The SyTrans objects can be created or combined together using the following functions. Notice that they are supplied as both functions that change an existing SyTrans, and as stand-alone functions that return a list-of-lists. The (transform) arguments to the functions can be either a SyTrans or a list-of-lists.
The XRot, YRot, and ZRot functions are particularly convenient for creating transformation matrices that match the specific ordering of rotations from other applications.
©2023 Boris FX, Inc. — UNOFFICIAL — Converted from original PDF.