Skip to main content

Key Press Changes Between Wireframe and Fill

No replies
okelly4408
Offline
Joined: 2012-08-12
Points: 0

I attempted to write code that made it so that when a key was pressed a 3d shape would be shown in wire mesh and when another key was pressed it's color would be changed and it would be filled in. The problem is once the appearance is set for the 3d shape it is not updated whenever the key is pressed. So I changed it to rerender the 3d shape each time the button is pressed but the program crashes.... here is the important code:

public class appearance{
private static Color3f color;
public static Appearance appearance(Boolean wire){
Appearance app = new Appearance();
PolygonAttributes polatr = new PolygonAttributes();
//polatr.setPolygonMode(PolygonAttributes.POLYGON_FILL);
if(wire == true){
polatr.setPolygonMode(PolygonAttributes.POLYGON_LINE);
color = new Color3f(0f, .7f,0f);
System.out.println("wire");
}
if(wire == false){
polatr.setPolygonMode(PolygonAttributes.POLYGON_FILL);
color = new Color3f(.7f, .3f,.1f);
System.out.println("fill");

}
polatr.setCullFace(PolygonAttributes.CULL_NONE);
app.setPolygonAttributes(polatr);
Color3f black = new Color3f(0.0f, 0.0f, 0.0f);
Color3f specular = new Color3f(0.9f, 0.9f, 0.9f);
    Material mat = new Material (color, black, color, specular,25f);
    mat.setLightingEnable(true);
    app.setMaterial(mat);
    return app;
}
}
else if(keycode == wireKey)
    new Landscape(pointPass.pointsArray).setAppearance(appearance.appearance(true));

    else if(keycode == fillKey)
    new Landscape(pointPass.pointsArray).setAppearance(appearance.appearance(false));
public class Landscape extends Shape3D {
public Landscape( Point3f[] pointarray){

  
int vert = pointarray.length;
System.out.println(vert+"+");
GeometryInfo geoI = new GeometryInfo(GeometryInfo.QUAD_ARRAY);
geoI.setCoordinates(pointarray);
NormalGenerator normal = new NormalGenerator();
normal.setCreaseAngle( (float) Math.toRadians(150));
normal.generateNormals(geoI);
    Stripifier triangler = new Stripifier();
    triangler.stripify(geoI);
    setGeometry(geoI.getGeometryArray());
    setAppearance(appearance.appearance(true));

}
}