java left logo
java middle logo
java right logo
 

Home arrow Other API Tips arrow Java3D arrow How to change the polygon mode in Java3D
 
 
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: 4100
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 change the polygon mode in Java3D E-mail
User Rating: / 14
PoorBest 

PolygonAttributes governs how polygon primitives are rendered in three ways: how the polygon is rasterized, if it is culled, and whether a special depth offset is applied. By default, a polygon is filled, but setPolygonMode() can change the polygon rasterization mode so that the polygon is drawn as wire frame(lines) or only as the points at the vertices.

This program shows how to change the polygon mode by PolygonAttributes.It will draw a Sphere in the virtual world and change the polygon mode of it according to the option.


Image

public class PolygonModeExample extends JFrame {
  // Define a member of PolygonAttributes
  private PolygonAttributes pa=new PolygonAttributes();
  
  public PolygonModeExample() {
    // Define a control panel for changing the polygon mode of pa
    JPanel panel=new JPanel();
    panel.add(new JLabel("Select the polygon mode:"));
    JRadioButton fillModeBtn=new JRadioButton("Fill");
    fillModeBtn.setSelected(true);
    fillModeBtn.addActionListener(new ActionListener(){
      public void actionPerformed(ActionEvent e) {
        pa.setPolygonMode(PolygonAttributes.POLYGON_FILL);
      }
    });
    JRadioButton lineModeBtn=new JRadioButton("Line");
    lineModeBtn.addActionListener(new ActionListener(){
      public void actionPerformed(ActionEvent e) {
        pa.setPolygonMode(PolygonAttributes.POLYGON_LINE);
      }
    });
    JRadioButton pointModeBtn=new JRadioButton("Point");
    pointModeBtn.addActionListener(new ActionListener(){
      public void actionPerformed(ActionEvent e) {
        pa.setPolygonMode(PolygonAttributes.POLYGON_POINT);
      }
    });
    ButtonGroup bg=new ButtonGroup();
    bg.add(fillModeBtn);
    bg.add(lineModeBtn);
    bg.add(pointModeBtn);
    panel.add(fillModeBtn);
    panel.add(lineModeBtn);
    panel.add(pointModeBtn);
    getContentPane().add(panel,BorderLayout.SOUTH);  
  }

  public BranchGroup createSceneGraph() {
    BranchGroup objRoot = new BranchGroup();
    
    ...
    
    Sphere sphere=new Sphere(0.5f);
    
    // Get the appearance of the sphere object
    Appearance appear=sphere.getAppearance();
    pa.setCapability(PolygonAttributes.ALLOW_MODE_WRITE);
    appear.setPolygonAttributes(pa);
    
    objRoot.addChild(sphere);
    
    return objRoot;
  }
  
  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.