Java Reference
In-Depth Information
Figure 2. Face normal and vertex normal
Vertex normal
Face normal 2
Face normal 1
Figure 3. Setting the normal manually and automatically
1.
private Geometry plane() {
2.
TriangleFanArray tfa;
3.
int strip[] = {4};
4.
Point3f co[] = new Point3f[4];
5.
Color3f col[] = new Color3f[4];
6.
Vector3f v[] = new Vector3f[4];
7.
for (int i = 0; i<=3; i++) {
8.
col[i] = blue;
v[i] = new Vector3f( 0f, 1f, 0f); } // all normal of z plane are the same
9.
co[0]=new Point3f(0f,0f,0f);
10.
co[1]=new Point3f(x,y,z);
11.
co[2]=new Point3f(x,y1,z);
12.
co[3]=new Point3f(x,y1,z1);
13.
tfa=new TriangleFanArray(4,TriangleFanArray.COORDINATES|TriangleFanArray.COLOR_3|
14.
TriangleFanArray. NORMALS,strip);
15.
tfa.setCoordinates(0,co);
16.
tfa.setColors(0,col);
17.
tfa.setNormals(0,v);
18.
return tfa; }
1.
private Geometry getnormal(Geometry g) {
2.
GeometryInfo gi = new GeometryInfo(g);
3.
NormalGenerator ng = new NormalGenerator();
4.
ng.generateNormals(gi);
5.
return gi.getGeometryArray(); }
Search WWH ::




Custom Search