Skip to main content

Adding rotation Interpolator

No replies
michelle123
Offline
Joined: 2006-05-07

Hello All,
Here is the code snippet i am using in my framework.

if (hasDataChanged(rotateIn)) {
rotate = rotateIn.get();
if (rotate == true) {

objRoot.detach();
objRoot.removeAllChildren();
world.deactivate();

System.out.println("rotate is true + object removed");

BranchGroup objRoot1 = new BranchGroup();
List objectList1 = objectsIn.get();
synchronized(Camera3D.class) {
for(BranchGroup object1 : objectList1) {
if(object1 == null)
continue;
if(!object1.getCapability(BranchGroup.ALLOW_DETACH)) {
object1.setCapability(BranchGroup.ALLOW_DETACH);
object1.setCapability(Group.ALLOW_CHILDREN_READ);
object1.setCapability(Group.ALLOW_CHILDREN_WRITE);
object1.setCapability(Group.ALLOW_CHILDREN_EXTEND);
}

Transform3D r1 = new Transform3D();
Transform3D r2 = new Transform3D();
r1.rotX(Math.PI/4.0d); r2.rotY(Math.PI/1.0d);
r1.mul(r2);
TransformGroup objRotated = new TransformGroup(r1);
objRotated.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
objRotated.setCapability( TransformGroup.ALLOW_TRANSFORM_READ );
// create a 4x4 transformation matrix
Transform3D yAxis = new Transform3D( );

// create an Alpha interpolator to automatically generate
// modifications to the rotation component of the transformation matrix
Alpha rotationAlpha = new Alpha( -1, Alpha.INCREASING_ENABLE,
0, 0,
4000, 0, 0,
0, 0, 0 );

// create a RotationInterpolator behavior to effect the TransformGroup
RotationInterpolator rotator = new RotationInterpolator( rotationAlpha, objRotated, yAxis, 0.0f, (float) Math.PI*2.0f );

BoundingSphere bounds = new BoundingSphere(new Point3d(5.0, 5.0, 5.0), 1000.0);

// set the scheduling bounds on the behavior
rotator.setSchedulingBounds( bounds );
rotator.setEnable(true);
objRotated.addChild(object1);
objRotated.addChild(rotator);
objRoot1.addChild(objRotated);
world.addChild(objRoot1);
world.activate1();

World contains virtual universe and locale. When I add this method, the object does appear but it is static and interpolator effect does not kick in.

Any suggestions????