PDA

View Full Version : glOrtho in GL_PROJECTION vs GL_MODELVIEW?



wmelgaard
03-22-2014, 06:19 PM
I have a model xmin = -264.000000, xmax = 384.000000; ymin = -263.942993, ymax = 330.480591; zmin = 673.751099, zmax = 1345.000000
If I include glOrtho((xmin -margin), (xmax +margin), (ymin -margin), (ymax +margin), -1.0, 1.0); in model view, everything works dandy.

Why is the Z parameter (-1.0, 1.0) instead of (zmin, zmax)?

What difference does it make if I put the glOrtho command in model view vs projection

Aleksandar
03-23-2014, 01:40 AM
Before going any further, please read this (http://www.glprogramming.com/red/chapter03.html).
You should not call glOrtho while GL_MODELVIEW_MATRIX stack is selected.

If you do that, matrix at the top of MODELVIEW stack is multiplied with parallel-projection matrix looking like this (http://msdn.microsoft.com/en-us/library/windows/desktop/dd373965(v=vs.85).aspx).
That produces some kind of scaling and translation that probably fixes some other transformation in your modeling approach.

Ah, I see! By setting z-scaling factor to -1 you actually translate model down the negative Z-axis, making it visible.
In OpenGL viewer is in (0,0,0) looking down the negative Z-axis, and your model is behind it (positive Z coordinates).

Please, read the Chapter 3 from the old Red book (first link).

wmelgaard
03-23-2014, 11:51 AM
From the tutorial, "do you want to move the camera in one direction, or move the object in the opposite direction?" All of the examples in Chapter 3 move the model. Nate Robins' robot arm is drawn in widget coordinate system, and then pasted into the model via transformation.
In my case, all elements are located and drawn in a global coordinate system which is not under control of the programmer (yeah, the programmer can transform it wherever he wants to, but it doesn't start out that way), and is almost certainly not centered at 0, 0, 0. All new elements are pasted into the model without any transformation whatsoever, in accordance with the original global coordinate system.

If I put the glOrtho command in GL_PROJECTION, do I also need to translate the camera while in projection mode? Or should I leave well enough alone and leave the glOrtho command in GL_MODEL_VIEW?


Before going any further, please read this (http://www.glprogramming.com/red/chapter03.html).
You should not call glOrtho while GL_MODELVIEW_MATRIX stack is selected.

If you do that, matrix at the top of MODELVIEW stack is multiplied with parallel-projection matrix looking like this (http://msdn.microsoft.com/en-us/library/windows/desktop/dd373965(v=vs.85).aspx).
That produces some kind of scaling and translation that probably fixes some other transformation in your modeling approach.

Ah, I see! By setting z-scaling factor to -1 you actually translate model down the negative Z-axis, making it visible.
In OpenGL viewer is in (0,0,0) looking down the negative Z-axis, and your model is behind it (positive Z coordinates).

Please, read the Chapter 3 from the old Red book (first link).