views:

184

answers:

1

I have a scene inside of a TransformGroup that allows the mouse to zoom/rotate/pan.

I need to set the camera position back far enough that I can see the entire scene, which I do with the following code:

    // Position the position from which the user is viewing the scene
    ViewingPlatform viewPlatform = universe.getViewingPlatform();
    TransformGroup viewTransform = viewPlatform.getViewPlatformTransform();
    Transform3D t3d = new Transform3D();
    viewTransform.getTransform(t3d);
    t3d.lookAt(new Point3d(0,0,50), new Point3d(0,0,0), new Vector3d(0,1,0));
    t3d.invert();
    viewTransform.setTransform(t3d);

Executing the above code works in that I can manipulate the scene with the mouse. However, if I swap out this line:

t3d.lookAt(new Point3d(0,0,50), new Point3d(0,0,0), new Vector3d(0,1,0));

with:

// Change value from 50 to 90 to push the camera back further
t3d.lookAt(new Point3d(0,0,90), new Point3d(0,0,0), new Vector3d(0,1,0));

I lose the ability to manipulate the screen with the mouse.

How can I maintain the capability to transform with the mouse while pushing the camera back further so that I can view the entire screen?

Much thanks in advance!

+1  A: 
    GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration();
    Canvas3D canvas3d = new Canvas3D(config);

    // Manually create the viewing platform so that we can customize it
    ViewingPlatform viewingPlatform = new ViewingPlatform();

    // **** This is the part I was missing: Activation radius
    viewingPlatform.getViewPlatform().setActivationRadius(300f);

    // Set the view position back far enough so that we can see things
    TransformGroup viewTransform = viewingPlatform.getViewPlatformTransform();
    Transform3D t3d = new Transform3D();
    // Note: Now the large value works
    t3d.lookAt(new Point3d(0,0,150), new Point3d(0,0,0), new Vector3d(0,1,0));
    t3d.invert();
    viewTransform.setTransform(t3d);

    // Set back clip distance so things don't disappear 
    Viewer viewer = new Viewer(canvas3d);
    View view = viewer.getView();
    view.setBackClipDistance(300);

    SimpleUniverse universe = new SimpleUniverse(viewingPlatform, viewer);
Cuga