Java Reference
In-Depth Information
Figure 22. Code segment and result of Tetrahedral1.java
1.
Tetrahedral1.setCoordinate(0, new Point3f(0.60f,0.0f, 0.60f));
2.
Tetrahedral1.setCoordinate(1, new Point3f( 0.0f, 0.0f, 0.0f));
3.
Tetrahedral1.setCoordinate(2, new Point3f( 0.0f, 0.60f, 0.0f));
4.
Tetrahedral1.setCoordinate(3, new Point3f( 0.60f,0.0f, 0.60f));
5.
Tetrahedral1.setCoordinate(4, new Point3f(-0.60f,0.0f, 0.60f));
6.
Tetrahedral1.setCoordinate(5, new Point3f( 0.0f, 0.60f, 0.0f));
7.
Tetrahedral1.setCoordinate(6, new Point3f( -0.60f, 0.0f, 0.60f));
8.
Tetrahedral1.setCoordinate(7, new Point3f( 0.0f, 0.0f, 0.0f));
Figure 22 shows another example for creating a Tetrahedral. To render the structure
most efficiently using LineStripArray, one side of the object has unavoidably had to be
drawn twice. In practice, such overlaps should be avoided as much as possible to save
rendering time.
Having discussed some simple examples to illustrate important concepts, we will now
present two slightly more complicated applications discuss using LineStripArray. The first
application is illustrated in Figure 23, where lines have been used to build a DNA type of
structure with two helixes jointed at various positions.
Note that to cater for the possibility where the user changes the number of vertices
dynamically, IndexedLineStripArray is not suitable for this application and LineStripAr-
ray is used instead. As can be seen from the code segment, the visual object can be built
relatively easily by first writing down a suitable equation for the structure. One only needs
to express the shape in its parametric form and set its corresponding coordinate.
Lastly, Figure 24 presents the code segment and result for creating a simple 3D maze
structure using recursive programming techniques. Note that the variable m and dz give
the separation between two layers and consecutive points. The construction of a maze with,
say, six layers is obtained from a recursive call by using the same method to construct a
maze with five layers, which in turn is obtained from a recursive call to build a maze with
four layers, and so on.
trianglestriparray
As illustrated in Figure 17, the use of TriangleStripArray will result in an object making up
of a series of triangles formed from the vertices provided. Figure 25 gives a simple example
where an hourglass shape is created based on five points or vertices.
Search WWH ::




Custom Search