Hi
I have a problem with nultiple ViewPlatform.
I wish to see a cube in tree different form (front, left and rigth views).
I rotate the TransformGroup that contain the ViewPlatform object. but it
does not works.
The code is below.
Help me.
Haroldo
################################
import java.awt.*;
import java.awt.event.*;
import javax.media.j3d.*;
import javax.vecmath.*;
import com.sun.j3d.utils.geometry.*;
import com.sun.j3d.utils.image.TextureLoader;
import com.sun.j3d.utils.universe.*;
public class MultViews extends Frame {
BoundingSphere bounds = new BoundingSphere(new Point3d(0.0,0.0,0.0),
100.0);
public BranchGroup createSceneGraph() {
// Create the root of the branch graph
BranchGroup objRoot = new BranchGroup();
// Create the transform group node and initialize it to the
// identity. Enable the TRANSFORM_WRITE capability so that
// our behavior code can modify it at runtime. Add it to the
// root of the subgraph.
TransformGroup objTrans = new TransformGroup();
objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
objRoot.addChild(objTrans);
Transform3D t = new Transform3D();
t.set(0.5);
TransformGroup objTrans2 = new TransformGroup(t);
objTrans2.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
objTrans.addChild(objTrans2);
Transform3D yAxis1 = new Transform3D();
yAxis1.rotZ(Math.PI);
Alpha tickTockAlpha = new Alpha(-1, Alpha.DECREASING_ENABLE |
Alpha.INCREASING_ENABLE, 0, 0, 10000, 0, 0, 0, 0, 0);
RotationInterpolator transInterpolator = new
RotationInterpolator(tickTockAlpha, objTrans, yAxis1, (float) Math.PI*2.0f,
(float) 0.0f);
transInterpolator.setSchedulingBounds(bounds);
objTrans2.addChild(transInterpolator);
// Create a simple shape leaf node, add it to the scene graph.
objTrans2.addChild(new ColorCube(0.4));
// Have Java 3D perform optimizations on this scene graph.
objRoot.compile();
return objRoot;
}
BranchGroup createViewGraph(SimpleUniverse u, Canvas3D c3d, int num) {
BranchGroup viewRoot = new BranchGroup();
TransformGroup offTg = new TransformGroup();
offTg.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
viewRoot.addChild(offTg);
TransformGroup offTg2 = new TransformGroup();
offTg2.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
offTg.addChild(offTg2);
// use same view distance as main view
Viewer viewer = u.getViewer();
double viewDistance = viewer.getView().getFieldOfView();
// Calculate the distance from the to the imageplate.
viewDistance = 1.0/Math.tan(viewDistance/2.0);
Transform3D offset = new Transform3D();
if (num == 0) { // VIEWPOINT 2 : LEFT VIEW
// Vector3d vet0 = new Vector3d(0.0, 0.0, viewDistance);
// offset.set(vet0);
offset.rotX(Math.PI);
offTg.setTransform(offset);
}
else { // VIEWPOINT 3 : RIGHT VIEW
offset.rotX(-Math.PI);
offTg.setTransform(offset);
}
PhysicalBody physicalBody = new PhysicalBody();
PhysicalEnvironment physicalEnvironment = new PhysicalEnvironment();
ViewPlatform viewPlatform = new ViewPlatform();
offTg2.addChild(viewPlatform);
View view = new View();
view.addCanvas3D(c3d);
view.setPhysicalBody(physicalBody);
view.setPhysicalEnvironment(physicalEnvironment);
view.attachViewPlatform(viewPlatform);
return viewRoot;
}
public static void main(String args[]) {
MultViews mv = new MultViews();
mv.setLayout(new GridLayout(2, 2, 10, 10));
GraphicsConfiguration config =
SimpleUniverse.getPreferredConfiguration();
Canvas3D suCanvas = new Canvas3D(config);
Canvas3D viewCanvas = new Canvas3D(config);
Canvas3D view2Canvas = new Canvas3D(config);
// Handle the close event
mv.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent winEvent)
{
System.exit(0);
}
});
SimpleUniverse u = new SimpleUniverse(suCanvas);
BranchGroup objRoot = mv.createSceneGraph();
BranchGroup viewRoot = mv.createViewGraph(u, viewCanvas, 0);
BranchGroup view2Root = mv.createViewGraph(u, view2Canvas, 1);
u.getViewingPlatform().setNominalViewingTransform();
u.addBranchGraph(objRoot);
u.addBranchGraph(viewRoot);
u.addBranchGraph(view2Root);
mv.add(suCanvas);
mv.add(view2Canvas);
mv.add(viewCanvas);
mv.setTitle("Java3D");
mv.setSize(456, 456);
mv.show();
}
}
________________________________________________________________________
Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com
===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA3D-INTEREST". For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".