Java Reference
In-Depth Information
Figure 31. Code segment and result of Laser1.java
1.
TriangleFanArray laser = new TriangleFanArray(vertex,
2.
TriangleFanArray.COORDINATES|TriangleFanArray.COLOR_3, StripCount);
3.
4.
int vertex = 12; // change this parameter
5.
int[] StripCount = {vertex};
6.
7.
for (n =0, a=0,z=100; n < vertex;a = 2*Math.PI/(vertex) * ++n)
8.
{
9.
x = (float) (r * Math.cos(a))/ z;
10.
y = (float) (r * Math.sin(a))/ z;
11.
z = (float) Math.sqrt (x*x + y*y);
12.
laser.setCoordinate(n, new Point3f(x, y, z));
13.
laser.setColor(n, red);
14. }
Figure 32. Code segment and result of DiamondTriangleFan.java
1. int N=5; //number of vertex in each fan
2. int totalN = 2*(N+1); //total num. of vertex
3. float r = 0.4f; //radius of fan
4. Point3f coords [] = new Point3f[totalN];
5. int StripCount[] = {N+1,N+1};
6. float x,z; double a; int n;
7.
8. coords[0*(N+1)] = new Point3f(0.0f,0.8f,0.0f);
9. coords[1*(N+1)] = new Point3f(0.0f,-0.8f,0.0f);
10.
11. for (a=0,n=0; n<N;a=2.0*Math.PI/(N-1)*++n)
12. {
13.
Vertex 4
Vertex 3
Vertex 0
Vertex 1
Vertex 2
x=(float)(r*Math.cos(a));
14.
z=(float)(r*Math.sin(a));
15.
coords[0*(N+1)+N-n] = new Point3f(x,0.0f,z);
16.
coords[1*(N+1)+n+1] = new Point3f(x,0.0f,z);
17. }
18.
19. TriangleFanArray tfa = new TriangleFanArray(totalN,TriangleFanArray.
20. COORDINATES,StripCount);
21.
22. tfa.setCoordinates(0,coords);       Search WWH ::

Custom Search