COMPGROUPS.NET | Search | Post Question | Groups | Stream | About | Register

### Finding the distance to the camera from any object

• Email
• 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

--
http://www.skyscan.be

```
 0

See related articles to this posting

```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