View Full Version : Interesting, Why glOrtho can use nagtive near argument?

reader1

06-08-2015, 07:19 PM

for example,

lOrtho (-3.5, 3.5, -3.5*(GLfloat)h/(GLfloat)w,

3.5*(GLfloat)h/(GLfloat)w, -3.5, 3.5);

where the near argument is -3.5, why can it use such nagtive number?

and the others, like perspective can not?

Alfonse Reinheart

06-08-2015, 07:46 PM

The space of the final result of a projection transformation (after the division by W) is a cube, centered at the origin, which extends to -1, 1 in all 3 axes. This space, called Normalized Device Coordinate (NDC) space, represents the visible part of the world, no matter what particular projection transformation you use.

So the job of a projection transform is to transform positions from some space into NDC space (after the division by W).

glOrtho defines a transformation from an axis-aligned rectangular prism (https://en.wikipedia.org/wiki/Cuboid) to the NDC space cube. The 6 coordinates define the sides of the axis-aligned prism. In such a space, a negative Z is no worse than a positive Z. The orthographic transformation defines everything in that prism to be visible, with everything outside of it not visible.

The perspective transformation is very different. The area of the world used by the perspective projection is a rectangular frustum (https://en.wikipedia.org/wiki/Frustum); essentially a pyramid with the top chopped off. Everything inside the frustum is considered visible, with everything outside of it not visible. Also, the tip of the frustum (where the top of the pyramid would be if the top wasn't chopped off) is where the camera resides.

Part of the definition of a frustum includes two distances: camera zNear and camera zFar. These are expressed as distances from the camera rather than absolute coordinates. So zNear has a positive distance, even though in eye-space, negative Z values are in front of the camera, with positive Z values behind.

Ignoring the fact that a negative distance makes no sense, if zNear were allowed to be negative, you still wouldn't have a reasonable transformation. If zNear were zero (which it isn't allowed to be, but let's pretend), then the frustum would be a perfect pyramid. The four sides would meet at the camera.

So if zNear were less than zero... what would be behind the camera?

The sides of the frustum are considered to be infinitely long planes. This includes the near and far planes, but also the four sides. And OpenGL's clipping rules state that any part of any object which falls behind even one of these 6 planes doesn't get rendered.

But all points behind the camera are behind at least one of the side clipping planes. So even if you could have a negative zNear, you wouldn't have any extra visibility compared to a zNear of zero (which again, is also not allowed).

reader1

06-08-2015, 08:41 PM

The space of the final result of a projection transformation (after the division by W) is a cube, centered at the origin, which extends to -1, 1 in all 3 axes. This space, called Normalized Device Coordinate (NDC) space, represents the visible part of the world, no matter what particular projection transformation you use.

So the job of a projection transform is to transform positions from some space into NDC space (after the division by W).

glOrtho defines a transformation from an axis-aligned rectangular prism (https://en.wikipedia.org/wiki/Cuboid) to the NDC space cube. The 6 coordinates define the sides of the axis-aligned prism. In such a space, a negative Z is no worse than a positive Z. The orthographic transformation defines everything in that prism to be visible, with everything outside of it not visible.

The perspective transformation is very different. The area of the world used by the perspective projection is a rectangular frustum (https://en.wikipedia.org/wiki/Frustum); essentially a pyramid with the top chopped off. Everything inside the frustum is considered visible, with everything outside of it not visible. Also, the tip of the frustum (where the top of the pyramid would be if the top wasn't chopped off) is where the camera resides.

Part of the definition of a frustum includes two distances: camera zNear and camera zFar. These are expressed as distances from the camera rather than absolute coordinates. So zNear has a positive distance, even though in eye-space, negative Z values are in front of the camera, with positive Z values behind.

Ignoring the fact that a negative distance makes no sense, if zNear were allowed to be negative, you still wouldn't have a reasonable transformation. If zNear were zero (which it isn't allowed to be, but let's pretend), then the frustum would be a perfect pyramid. The four sides would meet at the camera.

So if zNear were less than zero... what would be behind the camera?

The sides of the frustum are considered to be infinitely long planes. This includes the near and far planes, but also the four sides. And OpenGL's clipping rules state that any part of any object which falls behind even one of these 6 planes doesn't get rendered.

But all points behind the camera are behind at least one of the side clipping planes. So even if you could have a negative zNear, you wouldn't have any extra visibility compared to a zNear of zero (which again, is also not allowed).

Either glOrtho or glPerspective is belong to projection. the last can't see the behind (as it were), but the front can see?

where is the projection plane? is it not at the camera place?

reader1

06-08-2015, 08:45 PM

and what's matter with this thread at

https://www.opengl.org/discussion_boards/showthread.php/186926-Draw-two-objects-but-only-one-teapot-display-why?p=1267496#post1267496

odd enough.

Alfonse Reinheart

06-08-2015, 09:55 PM

Either glOrtho or glPerspective is belong to projection. the last can't see the behind (as it were), but the front can see?

The perspective projection transformation defines the "camera" as a specific position (the eye-space origin). However, orthographic projections don't really have a camera at all. The closest thing to a camera you might say is a camera plane, but even that's not really correct.

It's just a fundamentally different kind of transformation.

reader1

06-09-2015, 06:21 AM

The perspective projection transformation defines the "camera" as a specific position (the eye-space origin). However, orthographic projections don't really have a camera at all.

It's just a fundamentally different kind of transformation.

thanks, I think we can conside the camera is located at infinit far place. Thus there is no begin and end. then there could be a nagtive relatively.

The closest thing to a camera you might say is a camera plane, but even that's not really correct.

WHAts that?

reader1

06-09-2015, 06:24 AM

and btw, have a look at

https://www.opengl.org/discussion_bo...96#post1267496

odd enough. what's matter with this thread ?

Powered by vBulletin® Version 4.2.3 Copyright © 2017 vBulletin Solutions, Inc. All rights reserved.