Search code examples
javaopenglgraphicsjava-3d

How to set capabilities of a universe in Java 3d?


How can I set the bounds on a SimpleUniverse instance created with a canvas3d object?

I tried the code below, but I get either a "Capability not set exception" if I try to set the bounds and a "Restricted access exception" if I try to set the capability to write bounds.

Here's my code:

GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration();
Canvas3D canvas3d = new Canvas3D(config);
SimpleUniverse universe = new SimpleUniverse(canvas3d);
ViewingPlatform viewPlatform = universe.getViewingPlatform();

// Below line throws RestricedAccessException
viewPlatform.setCapability(ViewingPlatform.ALLOW_BOUNDS_WRITE); 
// I want to set the bounds, thus the need for the capability above
viewPlatform.setBounds(bounds);

Please help!


Solution

  • I figured it out. Rather than set up the universe like this:

    GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration();
    Canvas3D canvas3d = new Canvas3D(config);
    
    SimpleUniverse universe = new SimpleUniverse(canvas3d);
    

    I set up the ViewingPlatform by itself, then created the universe with it:

    GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration();
    Canvas3D canvas3d = new Canvas3D(config);
    
    ViewingPlatform viewingPlatform = new ViewingPlatform();
    viewingPlatform.setCapability(ViewingPlatform.ALLOW_BOUNDS_WRITE);
    viewingPlatform.setBounds(bounds);
    Viewer viewer = new Viewer(canvas3d);    
    
    SimpleUniverse universe = new SimpleUniverse(viewingPlatform, viewer);