views:

225

answers:

1

Ok, so - this is heavily related to my previous question Transforming an object between two coordinate spaces, but a lot more direct and it should have an obvious answer.

An objects local coordinate space, how do I "get a hold of it"? Say that I load an Orc into my game, how do I know programatically where it's head, left arm, right arm and origin (belly button?) is? And when I know where it is do I need to save it manually or is it something that magically exists in the DirectX API? In my other question one person said something about storing a vertice for X,Y,Z directions and and origin? How do I find these vertices? Do I pick them arbitrarily, assign them in the model before loading it into my game? etc.

This is not about transforming between coordinate spaces

+3  A: 

Actually, it is about transforming between coordinate spaces.

Ok, you understand that you can have a Matrix that does Translation or Rotation. (Or scaling. Or skew. Etc.) That you can multiply such a Matrix by a point (V) to get the new (translated/rotated/etc) point. E.g.:

Mtranlate = [ 1 0 0 Tx ]   *  V = [ Vx ]   =   [ Vx + Tx ]
            [ 0 1 0 Ty ]          [ Vy ]       [ Vy + Ty ]
            [ 0 0 1 Tz ]          [ Vz ]       [ Vz + Tz ]
            [ 0 0 0 1  ]          [  1 ]       [  1      ]

Or rotation about the X/Y/Z axis:

Mrotate_x = [ 1  0     0    0 ]  * V =  [ Vx ]   =   [ Vx              ]
            [ 0 cos  -sin   0 ]         [ Vy ]       [ Vy*cos - Vz*sin ]
            [ 0 sin   cos   0 ]         [ Vz ]       [ Vy*sin + Vz*cos ]
            [ 0  0     0    1 ]         [  1 ]       [  1              ]

That you can combine multiple operations by multiplying the matrices together.
For example: Mnew = Mtranslate * Mrotate_x.
(And yes, the order does matter!)

So given a real-world base origin, you could translate to your (known/supplied) orc's xy location, deduce from the terrain at that point what your orc's feet's z location is and translate to that. Now you have your orc's "feet" in global coordinates. From there, you might want to rotate your orc so he faces a particular direction.

Then translate upwards (based on your orc's model) to find it's neck. From the neck, we can translate upwards (and perhaps rotate) to find its head or over to find its shoulder. From the shoulder, we can rotate and translate to find the elbow. From the elbow we can rotate and translate to find the hand.

Each component of your orc model has a local reference frame. Each is related to the reference frame where it is attached by one or more transforms (matrices). By multiplying through all the local matrices (transforms), we can eventually see how to go from the orc's feet to his hand.

(Mind you, I'd animate the orc and just use his feet x,y,z location. Otherwise it's too much work.)

You see a lot of this sort of thing in robotics which can provide a nice elementary introduction to forward kinematics. In robotics, at least with the simpler robots, you have a motor which rotates, and a limb-length to translate by. And then there's another motor. (In contrast, the human shoulder-joint can rotate about all three axis at once.)

You might look over the course HANDOUTS for CMU's Robotic Manipulation class (15-384).

Perhaps something like their Forward Kinematics Intro.

Mr.Ree