Stereo Viewing

As mentioned already, there are a couple of different options for stereo viewing. The first uses so-called shutter glasses that alternate between eyes in sync with the computer monitor. Recall that stereoscopic perceptions require that each eye receives a separate view of the scene. The view must be from a slightly different angle and roughly matched to the separation of the eyes. The distance between an individual's pupils is called the interocular distance.

The second way to generate stereoscopic objects and scenes is by having two separate monitors, one for each eye. In this case, no flickering is required. This is exactly how an HMD is set up to work. In essence, each eye has its own little monitor. Again, a slightly different view is needed for each eye, but there is no switching between eyes; both monitors are constantly on.

Listing 13.2 demonstrates how to generate stereo images with Java 3D. There are several issues to keep in mind when setting up the displays for stereo. The first and most frequently encountered problem is that the user has a stereo card that is not supported by Java 3D. One source of confusion arises when the target system has a card that is indeed stereo capable but that is not supported in stereo by Java 3D. Many cards are supported by Java 3D, but some are not. Regardless, this is an important factor to consider, and it is worth investigating a particular card before spending too much time with it.

Otherwise, most of the other challenges are the result of not setting the options correctly. The first procedural rule is to run a stereo program using the command line option

-Dj3d.stereo=REQUIRED

The second necessary change for setting up stereo is to set the GraphicsConfiguration options in the code itself. In Listing 13.2, take special notice of the following lines:

GraphicsConfigTemplate3D g3d = new GraphicsConfigTemplate3D();
g3d.setStereo(GraphicsConfigTemplate3D.REQUIRED);
GraphicsConfiguration gc =
GraphicsEnvironment.getLocalGraphicsEnvironment().         getDefaultScreenDevice().
getBestConfiguration(g3d);

Finally, the program must set a flag on the Canvas3D object with

Canvas3D.setStereoEnable(true)

After these steps are taken care of, the application is ready for stereo. The full listing is given in Listing 13.2.

Listing 13.2 StereoRecipdeJ3D.java
import com.sun.j3d.loaders.objectfile.ObjectFile;
import com.sun.j3d.loaders.ParsingErrorException;
import com.sun.j3d.loaders.IncorrectFormatException;
import com.sun.j3d.loaders.Scene;
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
import com.sun.j3d.utils.applet.MainFrame;
import com.sun.j3d.utils.universe.*;
import javax.media.j3d.*;
import javax.vecmath.*;
import java.io.*;
import com.sun.j3d.utils.image.TextureLoader;
import com.sun.j3d.utils.behaviors.vp.*;
import com.sun.j3d.utils.geometry.ColorCube;

import java.applet.Applet;
import java.awt.BorderLayout;
import java.awt.event.*;
import java.awt.GraphicsEnvironment;

import java.awt.GraphicsConfiguration;
import com.sun.j3d.utils.applet.MainFrame;
import com.sun.j3d.utils.geometry.Box;
import com.sun.j3d.utils.geometry.Cone;
 import com.sun.j3d.loaders.ParsingErrorException;
import com.sun.j3d.loaders.IncorrectFormatException;

import com.sun.j3d.utils.geometry.Primitive;
import com.sun.j3d.utils.universe.*;
import javax.media.j3d.*;
import javax.vecmath.*;
import com.sun.j3d.utils.behaviors.mouse.MouseRotate;

public class StereoRecipeJ3D extends Applet {
  VirtualUniverse universe;
  Locale locale;
  TransformGroup vpTrans;
  View view;
  Bounds bounds;
  PhysicalBody body;
    public BranchGroup createSceneGraph() {
       // Create the root of the branch graph; this will be returned
        Appearance app = new Appearance();
        BranchGroup objRoot = new BranchGroup();
        TransformGroup geoTG = new TransformGroup();
        geoTG.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
        geoTG.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);

        BoundingSphere bounds =
             new BoundingSphere(new Point3d(0.0,0.0,0.0), 1000.0);
        MouseRotate mouseBeh = new MouseRotate(geoTG);
        geoTG.addChild(mouseBeh);
        mouseBeh.setSchedulingBounds(bounds);

        geoTG.addChild(new ColorCube(2));
        objRoot.addChild(geoTG);

        Color3f blue = new Color3f(0.f, 0.9f, 0.f);
        Vector3f bluedir  = new Vector3f(0.0f, -8.0f, -8.0f);
      Color3f bgColor = new Color3f(0.9f, 0.9f, 0.0f);
        AmbientLight al = new AmbientLight(true, new Color3f(.5f,.5f, .5f));
        DirectionalLight bluelight = new DirectionalLight(blue, bluedir);
        al.setInfluencingBounds(bounds);
        bluelight.setInfluencingBounds(bounds);

        objRoot.addChild(al);
        objRoot.addChild(bluelight);

        return objRoot;
     }

   public BranchGroup createViewGraph() {
         BranchGroup objRoot = new BranchGroup();
         Transform3D t = new Transform3D();
         t.setTranslation(new Vector3f(0.0f, 0.0f,10.0f));
         ViewPlatform vp = new ViewPlatform();
         vpTrans = new TransformGroup();
         vpTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
         vpTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
         vpTrans.setTransform(t);
         DisparityBehavior db = new DisparityBehavior(body);
         NavigationBehavior nav = new NavigationBehavior(vpTrans);
         vpTrans.addChild(nav);
         nav.setSchedulingBounds(bounds);

         db.setSchedulingBounds(bounds);
         vpTrans.addChild(db);

         vpTrans.addChild(vp);
         view.attachViewPlatform(vp);
        objRoot.addChild(vpTrans);
         return objRoot;

    public StereoRecipeJ3D() {
        setLayout(new BorderLayout());
        GraphicsConfigTemplate3D g3d = new GraphicsConfigTemplate3D();
        g3d.setStereo(GraphicsConfigTemplate3D.REQUIRED);
        GraphicsConfiguration gc = GraphicsEnvironment.getLocalGraphicsEnvironment(). 
getDefaultScreenDevice().getBestConfiguration(g3d);
        Canvas3D c = new Canvas3D(gc);
         add("Center", c);
         universe = new VirtualUniverse();

         locale = new Locale(universe);
         body = new PhysicalBody();
         PhysicalEnvironment environment = new PhysicalEnvironment();
         view = new View();
         view.setTrackingEnable(true);
         c.setStereoEnable(true);
         System.out.println("stereo enable: " + c.getStereoEnable());
         System.out.println("stereo available: " + c.getStereoAvailable());
         view.addCanvas3D(c);
         view.setPhysicalBody(body);
         view.setPhysicalEnvironment(environment);
        // Create a simple scene and attach it to the virtual universe

         bounds = new BoundingSphere(new Point3d(0.0,0.0,0.0), 100.0);
         BranchGroup scene = createSceneGraph();
         BranchGroup vgraph = createViewGraph();
        locale.addBranchGraph(vgraph);
        locale.addBranchGraph(scene);
    }
    //
    //
    public static void main(String[] args) {
        new MainFrame(new StereoRecipeJ3D(), 256, 256);
    }
}

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset