Tài liệu 3D Game Programming All in One- P20 docx

30 294 0
Tài liệu 3D Game Programming All in One- P20 docx

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

the midline of the tire are aligned with the origin bug. Testing Your Runabout In order to test the runabout, we first need to export it from MilkShape. 1. After saving your work, choose File, Export, Torque Game Engine DTS. You will see the Torque Game Engine (DTS) Exporter dialog box appear. 2. Use defaults, but make sure they are correct. You want to have Export animation and Export material information selected, and Collision Mesh should be set to Collision Meshes (this is automatic if the exporter finds a mesh whose name starts with "Col- lision"). Click OK when ready. 3. Export your runabout to DTS format as C:\3DGPAi1\racing\ data\shapes\car\runabout.dts. 4. Open your wheel model and export it as C:\3DGPAi1\racing\data\shapes\car\wheel.dts. Next, you need to edit the script that controls the vehicle so it will look for your model and not the default one. 1. Locate the file C:\3DGPAi1\racing\server\scripts\car.cs and open it with UltraEdit. 2. There are two lines that say this: shapeFile = "~/data/shapes/rifle/weapon.dts"; Replace each of them with this line: shapeFile = "~/data/shapes/tommygun/tommygun.dts"; 3. Then find the line that says this: shapeFile = "~/data/shapes/buggy/wheel.dts"; Testing Your Runabout 477 Figure 15.32 Seat mounts. Figure 15.33 Collision mesh. Team LRN Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. And replace it with this line: shapeFile = "~/data/shapes/car/wheel.dts"; 4. Save the file. Okay, now it's time to run the racing demo. The following may look familiar to you, since we did this back in Chapter 9. 1. Browse to C:\3DGPAi1 and click the Run racing Demo shortcut. 2. Click Start Mission. 3. In the Launch dialog box, make sure that the Multiplayer Mission box is cleared. 4. Select Car Race Track from the mission list. 5. Click Launch. 6. After the game loads, have at it! You probably should switch to Chase view by pressing the Tab key—there's more to see. See Table 15.1 for the keyboard controls. Moving Right Along Building the model is only half the battle—well, maybe three-quarters. There is still the mat- ter of defining the vehicle's characteristics, like mass, drag, speeds, particle generators, colli- sion handlers, and so on. You take care of these things in scripts that run on the server. To do the testing you just did, you used the existing demo buggy script that comes with the Torque Engine and simply substituted our model in place of the dune buggy. It looks like a roadster but drives like a dune buggy! In fact you will recall that you had a test-drive of a dune buggy back in Chapter 9. Later, in Chapter 22, we will create the script that will define the behavior of the vehicle that we've modeled here and its response to user inputs and game environment stimuli. Coming up next in Chapter 16, we'll continue with MilkShape and make some weapons and other items. Chapter 15 ■ Making a Vehicle Model478 Table 15.1 Torque Racing Demo Controls Key Description mouse steering left or right Up Arrow accelerate Down Arrow brake Tab toggle from first- to third-person viewpoint Escape exit the game Team LRN Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. 479 Making Weapons and Items chapter 16 I n this chapter we're going to make a bunch of things. Most of the techniques used will basically be a review for you, so you can see this chapter as one big exercise in apply- ing what you've learned to different situations. We're going to make a few weapons, and in order to maintain balance, we'll make some- thing that can be used in game to counteract the effects of these weapons. We'll also make some items that one might call decorations for the game. The purpose of these items—some trees and a rock—is to provide some clutter. This is to help fill out oth- erwise sterile-looking game worlds, making them more interesting to wander around in. The Health Kit We'll start out with an easy one. Like I said, this will be a basic review, but it's important to go over the process involved in creating an item for use in the game so that the broad steps become obvious and second nature. The Model The Health Kit is little more than a fancy-looking box, as you can see from Figure 16.1. So this won't take long. 1. Fire up MilkShape and create an empty document. 2. Use the Box tool to create a box, as shown in Figure 16.2. 3. Align the box to be centered at the origin for all three axes, as you can see in Figure 16.2. Team LRN Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. 4. On the Materials tab, create a new material, using C:\3DGPAi1\RESOURCES\CH16 \ healthkit.png as the bitmap. 5. Name the material "healthkit". 6. Select the box and assign the healthkit material to it. 7. Make sure that the 3D view has been set to texture mode. You should see a nice, shiny new first- aid kit kind of item there, like that in Figure 16.3. This one always has bandages in it! 8. Save your work. 9. After saving your work, choose File, Export, Torque Game Engine DTS. You will see the Torque Game Engine (DTS) Exporter appear. 10. You want to take the defaults but have Collision Mesh set to None. 11. Export the box to C:\3DGPAi1\ fps\data\shapes\items\healthk- its.dts. Click Yes if you get an alert asking if you want to replace an existing file with that name. Testing the Health Kit To use the Health Kit in game, you merely have to run over it to pick it up. Then you activate it by pressing the "h" key to restore your health whenever it gets too low. You may remember using a kind of first-aid kit in one of your sample games from an earlier chap- ter—Emaga5—where you got health back just by running over the first-aid kit, or Health Kit. This one you have to Chapter 16 ■ Making Weapons and Items480 Figure 16.1 The Health Kit in game. Figure 16.2 The box. Figure 16.3 The Health Kit model. Team LRN Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. pick up and activate; we'll test that functionality later when we get back into server scripts. Right now we just want to see our fine creation in the game world. 1. Browse to C:\3DGPAi1 and click the Run fps Demo shortcut. 2. Click Start Mission. 3. In the Launch dialog box, make sure that the Multiplayer Mission box is cleared. 4. Select Water World from the mission list. 5. Click Launch. 6. After the game loads, look around for a big gray block jutting out from the side of a hill into the water. Figure 16.4 shows what the block (marked by the arrow) looks like. 7. Run over to the block. On top of it you will find the Health Kit. You can stand there and admire it for a while if you like. 8. Run over the kit to automatically pick it up. You will see a message in your chat window telling you that you've picked it up. A Rock Oh, big deal, a rock—what's up with that, you ask? Well, it is going to be your own handmade rock! That should be worth something. The point here is that, even though the rock is not much more complex than the Health Kit, it is somewhat more complex nonetheless. It does less for us in the game, but it is one of those decoration-type items I mentioned— and stuff like this, while unglamorous, can greatly contribute to the ambience of your game. 1. Fire up MilkShape and create an empty document. 2. Use the Sphere tool to create a sphere, as shown in Figure 16.6. 3. In the Side view, select the bottom three rows of vertices. 4. Choose Vertex, Flatten, Y. The bottom three rows should be squished together A Rock 481 Figure 16.4 Locating the big gray block. Figure 16.5 The rock in game. Team LRN Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. in a horizontal flat plane, as shown in Figure 16.7. Already it's starting to look like a rock. 5. Still in the Side view, drag the vertices around on the left side until you get something resembling Figure 16.8. 6. Now in the Top view, drag some more vertices around until you get something resembling Figure 16.9. It's almost a rock now! 7. On the Materials tab, create a new mate- rial, using C:\3DGPAi1\RESOURCES\ CH16\rock.png as the bitmap. 8. Name the material "rock". 9. Select the entire rock model and assign the rock material to it. 10. Make sure that the 3D view has been set to texture mode. You should see a nice lumpy and ancient-looking rock there, like that in Figure 16.10. 11. Save your work. 12. After saving your work, choose File, Export, Torque Game Engine DTS. Chapter 16 ■ Making Weapons and Items482 Figure 16.6 The sphere. Figure 16.7 The truncated sphere. Figure 16.8 The stretched rock-sphere. Figure 16.9 The almost rock. Team LRN Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. 13. You want to take all the defaults (Collision Mesh should be set to Bounding Box). 14. Export the box to C:\3DGPAi1\fps\data\ shapes\organic\rock1.dts. Click Yes if you get an alert asking if you want to replace an existing file with that name. Testing the Rock The rock has a bounding box set for collision because it is, after all, a rock—you can't go through it. 1. Browse to C:\3DGPAi1 and click the Run fps Demo shortcut. 2. Click Start Mission. 3. In the Launch dialog box, make sure that the Multiplayer Mission box is cleared. 4. Select Water World from the mission list. 5. Click Launch. 6. After the game loads, look around for your rock jutting out from a saddle between two hills into the water. Figure 16.11 shows what the rock (marked by the arrow) looks like. 7. Run over to the rock. On top of it you will find the Health Kit. 8. Run over the kit to automatically pick it up. You will see a message in your chat window telling you that you've picked it up. Trees If Joyce Kilmer had been a game devel- oper, he might have written, "I think that I shall never see, a model so annoy- ing as a tree." Or something like that. But he didn't, so that's too bad. Really talented game developer poets are rare. Nonetheless, computer model trees really are annoying. There is this Trees 483 Figure 16.10 The rock model. Figure 16.11 Locating the rock. Team LRN Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. conundrum: If you can interact reasonably well with a model tree, then it looks awful. If the tree looks really good, then interacting with it is awful. The problem is twofold. We see them everywhere, in most parts of the world, so they pro- vide a great deal of the background to our daily lives. This means that in virtual worlds, if there are no trees in the background, we just know something's wrong even if we can't quite put our finger on the problem. They are ubiquitous. And that means we also have a highly developed subconscious sense of what they should look like, when we aren't…um… actually looking at them. With me so far? Okay, that's problem number one. The other problem is that they are so dad-blamed complex! Even a sapling has lots of lit- tle branches and twigs and leaves and buds and stuff. If you have a polygon budget (and if you are making games, you have a polygon budget!), then these suckers will dry up that account faster than a barking moonbat can change its mind. So, on the one hand, to have convincing trees that satiate the subconscious gamer's mind, we need to be attentive to details. And on the other hand, those very details can drag our frame rates lower than a snake's belly in a wheel rut. To interact well with a tree means several things: When you approach it, circle it, look up into its branches and leaves, you see things properly in three-dimensional perspective. You can collide with the thicker parts like the trunk and the big lower branches, but if you fell onto a tree from above, you would likely fall a long way down through the airy upper structures before you stopped. But unless you want to put 30,000 polygon trees into your game world, you'll have to com- promise on all those fiddly details. There are ways to strip off a few thousand polygons here and there, but long before you get anywhere reasonable, your compromises start making the tree much less treelike. So then you have to pass a few edicts like this: From this point hence, this tree, and all other trees like this tree that grace our fair land, may only be viewed from certain angles—all of the aforementioned angles being from a level on the ground to a level not exceeding the height that one man can jump. But then you start to drain the flexibility out of your game world. What if you are stand- ing on the back of a truck? Or on a nearby hill? Or flying overhead in an ornithopter? Well, you can't do any of those things if you really want to save the trees! And don't even talk to me about having forests of these things in a game. Though there are ways to make trees look absolutely stunning from a distance, and only take two poly- gons to accomplish the task! Using a technique called billboarding we can create trees that look great from any angle as long we are at least moderately far from the tree—say a cou- ple dozen meters or more. But up close they are nothing but flat planes that turn to always face you. You can't look up into them from below and search for robin's nests. You can't climb them. And you certainly can't fall into them from above! I mean, what fun is that? Chapter 16 ■ Making Weapons and Items484 Team LRN Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. So why all the blather, you ask? Well, I'll tell you. We're going to look at modeling some game-friendly trees in this section, and I want you to enter into this prepared, under- standing why I'm going to show you two different ways to model a tree. There are other ways, but the two represent the opposite extremes. First, we'll create a "normal" low-poly- gon solid tree with a collision mesh. One that you could potentially climb using appropri- ate program code. One that you could actually get beneath and peer up into. It won't look all that great, but it will look like a tree. After that, we'll create a billboard tree that can be used to make vast forests of trees that will actually look like forests. The Solid Tree The solid tree is constructed of 3D object primitives, mostly cylinders that join end to end and taper. The one we'll make won't have any leaves—it's a generic big backyard tree in the winter. I should warn you now that we aren't going to build a megapolygon old oak tree or any- thing like that here. Instead, we're going to do just enough so you'll have a good idea where you can go with the model and what's involved with this approach. Having said all that, go ahead and create a new empty document in MilkShape, and let's get crackin'. 1. Select the Cylinder tool and set it to 4 stacks and 12 slices in the parameter boxes. 2. Click your cursor in the Side view, and drag down and to the right to create a cylinder like the one shown in Figure 16.12. 3. Still in the Side view, select the vertices in the second row from the bottom, and then use the Move tool to shift them to one side. 4. Switch to the Top view and do the same thing, moving the vertices slightly away from being aligned with the cen- ter of the cylinder. 5. Repeat steps 3 and 4 with the next two rows of vertices going up, one row at a time, using Figure 16.13 as a guide. 6. Do an incremental scaling working from the second row of vertices going up, so that you get a tapered trunk, like that shown in Figure 16.14. 7. Use the Duplicate function to make a copy of the trunk. Trees 485 Figure 16.12 Four-stack cylinder. Team LRN Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. tip If you've forgotten how to duplicate an object, I'll go over it quickly here. First make sure that the object to be copied has been selected in face mode. Then choose Edit, Duplicate Selection. Make sure you only do that once, and don't click your mouse in the window. It will look like nothing happened, but a copy was made in place. Select the Move tool and then drag the selected object to a clear area. There you go— you will have the copy, and the original object will have been left behind. 8. Move the copy to one side. Then scale it and rotate it so that you get something that looks like Figure 16.15. 9. Drag the branch over to the trunk and place it with the larger end inside the bounds of the trunk. 10. Make more copies of the branch, scaling, rotating, and tweaking them as desired, until you get something like the model shown in Figure 16.16. 11. On the Materials tab, create a new mate- rial, using C:\3DGPAi1\RESOURCES\CH16\bark.p ng as the bitmap. 12. Name the material "bark". 13. Select the trunk using the Groups tab, and assign the bark material to it. 14. Assign the bark material to each of the branches. Do not select them all at once and assign the material—instead, do them one at a time. Chapter 16 ■ Making Weapons and Items486 Figure 16.13 Crooked cylinder. Figure 16.15 Branching out. Figure 16.14 Crooked cylinder becomes a tree trunk. Team LRN Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. [...]... Making Weapons and Items 15 In the Top view, select all faces 16 Rotate the gun about 8 degrees to the left, as shown in Figure 16.31 17 Move the nodes to align them with the gun, using Figure 16.31 as a guide Voilá! Insta-gun Save your work Skinning the Tommy Gun Way back in Chapter 13 you learned how to use UVMapper and Paint Shop Pro to create a skin for objects In this chapter we'll look at using... available to use for creating DIF objects A very good open source (it doesn't cost you anything to use and it is published under the GNU General Public License) is QuArK (short for Quake Army Knife) 499 Team LRN 500 Chapter 17 ■ Making Structures Installing QuArK All of the parts you will need to install QuArK on your hard drive are included on the companion CD After installing the program, you'll need... the companion CD After installing the program, you'll need to verify the configuration, as described in the following sections Using the Installer When you install QuArK, you will also be installing a stripped-down version of the Python scripting language Do the following: 1 2 3 4 Browse to your CD in the \QuArK directory Locate the Setup.exe file and double-click it to run it Click the Next button... fine for our purposes This model will have as few polygons in it as I think we can get away with I've made two versions of it for you to use: one for the skin and one to act as the extrusion reference image Making the Model Get MilkShape running and warming up in the driveway, and we'll get started in a minute We will use C:\3DGPAi1\RESOURCES\ CH16\tommygun.png as the texture for the Tommy gun's skin... have a specific reason to do otherwise Note that this is not the official QuArK installer—there isn't any This installer is only available on the companion CD for this book After installation you will have QuArK installed into a directory structure that should look exactly like that in Figure 17.1 Configuration The installation program will have already ensured that you have the correct configuration... appear, as shown in Figure 17.4 Team LRN Quick Start 4 Verify the setting of each parameter by checking it against Table 17.1 All parameters not listed in the table should be left blank Also note that the settings in the first program through the sixth program entries are almost identical, with the only difference being the middle of the three command-line switches in the fixed command-line arguments... position it as shown in Figure 16.18 17 Rename the box, calling it "Collision" 18 Save your work 19 After saving your work, choose File, Export, Torque Game Engine DTS 20 You want to take all the defaults (Collision Mesh should set to Bounding Box) 21 Export the box to C:\3DGPAi1\ fps\data\shapes\organic\tree1.dts Click Yes if you get an alert asking if you want to replace an existing file with that... are finished Next, let's make something! Figure 17.2 QuArK Edit menu Quick Start What we'll do is fire up the QuArK Map Editor and quickly create a structure that we can stick in our sample Torque game and poke around with note More taxing terminology! In QuArK development circles what you create are often called rooms This harkens back to QuArK's beginnings as an editor for Quake, where everything... The preceding steps are a way to manually insert your creation into the mission map file at the location of one of the existing hovel structures Because of differences in construction between the two structures, you needed to adjust the position of the new structure somewhat 12 Run your Emaga6 sample game After spawning in, you should see the new structure directly in front of you, as shown in Figure... use something called brushes to create their objects A brush in this sense is like a building block You select a particular brush (also called a polyhedron in QuArK) for a particular need and apply it to your model Figure 17.10 The test structure in Emaga6 3 Select the Cube brush by clicking its icon, as shown in Figure 17.11 After clicking the Cube brush icon, you will see a cube appear in your model, . reference image. Making the Model Get MilkShape running and warming up in the driveway, and we'll get started in a minute. We will use C:3DGPAi1RESOURCES CH16 ommygun.png. create a skin for objects. In this chapter we'll look at using the built -in Texture Coordinate Editor in MilkShape to accomplish the same thing. It can

Ngày đăng: 26/01/2014, 18:20

Từ khóa liên quan

Tài liệu cùng người dùng

  • Đang cập nhật ...

Tài liệu liên quan