Example usage for javax.media.j3d GraphicsContext3D STEREO_RIGHT

List of usage examples for javax.media.j3d GraphicsContext3D STEREO_RIGHT

Introduction

In this page you can find the example usage for javax.media.j3d GraphicsContext3D STEREO_RIGHT.

Prototype

int STEREO_RIGHT

To view the source code for javax.media.j3d GraphicsContext3D STEREO_RIGHT.

Click Source Link

Document

Specifies that rendering is done to the right eye.

Usage

From source file:PureImmediateStereo.java

public void run() {
    // Set up Graphics context
    gc = canvas.getGraphicsContext3D();//from   w w  w . j a v a  2s.  c  om

    // We always need to set this for PureImmediate
    // stereo mode
    gc.setBufferOverride(true);

    Color3f lightColor = new Color3f(1, 1, 1);
    Vector3f lightDir = new Vector3f(0, 0, -1);
    DirectionalLight light = new DirectionalLight(lightColor, lightDir);

    gc.addLight(light);

    Appearance redApp = new Appearance();
    Appearance greenApp = new Appearance();
    Color3f ambientColor = new Color3f(0, 0, 0);
    Color3f emissiveColor = new Color3f(0, 0, 0);
    Color3f diffuseColor = new Color3f(1, 0, 0);
    Color3f specularColor = new Color3f(1, 1, 1);
    redApp.setMaterial(new Material(ambientColor, emissiveColor, diffuseColor, specularColor, 5));
    diffuseColor = new Color3f(0, 1, 0);

    greenApp.setMaterial(new Material(ambientColor, emissiveColor, diffuseColor, specularColor, 5));

    // Set up geometry
    Cone leftCone = new Cone(0.4f, 0.6f, Primitive.GENERATE_NORMALS, redApp);
    Cone rightCone = new Cone(0.4f, 0.6f, Primitive.GENERATE_NORMALS, greenApp);
    leftConeBody = leftCone.getShape(Cone.BODY);
    leftConeCap = leftCone.getShape(Cone.CAP);

    rightConeBody = rightCone.getShape(Cone.BODY);
    rightConeCap = rightCone.getShape(Cone.CAP);
    leftTrans = new Vector3f(-0.6f, 0, 0);
    rightTrans = new Vector3f(0.6f, 0, 0);

    while (true) {
        // compute data which is can be used
        // for both left and right eye
        computeSharedData();

        if (stereoSupport) {
            if (!sharedStereoZbuffer) {
                gc.setStereoMode(GraphicsContext3D.STEREO_BOTH);
                // This clear both left and right buffers, we
                // must set STEREO_BOTH before it. Otherwise
                // it only clear LEFT or RIGHT buffer unless
                // this is invoke twice for each buffer.
                gc.clear();
            }

            gc.setStereoMode(GraphicsContext3D.STEREO_LEFT);
            renderLeft();

            gc.setStereoMode(GraphicsContext3D.STEREO_RIGHT);
            renderRight();
        } else {
            gc.clear();
            renderLeft();
        }

        // This swap both left and right buffers so
        // there is no need to set STEREO_BOTH before it
        canvas.swap();

        // Be polite to other threads !
        Thread.yield();
    }
}