|
by Logan Everett (E-mail Me)#3 - The Basics of 3D GamesOkay, it's time for me to stop rambling about random topics and get back to the focus of this site: Games. This week we look at 3D Games, how they work, and what makes them so great. I will use the terminology from this one a lot in future articles, so listen up! First off we need to discuss how all games work. A game has two
main parts, the engine and the data:
Usually, the most complex part of a 3D game engine is used just for graphics. 3D objects are recorded in memory as polygons. One polygon represents a single triangle in 3-dimensional space. Therefore it is always 3 coordinates, each having 3 values (x,y,z). You might be thinking "whoa, slow down tough guy, a co-what?" A coordinate is a single point in space. On a 2-dimensional graph, which I'm sure we've all done in high school, each point is represented by a set of numbers like this: {4, 8}. The first number is the x coordinate. In this case the point is 4 units away from the origin or center. You may be wondering "What units are we using? Where's the center? What's the meaning of life?" Well, all of these things are determined by the game engine. Getting back to what I was originally saying, this point is 4 units away from the origin on the x-axis, or a horizontal line running through the origin. It is also 8 units away from the origin on the y-axis, or a vertical line running through the origin. So, if we combine these two values we have a point that is 4 units over, and 8 units up from the origin. The direct distance (the distance of a line drawn straight from the origin to the point) could be calculated with all sorts of fancy equations called trigonometry. I won't bore you with that, though. In a 3D environment we need a third axis, called the z-axis which measures depth. NOTE: In most 3D games they orient the axis differently, so that X is length, Z is height, and Y is depth. For this setup, just pretend the graph paper is flat on a table, and the Z axis comes up out of the center of it. This adds a third coordinate to our point. If our point becomes {4, 8, 12} then we know that it is also 12 units away straight in front of us. The direct distance to the origin is now really, really complex to figure out, and because of this there is a lot of work that the engine has to do, especially if it processing 5 million polygons each second. Keep in mind that a polygon is 3 points, so we are processing 15 million points a second. But a point is 3 numbers! We are processing 45 million numbers each second, and that's below average for more recent games. The point of processing all this is to calculate how the 3D polygon would look from a certain viewpoint and draw it that way on screen. However, polygons alone don't make something look realistic. You may have played older games in which each polygon is filled with one color. This is neat for about a few seconds, and then you realize that it looks horrible. Current 3D games use textures. A texture is a 2D image, like the logo at the top of this page. A part of this image is drawn onto a polygon. I say "a part" because the polygon is triangular and the texture is a rectangle so it can never fit exactly. Then the computer calculates how that piece of the texture would look from a certain viewpoint and warps the image to make it look 3D. The most important thing to know is that a texture is a 2D image drawn on the surface of a 3D object. Textures add detail. Now it is time for me to briefly explain how a 3D card works. The 3D card has special sets of RAM and processors to handle all the graphics tasks. First the 3D card is given all the polygons in one portion of RAM. A second portion of RAM gets the textures. The processors then draw the textures onto the polygons and generates a new 2D image, called a frame, that shows how the scene would look from a certain viewpoint. Each frame is the size of the screen and is copied to RAM on the 3D card or video card (if it is a separate piece of hardware). The frames are drawn on the monitor very quickly to create the illusion that you are moving through 3D space. Now, what kind of data do 3D games use? While exact formats and
file types vary, they all fit into 7 general categories:
Now, for an example that encompasses all of what you have learned. Supposed we want to make a map of a room in a house. The walls, floors, and ceiling are all made up of brushes. The simple furniture, such as dresser, desk, and bed are also brushes. The wallpaper, blankets, and wooden patterns are all saved as textures. Not that we would need a separate texture for each visible side of the furniture, one for the ceiling, one texture that can be tiled across the walls, and one for the floor. When a texture is tiled it is repeated more than once, like a tiled floor. The texture itself only holds the image of one tile, but when we cover a floor with them we see a larger, somewhat repetitive image. Let's say that there is also a chair in the room. We could make the chair out of brushes, but this would require a lot of small, detailed brushes (and that is bad). The best way to handle detail is with models. The surfaces of the chair would be held in a skin file that is designed to wrap around that particular model. We could even have 2 similar chairs, one green and one blue, by copying the same model and using 2 different skins. Now we want to have a door that swings open and creaks. First we create a wall that has a doorway in it (using however many brushes it takes, it can be done in 3), and a separate brush for the door. We texture the brush and associate it with an entity that tells the game engine to rotate the brush in a manner similar to the swinging of a real door. The entity also tells the game engine to load "creak.wav" and play it as the door opens. Next week I will write about game modifications or "MOD's" and completely blur the line I've drawn between the game engine and game data. I will also explain ".dll" files, as promised. Page Updated: 1/23/00 |