Question

in my Opengl programs (before i apply perspective projection matrix) whenever i draw some object I draw it at the origin of the world coordinate system, however almost all of the Opengl tutorials states that the camera (My projection view) is located at the origin looking toward positive z-axis (which depends on how you treat z value in the projection matrix later on), however if that is true how does my camera (located in the origin) is able to view an object located in the origin.

Note: i need this information so that i shift the world and rotate it around the origin so i get a rotating camera illusion.

Was it helpful?

Solution

What appears on your screen will depend on the whole transformations you apply to it. I interpret your question in the way that you use an identity matrix both for the projection and the (model)view transformation. In that case, you are directly drawing in clip space. Technically, this will define a camera position at the origin, but the view frustum will be equivalent to an Ortho(-1.0, 1.0, -1.0, 1.0, 1.0, -1.0) setup - so your view frustum will lie half behind the camera (which is perfectly fine for ortho projections, but might seem counterintuitive). For the camera orientation, that part is a bit more ambigous. Usually, GL had the convention that the camera looks into the -z direction, but in clip space, +z will point into the screen, and the classic Ortho and Perspective functions treat this by actually using z_near=-near and z_far=-far for the near and far parameters. (That is also is also the reason why identy transform is achieved through that Ortho call with the last two signs flipped relative to the x and y ranges). So in that case, one could argue that the camera is actually looking along +z, or one could argue that the camera looks along -z, but the near and far planes are swapped by the projection. That is a matter of how you like to interpret these things. These conventions mostly matter to classic "fixed-function" GL, which uses the eye position for lighting and fog calculations (and maybe a view things else). And it also might assume the "camera looks along -z" convention for calculation of the specular lighting term if GL_LIGHT_MODEL_LOCAL_VIEWER is not enabled (which is disabled by default, see glLightModel().

In modern GL, no such conventions exist besides the left-handedness of the clip space, and you can make your own conventions for an eye space (if you need one).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top