Login  Register

Canvas3D -> JCanvas3D advice?

Posted by LordSmoke on Feb 11, 2013; 10:43am
URL: https://forum.jogamp.org/Canvas3D-JCanvas3D-advice-tp4028195.html

Hello, folks. I haven't posted since last May, I think, when I was abroad and had the time to work intently on getting my graphics routines updated to jogl2 and the associated j3d. I have checked in periodically to see that development was active and ongoing. In the past couple of months, I have had some coding time and been working to polish other aspects of the program to get it ready for release. I have just finished cleaning and JavaDoc'ing its 93 classes and 83000+ lines of code. I am rather happy with it except for one little issue...

The program is designed as a main desktop window with internal frames. Alas, because of early heavyweight issues, the graphics reside in their own window outside of the program desktop.

Any advice on how to convert from Canvas3D to JCanvas3D and move the window to an internal frame would be appreciated, or a pointer to a simple JCanvas3D example or usage tutorial would be most helpful. The old stuff I have found online don't work for me.

Below is the constructor for my class that handles all of the j3d/jogl-specific code. None of my other classes know anything about j3d/jogl, and canvas (Canvas3D or JCanvas3D) is only accessed within this class to capture an image of the onscreen plot and in the plotting-panel class that adds the canvas to that panel. I have left some commented code from my initial fumblings at trying to get this conversion going.

TIA and best, LS.

PS: This is not a universe subclass. It just handles all universe management and access.

===================================================

    /**
     * A class providing basic methods for
     * creating and drawing scene components. E.g., points, lines,
     * 3d lines, etc. This class knows nothing about my data, and
     * none of the other classes know anything about j3d or jogl
     * other than color and coordinate data types.
     */
    public My_Universe() {
        super();
        // Get the preferred graphics configuration for the default screen
// JCanvas3D stuff
// GraphicsConfigTemplate3D gct = new GraphicsConfigTemplate3D();
// canvas = new JCanvas3D(gct, GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getBestConfiguration(gct));
// canvas = new JCanvas3D(new GraphicsConfigTemplate3D());
        GraphicsConfiguration config = SimpleUniverse
                .getPreferredConfiguration();
        canvas = new Canvas3D(config);
//JCanvas3D stuff
//canvas = new JCanvas3D(new GraphicsConfigTemplate3D());

//JCanvas3D stuff
// Must set size or no internal Canvas3D created?
// canvas.setSize(100,100);

        universe = new SimpleUniverse(canvas);

        universe.getViewingPlatform().setNominalViewingTransform();
        universe.getViewer().getView().setFrontClipDistance(universe.getViewer().getView().getFrontClipDistance() / 10);
        setProjectionPolicy(projectionPolicy);
        // Set up the offScreenCanvas for screen captures.
        GraphicsConfigTemplate3D gcTemplate = new GraphicsConfigTemplate3D();
        gcTemplate.setDoubleBuffer(GraphicsConfigTemplate3D.UNNECESSARY);
        GraphicsConfiguration gc = GraphicsEnvironment.getLocalGraphicsEnvironment()
                .getDefaultScreenDevice().getBestConfiguration(gcTemplate);
        offScreenCanvas = new MVis_OffScreenCanvas3D(gc, true);
        Screen3D sOn = canvas.getScreen3D();
//        JCanvas3D c = new JCanvas3D();

        Screen3D sOff = offScreenCanvas.getScreen3D();
        sOff.setSize(sOn.getSize());
        sOff.setPhysicalScreenWidth(sOn.getPhysicalScreenWidth());
        sOff.setPhysicalScreenHeight(sOn.getPhysicalScreenHeight());
        universe.getViewer().getView().addCanvas3D(offScreenCanvas);

        // Add some initial hints.
        clearUniverse();
        createDefaultScene();
        objRoot.compile();
        universe.addBranchGraph(objRoot);
    }