Java Reference
In-Depth Information
Figure 47. Constructor and result of
public Exhibit()
//end Exhibit constructor
method to create a geometry object for the glass case and append this to the list of geometry
components. Note that all appended objects should be equivalent in classes. That is, the
list must consist of only Geometry or Raster or Text3D objects.
Figures 48 and 49 show the code segments for the Artefact() and Glass_case() methods.
Created using IndexedTriangleFanArray, the artifact has 20 physical vertices and 72 ac-
cessing indices, and a few loops are used to set these to their appropriate values.
utIlIty class
Rather than using basic and rather primitive geometry classes, the creation of some common
objects can be easily achieved through geometry utility classes in Java 3D. These include
the creation of boxes, spheres, cylinders, and cones. Figure 50 demonstrates how these can
be done together with the results, including the use of lighting, which will be discussed in
detail in later chapters, for illumination.
The creation of the first object, a sphere, is carried out in the block of codes starting
from line five. Setting the translation of a Transform3D object, line six specifies the place-
ment of a visual object at (0.5, 0.5, -0.5). Line 11 creates a sphere of radius 0.3 units using
its constructor. Note that in addition to its radius, an optional appearance parameter on an
appearance defined earlier is also passed. This is to avoid the creation of a default black
sphere which will not be visible in a black background.
The next few blocks of codes for the building of a box, cone and cylinder are similar to
that for the creation of the sphere. Lines 39 to 41, however, add lighting to the universe by
attaching a created light object, which will be further discussed in subsequent chapters,
to the initial TransformGroup.
Search WWH ::

Custom Search