Hi Alex,

   Here is a simple test to display multiple canvases
on different screen. It works only on jdk1.3.

- Kelvin


>MIME-Version: 1.0
>Date: Mon, 28 Aug 2000 18:57:40 -0400
>From: Alex Terrazas <[EMAIL PROTECTED]>
>Subject: [JAVA3D] Cave and Java3D
>To: [EMAIL PROTECTED]
>
>I am trying to setup a multiprojector cave system.  The Java3D
>documentation is practically nonexistent on this subject except to say
>that it is possible.
>
>I saw a non-Java3D demo at SIGGRAPH that used several networked PCs to
>drive each projector.  I am hoping to avoid networking PCs if I can and
>was wondering if one could use several graphics cards in a single PC, each
>driving a monitor/projector.  I realize that I would need a separate
>Cavnas3D and Screen3D for each monitor but what method does one use to
>assign a unique Screen3D to a unique monitor?
>
>I also made of copy of Proejcts in VR: The Java3D API and Virtual Reality
>in IEEE Computer Graphics and Applications but there wasn't much detail.
>
>Thanks to anyone who can help.  I promise to post a code example and
>description when I get it running.
>
>Alex Terrzas
>
>===========================================================================
>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".
/*
 *      @(#)MultiScreens.java 1.4 99/09/15 13:39:39
 *
 * Copyright (c) 1996-1999 Sun Microsystems, Inc. All Rights Reserved.
 *
 * Sun grants you ("Licensee") a non-exclusive, royalty free, license to use,
 * modify and redistribute this software in source and binary code form,
 * provided that i) this copyright notice and license appear on all copies of
 * the software; and ii) Licensee does not utilize the software in a manner
 * which is disparaging to Sun.
 *
 * This software is provided "AS IS," without a warranty of any kind. ALL
 * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY
 * IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
 * NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE
 * LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
 * OR DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS
 * LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT,
 * INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER
 * CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF
 * OR INABILITY TO USE SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGES.
 *
 * This software is not designed or intended for use in on-line control of
 * aircraft, air traffic, aircraft navigation or aircraft communications; or in
 * the design, construction, operation or maintenance of any nuclear
 * facility. Licensee represents and warrants that it will not use or
 * redistribute the Software for such purposes.
 */

import java.awt.Frame;
import java.awt.Panel;
import java.awt.BorderLayout;
import java.awt.GraphicsEnvironment;
import java.awt.GraphicsDevice;
import java.awt.GraphicsConfiguration;
import java.awt.event.*;
import com.sun.j3d.utils.universe.*;
import com.sun.j3d.utils.geometry.ColorCube;
import javax.media.j3d.*;
import javax.vecmath.*;

public class MultiScreens {
    public BranchGroup createSceneGraph() {
        // Create the root of the subgraph
        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);

        // Create a simple shape leaf node and add it into the scene graph.
        objTrans.addChild(new ColorCube(0.4));

        // Create a new Behavior object that will perform the desired
        // operation on the specified transform object and add it into the
        // scene graph.
        Transform3D yAxis = new Transform3D();
        Alpha rotation = new Alpha(-1, Alpha.INCREASING_ENABLE,
                                   0, 0,
                                   4000, 0, 0,
                                   0, 0, 0);

        RotationInterpolator rotator =
            new RotationInterpolator(rotation,
                                     objTrans, yAxis,
                                     0.0f, (float) Math.PI*2.0f);
        BoundingSphere bounds =
            new BoundingSphere(new Point3d(0.0,0.0,0.0), 100.0);
        rotator.setSchedulingBounds(bounds);
        objTrans.addChild(rotator);

        // Have Java 3D perform optimizations on this scene graph.
        objRoot.compile();

        return objRoot;
    }

    public MultiScreens(Canvas3D[] canvases) {
        // Create a simple scene and attach it to the virtual universe
        BranchGroup scene = createSceneGraph();
        SimpleUniverse u = new SimpleUniverse(canvases[0]);

        // This will move the ViewPlatform back a bit so the
        // objects in the scene can be viewed.
        u.getViewingPlatform().setNominalViewingTransform();

        View view = u.getViewer().getView();
        for (int i = 1; i < canvases.length; i++) {
            // Attach the new canvas to the view
            view.addCanvas3D(canvases[i]);
        }

        u.addBranchGraph(scene);
    }


    public static void main(String[] args) {
        int nViews = 2;

        if (args.length > 0) {
            try {
                nViews = Integer.parseInt(args[0]);
            }
            catch (NumberFormatException e) {
                System.out.println("Usage: java MultiScreens [#views]");
                System.exit(1);
            }
        }

        int i;

        Panel[] panels = new Panel[nViews];
        for (i = 0; i < nViews; i++) {
            panels[i] = new Panel();
        }

        GraphicsDevice[] allScreenDevices = GraphicsEnvironment.
            getLocalGraphicsEnvironment().getScreenDevices();
        System.out.println("Found " + allScreenDevices.length +
                           " screen devices");
        for (i = 0; i < allScreenDevices.length; i++)
            System.out.println(allScreenDevices[i]);
        System.out.println();

        GraphicsDevice[] graphicsDevices = new GraphicsDevice[nViews];
        for (i = 0; i < nViews; i++) {
            graphicsDevices[i] = allScreenDevices[i % allScreenDevices.length];
        }

        GraphicsConfigTemplate3D template;
        GraphicsConfiguration gConfig;

        Canvas3D[] canvases = new Canvas3D[nViews];
        for (i = 0; i < nViews; i++) {
            template = new GraphicsConfigTemplate3D();
            gConfig = graphicsDevices[i].getBestConfiguration(template);
            canvases[i] = new Canvas3D(gConfig);
            panels[i].setLayout(new BorderLayout());
            panels[i].add("Center", canvases[i]);
            Screen3D screen = canvases[i].getScreen3D();
            System.out.println("Screen3D[" + i + "] = " + screen);
            System.out.println("    hashCode = " + screen.hashCode());
        }

        new MultiScreens(canvases);

        Frame[] frames = new Frame[nViews];
        for (i = 0; i < nViews; i++) {
            gConfig = graphicsDevices[i].getDefaultConfiguration();
            frames[i] = new Frame(gConfig);
            frames[i].setLayout(new BorderLayout());
            frames[i].setTitle("Canvas " + i);

            frames[i].addWindowListener(new WindowAdapter() {
                public void windowClosing(WindowEvent winEvent) {
                    System.exit(0);
                }
            });

            frames[i].add("Center", panels[i]);

            frames[i].setLocation(300*(i % 3), 300*(i / 3));
            frames[i].setSize(256, 256);
            frames[i].setVisible(true);
        }

        try {
            Thread.sleep(5000);
        }
        catch (InterruptedException e) {
        }

        for (i = 0; i < nViews; i++) {
            Screen3D screen = canvases[i].getScreen3D();
            System.out.println("Screen3D[" + i + "] = " + screen);
            System.out.println("    hashCode = " + screen.hashCode());
        }
    }
}

Reply via email to