Java Reference
In-Depth Information
Figure 25. Code segment and result of Hourglass1.java
1.
int vertex = 5;
2.
int StripCount[] = new int [1];
3.
StripCount[0] = vertex;
4.
5.
TriangleStripArray Triangleshape = new TriangleStripArray(vertex,
6.
TriangleStripArray.COORDINATES|TriangleStripArray.COLOR_3, StripCount);
7.
8. Triangleshape.setCoordinate( 0, new Point3f(0.5f,-0.5f,0.0f));
9. Triangleshape.setCoordinate( 1, new Point3f(-0.5f,-0.5f,0.0f));
10. Triangleshape.setCoordinate( 2, new Point3f(0.0f,0.0f,0.0f));
11. Triangleshape.setCoordinate( 3, new Point3f(0.5f,0.5f,0.0f));
12. Triangleshape.setCoordinate( 4, new Point3f(-0.5f,0.5f,0.0f));
13.
14. Triangleshape.setColor( 0, red);
15. Triangleshape.setColor( 1, green);
16. Triangleshape.setColor( 2, red);
17. Triangleshape.setColor( 3, red);
18. Triangleshape.setColor( 4, green);
Point
5
Point
4
Point
Point
2
Point
1
Yet another approach to resolve this is to set PolygonAttributes to the geometry created.
This is illustrated in Figure 26 and will be discussed in detail in later chapters. Essentially,
appearance class has been used to set appropriate polyAttributes. Note that the cull face has
to be set to none to view the triangles under all rotation angles. Also, if POLYGON_LINE
is used, the wire frame appearance shown will result.
The construction of structures that cannot be easily carried out by a single strip of
triangles can sometimes be more conveniently done by using many strips. Figure 27 and
28 show an example where a diamond is constructed by having a few invocations of Tri-
angleStripArray. Note that apart from the first strip, the other strips are added onto the
existing geometry one after another. In programming, it may save time if it is possible to
Search WWH ::




Custom Search