Java Reference
In-Depth Information
Figure 3. Code segment structure for setting up a scene with a single Shape3D node
1.
public class Testing extends Applet
2.
{
3.
. . .
4.
5.
public Testing()
6.
{
7.
}
8.
9.
public void init()
10.
{ . . . }
11.
12.
public void destroy()
13.
{ . . . }
14.
15.
public BranchGroup createSceneGraph()
16.
{
17.
BranchGroup objRoot = new BranchGroup();
18.
TransformGroup objTrans = new TransformGroup();
19.
objRoot.addChild( objTrans );
20.
objTrans.addChild( new createShape3D() );
21.
objRoot.compile();
22.
return objRoot;
23.
}
24.
25.
public static void main ( String[] args )
26.
{ . . . }
27.
28.
public class createShape3D extends Shape3D
29.
{
30.
public createShape3D()
31.
{
32.
this.setGeometry( createGeometry() );
33.
}
34.
35.
private Geometry createGeometry()
36.
{
37.
. . . return . . .;
38.
}
39.
}
40. }
line 17, objRoot is an instance of the branch group. Line 18 creates an object objTrans and
add it as a child of objRoot in the scene graph. In line 20, the constructor for the create-
Shape3D subclass is invoked and an instance of the Shape3D class is created and added to
the TransformGroup. Using the setGeometry method, line 32 specifies the geometry for the
created Shape3D object to that from a private createGeometry method. This private method
Search WWH ::




Custom Search