Given a cube I'd like to
spin it in
space by rotating it about its
y-axis once every 4 seconds, about its x-axis once every 3 seconds and
about its z-axis once every 5 seconds.
Do not know how to proceed from following
code which rotates it about
y-axis
objTrans.addChild(new ColorCube(0.4));
Transform3D yAxis = new Transform3D();
Alpha yAlpha = new Alpha(-1, 4000);
RotationInterpolator yRotator =
new RotationInterpolator(yAlpha, objTrans, yAxis,
0.0f, (float) Math.PI*2.0f);
BoundingSphere bounds =
new BoundingSphere(new Point3d(0.0,0.0,0.0), 100.0);
yRotator.setSchedulingBounds(bounds);
objRoot.addChild(yRotator);
wrote in message:
The other option is to make three nested transformgroups, each one of
which is responsible for its own axis of rotation and has its own
rotationinterpolator.
I persevered at
bit and came up with this:
/*
* SceneGraph1.JAVA
*/
import com.sun.j3d.utils.geometry.ColorCube;
import JAVAx.media.j3d.Alpha;
import JAVAx.media.j3d.Background;
import JAVAx.media.j3d.BoundingSphere;
import JAVAx.media.j3d.BranchGroup;
import JAVAx.media.j3d.RotationInterpolator;
import JAVAx.media.j3d.Transform3D;
import JAVAx.media.j3d.TransformGroup;
import JAVAx.vecmath.Color3f;
import JAVAx.vecmath.Point3d;
public
class SceneGraph1 extends BranchGroup
{
private BoundingSphere boundingSphere;
public SceneGraph1 ()
{
super();
TransformGroup xGimbal = new TransformGroup();
TransformGroup yGimbal = new TransformGroup();
TransformGroup zGimbal = new TransformGroup();
xGimbal.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
yGimbal.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
zGimbal.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
addChild(xGimbal);
xGimbal.addChild(yGimbal);
yGimbal.addChild(zGimbal);
ColorCube cube = new ColorCube(0.4);
zGimbal.addChild(cube);
Transform3D xAxis = new Transform3D();
Transform3D yAxis = new Transform3D();
Transform3D zAxis = new Transform3D();
xAxis.rotX(Math.PI/2.05);
yAxis.rotY(Math.PI/1.25);
zAxis.rotZ(Math.PI/1.43);
Alpha xRotationAlpha = new Alpha(-1,
Alpha.INCREASING_ENABLE|Alpha.DECREASING_ENABLE, 0, 90,2500,200,
0,1460,200, 0);
Alpha yRotationAlpha = new Alpha(-1,
Alpha.INCREASING_ENABLE|Alpha.DECREASING_ENABLE,
0,210,2120,100,125,1425,150, 90);
Alpha zRotationAlpha = new Alpha(-1,
Alpha.INCREASING_ENABLE|Alpha.DECREASING_ENABLE,
0,320,2800,150,100,1900,640,120);
RotationInterpolator xRotator = new
RotationInterpolator(xRotationAlpha, xGimbal, xAxis, 0f, (float)
Math.PI*2.0f);
RotationInterpolator yRotator = new
RotationInterpolator(yRotationAlpha, yGimbal, yAxis, 0f, (float)
Math.PI*2.0f);
RotationInterpolator zRotator = new
RotationInterpolator(zRotationAlpha, zGimbal, zAxis, 0f, (float)
Math.PI*2.0f);
boundingSphere = new BoundingSphere(new Point3d(0.0,0.0,0.0),
100.0);
xRotator.setSchedulingBounds(boundingSphere);
yRotator.setSchedulingBounds(boundingSphere);
zRotator.setSchedulingBounds(boundingSphere);
xGimbal.addChild(xRotator);
yGimbal.addChild(yRotator);
zGimbal.addChild(zRotator);
// Set
background color
Color3f bgColor = new Color3f(0.5f,0.5f,0.5f);
Background bgNode = new Background(bgColor);
bgNode.setApplicationBounds(boundingSphere);
addChild(bgNode);
// Have JAVA 3D perform optimizations on this scene graph.
compile();
}
public BoundingSphere getBoundingSphere ()
{
return boundingSphere;
}
}