Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Simple Java 3D - Unable to apply Transform3D to rotate object

Status
Not open for further replies.

TZRick

Programmer
Nov 10, 2002
11
US
Hello experts!

I have a project that has been quite frustrating to me. Please help me get the rotation work...

Below is a function that is called by clicking on a JButton. This code works:

private void zoom(boolean in) {
Transform3D zoom = world3d.zoom;
zoom.set(zoom.getScale()+(in ? -0.2 : 0.2));
world3d.zoomg.setTransform(zoom); // access member variable
}

However, the procedure doesn't work for rotation as follows:

private void rotateX(boolean cw) {
Transform3D rot = world3d.rotateX;
xrot = xrot + (cw ? 0.1 : -0.1);
rot.rotX (xrot);
world3d.tgRotateX.setTransform(rot); // access member variable
}

The constructor for the World3D class is as follows:

public World3D (Canvas3D canvas3d) {

mainShuttle = new Shuttle (); // returns BranchGroup with 3D object

Transform3D translate = new Transform3D ();
translate.set (new Vector3f (0.15f, 0.0f, 0.7f)); // Translate to fit on screen
TransformGroup tg = new TransformGroup (translate);

zoom.set (0.5);
zoomg = new TransformGroup (zoom); // Allow for dynamic zoom
zoomg.setCapability (TransformGroup.ALLOW_TRANSFORM_READ);
zoomg.setCapability (TransformGroup.ALLOW_TRANSFORM_WRITE);

tgRotateX = new TransformGroup (rotateX); // Allow for dynamic x-rotation
tgRotateX.setCapability (TransformGroup.ALLOW_TRANSFORM_READ);
tgRotateX.setCapability (TransformGroup.ALLOW_TRANSFORM_WRITE);

zoomg.addChild (mainShuttle.getBG ());
tg.addChild (zoomg);
BranchGroup mainScene = new BranchGroup ();
tgRotateX.addChild (tg);
mainScene.addChild (tgRotateX);
mainScene.compile ();

SimpleUniverse simpleU = new SimpleUniverse (canvas3d);

// This moves the ViewPlatform back a bit so the
// objects in the scene can be viewed.
simpleU.getViewingPlatform ().setNominalViewingTransform ();

simpleU.addBranchGraph (mainScene);
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top