Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / Java 3D / November 2006

Tip: Looking for answers? Try searching our database.

Using RotationInterpolator to rotate about multiple axis?

Thread view: 
Richard - 03 Nov 2006 21:17 GMT
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
about its z-axis once every 5 seconds.

Don't 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);
sanbikinoraion - 04 Nov 2006 11:22 GMT
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

> 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
[quoted text clipped - 18 lines]
>        
>     objRoot.addChild(yRotator);
Richard - 04 Nov 2006 22:49 GMT
...
> 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 ]
Richard - 05 Nov 2006 01:23 GMT
> 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;
  }
}
sanbikinoraion - 05 Nov 2006 11:29 GMT
Have you seen this site? I found it very useful when I was starting
out:

http://www.java-tips.org/other-api-tips/java3d/


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.