Skip to main content

Animation and rotation with a single TransformGroup

No replies
Hatta
Offline
Joined: 2011-10-18

Hello to everyone.
I'm studying the Java3D tutorial provided by Oracle and I just finished the first chapter.

Starting from the last example of the first chapter (the one that shows how to animate the cube rotated on the x and y axes), i don't understand why not create an animation on a TrasformGroup created on a rotation transformation.

Let me explain.
The proposed code and running using two TransformGroup objects: the first one to rotate the cube on the x and y axes, the second to apply the rotation. The code is as follows:

BranchGroup objRoot = new BranchGroup();

Transform3D rotate = new Transform3D();
Transform3D tempRotate = new Transform3D();

rotate.rotX(Math.PI/4.0d);
tempRotate.rotY(Math.PI/5.0d);
rotate.mul(tempRotate);

TransformGroup objRotate = new TransformGroup(rotate);
TransformGroup objSpin = new TransformGroup();

objSpin.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
objRoot.addChild(objRotate);
objRotate.addChild(objSpin);

objSpin.addChild(new ColorCube(0.4));

Alpha rotationAlpha = new Alpha(-1, 4000);
RotationInterpolator rotator =  new RotationInterpolator(rotationAlpha, objSpin);

BoundingSphere bounds = new BoundingSphere();
rotator.setSchedulingBounds(bounds);
objSpin.addChild(rotator);

Why can not I have the same effect using a single TransformGroup? I tested the following code:
BranchGroup objRoot = new BranchGroup();

Transform3D rotate = new Transform3D();
Transform3D tempRotate = new Transform3D();

rotate.rotX(Math.PI/4.0d);
tempRotate.rotY(Math.PI/5.0d);
rotate.mul(tempRotate);

TransformGroup objSpin = new TransformGroup(rotate);

objSpin.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
objRoot.addChild(objSpin);
objSpin.addChild(new ColorCube(0.4));


Alpha rotationAlpha = new Alpha(-1, 4000);

RotationInterpolator rotator =  new RotationInterpolator(rotationAlpha, objSpin);

BoundingSphere bounds = new BoundingSphere();
rotator.setSchedulingBounds(bounds);
objSpin.addChild(rotator);

The problem is that i only see the animation, but the cube remains in its original position without being rotated, though the object is created departing from TransformGroup object Transform3D.
I hope I was clear,
Thank you.