1. Trang chủ
  2. » Công Nghệ Thông Tin

Tài liệu 3D Game Programming All in One- P21 doc

30 253 0

Đ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

Thông tin cơ bản

Định dạng
Số trang 30
Dung lượng 0,97 MB

Nội dung

You will end up with a textured bridge (see Figure 17.17) in your 3D view at the upper left. 11. For safety's sake, save your work, by Choosing File, Save As File. In the Save As Type combo box, select Quake map file (*.map). 12. Choose Torque, Export220map/Build High Detail DIF. This will export the map again, overwriting what you just saved (so you can see that you could have gotten away with not doing the initial Save As operation), and then compile the map to DIF format and gather all of the used textures into the used textures directory. Contrast this all-in-one operation with the discrete steps we executed earlier when we did the quick start with the default room. This is certainly more convenient! 13. Copy the textures and the bridge.map file to C:\aEma- gaCh6\control\data\structures. There is already a bridge with that name in that directory that is being used in the mission file. Go ahead and replace that file, as well as the textures, if necessary. 14. Launch Emaga6 and when you spawn in, turn to your right and run to the edge of the wadi. You should see your bridge spanning the wadi ahead of you, as depicted in Fig- ure 17.18. Building Bridges 507 Figure 17.14 A new cube. Figure 17.15 The Texture item in the Object pop-up menu. Team LRN Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. Building a House The bridge was nice and certainly useful. But one must admit that it's fairly simple. Of course, if you need a bridge you will probably make something more ornate. In this section we will go a little bit farther and make something more complex: a house with a door opening and a window and internal lighting. 1. Launch QuArK and open the Torque Map Editor. Delete the default room and save the empty file as C:\QuArK 6.3\torque\tmpquark\maps\house.map. 2. Select the Cube brush and create a cube that measures 260 units in width by 360 units in length by 256 units in height. You can see the dimensions by hovering the cursor over the cube and looking in the lower-left corner of the Map Editor window. 3. Create a smaller brush in front of the first cube, as shown in Figure 17.19. This will be used to create the front stairs. 4. Select the new brush in the lower- left window, and then right-click to get the pop-up menu and choose Stair. You will see your brush change into a staircase, as shown in Figure 17.20. 5. Select the large brush, right-click to get the pop-up menu, and choose Make Hollow. Your large Chapter 17 ■ Making Structures508 Figure 17.16 The Texture Browser. Figure 17.17 The finished bridge. Figure 17.18 The bridge in Emaga6. Team LRN Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. brush will now be a hollowed room and will look like the one in Figure 17.21. 6. Create another brush and place it in the wall above the stairs, as shown in Figure 17.22. This brush will be used for an opera- tion called a subtraction. 7. Ensure that the new brush is selected, right-click it, and choose Brush Subtraction. You will see a bunch of new lines appear in the wall in which the brush is embedded. 8. Select the Subtraction brush and press the Delete key to make it go away. You will see a hole in the wall now, as depicted in Fig- ure 17.23. This is the doorway. 9. Using the texture assignment technique you learned in the earlier sections of this chapter, set the house's texture to con- crete and the stairs' texture to 256_BrickA. Now you have to add a special brush of a type known as an entity. Entities are constructs used when making maps that give special instructions to the map compiler about things it needs to do or understand when it goes about building the DIF version of the map for use in Torque. You are going to create an entity called a portal. Portals tell Torque how to go about lighting the interior of the object when Building a House 509 Figure 17.19 The Stair brush. Figure 17.20 The stairs. Figure 17.21 The hollowed room. Team LRN Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. there is an opening. By placing the portal in the doorway, you can tell Torque that it should not try to do its special interior lighting outside the door. You can also indicate whether or not Torque will allow external light to pass through the portal to the interior. 10. Locate the Entities panel in the upper-left portion of the Map Editor, and in it find the Torque Entities button. Click it. 11. Choose Brush-based entities, portal, as shown in Figure 17.24. 12. An entry for the entity will appear in the Tree view in the lower-left portion of the Map Editor, as shown in Figure 17.25. 13. Select the portal entity and then click the Cube button to create a Portal brush, as shown in Figure 17.26. A new brush will appear in the model—this is the Portal brush. 14. Reshape the Portal brush to be just a little larger than the doorway in width and height, and a little narrower than the doorway in thickness, as you can see in Fig- ure 17.27. 15. In the Tree view, double-click the portal icon (not the poly icon that it contains). A small dialog box will appear; the bottom field is the parameter ambient_light set- ting for the portal. Choose passes through from the combo box. 16. Using the texture assignment technique you learned in the earlier sections of this chapter, set the portal's texture to NULL . Next we are going to create another entity—a light entity. The process is similar to the portal entity at first, but a light entity is a point entity, not a brush entity, so things will be just a little different. Chapter 17 ■ Making Structures510 Figure 17.22 The Subtraction brush. Figure 17.23 The doorway. Team LRN Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. 17. As before, go to the Entities panel and find the Torque Enti- ties button. Click it and choose light_*entities, light_omni, as shown in Figure 17.28. 18. A new light entity will be cre- ated in the Tree view, and a small rendition of a light bulb will appear in your map. Move it up closer to the ceiling, as you can see in Figure 17.29. 19. Double-click the light_omni entity in the Tree view to get to its settings. Ensure that alarm_type is set to nor- mal only. 20. Save your work and export it using the methods you learned earlier in the Quick Start section. 21. Use UltraEdit to open the mission file for Emaga6, C:\aEmagaCh6\control\data\maps\ book_ch6.mis. 22. Locate this line: interiorFile = "~/data/structures/newmap.dif"; If the line doesn't exist in the file, then locate this one: interiorFile = "~/data/structures/hovelb.dif"; Change whichever line you find to reflect your new structure as follows: interiorFile = "~/data/structures/house.dif"; 23. Run Emaga6 and check out your new house, which should be in front of you. Go on inside and see the effect the lighting has. Building a House 511 Figure 17.27 The portal in place. Figure 17.28 The light entity. Figure 17.25 The portal entity in the Tree view. Figure 17.26 The portal entity's brush in the Tree view. Figure 17.24 The portal entity. Team LRN Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. Moving Right Along So, in this chapter you've learned yet another tool. QuArK is an extremely feature-complete tool for creating structures for Torque. You've built the two most common sorts of structures, an outdoor structure (the bridge) and a building with a lighted interior. Your imagination is the only real limit here—castles, complex underground tunnel systems, factories, playgrounds, and just about anything else can be created with QuArK. Normally, I would include a reference section for QuArK in this chapter. However, the program has so many features and options that the material is just too hefty to present in the chapter. Instead, I've included the QuArK reference in Appendix D. In the next chapter, we'll take a look at how to make things for the game world environment. Chapter 17 ■ Making Structures512 Figure 17.29 The repositioned light entity. Team LRN Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. 513 Making the Game World Environment chapter 18 I n many games, having a full suite of character models, buildings, trees, and other visual clutter is still not enough to accomplish the needed sense of immersion. There are a number of other aspects to the game world that come from the world around us that we often take for granted: the background sky, the appearance of water, the appear- ance of clouds in motion, and the terrain. Figure 18.1 is a nice serene picture of ocean- side forested hills just after sunset. No, it's not a photograph—it's a screen shot from the game Tubettiworld being developed using the Torque Game Engine. Now way back in Chapter 12 we covered terrains to a certain extent, so you probably have a reasonable sense of what is involved with creating terrains using a height map. In this chapter we will revisit terrains using the more labor-intensive method of manually build- ing up a terrain with the in-game editor. We'll get into that at the end of this chapter. First, however, we will visit sky, clouds, and water—the environmental triad of computer game ambience. Skyboxes When you are tasked to create a 3D game that offers unrestricted player movement in unlimited vistas, you will need to come up with ways to provide that open, outdoors perception. A technique that works well is to pro- vide a static background sky that con- tains elements of the sky that we often Figure 18.1 A serene scene. Team LRN Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. take for granted, like clouds, and a color gradient that changes as you move farther away from the horizon. We do this using a construct known as a skybox. A skybox is a cube that surrounds the game player. The player stands inside the box, and no matter which way he turns, he will see some part of the box as long as it isn't obscured by other in-game objects. The box never rotates, and the sides are always the same distance away from the player no matter how far or how fast he moves. Because of the way the images on the faces of the skybox are created, the player does not have the feeling that he is inside a big cube. The skybox images are on the inside faces of this cube, as you can see in Figure 18.2. The back view has been left out to help illustrate the point. When using skyboxes, we treat them as if they are infinitely large. Only objects that the player can never reach will look correct, like clouds in the sky or distant mountains. If you limit a player's movement to just viewing from a fixed location, you could even use a sky- box for nearby scenery. Figure 18.3 shows an exploded view of the skybox images and how they relate to each other. Note that the image for the bottom is a black field. If you were depicting an area with a usable view in that direction, you would of course include an appropriate image. To create the illusion that the player is embedded in a large and seamless world, there are two things that you must get right when creating a skybox: seamless, matching adjacent edges and correct perspective. The edge matching issue is one we are already familiar with from previous tex- ture endeavors. The perspective issue is a little less obvious when you first consider mak- ing skyboxes—but take a look at Figure 18.4. Remember that the sky- box is always the same distance away from the player, and the orientation is fixed. The front face, if it happens to be facing north, will always face north, no matter which way the player is fac- ing or looking. This causes a visual problem when viewing the images on the skybox faces. Chapter 18 ■ Making the Game World Environment514 Figure 18.2 A pictorial skybox. Figure 18.3 An exploded skybox. Team LRN Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. The image areas that are on the face closest to the player will appear larger than the portions of the image nearest the corners, because the corners are farther away. Figure 18.5 simulates what that would look like. In order to remove the distortion when the image is viewed in game, we need to distort its appearance outside the game environment in such a way that when the perspective comes into play in game, the image looks natural. Figure 18.6 shows such a predistorted image. Each of the six square skybox images should be created with the same reso- lution. The most common resolution to use is 256 by 256 pixels. The higher the resolution, the better the skybox will look in most cases, but there is a limit beyond which higher skybox image resolution doesn't help the appearance. Because we are always worried about memory used and processing time consumed, we want to make sure we don't go higher than the maximum. If you are interested in using larger skybox images, there is a way to calculate the maximum resolution to use as your upper limit, using this mathematical formula: maxSkyboxResX = maxScreenResX * 1/tan(FOV/2) maxSkyboxResY = maxScreenResY * 1/tan(FOV/2) The basic concept is that the smaller the Field of View (FOV), the higher the resolution you will need for the skybox. This is because as the FOV gets small- er, you are looking farther and at a smaller portion of the skybox image. This smaller por- tion fills the view, and therefore the pixels are larger. Typical first-person point-of-view games use a 90-degree FOV and often have a 60-degree (or even smaller) zoomed-in view for sniper scopes or binoculars. For example, if our screen resolution is 800 by 600 pixels and our FOV is 90 degrees, then applying our formula yields this: maxSkyboxResX = 800 * 1/tan(90/2) maxSkyboxResX = 800 * 1/1 maxSkyboxResX = 800 It also follows that we don't need to recompute the Y resolution because it will scale pro- portionally. So for this 800 by 600 pixel display with a 90-degree FOV, the highest resolu- tion we should use for the skybox images is 800 by 600 pixels, by happy coincidence! Skyboxes 515 Figure 18.4 Skybox edge distances. Figure 18.5 Distorted image. Figure 18.6 Predistorted image. Team LRN Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. However, if we want to know the deal for the 60-degree FOV that our player's binoculars provide, we need to recompute that value as follows: maxSkyboxResX = 800 * 1/tan(60/2) maxSkyboxResX = 800 * 1/ 0.57735 maxSkyboxResX = 800 * 1.732 maxSkyboxResX = 1386 For the Y resolution, the value is 1,039. So if you decide to create a high-resolution sky- box, you should probably go with nothing larger than 1,280 by 1,024 pixels. (Most games, including Torque, need the image resolution values to be powers of two.) Personally, I would go with 1,024 by 1,024 as a reasonable compromise for a maximum resolution. These dimensions would apply to all of your skybox panels in a given skybox. The size you eventually choose for your game will in the end be a judgment call, but by using the previous calculations, not just a hopeful stab in the dark. Creating the Skybox Images As with other texture-related issues, there is always the question of where to obtain source material. Once again, you have the option of creating your own by using a digital camera or a camera and scanner combination or by simply drawing your own images. In this section I will walk you through drawing some clouds on the horizon for your sky- box—this is a common sunny-day sort of scene. Low cumulus clouds in the distance peek just above the horizon, all around you. 1. Open Paint Shop Pro and create a new image by selecting File, New. Fill in the dia- log box with 256 for both the height and width of the blank image. Make sure that the color depth is set to 16 million colors (24 bit). 2. Save this blank file as C:\aEmaga6\control\data\maps\front.png. 3. Select the Fill tool. 4. Over in the Materials palette, select the Foreground and Stroke Properties check box, just to the right of the color picker (see Figure 18.7). 5. When the Materials dialog box opens, click the Gradient tab. 6. Make sure the value in the Angle window is set to 0, and then click the Edit button. 7. Set the Gradient scale to have two color mark- ers (they look like little pens) on the bottom side of the scale to approximate the settings shown in Figure 18.8. Do the same for the range modifier (the little diamond on the top). Chapter 18 ■ Making the Game World Environment516 Figure 18.7 Foreground and Stroke Properties check box. Team LRN Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. [...]... cloud textures In fact, you can even get away with using cloud textures in a pinch! Take a look at Figure 18.17 to see a water block in action Terraforming You've already seen in Chapter 12 how to create a terrain using height maps Torque also has a built -in Terrain Editor that you can use to manually modify the terrain height map and square properties Terrain editing is done using a Terrain brush The... defines a coloring that is applied when the bolt first appears, and the color values are changed over the life of the bolt until they reach the settings in fadeColor The useFog property indicates whether the fog defined by the stormFogn property in the Sky mission object will be used In Figure 18.16 you can see a lighting bolt coming out of the sky in the game setting Rain You can make it rain in much... actually look like You do this by specifying an image file in the same material file that you used to specify the skybox image files After the first six lines in that file that indicate the skybox images, the next lines indicate the cloud image files One line equals one cloud layer, with the first line after the skybox image lines indicating layer one, the next being layer two, and the last being layer... ShoreDepth DepthGradient MinAlpha/MaxAlpha TessSurface/TessShore SurfaceParallax FlowAngle/FlowRate DistortGridScale/ DistortMag/DistortTime Team LRN 535 536 Chapter 18 ■ Making the Game World Environment brush fall-off rate in the Terrain Editor Settings dialog box, found under the menu Edit, Terrain Editor Settings 1 Run your sample game, and when you have spawned into the game, press F8 to switch... the surrounding terrain 3 Press F11 to switch to the Editor GUI Figure 18.18 Terrain brush 4 Choose Window, Terrain Editor 5 Wave your cursor over the terrain, and notice the Terrain brush marked on the terrain 6 Drag your mouse up and down after clicking over some area of terrain You will see your terrain change to conform 7 Experiment with using different actions to see how the Terrain Editor works... reached, after which nothing is rendered By using these two properties, you can prepare a game world where there is a natural-appearing haziness that slowly obscures distant objects until they disappear completely note You should always make sure that visibleDistance is a bigger number than fogDistance, otherwise you risk crashing the game engine in clients in certain situations In fact, for the sake... lightning.dml material file looks like this: lightning1frame1 lightning1frame2 lightning1frame3 The lightning.dml material file is a list of lightning image files that are displayed in sequence as the lightning stroke occurs Figure 18.15 shows each of these images in order, from left to right When making the lightning frame files, you need to make them 128 pixels wide by 256 pixels high Draw your lightning... altitudes using the for each specified cloudHeightPer[n] and have the game engine figure out the relative motion based on pseudo-altitude and the speed at that altitude Unfortunately, Torque doesn't handle wind direction for clouds as well—that would be the final link needed to provide really neat cloud motion Wind direction is specified by a single windVelocity property that applies to all layers In real... skybox Not all of the properties in the skybox are particularly interesting; they owe their presence to Torque's beginnings as the code that drives the Tribes 2 game The position, scale, and Team LRN 519 520 Chapter 18 ■ Making the Game World Environment rotation properties don't accomplish much when you use them—they are there because all objects have those properties whether or not they are meaningful... of the side images all have the same RGB value—0,0,192 Also, the bottom doesn't need to be blended either, because it's not going to be visible beneath our terrain So that just leaves the perspective distortion to fix Adjusting for Perspective Although we are going to be adjusting for perspective distortion, we aren't going to use the built -in perspective tools in Paint Shop Pro Instead, we will use . involved with creating terrains using a height map. In this chapter we will revisit terrains using the more labor-intensive method of manually build- ing. screen shot from the game Tubettiworld being developed using the Torque Game Engine. Now way back in Chapter 12 we covered terrains to a certain extent, so you

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