Sign in to follow this  
Rasmadrak

Relative coordinates - Absolute coordinates?

Recommended Posts

Rasmadrak    196
Hi! Something that should be "really easy" to do is slipping my mind... How do I transform a bunch of rotations and transforms into absolute coordinates and an absolute matrix?
//pseudo:
obj.pos(10,0,0);
obj.rot(1,0,0,90);
obj.child1.pos(10,0,0);  //child1 gets translated with parents matrix.
obj.child1.rot(1,0,90);  //child1's children would get translated by child1.matrix

obj.child1.getAbsoluteCoords();



What I've got so far is the following, but only the first child (root->child) is rotated correctly, root->child->child is rotated globaly (or something...).
            rot = parentRot * localRot;
            Vector3<scalar> direction = rot * localPos; 
            globalPos = position + direction;
            globalRot = rot;

            for (list<sceneNode>::iterator child=children.begin(); child != children.end(); ++child)
                (*child)->setGlobalPos(globalPos,globalRot);


For the moment I'm using quaternions and vectors, and OpenGL for rendering, if that matters. :) Would be nice if any of you fine people could help a laddie in distress. :P /Robert

Share this post


Link to post
Share on other sites
haegarr    7372
I assume you use the typical order (given for column vectors, since you spoke of OpenGL)
T * R
where T denotes a translation and R a rotation. Then the composited transformation matrix of a local frame 1 is just
M12 := T1 * R1
what relates local co-ordinates to the superior frame 2. The superior frame 2 itself is related to its own superior frame 3
M23 := T2 * R2
Then frame 1 is related to frame 3 by
M13 := M23 * M12

You may have a look at this thread, too. It shows an efficient mechanism how to deal with the issue.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this