have a look at this example. you will see how you can change the axis of Rotation interpolator at line 50
import java.awt.*;
import com.sun.j3d.utils.applet.*;
import Behavior;
import ;
import ;
import com.sun.j3d.utils.universe.*;
import javax.media.j3d.*;
import javax.swing.JApplet;
import javax.vecmath.*;
public class TestPlatform2 extends JApplet {
private SimpleUniverse u;
private BranchGroup scene;
private Canvas3D c;
private Behavior orbitBehavior;
private Transform3D randomShapeTransform;
private TransformGroup randomShapeTransformGroup, mainTG, shapeTG;
private Shape3D shape3D;
private RotationInterpolator rotation;
private Alpha alphaRotation;
private BranchGroup mainBG;
private Transform3D cameraTransform;
private BranchGroup shapeBG;
public BranchGroup createSceneGraph () {
mainBG = new BranchGroup ();
shapeBG = new BranchGroup ();
mainTG = new TransformGroup ();
mainTG.setCapability ();
mainTG.addChild (shapeBG);
mainBG.addChild (mainTG);
shapeTG = new TransformGroup ();
shapeBG.addChild (shapeTG);
BoundingSphere bounds = new BoundingSphere (new Point3d (0.0, 0.0, 0.0), 1000.0);
Background back = new Background (new Color3f (0.8f, 0.8f, 1f));
back.setApplicationBounds (bounds);
mainBG.addChild (back);
alphaRotation = new Alpha (-1, 10000);
rotation = new RotationInterpolator (alphaRotation, mainTG);
// Axis of Transformation !!!
Transform3D Transform = new Transform3D ();
Transform.rotZ(-Math.PI/2.0);
rotation.setTransformAxis(new Transform3D (Transform));
rotation.setSchedulingBounds (bounds);
mainBG.addChild (rotation);
createRandomShapes (30);
DirectionalLight light1 = new DirectionalLight (new Color3f (1f, 1f, 1f), new Vector3f (1f, 1f, 0.5f));
light1.setInfluencingBounds (bounds);
mainBG.addChild (light1);
mainBG.compile ();
return mainBG;
}
public void init () {
setLayout (new BorderLayout ());
GraphicsConfiguration config = ();
c = new Canvas3D (config);
add ("Center", c);
u = new SimpleUniverse (c);
cameraTransform = new Transform3D ();
cameraTransform.setTranslation (new Vector3d (0.0, 0.0, 15.0));
u.getViewingPlatform ().getViewPlatformTransform ().setTransform (cameraTransform);
scene = createSceneGraph ();
orbitBehavior = new Behavior (c, Behavior.REVERSE_ALL);
(new BoundingSphere ());
u.getViewingPlatform ().setViewPlatformBehavior (orbitBehavior);
u.addBranchGraph (scene);
setSize (600,400);
setVisible (true);
}
private void createRandomShapes (int count) {
for (int i = 0; i < count; i++) {
randomShapeTransform = new Transform3D ();
(new Vector3d (createRandomSign () * Math.random () * 2.5f, createRandomSign () * Math.random () * 2.5f, createRandomSign () * Math.random () * 5.5f));
randomShapeTransformGroup = new TransformGroup (randomShapeTransform);
shape3D = new Shape3D ();
shape3D.setGeometry (new Sphere ((float) Math.random () * 0.3f, Primitive.GENERATE_NRMALS, 24, null).getShape (Sphere.BDY).getGeometry ());
shape3D.setAppearance (buildAppearance (true));
(shape3D);
shapeTG.addChild (randomShapeTransformGroup);
}
}
private int createRandomSign () {
return (Math.random () 0.5 ? 1 : -1);
}
private Appearance buildAppearance (boolean wireFrame) {
Appearance appear = new Appearance ();
Color3f matAmbient = new Color3f (0.0f, 0.0f, 0.0f), matEmissive = new Color3f ((float) Math.random (), (float) Math.random (), (float) Math.random ()), matDiffuse = new Color3f (1f, 1f, 1f), matSpecular = new Color3f (
1f, 1f, 1f);
float matShininess = 81f;
Material material2 = new Material (matAmbient, matEmissive, matDiffuse, matSpecular, matShininess);
PolygonAttributes pa = new PolygonAttributes ();
if (!wireFrame)
pa.setPolygonMode (PolygonAttributes.PLYGN_FILL);
else
pa.setPolygonMode (PolygonAttributes.PLYGN_LINE);
pa.setCullFace (PolygonAttributes.CULL_NNE);
appear.setMaterial (material2);
appear.setPolygonAttributes (pa);
return appear;
}
public void destroy () {
u.cleanup ();
}
public static void main (String[] args) {
new MainFrame (new TestPlatform (), 800, 600);
}
}
[Message sent by forum member 'BrainC' (BrainC)]
#128725
To unsubscribe, e-mail: interest-unsubscribe (AT) java3d (DOT) dev.java.net
For additional commands, e-mail: interest-help (AT) java3d (DOT) dev.java.net