Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenGL (ES) -- What's the difference between frustum and ortho?

When I use each of them with the same parameters the only difference I notice is how close the 'camera' is from the objects. What is the difference here, and which is preferred for a mainly 2D game?

like image 416
farm ostrich Avatar asked Apr 29 '11 18:04

farm ostrich


People also ask

What is perspective division?

Once all the vertices are transformed to clip space a final operation called perspective division is performed where we divide the x , y and z components of the position vectors by the vector's homogeneous w component; perspective division is what transforms the 4D clip space coordinates to 3D normalized device ...

What is glFrustum?

The glFrustum function multiplies the current matrix by this matrix, with the result replacing the current matrix. That is, if M is the current matrix and F is the frustum perspective matrix, then glFrustum replaces M with M F. Use glPushMatrix and glPopMatrix to save and restore the current matrix stack.


2 Answers

I don't agree with LeffelMania, although his answer is already accepted, I would like to explain again what a frustum is and what the differences between orthographic and perspective projections are.

A frustum is a pyramid without the top shaped 3D object (in the link defined by the space between the zNear and zFar plane).

view frustum

The frustum is used to determine what the camera can see. Everything that is inside or intersects with the camera's view-frustum has to be rendered, all the rest can be ignored.

Because a frustum is a difficult shape to do intersection checks on, often a matrix transform is constructed so that the view frustum is transformed to a cube. This matrix transform is also applied to all scene objects so that we can now do a simple 'does it intersect with a cube' check. This is called the canonical view frustum (see more info here)

Now about perspective vs orthographic projection. In the picture you see the camera, or center of projection (COP). In a perspective projection the COP is near the near plane. Rays from all positions on the far plane are pointing at the COP. Where these rays intersect the near plane (aka viewport) a pixel is colored according to the color of the closest thing to the near plane that the ray hit. A perspective projection leads to (multiple) vanishing points and objects further away from the camera are smaller, also parallel lines in the world are not necessarily parallel on the picture.

In an orthographic projection the COP is infinitely far away, so the rays are almost parallel to each other. There is no vanishing point, more distant objects are not drawn smaller and parallel lines in the world are parallel on the picture.

like image 110
Roy T. Avatar answered Oct 13 '22 09:10

Roy T.


Generally speaking a Frustum is used for 3D scenes to accommodate a Perspective view projection. It accounts for each object's distance from the camera as well as viewing angle to determine an object's size and position on the screen. An orthographic projection simply takes each object and draws a straight line from the object to a pixel on the screen, making it just a flat scene. That's a gross generalization and there's a lot to be said on the subject, but for a 2D game you'll want to use an orthographic projection.

like image 43
LeffelMania Avatar answered Oct 13 '22 08:10

LeffelMania