Simple Java 3D - Unable to apply Transform3D to rotate object
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Taarik_Rahaman
Posted On:   Tuesday, January 25, 2005 04:01 PM

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);    More>>

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);
}
   <<Less
About | Sitemap | Contact