View Full Version : How to find pos/rot values based on extended parents objects space
03-29-2004, 04:54 PM
Iím trying to determine how to find the local position and rotation values of an object based on an extended parentís object space. Here is an example situation:
------groupRoot (null, possibly animate, child of GroundPlane)
------CTRL (null, animated, child of groupRoot)
------ Ball (mesh, may or may not be animated, child of control)
So for example the position values are:
GoundPlane [World 0,0,0 || Local 0,0,0]
groupRoot [W 1,0,0 || L 1,0,0]
CTRL [W 2,0,1 || L 1,0,1]
Ball [W 2,0,1 || L 0,0,0]
For now assume all rotation values are 0.
What I want to find is what the local value for Ball would be based on the object space of groupRoot. The problem right now is if I use world position and then rotate GroundPlane or groupRoot all the calculations get thrown off, so I need to account for the affected position of groupRoot and any additional changes made by GroundPlane. I canít use local values for Ball because most if not all animation is done to CRTL so Ballís local values do not change.
My thought is I need to get the world values for groupRoot and Ball then modify Ballís values to reflect itís local position in groupRootís object space. So far Iíve yet to figure out an approach to achieve this. In the end I the x,y,z,h,p,b values for Ball in relation to groupRoot.
Iím working in C using the messiah API, which provides me access to channel values and matrix values for objects, along with the standard C math libraryís.
03-30-2004, 08:01 AM
Your description leaves me feeling a little confused.
I think what you're after is Ball's position/rotation(/scale), relative to groupRoot, right?
I can get into a more dtailed explanation about coordinate systems and transforms if you want, but the short answer is:
o Each of your objects has its own transform. This tells you where it is relative to its parent
o As you step up the heirachy, you concatenate each object's transformation matrix
So for groupRoot, CTRL and Ball we have transfomation matrices Tgr, Tc and Tb, respectively.
To find the relative transformation of Ball from groupRoot, Tbgr, we must first find the relative transform of Ball from its parent, then of its parent from groupRoot:
Tbgr = Tb X Tc
If we are assuming all rotation values are 0, that means that Ball is translated [ 2 0 1 ] from groupRoot, as when we multiply the transformation matrices, the translation values are added together, as you would expect.
03-30-2004, 03:48 PM
playmesumch00ns, your correct on what I'm trying to do. Thanks for the explanation, I'll start trying it out.
I have 3 options for reading an objects matrix, local, world and rotate only. From your discription I should concatenate the local matrix's for the items up the hiearchy by multipling the matrixes together, correct? And this will take rotation of the parents into account when I get my final position for Ball?
03-30-2004, 05:14 PM
The transformation matrix encodes rotation, position, scale, skew, and whatever else you could want to do all in one.
Yep, grab the local transformation matrices and multiply up the heirachy. Depending on the matrix notation convention used by your API, you'll want to do the multiplication in a particular order. If it doesn't work one way, try it the other
03-30-2004, 07:46 PM
I'm trying to not get to complicated yet, but here I go anyway. If groupRoot is a child of another item can I just get the world matrix for groupRoot and stop going up the hierarchy?
03-31-2004, 08:22 AM
Yep. try it out and see if it works
03-31-2004, 09:22 AM
if i understood correctly, you want to be able to get an objects position local to an arbitrary object in your scene?
most apps already have local/worldspace matrices/transforms/kinematics, so this shouldn't be any trouble, just get the global position & matrix, then follow the basic rules:
going between local and global space using matrices:
local to global:
multiply the position by the global matrix (world matrix) to shift from local space of the object you got your global matrix from into world space.
global to local:
multiply by the inverted global matrix of any object in order to find your position relative to that object in it's local space.
so all you need are the global matrices (including global position) for all your objects. which should be directly accesible in whatever app you use.
03-31-2004, 01:45 PM
I'm doing something wrong, I keep getting the world position back from the resulting matrix.
I want to find the local position and rotation for an object in relation to an arbitrary object. So to simplify based on you explanation:
target object = T
arbitrary object = A
I can get:
Target position local vector = TpVEC
Target position world vector = TpwVEC
Target rotation local vector = TrVEC
Target rotation world vector = TrwVEC
Target local matrix = Tm
Target world matrix = Twm
Arbitrary position local vector = ApVEC
Arbitrary position world vector = ApwVEC
Arbitrary rotation local vector = ArVEC
Arbitrary rotation world vector = ArwVEC
Arbitrary local matrix = Am
Arbitrary world matrix = Awm
so based on on these I want the local pos/rot for Target in relation to Arbitrary.
does that mean the I need to:
TpwVec*Inverse(Awm) = result matrix?
or is it
(TpVec*Twm)*Inverse(ApVec*Awm)= result matrix
or am I completely off in what I need to do?
04-11-2004, 04:06 PM
I got it working, the problem was I did not realize the invertmatrix function I was using was 3x3 only. I added a 4x4 invert function of my own and it worked.
Thanks for the help playmesumch00ns and mdme_sadie.
01-17-2006, 10:00 PM
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.
vBulletin v3.0.5, Copyright ©2000-2013, Jelsoft Enterprises Ltd.