On 7/24/2012 6:22 AM, Ron Mayer wrote:
> Thanks Paul, I will go and change the code to move the camera. Can you give a concrete example for the usage of the camera's eye coordinates inside openGL?
The clearest example would be the computation of specular reflection. Suppose
you have a scene consisting of a light source and a shiny table, and you want to
position your eye so that the light produces a nice bright specular reflection
off the table top. (Picture a 'V' shape, with the light at upper left, the table
surface at the bottom of the 'V', and the eye at upper right. In this scene, the
eye would "see" the light reflected off the table.)
If you use the modelview matrix to contain the eye transformation, then the eye
coordinate eye position will be at the origin, and the table and light will be
in -z space. In this case, the specular reflection will be computed correctly,
and the lighting math will determine that the eye is within the cone of the
reflected light vector.
However, matrices are just matrices, so you could get the same net *clip*
coordinate transformation if you (inadvertently) placed the eye transformation
in the projection matrix. You'd still see the table rendered in the same
location as in the previous example, but the specular reflection would almost
certainly be missing, because the math used to compute the specular reflection
would use the wrong eye location. This happens because the light computation is
done in eye coordinates == after multiplying by the modelview matrix, but
*before* multiplying by the projection matrix == so there's no way for the
OpenGL lighting code to know where you've placed the eye.
Tying this into OSG, the Camera has a view matrix, and the scene graph can have
other Transform nodes such as MatrixTransform and PositionAttitudeTransform. It
is the accumulated hierarchical concatenation of these matrices that end up
being sent to OpenGL as the modelview matrix.
As I mentioned before, the OpenGL books go into detail on this.
The OpenGL technical FAQ has some info here:
http://www.opengl.org/archives/resources/faq/technical/transformations.htm#tran0011
It's the old FAQ at this point, but it describes the OpenGL 1.x / 2.x FFP, and
that hasn't changed and it's what OSG uses by default.
-Paul