Jump to content
  • Advertisement
Sign in to follow this  
Rasmadrak

Relative coordinates - Absolute coordinates?

This topic is 3598 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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
Advertisement
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!