Sagewire Logo

Using RotationInterpolator to rotate about multiple axis?

5 Message(s) by 2 Author(s) originally posted in 3d java


From: Richard Date:   Friday, November 03, 2006
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);


From: sanbikinoraion Date:   Saturday, November 04, 2006
I believe (and iirc there's a fuller answer earlier in this newsgroup
somewhere) that you make three transfrom3ds and use .rotX , .rotY and
.rotZ (one on each), and then do t3d1.mul(t3d2); t3d1.mul(t3d3); . So
make transform3ds for each rotational component, specifying the spin
rate, multiply them together, and then use that multiplied transform as
the transform for the rotationinterpolator.

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.

Cheers,

sanbikinoraion

wrote in message:
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);






From: Richard Date:   Saturday, November 04, 2006
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.



Pretty new to this TransformGroup stuff. Can you guide me to any
examples of nested transforms (especially with different rotations) ?

The idea is the same as "The Multi-Axis Spin-Test Inertia [186]
Facility (MASTIF) trainer" pictured at
http://history.nasa.gov/SP-45/ch10.htm [
http://history.nasa.gov/SP-45/p178i.jpg ]


From: Richard Date:   Saturday, November 04, 2006
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;
}
}


From: sanbikinoraion Date:   Sunday, November 05, 2006
Have you seen this site? I found it very useful when I was starting
out:

http://www.JAVA-tips.org/other-api-tips/JAVA3d/



Next Message: Graphics applet blinks on fast processors


Blogs related to Using RotationInterpolator to rotate about multiple axis?

Using RotationInterpolator to rotate about multiple axis?
Summary: Given a cube I would 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 ... Transform3D yAxis = new Transform3D; ...


Programming | Sports | Autos

copyright 2006
Valid XHTML 1.0 Transitional