appendix A

Example code

A.1 List of examples

A.2 Installation notes

A.3 Instructions for running the examples

A.1 List of examples

Table A.1 lists the example code that appears throughout this book. The code itself may be downloaded from http://www.manning.com/selman.

Table A.1
Title Description Chapter
AlphaTest Plots an interactive graph of the parameterized Java 3D Alpha function. 12
AppearanceTest Allows the elements of the Appearance attribute to be interatively modified. 14, 11, 9
AvatarTest Creates a simple virtual world that implements simple collision detection and includes sound. Demonstrates Java 3D platform geometry support using the SimpleUniverse class. 11, 6
BehaviorTest Defines six custom behaviors: rotation interpolator, stretch (springs and masses geometry modification), size reporting, exploding geometry, frames-per-second display, bounds display. 13
BillboardTest Displays geometry and attaches a simple billboard behavior. 11, 8
BillboardTest Displays geometry and attaches a simple billboard behavior. 11, 8
BoundsTest Creates a variety of geometry and displays the Java 3D bounds information. 5
common A shared package of reusable code for Java 3D.  
CompileTest Creates a simple scene and compiles the scene.  
CuboidTest Demonstrates the geometry differences between the Box and Cuboid objects. A3
CustomAlphaTest Plots an interactive graph of a custom alpha function that loads its values from an external text file. 12
HiResCoordTest Creates a scene using the Java 3D Locale to define different coordinates within the virtual world. 6
ImmediateTest Performs Immediate Mode rendering using Java 3D. 4
InterpolatorTest Uses a SwitchInterpolator to switch between a range of Java 3D interpolators. 12, 5
JavaMet Sample Swing based Java 3D application (applet). Run run.bat to start the applet. Configuration parameters are read from JavaMet_App.properties. 7
KeyNavigateTest A DOOM style immersive 3D world that demonstrates simple collision detection and an external map file. 11
LightTest An interactive preview application that allows you to edit all the light parameters. 10
LoaderTest Demonstrates using the Java 3D Object (obj) file loader. 15
MixedTest Uses Java 3D mixed mode: rendering in immediate and retained mode. 4
MouseNavigateTest Demonstrates direct object manipulation using the mouse. 11
MultiView Creates multiple Canvas3D based views into the same 3D world.  
MyJava3D Implements simple wire frame 3D rendering using a homegrown graphics API. 2
NodesTest Creates a scene that illustrates using many of the Java 3D Nodes. 5
PickCollisionTest Creates a 3D box with spheres bouncing around within it. Uses picking-based collision detection to respond to sphere-sphere and sphere-box collisions. 16
PlatformTest Uses multiple views and platform geometry support (on SimpleUniverse). Each viewer can interact with the scene and see the other. 6
PointTest Demonstrates rendering points in many styles. 9
RasterTest Draws an image into the 3D scene as a Raster and reads the depth components of the 3D scene into a Raster. 8
ScenegraphTest Builds a simple hierarchical model of the upper torso and uses RotationInterpolators to crudely animate the model. 4
SimpleTest Builds a simple scene using the SimpleUniverse class and demonstrates lighting, textures, and background geometry. 3
SplineInterpolatorTest the city of Boston rendered from satellite images. Uses 3D spatial sound to associate sounds with helicopters in the scene. 12, 11
SwingTest Displays a Swing- and Java 3D-based application that illustrates using JMenus with Java 3D. Allows you to capture screen shots and saves them as JPEG files. 5, 17
SwitchTest Illustrates using the Switch node to interactively select geometry for display. 5
TexCoordTest Demonstrates Java 3D texture mapping, including OBJECT_LINEAR, EYE_LINEAR and SPHERE_MAP modes. 14
Text2DTest Uses Text2D nodes to render labels into the 3D scene.  
Text3DTest Uses Text3D nodes to render 3D labels into the 3D scene. 8
TextureTest Reads texture coordinates and a texture image from disc and generates texture mapped geometry for rendering. 14
TextureTransformTest Uses texture transformation to interactively rotate a texture around a Box using the mouse. 14
TriangulatorTest Uses the Java 3D triangulation and normal generation utilities to triangulate geometry (including a hole). 15
VrmlPickingTest Loads a VRML file using the VRML loader and illustrates using the Java 3D picking utilities to identify components of the model that are clicked with the mouse. 15, 16

A.2 Installation notes

Before running any of the included examples, please complete the general Java 3D installation instructions described in chapter 3. Verify that Sun’s Java 3D demo applications run from the command line. For example:

C:\jdk1.3\demo\java3d\HelloUniverse>java HelloUniverse

should pop up a window with a rotating cube.

Next, download and unzip the examples for the book to a suitable directory.

Copy the utility JAR files:

to the JDK extensions directory. For example, copy them to

C:\JDK1.3\JRE\LIB\EXT

This will make the classes within the JAR files available to Java applications without referencing them in the CLASSPATH, making it easier to run the examples.

A.3 Instructions for running the examples

Set the SELMAN_CLASSPATH environment variable to the installation location:

set SELMAN_CLASSPATH=“C:\dselman\classes”

Set the location of your JDK installation:

set JAVA_HOME=c:\jdk1.3

Running the examples should now be as easy as switching to the relevant directory and typing run.bat.

Most of the examples have been formatted to run comfortably on fairly modest hardware without hardware acceleration. If you have a fast machine and hardware acceleration, you should be able to increase the size of the rendering window by simply resizing it.

In addition to the rendering window, many of the examples use J3dTree to pop up a scenegraph introspection window that will show you the structure of the Java 3D scenegraph being rendered.

A.3.1 Running applet examples

Some of the examples are available as both an application and an applet. Applets use the JDK 1.2 plug-in and include an HTML file in their example directory. If you have followed the installation instructions in chapter 2, the examples should run by just double-clicking the HTML file to open it in your Netscape or Internet Explorer web browser.

Note that the dselman.jar file containing all the class files for the book should be copied into the JRE\LIB\EXT directory.

The following examples are available in applet and application form:

[previous]  |  [main]  |  [next]