Java Reference
In-Depth Information
Figure 3. Code segment and result of DemoRotationInterpolator.java
1.
public BranchGroup createSceneGraph()
2.
{
3.
BranchGroup objRoot = createBranchScene();
4.
5.
BoundingSphere bound = new BoundingSphere();
6.
Alpha alpha = new Alpha(-1, Alpha.INCREASING_ENABLE|Alpha.DECREASING_ENABLE, 0, 0,
7.
4000, 2000,1000, 4000, 2000, 1000);
8.
9.
TransformGroup objRotate = new TransformGroup();
10.
objRotate.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
11.
objRotate.addChild(new Quad());
12.
13.
RotationInterpolator rotateInterpol = new RotationInterpolator(alpha, objRotate);
14.
rotateInterpol.setSchedulingBounds(bound);
15.
16.
TransformGroup objTilt = new TransformGroup();
17.
Transform3D tiltX = new Transform3D();
18.
tiltX.rotX(Math.PI/5.0d);
19.
objTilt.setTransform(tiltX);
20.
21.
objRoot.addChild(objTilt);
22.
objTilt.addChild(objRotate);
23.
objRotate.addChild(rotateInterpol);
24.
25.
objRoot.compile();
26.
27.
return objRoot;
28. }
y = ay sin(b)
z = az sin(b)
As an example, to rotate by 180 degree about the y-axis, where ax = 0, ay = 1 and
az = 0, the quaternion will be given by q = [ 0 1 0 0 ], and a declaration given by new
Quat4f(0f,1f,0f,0f ) will have to be invoked in Java3D. Note that the quaternion q = [ 0 0 0
1 ] corresponds to maintaining the original position with no rotation.
With the possibility to change the axis of rotation, RotationPathInterpolator allows for
a complex sequence of rotations to be stringed together. This is illustrated in the example
code segment and result of Figure 4. Note that the rotation depends on the local coordinate
system as defined by the Transform3D object, and the size of the knots and quats arrays
must be the same.
Search WWH ::




Custom Search