Home Other API Tips Java3D How to define the surface normals

Java Network
 Java Forums Java Blog

Most Visited Tips
Top Rated Tips
Statistics
 Registered Users: 4118 Java SE Tips: 614 Java ME Tips: 202 Java EE Tips: 183 Other API Tips: 779 Java Applications: 298 Java Libraries: 209 Java Games: 16 Book Reviews:

 How to define the surface normals
User Rating: / 0
PoorBest

As known, normals are required for shaded visual objects. When creating visual objects using Geometry classes, use one of the setNormal() methods to specify per vertex normal vectors.

Through defining the surface normals of the geometry of box, this program illustrates how to define the surface normals for the Shape created by GeometryArray.

 ``` private Geometry createGeometry(){     int pNum=24;     // Define the geometry which need to define the normals     QuadArray quadArray=new QuadArray(pNum,        GeometryArray.COORDINATES|GeometryArray.NORMALS);     // Create a array of Vector3f to store the normal for per vertex     Vector3f[] normals=new Vector3f[pNum];          ...          int i=0;          for(i=0;i<4;i++){       normals[i]=new Vector3f(0.0f,0.0f,1.0f);     }     for(;i<8;i++){       normals[i]=new Vector3f(1.0f,0.0f,0.0f);       }     for(;i<12;i++){       normals[i]=new Vector3f(0.0f,0.0f,-1.0f);     }     for(;i<16;i++){       normals[i]=new Vector3f(-1.0f,0.0f,0.0f);     }     for(;i<20;i++){       normals[i]=new Vector3f(0.0f,1.0f,0.0f);     }     for(;i<24;i++){       normals[i]=new Vector3f(0.0f,-1.0f,0.0f);     }          quadArray.setCoordinates(0,points);     // Set the normals for this geometry     quadArray.setNormals(0,normals);          return quadArray; }```

### Related Tips

Page 1 of 0 ( 0 comments )

Name (required)

E-Mail (required)

Your email will not be displayed on the site - only to our administrator
Homepage(optional)

Comment Enable HTML code : Yes No