3D Game Programming All in One- P22

30 433 0
3D Game Programming All in One- P22

Đ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

Terraforming 537 Table 18.3 Terrain Editor Functions Function Description Select Selects grid points that will be painted with the brush. Adjust Selection Raises or lowers the currently selected grid points as a group. Add Dirt Adds "dirt" to the center of the brush. Excavate Removes "dirt" from the center of the brush. Adjust Height Drags the brush selection to raise or lower it. Flatten Sets the area bounded by the brush surface to be a flat plane. Smooth Smoothes, within the bounds of the brush, rough areas of varying terrain height. Set Height Sets the terrain within the brush to a constant height as specified in the Terrain Editor settings. Set Empty Converts the squares covered by the brush into holes in the terrain. Clear Empty Makes the squares covered by the brush solid. Paint Material Paints the current terrain texture material with the brush. Table 18.4 Terrain Terraform Editor Functions Function Description fBm Fractal Creates bumpy hills. Rigid Multifractal Creates ridges and sweeping valleys. Canyon Fractal Creates vertical canyon ridges. Sinus Creates overlapping sine wave patterns with different frequencies useful for making rolling hills. Bitmap Imports an existing 256 by 256 bitmap as a heightfield. Turbulence Perturbs another operation on the stack. Smoothing Smoothes another operation on the stack. Smooth Water Smoothes water. Smooth Ridges/Valleys Smoothes an existing operation on edge boundaries. Filter Filters an existing operation based on a curve. Thermal Erosion Erodes an existing operation using a thermal erosion algorithm. Hydraulic Erosion Erodes an existing operation using a hydraulic erosion algorithm. Blend Blends two existing operations according to a scale factor and mathematical operator. Terrain File Loads an existing terrain file onto the stack. Team LRN Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. Moving Right Along So, you've now seen how you can create and modify your game environment. The three main environmental elements are Sky, Clouds, and Water. We looked at the different ways each of those three elements can be created using tools and techniques available in Torque. In most cases, you will probably use some form of all of those techniques when you cre- ate your game. For example, you would judiciously mix overhead cloud layers with sky- box renderings of distant clouds on the horizon. We've also looked at the combined weather effects involved in storms, and how you can initiate an automated process to start and end storms over time using Torque Script. In this chapter, we were introduced to sounds in the form of thunder for the lightning strikes. In the next chapter we will more thoroughly explore how to incorporate sounds in our game. Chapter 18 ■ Making the Game World Environment538 Team LRN Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. 539 Creating and Programming Sound chapter 19 A s I mentioned in Chapter 1, audio artists compose the music and sound in a game. Good designers work with creative and inspired audio artists to create musical compositions that intensify the game experience. It also bears repeating that audio artists work closely with the game designers determining where the sound effects are needed and what the character of the sounds should be. They often spend quite a bit of time experimenting with sound-effect sources, looking for differ- ent ways to generate the precise sound needed. Visit an audio artist at work and you might catch him slapping rulers and dropping boxes in front of a microphone. After capturing the basic sound, an audio artist will then massage the sound with sound-editing tools, varying the pitch, speeding up the sound or slowing it down, removing unwanted noise, and so on. It's often a tightrope walk balancing realistic sounds with the need sometimes to exaggerate certain characteristics in order to make the right point in the game context. When creating your game, you have a choice between two basic approaches: obtain a good source of sound effects and music (like an audio library) or create your own sounds. Of course, you also have the option to combine the two approaches. Audio libraries are avail- able from a wide variety of sources, and the commercial ones are quite thorough and pro- fessionally made. There are audio libraries available via the Internet for free, but the qual- ity of these sources varies widely in breadth, depth, and recording fidelity. In this book we are going to take the do-it-yourself approach. The main advantage of going this way is the price; a secondary advantage is that you have total control over the contents of your sound files. Team LRN Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. Audacity There are several tools available to use for recording and editing sound effects and music. A very good open source program—it doesn't cost you anything to use and is made avail- able under the GNU General Public License—is Audacity. This chapter will show you how to use Audacity (see Figure 19.1) to make sounds for use in your game. Installing Audacity To install Audacity, do the following: 1. Browse to your CD in the \Audacity directory. 2. Locate the audacity-win-1_0_0.exe file and double-click it to run it. 3. Click the Next button for the Welcome screen. 4. Follow the various screens, and take the default options for each one, unless you know you have a specific reason to do otherwise. Using Audacity You need to ensure that you've got your microphone set up properly—connected to the MIC or microphone input jack on your sound card. Of course, you don't need to obtain your sounds directly from a microphone; you can record from a CD or another audio source. In any event, you need to have that source connected to the correct input and ensure that your audio mixer is set up to record from that source. You should refer to your sound card documentation if you don't know how to do this. The basic operation of Audacity is quite straightforward for recording, simple editing, play- back, and saving your data. Recording Let's record some sound: 1. Launch Audacity by choos- ing Start, Programs, Audac- ity, Audacity. You will get the main window, as you saw earlier in Figure 19.1. 2. Click the Record button, as shown in Figure 19.2. Chapter 19 ■ Creating and Programming Sound540 Figure 19.1 Audacity main window. Team LRN Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. The program is now recording from the microphone. You can see the progress of the recording and the waveforms of the sounds in the window as the recording proceeds, as shown in Figure 19.3. 3. Speak into the microphone, or if you don't want to hear your own voice, make a noise, like slapping a book down on the desk or something. You will see the sound you made appear in the waveform. Figure 19.4 shows the waveform created when I tapped a pen on the desk next to the microphone. 4. When you have your sound recorded, click the Stop button, as shown in Figure 19.5. 5. Now you can play back your record- ing, by clicking the Play button, as shown in Figure 19.6. We'll continue working with Audacity in a moment, but first I want to point out that if you have a waveform but don't hear any sound, make sure that you have the volume turned up high enough in your speakers. Also be sure that it is turned up high enough—and is not muted—in your Windows Volume Control applet (in the Control Panel, and usually on the Windows System Tray on the right side of the taskbar). Simple Editing Now if you're like me you probably have a long period of dead air before the sound effect you made and another chunk afterward. That's fine, because it's easy to fix. So, picking up where we left off in the previous section: Audacity 541 Figure 19.2 The Record button. Figure 19.3 Recording in progress. Figure 19.4 Waveform in Audacity. Figure 19.5 Stop recording. Team LRN Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. 6. Place your cursor to one side of the portion of the waveform you want to eliminate, and drag it across to the other side. This selects an area to be worked on. See Figure 19.7. 7. Choose Edit, Delete. The selected portion will be excised from the waveform. 8. Repeat the preceding two steps for the unwanted portions of the waveform on the other side of your sound effect. Eventually you will end up with something like Figure 19.8. We're not finished with our procedure yet; there's still some exporting to do. But before we cover that, I want to mention that above the waveform panel is a series of numbers on a scale. This is the elapsed time scale. The example in Figure 19.8 shows that my final waveform is just a little more than three-quarters of a second in duration. Exporting Now, once again picking up where we left off, you need to save the sound effect as a file before you can use it: 9. Choose File, Export as WAV. Name your file and save it some- where convenient for the moment, such as on your desktop. 10. Browse to your desktop (or wherever you saved your file) and double-click your newly created file. Whichever program is set up to play sounds in Windows on your computer will be launched and play your sound. There are other export options available, but we'll stick with the WAV format for its sim- plicity and wide availability on Windows platforms. For other platforms, Ogg Vorbis is probably the format of choice on Linux, and AIFF for Macintosh. Audacity Reference This section contains some useful reference details to help you use Audacity. The Main Screen Figure 19.9 shows the Audacity main screen, with the major components labeled. This section will provide some detail on those components. Chapter 19 ■ Creating and Programming Sound542 Figure 19.6 Playback. Figure 19.7 Selecting a portion of the waveform. Figure 19.8 The final waveform of the sound effect. Team LRN Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. The toolbar is where you will find the tools that you will prob- ably use more than any other tools available with Audacity. Use Figure 19.9 to locate the tools in the toolbar, and Table 19.1 to review their functions. The Track Panel contains tools for managing specific tracks and groups of tracks. See Table 19.2 for details. Audacity 543 Envelope Toolbar Time Scale Play Stop Record Master Gain Selection Time Shift Zoom Track Delete Track Panel Waveform Panel Track Menu Track Mute Track Solo Sample Rate Figure 19.9 The Audacity main screen. Table 19.1 Toolbar Tools Tool Description Selection Selects a portion of the audio track. You can set the position of the track cursor simply by clicking at the right place in the track. Select a range of audio by clicking and dragging over the desired portion. Select multiple tracks by dragging across the tracks. Playback begins at the position of the track cursor and will play to the end of the track. If you have selected a range of audio, only the selected range will be played. Time Shift Changes the positioning of tracks relative to one another in time. Select this tool, then click in a track and drag it to the left or right. Envelope A handy audio processing tool. Its presence directly in the main window of the program is an innovative move. You get detailed control over how tracks fade in and out, right in the main track window with this tool. When you select the Envelope tool, the amplitude envelope of each track is highlighted in a green line; there are control points at the beginning and end of each track. To move a control point, click it and drag it to its new position. To add a new point, click anywhere in the track where a control point doesn't already exist. To remove a point, drag it outside of the track. Zoom Zooms in or out of a specific part of the audio. Clicking anywhere in the audio will zoom you in. Right-click or shift-click to zoom out. You can also zoom into a region by dragging the mouse to highlight the region while you have the Zoom tool selected. Play Enables you to listen to the audio file currently loaded or to a recording you have just created. The spacebar can be used as a stop and start toggle. Playback always begins at the current cursor position. If a region of audio is selected, only the selected region will play. To play the entire project, choose Edit, Select All and then click the Play button. All tracks on a given channel will be mixed automatically for playback. Stop Halts playback. Record Records a new track from your microphone or another input device. You can configure recording options by choosing Edit, Preferences. Recording always happens at the project's sample rate. Master Gain Controls the volume of the audio output by Audacity to your hardware. Volume increases as you move the slider from left to right. Team LRN Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. Audacity supports three different track types that can be viewed simultaneously when they exist in a single channel. These three track types let you view waveform, MIDI information, and label information for a given audio file. Table 19.3 describes each of the three types. note Common values for audio sample rates are shown in Table 19.4. Chapter 19 ■ Creating and Programming Sound544 Table 19.2 Track Panel Tools Tool Description Track Menu Allows the user to display a track in different formats. This menu also provides the Set Name option that allows the user to create a name for a given track. Track Delete Immediately deletes a track, without the option to undo. Use this button carefully. Solo Switches the current track to solo mode. You can change a track out of solo mode by clicking it again. When in solo mode, the button for that track turns red. Only tracks that have the Solo button enabled will be played when in solo mode. Mute Switches off a track without deleting it. You can unmute a track just by clicking the Mute button again. When muted, a track's Mute button will be green. Table 19.3 Track Types Tool Description Audio Audio tracks contain digitally sampled sounds. Two stereo channels are represented by two stereo tracks. Each audio track has a sample rate that is the same as the project sample rate. Note Note tracks display data loaded from a MIDI file. They cannot be changed or played, only viewed. Label Label tracks can be used to mark a document with annotations. Annotations can be saved to a text file. Table 19.4 Common Sample Rates Frequency Usage 8000 Hertz Typical telephone 11025 Hertz Minimum "voice quality" 16000 Hertz Typical "voice quality" 22050 Hertz Common digital interactive media 44100 Hertz CD audio, DAT (digital audiotape) 48000 Hertz Digital studio quality 96000 Hertz Digital studio quality (newer) Team LRN Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. Menus The Audacity menus provide access to functions for managing files, editing, adjusting views, managing Audacity projects, and finally, creating special effects. There is also a standard Help menu. The File Menu Figure 19.10 shows the File menu, and Table 19.5 contains an itemized description of the menu. Note that menu items that have names ending with three ellipsis points (three dots) will bring up a dialog box where you can fill in some parameters. The Edit Menu Figure 19.11 shows the Edit menu, and Table 19.6 contains an itemized description of the menu. Parts of this menu contain the standard Cut, Copy, and Paste functions; the rest are related func- tions that are specific to Audacity's capabilities. The View Menu The View menu provides functions that you can use to control what you see in the Audacity window and how you see it. Figure 19.12 shows the View menu, and Table 19.7 contains an itemized description of the menu. The Project Menu Audacity uses the concept of projects that you've encountered elsewhere, such as with UltraEdit earlier in this book. By using projects, you can organize data files as well as configura- tion and operational parameters in one collec- tion that can be recalled at any time. This really helps when dealing with complex tasks. Figure 19.13 shows the Project menu, and Table 19.8 con- tains an itemized description of the menu. The Effect Menu Audacity includes many built-in effects and also lets you use plug-in effects. To apply an effect, sim- ply select part or all of the tracks you want to mod- ify, and select the effect from the menu. Figure 19.14 shows the Effect menu, and Table 19.9 con- tains an itemized description of the menu. Audacity 545 Figure 19.10 File menu. Figure 19.11 Edit menu. Figure 19.13 Project menu. Figure 19.12 View menu. Figure 19.14 Effect menu. Team LRN Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. Chapter 19 ■ Creating and Programming Sound546 Table 19.5 File Menu Menu Item Description New Creates a new empty project window. Open Presents you with a dialog box to choose a file to open. If a project window is open and empty, the new file will appear in that window; otherwise a new project window will open. Close Closes the current project window. Save Project Saves the current Audacity project file in AUP format. Audacity projects are not usable by other programs. Audio data for an Audacity project is not stored in the AUP file—instead, it is stored in a directory with the same name as the project. Save Project As Saves the current Audacity project file, with a different name or directory path. Export as WAV Exports the current Audacity project as a standard audio file format, such as WAV or AIFF. Change the format of the exported file in the Preferences dialog box. Export Selection as WAV The same as Export as WAV, but only exports the selected portion of the project. Export as MP3 Exports the current Audacity project as an MP3 file. Exporting MP3 files requires that you install a separate MP3 encoder, not included with Audacity. Export selection as MP3 The same as Export as MP3, but only exports the selected portion of the project. Export as OGG Exports the current Audacity project as an Ogg Vorbis file. Export selection as OGG The same as Export as OGG, but only exports the selected portion of the project. Export Labels Exports label tracks to a text file. Preferences Place where you configure Audacity. Exit Closes all project windows and exits Audacity. It will ask if you want to save changes to your project. Team LRN Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. [...]... new tool—this time for dealing with sound You've learned how to create and export a WAV file for use in a game, and then how to insert a sound into a Torque game You've also seen how you can adjust a sound using Torque Script, as well as position a sound in the 3D game world In the next chapter we'll look at sound effect in the game world in more detail Team LRN chapter 20 Game Sound and Music I n the... AudioProfile and 3D coordinates in the world space Conveniently we can get those coordinates from a simple call to getTransform The serverPlay3D function then internally tells all clients to play that sound effect at those world coordinates And hey, presto! You have a footstep Before exiting playFootstep, the schedule method is called again to schedule another footstep in half a second It will keep doing this... something, something that other players can hear, by pressing a key The process is going to be quite similar to the footsteps First, make another recording, at the sample rate of your choosing Holler something into the mike, like, "Your mother wears army boots!" or something equally endearing Save it as C:\koob\control\data\sound\insult1.wav or something like that Then add the following code in C:\koob\control\server\players\player.cs... (Application Programmer's Interface) In this book we won't be directly addressing programming with OpenAL, but we do need to ensure that OpenAL is installed with the correct version The Torque installation procedure you followed in an earlier chapter will have taken care of that for you In your root main directory, make sure that the file OpenAL32.dll is there If it isn't, you will need to reinstall Torque If... to bind a key to press to trigger the whole thing We use PlayerKeymap.bind to do that, pointing it to the Yell function There you go—you're in business Team LRN Weapon Sounds One more variation you should try is recording several different insults and saving them as insult1.wav, insult2.wav, and so on Let's go ahead and record six different insults Now make six different AudioProfiles that have incremental... C:\koob\control\server\players\player.cs and find the line that reads as follows: datablock PlayerData(HumanMaleAvatar) At the end of the datablock that starts with that line, before the closing brace ("}") that ends the datablock, insert the following lines: maxInv[Tommygun] = 1; maxInv[TommygunAmmo] = 20; This indicates how many of the listed items the player can have in his possession, or inventory, at any given time And finally, open... this time seeming to come from a specific direction Again, play with the volume setting, trying different values less than 1.0 You can also play with the 3D coordinate values in the call to alxPlay() in the AudioTestB() function Koob In the following chapter, and in later chapters, we will be using audio features a great deal more, so take the time in the balance of this chapter to add some more files... for all datablock types, because the server can only define true datablocks Trying It Out Let's try it out, using your Emaga6 sample game Open up your root main file (main.cs) and add the following lines to the very top: new AudioDescription(AudioTest) { volume = 1.0; isLooping= false; Team LRN 553 554 Chapter 19 is3D type ■ Creating and Programming Sound = false; = 0; }; new AudioProfile(AudioTestProfile)... launch your game After you've spawned in, open the console window (using the Tilde key) and type in the following: AudioTestA(1.0); You should hear the "electronic drip" test sound Play with the volume setting, trying different values less than 1.0 Next type this into the console window: AudioTestB(1.0); Team LRN Koob You should hear the electronic drip test sound again, but this time seeming to come... function call refers to the profile, not the description datablock The three parameters that follow define a location in 3D coordinates in the game world The sound, when played, will seem to come from that location It's important to understand that when activating sounds in this manner, you must ensure that the sound file contains a monophonic sound, and not stereo Also, the is3D property in the datablock . use in your game. Installing Audacity To install Audacity, do the following: 1. Browse to your CD in the Audacity directory. 2. Locate the audacity-win-1_0_0.exe. the 3D coordinate values in the call to alxPlay() in the AudioTestB() function. Koob In the following chapter, and in later chapters, we will be using

Ngày đăng: 18/10/2013, 00:15

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