Rotating object inside actionPerformed()

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Rotating object inside actionPerformed()

bchinfosieeuw
I am rotating a cylinder like this:
TransformGroup cylinder4RotGroup = rotate(cylinder4TransGroup, new Alpha(-1, Alpha.INCREASING_ENABLE|Alpha.DECREASING_ENABLE, 0, 0, 1000, 0, 0, 1000, 0, 0));
       
TransformGroup rotate(Node node, Alpha alpha){
    TransformGroup xformGroup = new TransformGroup();
    xformGroup.setCapability(
                    TransformGroup.ALLOW_TRANSFORM_WRITE);
    Transform3D axisOfTransform = new Transform3D();
    RotationInterpolator interpolator = new RotationInterpolator(alpha, xformGroup, axisOfTransform, 0, 1);
    interpolator.setSchedulingBounds(new BoundingSphere(new Point3d(0.0,0.0,0.0),1.0));  
    Transform3D axisZ = new Transform3D();
    axisZ.rotZ(Math.PI/2);
    interpolator.setTransformAxis(axisZ);
    xformGroup.addChild(interpolator);
    xformGroup.addChild(node);
    return xformGroup;
}

However, I need more control over the rotation. Is it an idea to call the rotate method from actionPerformed()? I do not want to use the -1 option from the Alpha to rotate repeatedly. I do not get it working. Any ideas? Please be concrete by providing some example code. (Currently the rotate method is called from createSceneGraph(), which is only carried out once.)
Reply | Threaded
Open this post in threaded view
|

Re: Rotating object inside actionPerformed()

philjord
Hi,
Thanks for posting this question on the forum.

It looks like you are a very near to where you want to be.

A great set of java3d 1.6 examples can be found here (and on various other repos):
https://github.com/chrfra/Java3D-examples 

Depending on what you want there are 2 examples that might fit your requirements.

The examples relies on the java3d-utils project, which for 1.6 can be found next to the core project here:
https://github.com/hharrison/java3d-utils

The example class
org.jdesktop.j3d.examples.swing_interaction.SwingInteraction
is simply a button that rotates a TransformGroup by 10 degrees on each click (or click repeat)

and
org.jdesktop.j3d.examples.objload.ObjLoad
has an interesting model loaded then either runs an auto spin that looks almost exactly like your code, or uses the com.sun.j3d.utils.behaviors.vp.OrbitBehavior from java3d-utils to allow the model to rotate by mouse movement.

If you find the OrbitBehavior a bit to complex then a very similar utility that is just pure rotation can be seen in java3d-utils here:
com.sun.j3d.utils.behaviors.mouse.MouseRotate

Hope this helps, please feel free to ask more questions once you've got these two project into your workspace.

Reply | Threaded
Open this post in threaded view
|

Re: Rotating object inside actionPerformed()

bchinfosieeuw
Thanks, the first example of SwingInteraction is helpful for me. Next question: how to rotate cylinder4, while rotating a cylinder 5 around cylinder4? When I do this:

public void actionPerformed(ActionEvent e ) {
        myBehavior5.rotate();
        myBehavior4.rotate();
}

then the two behaviors cause the cylinders to spirale out of the universe. So should I implement two separate behavior classes? Or is there another solution? Thanks in advance.