Matrix to position in Python


#1

In Poser 4 Pro I’m using Python to create a command that would allow me to transfer a prop to the position of an actor object, like the head or a hand. Poser Python has a method, actor.WorldMatrix() that returns the world matrix of the actor object as a “Float Type 4x4 Tuple”, which when printed out looks like this…

((0.212241604924, 0.62350487709, 0.752459228039, 0.0), (-0.918641448021, 0.38988211751, -0.0639495104551, 0.0), (-0.333243250847, -0.677667558193, 0.655526697636, 0.0), (0.650325059891, 0.25583088398, 0.0927870869637, 1.0))

My problem is I don’t understand it and what ever I try, haven’t managed translating this into a new global position for my target prop object. Anyone have any idea what I should be doing?


#2

your matrix seems to be row oriented:

0.212241604924, 0.62350487709, 0.752459228039, 0.0,
-0.918641448021, 0.38988211751, -0.0639495104551, 0.0,
-0.333243250847, -0.677667558193, 0.655526697636, 0.0,
0.650325059891, 0.25583088398, 0.0927870869637, 1.0

which in this case would mean the actor should at location (assuming SRT transforms order):

x = 0.650325059891 y = 0.25583088398 z = 0.0927870869637

i am -guessing- that this transformation is to be applied to the vertices of the actor to bring them into world space. you want to move the prop into the actor space, so you’ll need to multiply your prop location by the inverse of this matrix.


#3

Many thanks for replying, shehbahn! Excuse my ignorance, but what does ‘inverse of the matrix’ mean? Is it negative value, division into 1, or something else? My maths is embarrassingly poor…


#4

You can try Poser’s WorldDisplacement() method instead, which returns only the translation part of the object’s world matrix.


#5

You might be referring to Poser 5, Poser 4 Pro doesn’t have the WorldDisplacement() method. Hope somone can help with the inverted matrix question…


#6

ProPack does have the WorldDisplacement() method. Make sure you have sr3 installed.


#7

Yes, you’re right, I’ve just found that out myself, thanks for bringing it up. I see the release fixes some other problems as well…

I would still like to know how to use the inverse of world matrix, it’s something I should know generally.


#8

well at this point you should really read a quick primer on matrices… but the short story:

translation / rotation / scaling are all “linear transformations” and can be represented by a matrix.

so… say we have MR, a 4x4 matrix that rotates points around an axis, MT that translates points around and MS that scales them, you can form:

M = MS * MR * MT

that is a combination of all 3 operations (not the order of multiplications is important). this complicated transformation has an “inverse” that undoes all the changes:

M * M-1 = I (where I is the “identity” matrix)

so if your world matrix M transforms a point from world to object space, there is an M-1 matrix that transforms points from object space back to world space.

anyway : google or any linear algebra book will set you on your way.


#9

Thanks again, shehbahn. I’ve stored your post in the scrapbook for future reference… when googling for inverting a matrix it seemed very scary, got as far as the gausian algorithm… at least for the job at hand I don’t need it, if I had, I found out it would have been a major pain as I’d have to translate the skeleton hierarchy up to the actor in question. Cheers,


#10

As a side note, there are some handy matrix operations available in the Python library ‘Numeric’. In particular you might be able to convert vertices or positions to single row matrices with Numeric.array, and then use Numeric.matrixmultiply to multiply them with the transformation matrix you should be able to get out of Poser. Then you will have world space vertices or positions.

Just have a look at the Numeric documentation for a starting point for that.


#11

This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.