Home » Android » android – OpenGL (ES) — What's the difference between frustum and ortho?

android – OpenGL (ES) — What's the difference between frustum and ortho?

Posted by: admin June 15, 2020 Leave a comment

Questions:

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?

How to&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.

Answer:

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.