java left logo
java middle logo
java right logo
 

Home arrow Other API Tips arrow Java3D arrow How to use Back Face Culling
 
 
Main Menu
Home
Java Tutorials
Book Reviews
Java SE Tips
Java ME Tips
Java EE Tips
Other API Tips
Java Applications
Java Libraries
Java Games
Java Network
Java Forums
Java Blog




Most Visited Tips
Java SE Tips
Java ME Tips
Java EE Tips
Other API Tips
Java Applications
Java Libraries
Java Games
Book Reviews
Top Rated Tips
Java SE Tips
Java ME Tips
Java EE Tips
Other API Tips
Java Applications
Java Libraries
Java Games
Book Reviews


Statistics
Registered Users: 4091
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 use Back Face Culling E-mail
User Rating: / 8
PoorBest 

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

 
< Prev   Next >

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.


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



 
       
         
     
 
 
 
   
 
 
java bottom left
java bottom middle
java bottom right
RSS 0.91 FeedRSS 1.0 FeedRSS 2.0 FeedATOM FeedOPML Feed

Home - About Us - Privacy Policy
Copyright 2005 - 2008 www.java-tips.org
Java is a trademark of Sun Microsystems, Inc.