How to code cameras and draw distances

54e97bcc4e4a2fc8f5f05594afd1683a
0
Gnarlyman 101 Mar 06, 2012 at 06:10

I’d like to know…

How is the actual camera, and what it views, and et cetera, programmed? Obviously, that’s tied to draw distance, but much more so, I’m very curious/puzzled as to the math/programming involved in cameras, which obviously have to “draw more of” the environment with the receding distance. Is there a certain ratio or math to get the cam to look right? I’m trying to code a camera system from scratch, and I’d like to know how to go about it. I hope this Q is coming across in a more or less understandable manner…

Thanks!

4 Replies

Please log in or register to post a reply.

820ce9018b365a6aeba6e23847f17eda
0
geon 101 Mar 06, 2012 at 07:12

Google for frustum and projection matrix. That should get you started.

54e97bcc4e4a2fc8f5f05594afd1683a
0
Gnarlyman 101 Mar 07, 2012 at 05:14

Thanks, I looked all of that up and have gotten a good handle on it. Thanks again. My next question would be…

What’s the general logic and process that governs the detection of meshes and…everything in the environment, really, within the viewing frustum?

A8433b04cb41dd57113740b779f61acb
0
Reedbeta 167 Mar 07, 2012 at 05:54

Usually people put a bounding volume of some kind around each object or mesh, such as an axis-aligned bounding box (AABB) or a sphere. These simplified shapes can easily and quickly be checked against the frustum (you can search for AABB-versus-frustum or sphere-versus-frustum intersection tests). The object is drawn if its bounding volume intersects the frustum, which is a conservative estimate of what’s visible.

For more efficient frustum culling of large numbers of objects, a hierarchy of bounding volumes is used, such as an AABB tree, sphere tree, octree or BSP tree.

Note that if you’re just trying to get the camera working, you should avoid frustum culling and simply draw all objects each frame, then put the frustum culling in later once you’ve got other things working (since it is a bit of a fiddly process with the potential for lots of odd bugs).

820ce9018b365a6aeba6e23847f17eda
0
geon 101 Mar 07, 2012 at 06:18

To know what’s inside the frustum, you need frustum culling and clipping. The clipping is done by the hardware and drivers in projection space. Any triangle outside the frustum is simply clipped. That way, every triangle left is able to be rasterized to screen pixels.

Frustum culling is just an optimization to avoid sending stuff to the hardware if it will all be clipped away anyway. Some primitive shape like a sphere or a box is assigned to each object. If the shape is completely outside the frustum, the object is not drawn.