Java Reference
In-Depth Information
Figure 2. Code segment and result of DemoPositionPathInterpolator.java
1.
public BranchGroup createSceneGraph()
2.
{
3.
BranchGroup objRoot = createBranchScene();
4.
Transform3D t3d = new Transform3D();
5.
t3d.rotY(Math.PI/4d);
6.
TransformGroup objRotate = new TransformGroup(t3d);
7.
TransformGroup objPositionPath = new TransformGroup();
8.
objRoot.addChild(objRotate);
9.
objRotate.addChild(objPositionPath);
10.
objPositionPath.addChild(new Axis().getBG());
11.
objPositionPath.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
12.
Point3f[] points = new Point3f[19];
13.
for (int i=0;i<18;i++) {
14.
float x = (float) 0.5*(float)Math.sin((float)Math.PI*2*i/17);
15.
float y = (float) 0.5*(float)Math.cos((float)Math.PI*2*i/17);
16.
points[i] = new Point3f(x,y,0);
17.
}
18.
Points[18] = new Point3f(0f,0.5f,0f);
19.
float[] knots = new float[19];
20.
for (int i=1;i<18;i++) knots[i] = 1.0f*i/17f;
21.
knots[0] = 0f;
22.
knots[18] = 1.0f;
23.
Alpha posAlpha = new Alpha (-1, 5000);
24.
t3d.rotY(-Math.PI/4d);
25.
PositionPathInterpolator path =
26.
new PositionPathInterpolator (posAlpha, objPositionPath, t3d, knots, points);
27.
BoundingSphere bounds = new BoundingSphere();
28.
path.setSchedulingBounds(bounds);
29.
objPositionPath.addChild(path);
30.
objRoot.compile();
31.
return objRoot;
32. }
Search WWH ::




Custom Search