Java Reference
In-Depth Information
Figure 7. Additional code segment PointAttributesExample2.java and result
25.
26.
public BranchGroup createSceneGraph() {
27.
BranchGroup objRoot = new BranchGroup();
28.
// add more point here with different coordinates and point width
29.
objRoot.addChild(new aPoint(0.3f, 0.4f, 0.0f, 4f));
30.
objRoot.addChild(new aPoint(0.4f, -0.3f, 0.0f, 8f));
31.
objRoot.addChild(new aPoint(-0.2f, 0.6f, 0.0f, 20f));
32.
33.
//add more code here
34.
Appearance sphereApp = new Appearance();
35.
PolygonAttributes polygonAtt = new PolygonAttributes();
36.
polygonAtt.setPolygonMode(PolygonAttributes.POLYGON_LINE);
37.
sphereApp.setPolygonAttributes(polygonAtt);
38.
objRoot.addChild(new Sphere(0.4f, sphereApp));
39.
//end adding new code
40.
41.
objRoot.compile();
42.
return objRoot;
43. }
Figure 8. First segment of LineAttributesExample1.java
1.
public class aLine extends Shape3D {
2.
3. public aLine(float x1, float y1, float x2, float y2, float width, int pattern, boolean antialias) {
4.
this.setGeometry(createLine(x1, y1, x2, y2));
5.
this.setAppearance(createLineApp(width, pattern, antialias));
6. }
7.
8. private Geometry createLine(float x1, float y1, float x2, float y2) {
9.
LineArray line = new LineArray(2, GeometryArray.COORDINATES);
10.
line.setCoordinate(0, new Point3f(x1, y1, 0.0f));
11.
line.setCoordinate(1, new Point3f(x2, y2, 0.0f));
12.
return line;
13. }
14.
15. private Appearance createLineApp(float width, int pattern, boolean antialias) {
16.
Appearance app = new Appearance();
17.
// create a LineAttributes
18.
// and LineWidth = width, LinePattern = pattern, antialiasing = antialias
19.
LineAttributes lineAtt = new LineAttributes(width, pattern, antialias);
20.
app.setLineAttributes(lineAtt);
21.
return app;
22. }
23.
24. }
Search WWH ::




Custom Search