Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:

3D Game Programming All In One (2004)

.pdf
Скачиваний:
139
Добавлен:
17.08.2013
Размер:
17.91 Mб
Скачать

588 Chapter 21 Creating the Game Mission

Table 21.1 File Menu Commands

Command

Description

New Mission

Creates a new empty mission with a default terrain and sky.

Open Mission

Opens an existing mission for editing.

Save Mission

Saves changes to the current mission to disk.

Save Mission As

Saves the current mission under a new name.

Import Terraform Data

Imports terraform rules from an existing terrain file.

Import Texture Data

Imports terrain texture rules from an existing terrain file.

Export Terraform Bitmap

(Only active from the Terrain Terraform Editor.) Exports the current

 

terraform map to a bitmap.

As is standard with windowed applications these days, there is an Edit menu that houses a variety of object and item editing commands. As you can see in Table 21.2, in addition to the ubiquitous Cut, Copy, and Paste functions, there are also commands that are used to access various settings for the editors.

Table 21.2 Edit Menu

Menu Item

Description

Undo

Undoes the last action in terrain or world editing. Not all actions can be

 

undone.

Redo

Redoes the last undone action.

Cut

Cuts the selected objects in the World Editor from the mission to the

 

Clipboard.

Copy

Copies the selected objects in the World Editor to the Clipboard.

Paste

Pastes the current clipboard contents into the mission.

Select All

Selects all mission objects in the World Editor.

Select None

Clears the current selection in the World and Terrain Editors.

Relight Scene

Recomputes the mission's static lighting and applies it.

World Editor Settings

Accesses the settings dialog box for the World Editor.

Terrain Editor Settings

Accesses the settings dialog box for the Terrain Editor.

Use the Camera menu, as described in Table 21.3, to change camera modes and adjust the camera fly mode speed.

The World menu is available by default and contains functions related to the World Editor—its capabilities will be described in the "World Editor" section, which is coming up next.

The Window menu is pretty straightforward, so it doesn't require a table to describe its functions. It is used to invoke each of the available subeditors.

Team LRN

Torque Mission Editor

589

Table 21.3 Camera Menu

Menu Item

Description

Drop Camera At Player

Moves the camera object to the location of the player, and sets the mode

 

to camera movement mode (camera fly mode).

Drop Player At Camera

Moves the player object to the location of the movable camera, and sets

 

the mode to player movement mode (player mode).

Toggle Camera

Toggles between player and camera fly movement modes. Your view will

 

also switch to the location of either the player or the camera, depending

 

on the mode.

Slowest to Fastest

Adjusts the movement speed of the camera fly mode.

World Editor

The World Editor provides a view of the 3D world. Objects in this view, like structures, interiors, shapes, and markers, can be manipulated with either the mouse or the keyboard.

There are three frames in the view: the World Editor Tree, the World Editor Inspector, and the World Editor Creator.

World Editor Tree

The World Editor Tree view is displayed in the frame in the upper-right screen corner in both the World Editor Inspector and the World Editor Creator. This tree displays the hierarchy of the mission data file. Objects selected in the Tree view will also be selected in the main view. Objects in the Tree view can be organized into groups.

There is a special group selection called the Instant Group, which is displayed with gray highlighting in the Tree view. This is the group in the Tree view where newly created or pasted objects are placed. Objects created from the World Editor Creator are also placed in the Instant Group. To change the current Instant Group, Alt+Click on a group in the Tree view.

World Editor Inspector

The World Editor Inspector lets you examine and specify properties of mission objects. When you select an object in Inspector mode, that object's properties are displayed in the frame at the lower right of the screen. After editing an object's properties, click the Apply button to commit those properties to the object. Dynamic properties can be assigned to objects with the Dynamic Fields Add button. Dynamic fields can be accessed via the scripting language and are normally used to add game-specific properties to objects.

World Editor Creator

The World Editor Creator displays an extra Tree view frame in the lower-right corner of the screen. This view contains all objects that can be created in a mission. Selecting an

Team LRN

590Chapter 21 Creating the Game Mission

object from this list creates a new instance of it and drops the new object at the center of the screen (by default) or as specified by the selected Drop at command in the World menu, which is shown in Table 21.4.

Table 21.4 World Menu

Menu Item

Description

Lock Selection

Locks the current selection so that it cannot be manipulated from the World

 

Editor view.

Unlock Selection

Unlocks a locked selection.

Hide Selection

Hides the current selection to help reduce visual clutter.

Show Selection

Unhides hidden objects in the selection.

Delete Selection

Deletes the currently selected objects.

Camera To Selection

Moves the camera to the selected objects.

Reset Transforms

Resets the rotation and scale on the selected objects.

Drop Selection

Drops the selected objects into the mission according to the drop rule (see Drop

 

Selection menu items that follow). If the object is already placed, it is picked up

 

and dropped again.

 

Drop at Origin: Drops newly created objects at the origin.

 

Drop at Camera: Drops newly created objects at the camera's location.

 

Drop at Camera w/ Rot: Drops newly created objects at the camera's

 

location with the camera's current orientation.

 

Drop below Camera: Drops newly created objects below the camera's

 

current location.

 

Drop at Screen Center: Drops newly created objects where the view

 

direction hits an object.

 

Drop at Centroid: Drops newly created objects at the center of the

 

selection.

 

Drop to Ground: Drops newly created objects to the terrain ground level

 

at their current location.

You can use both the mouse and the keyboard for editing, as shown in Table 21.5.

Gizmos are the visual representation of each object's three axes. When you select an object, and if you have gizmos enabled in the World Editor Settings dialog box, then they will appear centered on that object's local origin.

If gizmos are enabled, they can be clicked and dragged (as described in Table 21.6) in order to modify the object to which they are attached.

Terrain Editor

We use the Terrain Editor to manually modify the terrain height map and square properties by using a mouse-operated brush. The brush is a selection of terrain points or squares

Team LRN

Torque Mission Editor

591

Table 21.5 Mouse and Keyboard Operations

Operation

Description

Clicking on an unselected object

Deselects all currently selected objects and selects the clicked

 

object.

Clicking in empty space

Click-drags a box around objects, and selects all objects in the

 

box.

Shift-clicking on an object

Toggles selection of the clicked object.

Mouse dragging a selected object

Moves the selected objects, either on a horizontal plane or

 

sticking to the terrain, depending on the setting of the Planar

 

Movement check box in the World Editor Settings dialog box.

Control-clicking and drag Alt-clicking and drag Alt-Ctrl-clicking and drag

Moves the selected objects vertically.

Rotates the selected objects about the vertical axis. Scales the selected object by a face on the bounding box.

 

Table 21.6

Gizmo Operations

 

Operation

Description

 

 

 

Click-drag gizmo axis

Moves selection along the selected axis.

 

Alt-click-drag gizmo axis

Rotates selection on the selected axis.

 

Alt-Ctrl-click-drag gizmo axis

Scales along the selected axis.

 

 

 

 

 

centered around the mouse cursor. Table 21.7 describes the functions available in the Brush menu.

Table 21.7 Terrain Editor: Brush Menu

Menu Item

Description

Box Brush

Uses a square-shaped brush.

Circle Brush

Uses a circular brush.

Soft Brush

Sets the brush so that its influence on the terrain diminishes toward the

 

edges of the brush. The brush square colors vary from red, where the

 

influence is greatest, to green, where the influence is least. The Terrain

 

Editor Settings dialog box Filter view has controls that adjust the falloff.

Hard Brush

Sets the brush so that the effect on the terrain is the same across the

 

surface of the brush. All squares in the brush are the same red color.

Size 1 1 to 25 25

Sets the brush sizes.

When we use the Terrain Editor, we modify the terrain as if we were piling dirt onto it or shoveling holes into the ground. Table 21.8 shows the operations available in the Terrain Editor via the Action menu.

Team LRN

592 Chapter 21 Creating the Game Mission

Table 21.8 Terrain Editor: Action Menu

Menu Item

Description

Select

Moves the brush in a painting motion to select grid points.

Adjust Selection

Raises or lowers the terrain at the currently selected grid points as a group by

 

dragging the mouse up or down.

Add Dirt

Adds terrain "dirt" to the terrain at the center of the brush, raising the affected

 

terrain area.

Excavate

Removes dirt from the center of the brush.

Adjust Height

Raises or lowers the area marked by the brush by dragging the mouse.

Flatten

Sets the area marked by the brush to a flat plane height.

Smooth

Smoothes the area marked by the brush—peaks are lowered and troughs are

 

raised.

Set Height

Sets the area marked by the brush to a constant height—the height is set using

 

the Terrain Editor Settings.

Set Empty

Makes a hole in the terrain in the squares covered by the brush.

Clear Empty

Fills in any holes in the squares covered by the brush.

Paint Material

Paints the current terrain texture material with the brush.

Terrain Terraform Editor

The Terrain Terraform Editor uses mathematical algorithms to generate terrain heightfields (height maps). Heightfield operations are arranged in a stack, which is an ordered list of operations. Operations in the stack depend on the results of previous operations to produce new heightfields. The results of the final operation on the stack can be applied to the terrain using the Apply button.

There are two Terrain Terraform Editor frames. The top frame displays information about the currently selected operation, and the bottom frame shows the current operation stack. Between them is a pull-down menu for the creation of new operations. The first operation in the stack is always the General operation, which can't be deleted.

Table 21.9 shows the operations available.

Terrain Texture Editor

The Terrain Texture Editor uses mathematical techniques to place terrain textures based on the heightfield at the bottom of the terraformer heightfield stack. The editor has three main interface elements on the right side of the screen. From top to bottom they are the operation Inspector frame, the Material list, and the Placement Operation list.

Terrain materials are textures that are added using the Add Material button. This will look for any texture (.png or .jpg) in a subdirectory of any directory named "terrains" (in this book, this also applies to a directory name maps). Once a material is added to the terrain,

Team LRN

Torque Mission Editor

593

Table 21.9 Terraform Operations

Operation

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

Jumbles the effects of another operation on the stack.

Smoothing

Smoothes the effects of another operation on the stack.

Smooth Water

Smoothes water.

Smooth Ridges/Valleys

Smoothes an existing operation on edge boundaries.

Filter

Applies a filter to an existing operation based on a curve.

Thermal Erosion

Applies an erosion effect to an existing operation using a thermal erosion

 

algorithm.

Hydraulic Erosion

Applies an erosion effect to an existing operation using a hydraulic erosion

 

algorithm.

Blend

Blends two existing operations according to a scale factor and a

 

mathematical operator.

Terrain File

Loads an existing terrain file onto the stack.

the user can select one of several placement operations that govern where that material will be placed on the terrain. They are shown in Table 21.10.

Table 21.10 Terrain Texture Editor Placement Operations

Operation Description

Place by Fractal

Place by Height Place by Slope Place by Water Level

Places the terrain texture randomly across the terrain based on a Brownian motion fractal operation.

Places the texture based on an elevation filter. Places the texture based on a slope filter.

Places the texture based on the water level parameter in the Terraform Editor.

Click the Apply button to commit the current texture operation list to the terrain file.

Mission Area Editor

The Mission Area Editor defines regions in the game that are used to constrain player travel. If we use mission areas in a game, we normally give warnings or disqualifications if a player leaves a mission area. Of course, you can probably find other uses for such a feature.

Team LRN

594Chapter 21 Creating the Game Mission

The Mission Area Editor displays an overhead height-map view of the current mission map in the upper-right corner of the screen. There are markers for mission objects, a box for the mission area, and a pair of lines denoting the current field of view. Clicking anywhere on the display will move the current view object (either camera or player) to that location in the mission.

To edit the mission area, select the Edit Area check box. This will display eight resizing knobs on the mission area box that can be dragged with the mouse.

Clicking the Center button will cause the terrain file data to be repositioned and centered at 0,0 in the center of the mission area box.

To mirror the terrain, click the Mirror button. This will put the Mission Area Editor in mirror mode. The Left and Right Arrow buttons adjust the mirror plane angle to one of eight different angles (two axis aligned, two 45-degree splits). Click the Apply button to commit the terrain mirroring across the mirror plane. Mirroring a mission area is a useful way to quickly create terrain for team-based games where each side would begin with identical terrain. This would stop either side from having a terrain advantage. You create the terrain for one side, and then simply mirror it for the other side.

Building the World

Let's get to work building the game world, and let's start with items 27 and 28 from our requirements list. I've chosen the fire and the waterfall to start with here because we haven't really looked at particles much yet, and with particles we get to touch on various topics we've covered in this chapter, like easing into using the Mission Editor, the World Editor Creator, and the World Editor Inspector. And besides that, particles are cool.

Particles

Remember the raindrops in Chapter 18? Those were particles. Particles are basically sin- gle-faced polygons that are generated in bulk by a game engine to simulate a variety of somewhat related real-world phenomena, such as rain, smoke, wispy fog, splashing and spraying water or mud, fire, and flames. Particles can be used to simulate any sort of constantly changing fluidor gaslike entity. Even a swarm of mosquitoes can be generated using particles.

What I'll do in this section is show you how to use the Torque particle system to make a campfire and a waterfall.

Particles are made of three parts:

Particle. The actual things we see.

Particle Emitter. The thing that causes the particles to come into existence.

Particle Emitter Node. The object that the emitter is attached to.

Team LRN

Building the World

595

If you attach the word data to the end of each, and remove the spaces, you'll have the formal names of the datablocks that define those terms of the particle system:

ParticleData

ParticleEmitterData

ParticleEmitterNodeData

Particles can live in the game world in one of two ways: as freestanding particles or as attached particles. Freestanding particles are defined using all three of the datablocks just mentioned, while attached particles only require defining the ParticleData and the ParticleEmitterData. The nodes aren't needed, because we are attaching the particle to some other object that supports particles. The object classes that support particles are players, weapons, projectiles, and all vehicle types. As noted already, Rain is a specialized object that has a built-in particle capability.

So in the case of freestanding particle emitters, one more definition of interest is required for placing emitters in the world:

ParticleEmitterNode

We'll look at freestanding particle emitters a bit more, shortly.

Campfire

To make a campfire, we'll need two particle definitions: one for the flames and one for the smoke. The particle types used will be freestanding, so we will need to define all three particle datablocks for both the smoke and the flames.

First, copy the image file C:\3DGPAi1\RESOURCES\CH21\flame.png to C:\koob\control\ data\particles.

Next, create the file C:\koob\control\server\misc\particles.cs and add the following code to it:

datablock ParticleData(Campfire)

{

textureName

= "~/data/particles/flame";

dragCoefficient

= 0.0;

gravityCoefficient

= -0.35;

inheritedVelFactor

= 0.00;

lifetimeMS

= 580;

lifetimeVarianceMS

= 150;

useInvAlpha = false;

 

spinRandomMin = -15.0; spinRandomMax = 15.0;

Team LRN

596

Chapter 21

Creating the Game Mission

 

colors[0]

= "0.8 0.6 0.0 0.1";

 

colors[1]

= "0.8 0.65 0.0 0.1";

 

colors[2]

= "0.0 0.0 0.0 0.0";

 

sizes[0]

= 1.0;

 

sizes[1]

= 2.0;

 

sizes[2]

= 4.0;

 

times[0]

= 0.1;

 

times[1]

= 0.4;

 

times[2]

= 1.0;

 

};

 

datablock ParticleEmitterData(CampfireEmitter)

{

ejectionPeriodMS = 15; periodVarianceMS = 5;

ejectionVelocity = 0.35; velocityVariance = 0.20;

thetaMin

=

0.0;

thetaMax

=

60.0;

particles = "Campfire" TAB "Campfire";

};

datablock ParticleEmitterNodeData(CampfireEmitterNode)

{

timeMultiple = 1;

};

Now open C:\koob\control\server\server.cs, locate the function OnServerCreated, and add the following line to the end of the function, before the closing brace ("}"):

exec("./misc/particles.cs");

Now, open your mission file (C:\koob\control\data\maps\koobA.mis or whatever your mission file is called, as long as it is the same as the one used for Chapter 6 and uses the same terrain) and add the following before the closing brace of the file:

new ParticleEmitterNode() {

position = "13.2665 -2.0218 196.6";

rotation = "1 0 0 0";

Team LRN

Building the World

597

scale = "1 1 1";

dataBlock = "CampfireEmitterNode";

emitter = "CampfireEmitter";

velocity = "1";

};

Okay, save your files, and then launch Koob. When your player spawns in, turn to the right—you should see a little fire burning in the gully there, as shown in Figure 21.1.

The flame is the glowing object to the left of the crosshair in the picture. Now let's add the smoke. We'll do it slightly differently. We begin by defining the particle and emitter as before, but then we'll place it in an easier way

using the World Editor.

Figure 21.1 Campfire.

Open up the particles.cs file you created earlier, and add the following:

datablock ParticleData(CampfireSmoke)

{

textureName

= "~/data/particles/smoke";

dragCoefficient

= 0.0;

gravityCoefficient

= -0.15;

inheritedVelFactor

= 0.00;

lifetimeMS

= 4000;

lifetimeVarianceMS

= 500;

useInvAlpha = false; spinRandomMin = -30.0; spinRandomMax = 30.0;

colors[0]

= "0.5 0.5 0.5 0.1";

colors[1]

= "0.6 0.6 0.6 0.1";

colors[2]

= "0.6 0.6 0.6 0.0";

sizes[0]

= 0.5;

sizes[1]

= 0.75;

sizes[2]

= 1.5;

times[0]

= 0.0;

times[1]

= 0.5;

times[2]

= 1.0;

};

Team LRN