Java Reference
In-Depth Information
Since a star with 5 lines is to be created, the number of vertices is 10 and this is speci-
fied in line 9 when LineArray is invoked. The variable r gives the distance from the origin
to every vertex. Note also that, with i <= 4, the index of coor[i+2] in line 24 may exceed
its maximum bound. To ensure that this does not happen, a modulus or % operator is
included in the code.
Note that the vertices must be provided in the form of pairs as Java 3D will render a
straight line, one pixel in thickness, between two vertices.
Quadarray
Using QuadArray, 3D objects constructed by using quadrilaterals can be rendered by
shape appearance attributes. Note: A quadrilateral must be planar and convex or results
are undefined. In the case where vertexCount is less than 4 or is not a multiple of 4, an il-
legal argument exception will occur. Each quadrilateral will have a solid white by default,
and will be drawn based on the coordinates of four vertices which defines the four sides
of the quadrilateral.
Figures 10 to 13 show the code segment and result from using QuadArray in an example
to build a house shaped object. Note that lines 86 to 90 set the appearance, which will be
discussed in subsequent chapters, appropriately so that the outline of the object can be seen.
Also, the house is built by specifying 12 vertices and then using appropriate combinations
of these to construct several quadrilaterals that give the various faces of the object.
Figure 10. First code segment of House_Quad_Array.java
1.
import javax.media.j3d.*;
2.
import javax.vecmath.*;
3.
4. public class House extends Shape3D
5. {
6. public House()
7. {
8. this.setGeometry(Draw_House());
9. this.setAppearance(App());
10. } //end of constructor
Search WWH ::




Custom Search