< Zurück | Inhalt | Weiter >

3.2 Your first Java 3D application

The SimpleTest example (figure 3.1) is intended to build upon the HelloUniverse example that comes with the Java 3D distribution. I’ve attempted to expand upon HelloUniverse by documenting the relationships between the various constructs used in the example and showcasing some of the features of Java 3D that enable you to

build fairly complex applications with very little code. This example is 280 lines (less than 100 without comments) and illustrates some fairly complex functionality:


image


Figure 3.1 The SimpleTest example. One hundred lines of Java code give you an animated scene, including a graphical textured background with directional lighting


Background geometry, in this case the scene is placed within a Sphere.

Textured geometry, an image is applied to the inside of the background Sphere to give the illusion of a distant skyline.

Lighting, a single directional light is created to provide depth cues through rendering.

Geometry, a second smaller Sphere is placed within the scene.

Appearance, the smaller Sphere has an Appearance and Material associated with it that interacts with the directional light to produce a shaded, colored effect.

Animation, a PositionInterpolator behavior is attached to the smaller Sphere to move it left and right using a complex time function (Alpha).


For instructions on running the examples that accompany the book please refer to appendix A.


To produce a comparable example using basic OpenGL would require many hundreds of lines of code. You can quickly see the benefits of a Java 3D’s higher−level of scene description—the scenegraph.

 

From SimpleTest.java