|
Polygons have two faces. For many visual objects, only one face of the polygons
need be rendered. To reduce the computational power required to render the
polygonal surfaces, the renderer can cull the unneeded faces.
The culling behavior is defined on a per visual object basis in the PolygonAttribute
component of Appearance. The front face of an object is the face for which the
vertices are defined in counter-clockwise order.
This program creates a box which one face is open and rotates it about the
y-axis. As the box rotates, the inside face of it seemed to disappear
because of Face Culling.
public class CullingBoxApp extends JFrame {
/**
* Define a Box
*/
public class MyBox extends Shape3D {
public MyBox() {
this.setGeometry(createGeometry());
this.setAppearance(createAppearance());
}
Geometry createGeometry() {
Point3f[] coords={
new Point3f(-0.2f,0.2f,-0.2f),
new Point3f(-0.2f,-0.2f,-0.2f),
new Point3f(0.2f,-0.2f,-0.2f),
new Point3f(0.2f,0.2f,-0.2f),
new Point3f(-0.2f,0.2f,0.2f),
new Point3f(-0.2f,-0.2f,0.2f),
new Point3f(0.2f,-0.2f,0.2f),
new Point3f(0.2f,0.2f,0.2f)
};
int[] indices={
7,3,0,4,
0,3,2,1,
3,7,6,2,
4,0,1,5,
5,1,2,6
};
IndexedQuadArray quadArray=new IndexedQuadArray(coords.length,
IndexedQuadArray.COORDINATES,indices.length);
quadArray.setCoordinates(0,coords);
quadArray.setCoordinateIndices(0,indices);
return quadArray;
}
/**
* Create appearance for the Box
*/
Appearance createAppearance() {
Appearance appear = new Appearance();
PolygonAttributes pa = new PolygonAttributes();
//polyAttrib.setCullFace(PolygonAttributes.CULL_NONE);
appear.setPolygonAttributes(pa);
return appear;
}
}
public BranchGroup createSceneGraph() {
...
Shape3D myBox = new MyBox();
objSpin.addChild(myBox);
...
}
public CullingBoxApp() {
...
}
public static void main(String[] args) {
...
}
}
|
Related Tips
|
You can share your information about this topic using the form below!
Please do not post your questions with this form! Thanks.