• Create Account

#ActualSuperVGA

Posted 15 July 2013 - 01:08 AM

Hi guys,

I've messed around with my fixed (only the width and heights) orthographic projection in relation to guis.

Now I'd like to put my neat, flexible Projection class to use and create a Camera that will render me an overview map.

The view vectors are potentially much different than the 2d stuff, as it doesn't need to picture my level from straight above, necessarily.

Unlike what many people say on the webs, it can be necessary to provide negative near and far clipping values to glOrtho, to get the wanted result. This is AFAIK because of some old ortho stuff from the early days of OpenGl.
(See http://mlucassmith.tumblr.com/post/10869898438/why-i-hate-glortho-and-all-its-offspring for more on glOrtho and why it doesn't behave like glFrustrum.)

What I'm getting if I just mess around with the values a bit (in case I want the ortho camera oriented directly downwards) is this:

[attachment=16772:argh.png]

(The floor slabs are gray on the top colored on the underside)

I have depth buffering enabled, but it looks like (perhaps because of the inverted clipping plane values (near  -100, far: 100) the depth values are swapped) If it's not this, then it's the "up" vector not working as I intend it to, and it mirrors the projection somehow.

I get the correct projection by swapping near and far, and swapping the target and the eye vectors. (aside from being an orthographic projection, it's similar to me seeing the toy car in my kid's room when i see from the toy car, vieweing from me (near, 32.0f) to it (far, 0.1f)) in the direction of where i stand.

I read up on projection matrices (just how to set them up), and I messed with the values to initially copy the behavior of glOrtho:

    GLfloat tx = -((ortho_right+ortho_left) / (ortho_right-ortho_left));
GLfloat ty = -((ortho_top+ortho_bottom) / (ortho_top-ortho_bottom));
GLfloat tz = -((clip_far+clip_near) / (clip_far-clip_near));
GLfloat cx =  (2.0f / (ortho_right - ortho_left));
GLfloat cy =  (2.0f / (ortho_top   - ortho_bottom));
GLfloat cz = -(2.0f / (clip_far    - clip_near));

GLfloat mtx[16] ={  cx, 0.0f, 0.0f,   0.0f,
0.0f,   cy, 0.0f,   0.0f,
0.0f, 0.0f,   cz,   0.0f,
tx, ty, tz, 1.0f };
glMultMatrixf(mtx);


I'd like to fix this so I end up with a more intuitive "myOrtho()" (meaning the clip_near resembles the direct linear distance ahead of the camera, in the view direction in which the near clipping plane exists, and the clip_far resembles the one of the far clipping plane (both being positive values)).

Unfortunately, my general projection matrix math is very rusty, and I barely managed to copy the khronos man page description for glOrtho.

Have you guys tried this before? The alternative would be to negate view directions and the near and far clipping values on every frame drawn into an orthographic projection. And I'm reluctant to do that as it seems a bit hackish. Shouldn't the projection just "work"?

#1SuperVGA

Posted 14 July 2013 - 02:04 PM

Hi guys,

I've messed around with my fixed (only the width and heights) orthographic projection in relation to guis.

Now I'd like to put my neat, flexible Projection class to use and create a Camera that will render me an overview map.

The view vectors are potentially much different than the 2d stuff, as it doesn't need to picture my level from straight above, necessarily.

Unlike what many people say on the webs, it can be necessary to provide negative near and far clipping values to glOrtho, to get the wanted result. This is AFAIK because of some old ortho stuff from the early days of OpenGl.
(See http://mlucassmith.tumblr.com/post/10869898438/why-i-hate-glortho-and-all-its-offspring for more on glOrtho and why it doesn't behave like glFrustrum.)

What I'm getting if I just mess around with the values a bit (in case I want the ortho camera oriented directly downwards) is this:

[attachment=16772:argh.png]

(The floor slabs are gray on the top colored on the underside)

I have depth buffering enabled, but it looks like (perhaps because of the inverted clipping plane values (near  -100, far: 100) the depth values are swapped) If it's not this, then it's the "up" vector not working as I intend it to, and it mirrors the projection somehow.

I read up on projection matrices (just how to set them up), and I messed with the values to initially copy the behavior of glOrtho:

    GLfloat tx = -((ortho_right+ortho_left) / (ortho_right-ortho_left));
GLfloat ty = -((ortho_top+ortho_bottom) / (ortho_top-ortho_bottom));
GLfloat tz = -((clip_far+clip_near) / (clip_far-clip_near));
GLfloat cx =  (2.0f / (ortho_right - ortho_left));
GLfloat cy =  (2.0f / (ortho_top   - ortho_bottom));
GLfloat cz = -(2.0f / (clip_far    - clip_near));

GLfloat mtx[16] ={  cx, 0.0f, 0.0f,   0.0f,
0.0f,   cy, 0.0f,   0.0f,
0.0f, 0.0f,   cz,   0.0f,
tx, ty, tz, 1.0f };
glMultMatrixf(mtx);


I'd like to fix this so I end up with a more intuitive "myOrtho()" (meaning the clip_near resembles the direct linear distance ahead of the camera, in the view direction in which the near clipping plane exists, and the clip_far resembles the one of the far clipping plane (both being positive values)).

Unfortunately, my general projection matrix math is very rusty, and I barely managed to copy the khronos man page description for glOrtho.

Have you guys tried this before? The alternative would be to negate view directions and the near and far clipping values on every frame drawn into an orthographic projection. And I'm reluctant to do that as it seems a bit hackish. Shouldn't the projection just "work"?

PARTNERS