Finding the distance to the camera from any object

  • Follow


I have a hard time finding a sollution to this, even using Google.

I have a set of transparent planes, and I need to draw them from back to
front to make the transparency realistic.
So I must find for every transparent plane object the distance to the
camera.
But it gets a little complicated because some objects are in orbit around
other objects and these are in turn in orbit around another object.

Is there a trick, like assuming that the camera is always located at 0,0,0
and then you use the model matrix (extract coordinates) to find the distance
to that camera to determin the sort order?

To put the camera I use gluLookAt() so it can be anywhere in the scene and
not in absolute coordinate 0,0,0, but somehow I believe that gluLookAt()
pushes the models away so that in reality the camera really stays in 0,0,0.
Or am I wrong?

This looks like Temporal mechanics, you get headaches if you think too much
about time travel. ;-)

-- 
http://www.skyscan.be


0
Reply Olaf 10/27/2004 8:54:39 AM

I think I found the sollution myself here:
http://www.opengl.org/resources/faq/technical/viewing.htm#view0050

8.050
Given the current ModelView matrix, how can I determine the object-space
location of the camera?

  The "camera" or viewpoint is at (0., 0., 0.) in eye space. When you turn
this into a vector [0 0 0 1] and multiply it by the inverse of the ModelView
matrix, the resulting vector is the object-space location of the camera.

  OpenGL doesn't let you inquire (through a glGet* routine) the inverse of
the ModelView matrix. You'll need to compute the inverse with your own code.


-- 
http://www.skyscan.be


0
Reply Olaf 10/27/2004 9:20:50 AM


1 Replies
827 Views

(page loaded in 0.031 seconds)

Similiar Articles:













7/24/2012 3:22:05 PM


Reply: