Chapter 1. Getting Acquainted With IRIS Performer

A complete sample application, perfly, as well as many short example programs are included with IRIS Performer. This chapter explains how to use these applications so you can get acquainted with some of the features of IRIS Performer. If you're already somewhat familiar with IRIS Performer or visual simulation in general, you might want to skip ahead to the overview in Chapter 2, “IRIS Performer Basics,” or jump directly to whatever chapter covers the specific topic you're interested in.

Source code for perfly is provided beneath /usr/share/Performer/src/sample/C in the perfly and common directories so that you can incorporate parts of these programs into your own applications. (A C++ version can be found under /usr/share/Performer/src/sample/C++).

Exploring the IRIS Performer Sample Scenes

The perfly application is a fairly basic visual simulation program that can load and store scene databases in any of a wide variety of common formats and display the resulting scenes. This section describes how to use perfly to look at several sample databases provided with IRIS Performer.

perfly provides a graphical user interface with which you can control many of the visual simulation features that are described in this guide, such as time-of-day selection, haze density, and so on. These options all default to reasonable values, so you don't need to learn about them before using perfly.

Installing the Software

Follow the instructions in the IRIS Performer Release Notes to install the software. This process places the appropriate libraries, header files, sample databases, reference pages, on-line books and demonstration programs on your system.

Figure 1-1. A Section of the New Jerusalem City Hall


Starting and Quitting perfly

To launch perfly, type

IRIS% perfly -d chamber.0.lsa


Note: Both OpenGL and IRIS GL versions of perfly are installed in /usr/sbin. The perfly command invokes the one more appropriate for your particular graphics hardware. To explicitly invoke the OpenGL or IRIS GL versions, run perfly_ogl or perfly_igl, respectively.

The perfly program allows several motion models; the –d on the command line tells the program to start in the Drive model, which provides an easy way to drive or walk through a scene while maintaining a fixed height above the ground.

When you want to quit perfly, either press the <Esc> key or click the “Quit” button on the control panel.

Look Around

Look around the scene using the mouse. First, place the cursor in the center of the simulation window. Now depress the middle mouse button and move the mouse to the left and to the right to turn in place; you'll continue to pivot until you place the cursor back in the center of the screen.

Don't despair if you inadvertently start moving around, lose sight of the building, or otherwise lose position or control. Just move the cursor into the control panel area and click the “Reset All” button on the control panel to get back to the original setup.

Approach the Building

To approach the City Hall model, turn until you're facing it (if you aren't already facing it) and then center the mouse in the screen. Depress the left mouse button briefly to start accelerating forward. When you release the button, you'll continue gliding forward at constant speed and can hold down the middle mouse button to steer.

Tap the middle mouse to stop in front of the building (if you actually entered the building, remember the “Reset All” button). Now accelerate backward by pressing the right button. When you're as far back as you want to go, hold down the left mouse button to gradually slow down, or tap the middle mouse button to stop immediately.

Now use the left mouse button again to start moving forward and drive slowly into the model. Notice that the walls closest to you are cut away at first so you can see inside; once you're completely inside the building, those walls reappear. Drive around and explore the building. Tap the middle mouse button to stop before you run into anything (but don't worry—at this point you'll bounce off of any walls you hit). If the walls get in your way, you can turn off collision detection with the button labeled “Collide” on the control panel, or press the c key on the keyboard.

More Controls

To see the underlying geometry used to create the model, click the “Style” button in the control panel, or press the w key on the keyboard. This changes the display to wireframe mode. In this mode you can more easily see how many polygons are used to represent an object. This information can be helpful when you're tuning a database, because it's important to know when the number of polygons becomes a limiting factor. To turn wireframe mode off, just click the “Style” button (or press w) again. The W key can be used to cycle through several different draw styles.

To close the entire control panel (and devote the entire screen to the model), click the “GUI Off” button at the upper right of the control panel, or just press the <F1> key. Press the <F1> key again to restore the control panel.

If you click the “Stats” button in the control panel, a transparent panel showing scene statistics appears overlaid on the screen. The buttons next to the “Stats” button allow you to choose one of the available statistical displays. Try moving around in the scene while watching how the statistics change. Note in particular that the number of triangles being considered for rendering changes drastically depending on where you look; this demonstrates IRIS Performer's use of culling to ignore objects that are completely outside the field of vision. For more information about culling, see Chapter 6, “Database Traversal.” For more detailed information on the statistics panels, see Chapter 12, “Statistics.”

Several other keys on the keyboard are active and can be used to control perfly even when the control panel isn't displayed. Pressing the “?” key will print a list of most key sequences to the shell window. For full details, the file /usr/share/Performer/src/sample/perfly/C/keybd.c contains a list of these key sequences and their effects. Remember that you can always use the <Esc> key to terminate perfly at any time.

The control panel's field-of-view slider can be used to select a wide angle view, up to 100 degrees.

As you travel through the building, try turning on the fog effect by clicking the Fog button. Experiment with the fog density and other controls. (Remember: If you've closed the control panel, the <F1> key will restore it.)

Flying

The Fly motion model provides an alternative to Drive. This model allows full motion in three dimensions (unlike the Drive model, which doesn't allow vertical motion). The mouse in the Fly model is used in much the same way to control motion, but when steering the vertical position of the mouse in the window controls your vertical tilt. You can select this mode by pressing the right mouse button on the button marked “Drive” and select “Fly” from the menu.

As when driving, the left button makes you go forward and the right button makes you go backward. As long as either button is pressed you'll continue to accelerate.

You turn holding the middle mouse button down and moving the cursor away from the center of the simulation window. Moving the cursor left or right causes left and right turns, respectively. Moving the cursor up or down causes the view direction to tilt up or down, respectively. The rate of turning and tilting is scaled by the distance of the cursor from the center of the simulation window; that is, no change of direction occurs when the cursor is at the center and full-speed rotation occurs at the edges of the window.

If you want to maintain a steady velocity rather than accelerating, hold down the middle mouse button to steer while using the left and right buttons to control the speed. To stop tap the middle mouse button.

Trackball

The trackball motion model provides a third option for controlling motion. You can select this mode by pressing the right mouse button on the button marked “Fly” and selecting “Trackball” from the menu.

In trackball mode, when you drag with the middle button the object rotates about its center as if it were attached to a large trackball that fills the screen. That is, dragging up and down causes rotation about the horizontal axis parallel to the screen and dragging left and right causes rotation about the vertical axis parallel to the screen.

By dragging with the left mouse, you can translate the object in the direction you drag, left, right, up or down. By dragging with the right mouse, you can translate the object in and out of the screen. In all cases, if you release the mouse button while dragging, the motion continues on its own.

Motion Using Paths

There are other approaches to traveling through a scene than the models described here. You can, for instance, build a specific path into the viewer, to prevent the user from straying outside your model. The path model is supported by a general path-following system in the libpfutil library. Many simulation applications require path support for such objects as: cars, trucks, and people (in driver-training software); waiting aircraft both on the ground and in the air (in flight simulation); and opposing forces in military trainers. Path support in libpfutil allows paths of varying speeds to be built from line segments and arcs with automatic fillet construction between segments for smooth transitions.

Instances

The bench objects in the City Hall scene were designed using the database concept known as instancing, in which a single geometric object such as a tree, house, car, or, in this case, bench, is used multiple times within a database at different locations and with different positions or scale factors. (In this case, the instances have been flattened to improve performance; each bench is now a separate object.) See “Instancing” in Chapter 5 for information on this topic.

Model Implementation and Database-Format Loaders

An important point about the implementation of this model is that the scene was created using a database modeler and is still in its original format. This demonstrates the data fusion capability of IRIS Performer: Databases need not be converted to a standard file format before being read in to an IRIS Performer application. Rather, unique file readers are constructed for each format to be used. IRIS Performer can thus work with data from multiple sources concurrently, using a common software interface, without needing intermediate translation or conversion steps.

Because these database importers operate at run time, they're able to supply executable functions that extend the regular IRIS Performer processing to whatever is required by various formats. This eliminates the least common denominator limitation, where database constructs that can't be represented in the common format must be either deleted or reconstructed. Such limitations are often encountered when all data must be converted to a fixed, shared file format. In the IRIS Performer paradigm, each importer can provide new functions to support the required features that aren't present in IRIS Performer—extending full native support for each desired database format.

To use the visual interface from perfly with your own databases, simply list your databases on the perfly command line. perfly examines the extension part of each filename to determine what format the file is in. File importers are provided as examples with IRIS Performer (and supported by perfly) for many file formats, including 3DStudio “3ds”, Designer's Workbench “dwb”, Medit Productions “medit”, MultiGen OpenFlight “flt”, SGI BIN and SGO (“bin” and “sgo”, respectively), Wavefront “obj”, Open Inventor™ “iv”, the STL stereolithography format, and so on.

If your files are in one or more of these formats, the perfly program can be used to view them. If you have files in other formats, you will need to add an importer for those formats to perfly before you can use it to view your files. This is not a difficult or daunting task, but it does require an understanding of most of IRIS Performer to be done properly. It should not be undertaken until you have completed reading this book. When you want to develop such file-importing routines, refer to Chapter 9, “Importing Databases,” for instructions and a discussion of the provided sample file-importers.

Exploring Code

Being a complete application makes perfly a good demonstration for IRIS Performer in action, but it is also a large rather complex piece of code. A better place to start exploring programming with IRIS Performer is the sample code provided in /usr/share/Performer/src/sample/pguide. Under this directory, you can find examples for programming many of the features available in each of the libraries that make up IRIS Performer, using either C or C++.

Going Beyond Visual Simulation

In perfly, you can view an object or scene from any angle and location, from points either inside or outside of the scene. This is the part of the visual simulation development task that IRIS Performer helps you create—the visual part, what you see when you look out the window.

But there's more to a simulation of reality than just visuals. Purely visual simulations of travel have much the same feel whether the simulation is of a boat, a car, a plane, or a magic carpet. In such simulations there's no nonvisual sensory input at all; the user simply watches scenery move past. IRIS Performer leaves the nonvisual aspects—the feel of the simulation—up to you. You determine the vehicle dynamics and construct an apparatus or create code to mimic its behavior. You develop a method for manifesting the physical sensation of how your simulation relates to its environment and responds to stimuli.

When you integrate physical aspects of a simulator with the real-time visuals created with IRIS Performer, the result can be a complete sensory environment, both visual and physical—creating a convincing simulation of reality. Since IRIS Performer puts the tools for rapid development of real-time visuals into your hands, you can spend more time developing the physical part of the simulation.

Another aspect of IRIS Performer that lies below the surface of the demos is its ability to accelerate graphics to top-rated performance levels on Silicon Graphics hardware. This means that IRIS Performer puts a virtual Silicon Graphics hardware and software expert at your fingertips, providing all the tools you need to custom-tune your graphics application for maximum performance on your system.

Deciding Where to Start

Now that you've seen what IRIS Performer can do, it's up to you to decide how to proceed. You can read through the remainder of this programming guide, beginning with the overview in Chapter 2, or you can skip directly to a chapter that describes a specific task you need to perform.