Ambigious OpenGL Default Camera position
Asked Answered
T

1

6

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.

Trews answered 20/4, 2014 at 19:50 Comment(0)
D
3

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).

Drummer answered 20/4, 2014 at 20:18 Comment(5)
There appears to be a minor issue in your last paragraph: Clip-space is actually left-handed in all major APIs. In GL, everything after eye-space is left-handed. D3D uses a right-handed window-space, but clip- and NDC-space are always left-handed no matter the API.Gambier
@AndonM.Coleman: Yes, you are right. I must have been a bit confused when I wrote that. I remember that a actually tested it whith my hands when I wrote that, but I confused left and right... Thanks for the hint, I corrected it.Drummer
@Drummer my problem was with the default orthographic projection as you stated, for the perspective projection i should always shift all objects toward +z which makes sense, thanks for the answer.Trews
this was a really interesting answer... i am wondering though, by leaving all matrices at identity are you technically drawing into "homogenous clip space"?Marjana
@racarate: yes, your are drawing directly in clip space. With the modern pipeline, you can completely skip the matrix multiplication in the shader and save a few cycles in this case. This is especially useful for drawing full-screen quads, but there are lots of other use cases.Drummer

© 2022 - 2024 — McMap. All rights reserved.