|
How to change the polygon mode in Java3D |
|
|
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.
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
|
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.