The Talemonger's Emporium
spacer
Gameweavers
Q and A
Weird!
Gametalk
Cool Links
News
Site Info
Home
spacer
spacer Answer Archive
And the Question is...

#include
main()
{
printf("to be answered by: any of the staff\n");
printf("My name is: Champ Boonyarat\n");
printf("The Question is: I've been learning C for almost a term, but I don't see it's connection to games programming at all. All I see are numbers and calculations. How can I relate programming to something like 3DSMax to create 3d games?
Object Orientation?\n");
}

Answered by: Jeff Pobst (programmer, Sierra On-Line)

"Games are big! Especially 3D games. So many elements come together to create a 3D game, it can seem like the basic fundamentals of programming leave you high and dry, and fail to provide you with everything necessary to put a 3D game together.

"The truth is, however, that all of the fundamentals are in there. They look different sometimes. Perhaps that big ol' three dimensional Spriggan attacking our hero on the screen doesn't remind you of the text output from your first-term Newton/Rhapson rootfinding routine. Or the camera swooping over gorgeous textured terrain only gives you motion sickness that reminds you of the bad pizza you had the night before your data structures final. No matter, the code underneath these programs looks remarkably similar in many areas.

"Now before you get all angry with me for thinking I'm going to oversimplify everything, let me admit that there are some significant elements required to get from point A (the text output program that calculates "the square root of pi") to point B (the three dimensional adventure where the monster turns "the square root of pi" radians before swinging his club and attacking our hero).

"The first big element that opens a programmer's eyes to what is possible with main(){ } is when she or he first discovers class and graphics libraries. Essentially, every game programmer needs to render a window, or place a button, or draw a line, or blit a bit and there's no sense in everyone writing them from scratch. So, when one spends the money to purchase a C/C++ (or other language) compiler, one of the main buying points is the class and graphics libraries that come with the compiler. These libraries are essentially prewritten functions or routines, like the familiar printf() or sqrt(), but which instead cover constructing a window, or drawing a line, or making a button work. They may be complicated and hard to understand at first because they're often written very generally to cover as many situations as possible. Often they favor generalization over optimization so they usually aren't very fast.

"Since speed is almost always a must in game coding, a game programmer may look at the source code for a specific function or class (usually the source code for classes is also included with the compiler) and write a more specific one that is optimized for the game being written. In a company that employs many programmers, many new functions are written and these libraries form the basis of the games that the company puts out. Once you have a set of routines that store and move information around, calculate things quickly, draw to the screen, and receive user input, the basis of a "game engine" is formed.

"For a 3D game, the engine must additionally decide where everything is in a 3D world, where the imaginary camera is, what's in front of it, how far the camera can see, what objects are covering other objects, what objects are going to get drawn, what angle they are going to get drawn from, and what lighting is available for the objects that are going to be drawn. Once that is decided, the rendering part of the code takes objects that the game artists have built, using programs such as 3DMax, and places them on the screen at the correct position and angle that corresponds to where our imaginary camera is. Many calculations take place in order to determine where an object is supposed to be at this very second, and if it isn't right, the game isn't very playable.

"Now, don't get me wrong, the new 3D textured art is amazing and wonderful and it takes very talented people to put these animated 3D objects together. Once they exist, though, it is up to the programmer using fundamental calculations to determine how these objects are going to appear on the screen and how the user's input changes the things that they see."

Read more questions and answers! spacer

spacer
see LEGAL page for copyright information