I am aware that a 3-D linear transform (combination of: stretch, shear, rotation) takes the form of a 3x3 matrix.
Also that if the transform is required to also handle translations, then one can either use 3x3 matrix + translation vector, or 4x4 matrix
However, I'm also aware that there is a different technique for handling rotations: to use quaternions, which looks like a 4x4 matrix (but does it behave in the same way?).
So my question is: how do these objects play with one another?
Say I start up my default Blender scene with a cube and a camera.
Now that transform panel is confusing to me. As it stands in that picture, I can imagine blender is using either 3x3 matrix + translation vector, or 4x4 matrix
But then there is a 'Rotation Order' pulldown which allows quaternions.
Can anyone explain what blender does behind the scenes?
The reason for my asking is that I'm attempting a script that transforms an object into camera space (i.e. If you were to transform the scene so that the camera is at the origin pointing downwards, wherever the object ends up, this is the location I use)
def main(context, num):
bpy.ops.scene.new(type='FULL_COPY')
cloneScene = bpy.context.scene
cloneScene.name = 'clone'
camera = cloneScene.camera
for ob in cloneScene.objects:
if ob.type == "MESH":
me = ob.data
# WorldToCam( ObToWorld( ObCoord ) )
world2cam = camera.matrix_world.inverted()
ob2world = ob.matrix_world
obj2cam = world2cam * ob2world
bm = bmesh.new()
bm.from_mesh(me)
bm.transform(obj2cam)
for v in bm.verts:
v.co = MyTransform(v.co)
cam2obj = obj2cam.inverted()
bm.transform(cam2obj)
# save back into orig mesh
bm.to_mesh(me)
And so I would like to have a clear understanding of what is happening when I apply a transform.
Although I've tested that this method works in simple cases, it looks like it might fall over when dealing with translations and quaternions (seeing as I'm inverting the matrix not the transform, I'm not sure if these are guaranteed to be the same. In a straight linear transformation they are...)
EDIT: http://www.essentialmath.com/GDC2013/GDC13_quaternions_final.pdf <-- amazing walkthrough!
ftp://ftp.cs.indiana.edu/pub/hanson/Siggraph01QuatCourse/vqr.pdf <-- starts good, lost me with the links
courses.cms.caltech.edu/cs171/quatut.pdf <-- Ken Shoemake Quaternions