Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


Transforming coordinates between two reference frames in a scene.

This topic is 6180 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

In what manner can you use OpenGL to transform the coordinates from another frame to the current frame? An example: Object1 is an object within the scene that has a target coordinate relative to the local frame (say - a dot on a sphere). Object2 is another object within the scene (say - a long thin cylinder along the local z-axis) that needs to be oriented so that the Z+ axis points towards the target coordinate of Object1. What you get is a cylinder that always points to the dot on the sphere no matter their relative positions. In what manner is OpenGL designed to be used to transform the target coordinate from the local reference frame of Object1 to the local reference frame of Object2 so that Object2 can then be correctly oriented? Is this something that OpenGL is even capable of doing, or must you rely on the matrix operation capabilities of your host CPU?

Share this post

Link to post
Share on other sites
I''m amazed at how well this question seems to have stumped people. I also posted it on the OpenGL Forum where I did get some replies. Unfortunately, no one seemed to really understand what I was talking about. I eventually figured out one way to do this and, since there were no replies on this forum, have reposted my findings here in the hope that either you will find it useful or that someone might know a better way.

Fortunately, I''ve figured out a way to do it. It''s a little cheesy, but it works and it uses the graphic hardware via OpenGL to do the matrix operations instead of the host CPU.

  • Transform to, render, and pop back from the target frame (F2).
  • Transform to the tracker frame (F1).
  • Push the model matrix and load the identity matrix.
  • Apply the inverse transform for F1.
  • Apply the transform for F2.
  • Cheesy part - Use a loaded matrix to hold up to 4 coordinates which will be transformed by the set of matrices we just applied.
  • Do a glMultMatrix() to transform the points.
  • Read back the current matrix using "glGetFloatv(GL_MODELVIEW_MATRIX, matrix);" (or glGetDouble()) to get the transformed coordinates.
  • Pop the F1 frame back in.
  • Orient the frame with the coordinates you just transformed from F2 to F1.
  • Render your frame.

Works like a charm. Here''s the display code. If you''d like to see this run, you can download my zipped GLUT example and try it out for yourself. It''s just a simplified example with a few keyboard controls.
  • F1 will toggle full-screen/windowed.
  • ''a'' toggles the frame axes.
  • ''g'' toggle the XZ grid.
  • ''+'' and ''-'' speed up/slow down the animation speed.

If anyone has a better way of using OpenGL to transform points between frames, Please let me know.


// Transform from view (FV) to world (FW).

gluLookAt(2.0, 4.0, 12.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);

// Draw FW objects.


// Draw the target frame (F2).


// Draw the tracker frame (F1).


// This F1 tracker must always orient its z-axis to the F2 point [0, 0, 0]

// (The center of the wandering purple piece of fuzz).

// We must transform the F2 point coordinates (PF2) to F1 coordinates (PF1).

// PF1 = inv(F1) x F2 x PF2


// Use a transformation matrix as a set of 4 points to transform.

// (We''re only going to use the first point)

GLfloat m[16];
m[ 0] = 0.0; m[ 1] = 0.0; m[ 2] = 0.0; m[ 3] = 1.0;

// Orient F1 to point the z-axis to the point now in F1 coordinates.

track(m[0], m[1], m[2], 0.0);

// Update the display.


Some screen shots:

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!