|
How to define the surface normals |
|
|
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 )
You can share your information about this topic using the form below!
Please do not post your questions with this form! Thanks.