Java Reference
In-Depth Information
scaleInterpolator
The ScaleInterpolator allows the apparent size of the object to be changed as time passes
by generating appropriate scale transforms in the local coordinate system.
In the example code segment and result in Figure 6, a bounding sphere on a live re-
gion and an associated alpha object are first specified before invoking ScaleInterpolator
to change the size of the trapezoidal object. The input parameter of 1.0f corresponds to
the maximum scale or size, while 0.2f sets the minimum scale or size for the object. An
appropriate Transform3D is then used to define the axis and the local coordinate system
under which ScaleInterpolator operates.
Figure 6. Code segment and result of DemoScaleInterpolator.java
25. System.out.println("1-Directional light");
26. System.out.println("2-Point light");
27. System.out.println("3-Spot light");
28. System.out.println("other-Ambient light");
30. try { String userInput = in.readLine(); light=Integer.parseInt(userInput); }
31. catch (IOException ioe) { System.out.println("IO error trying to read input!"); System.exit(1); }
32.
33.
// create light source at the origin
34.
lit = new AmbientLight(new Color3f( 0.5f, 0.5f, 0.5f));
35.
if (light==1){ lit = new DirectionalLight(new Color3f( 0.5f, 1.0f, 0.5f), new Vector3f( 0.2f,-0.5f,-1.0f));}
36.
if (light==2){ lit = new PointLight(new Color3f(1,1,1), new Point3f(0,0,0), new Point3f(1,1,0));}
37.
if (light==3){ lit = new SpotLight(new Color3f(1f,1f,1f), new Point3f(0.0f,0.0f,0.0f),
38.
new Point3f(1.0f,1.0f,0.0f), new Vector3f(0.0f,0.0f,1.0f), (float)(Math.PI/2.0f),0f);}
39.
lit.setInfluencingBounds(new BoundingSphere());
40.
41.
// make the light source move around the box
42.
Alpha alpha = new Alpha(-1,5000);
43.
Transform3D y = new Transform3D();
44.
float knots[] = {0.0f , 0.5f , 1.0f};
45.
Point3f pts[] = { new Point3f(-2f,0f, 2f), new Point3f( 2f,0f, 2f), new Point3f(-2f,0f, 2f)};
46.
PositionPathInterpolator posinterpolator = new PositionPathInterpolator(alpha,sphere1,y,knots,pts);
47.
RotationInterpolator rotinterpolator = new RotationInterpolator(alpha,sphere2);
48.
posinterpolator.setSchedulingBounds(new BoundingSphere());
49.
rotinterpolator.setSchedulingBounds(new BoundingSphere());
50.
51.
52.
53.
54.
55.
sphere1.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
56.
sphere2.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
57.