Three dimensional sound can add to the feeling of immersion in a virtual environment, but it generally isn't as important as lighting or 3D user interaction. As has been stated often in this book, spatial navigation in the real world is multisensory in nature. As with any spatial cue, lack of or improper use of aural cues will detract from the user's feeling of immersion.
Java 3D has a fairly sophisticated 3D Sound model that can be used to advantage in many situations. At present, the Java 3D Sound model is based on panning only. Panning is the gradual switching between speakers. When we develop our 3D shopping mall demonstration in Chapter 14, we will use the JMF Sound Player in conjunction with the Java 3D Sound classes.
In general, it is helpful to think of Sound nodes in terms of some of the ideas presented in the section on “Lighting.” Like lighting, sounds can be directional and can fall off over distance. For many of the same reasons that lighting can be challenging, sound too can be difficult to use. It is often difficult to notice the subtleties of sound effects.
The Java 3D sound package supports three basic types of sounds: 1) Background sounds that are present throughout the environment (much like an ambient light), 2) Point sounds that emanate in all directions and have an attenuation (much as a PointLight simulates light energy), and 3) Cone sounds that act like a SpotLight to provide a directional source of sound.
Two additional classes are useful in creating sounds. The SoundScape node class specifies the area of space in which a sound is active, much like Bounds are used in lighting the scene.
The second class used to create sounds is the AuralAttributes object. This object is used to control how the amplitude of the sound attenuates with respect to distance from the object (like the Fog and Light nodes). Other properties are contained in the AuralAttributes object including looping and playback properties.
Because the sound objects are Leaf nodes, they can be added the same way as any Leaf node.
You must remember to set the SchedulingBounds for any sound that is to be heard. Again, this is directly analogous to the situation for lighting.
Listing 11.14 demonstrates the use of Directional and Point Sound Nodes.