Example usage for javax.media.j3d Transform3D invert

List of usage examples for javax.media.j3d Transform3D invert

Introduction

In this page you can find the example usage for javax.media.j3d Transform3D invert.

Prototype

public final void invert() 

Source Link

Document

Inverts this transform in place.

Usage

From source file:MultiView.java

public TransformGroup[] getViewTransformGroupArray() {
    // increment the view count
    m_nNumViews++;/*ww w .ja v a2s  .co m*/

    TransformGroup[] tgArray = new TransformGroup[1];
    tgArray[0] = new TransformGroup();

    Vector3d vTrans = new Vector3d(0.0, 0.0, -20);

    // move the camera BACK so we can view the scene
    // also set the scale so that the more views we have
    // the smaller the scene will be scaled
    Transform3D t3d = new Transform3D();
    t3d.setTranslation(vTrans);
    t3d.setScale(1.0 / m_nNumViews);
    t3d.invert();
    tgArray[0].setTransform(t3d);

    return tgArray;
}

From source file:MixedTest.java

public TransformGroup[] getViewTransformGroupArray() {
    TransformGroup[] tgArray = new TransformGroup[1];
    tgArray[0] = new TransformGroup();

    // move the camera BACK a little...
    // note that we have to invert the matrix as
    // we are moving the viewer
    Transform3D t3d = new Transform3D();
    t3d.setScale(getScale());/* w  w w.  ja  va 2 s.c om*/
    t3d.setTranslation(new Vector3d(0.0, 0.0, -20.0));
    t3d.invert();
    tgArray[0].setTransform(t3d);

    return tgArray;
}

From source file:SwingTest.java

/**
 * Get the TransformGroup for the View side of the scenegraph
 *///from   w  w w .ja v a 2s  .  c om
public TransformGroup[] getViewTransformGroupArray() {
    TransformGroup[] tgArray = new TransformGroup[1];
    tgArray[0] = new TransformGroup();

    // move the camera BACK a little...
    // note that we have to invert the matrix as
    // we are moving the viewer
    Transform3D t3d = new Transform3D();
    t3d.setScale(getScale());
    t3d.setTranslation(new Vector3d(0.0, 0.0, -20.0));
    t3d.invert();
    tgArray[0].setTransform(t3d);

    return tgArray;
}

From source file:HiResCoordTest.java

public TransformGroup[] getViewTransformGroupArray() {
    TransformGroup[] tgArray = new TransformGroup[1];
    tgArray[0] = new TransformGroup();

    Vector3d vTrans = new Vector3d(0.0, 0.0, -m_TranslateSunZ);

    // move the camera BACK so we can view the scene
    // note that the coordinate directions are
    // reversed as we are moving the view
    Transform3D t3d = new Transform3D();
    t3d.setTranslation(vTrans);/*w ww .  j a  v  a2 s  .c om*/
    t3d.invert();
    tgArray[0].setTransform(t3d);

    return tgArray;
}

From source file:HiResCoordTest.java

public TransformGroup[] getViewTransformGroupArray(int nIndex) {
    TransformGroup[] tgArray = new TransformGroup[1];
    tgArray[0] = new TransformGroup();

    Vector3d vTrans = null;//w  w w .j  a  va  2 s  . co  m

    if (nIndex == 1)
        vTrans = new Vector3d(0.0, 0.0, -m_TranslateEarthZ);
    else
        vTrans = new Vector3d(0.0, 0.0, -m_TranslateHouseZ);

    // move the camera BACK so we can view the scene
    // note that the coordinate directions are
    // reversed as we are moving the view
    Transform3D t3d = new Transform3D();
    t3d.setTranslation(vTrans);
    t3d.invert();
    tgArray[0].setTransform(t3d);

    return tgArray;
}

From source file:PlatformTest.java

public PlatformTest() {
    m_KeyHashtable = new Hashtable();
    m_Bounds = new BoundingSphere(new Point3d(0, 0, 0), 100);
    // get the graphics configuration for the graphics device
    GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration();

    // create the first canvas, this is the top-down view
    Canvas3D c = new Canvas3D(config);
    c.setSize(m_kWidth, m_kHeight);/*from   w w w . j  a v  a  2  s.  c o m*/
    add(c);

    // create the second canvas, this is used for "Jim's" Viewer
    Canvas3D c2 = new Canvas3D(config);
    c2.setSize(m_kWidth, m_kHeight);
    add(c2);

    // create the third canvas, this is used for "Dan's" Viewer
    Canvas3D c3 = new Canvas3D(config);
    c3.setSize(m_kWidth, m_kHeight);
    add(c3);

    // Create the simple environment
    BranchGroup scene = createSceneGraph();

    // create the first Viewer, this is a static top-down view
    // create a ViewingPlatform with 2 TransformGroups above the
    // ViewPlatform
    ViewingPlatform vp = new ViewingPlatform(2);

    // create the Viewer and attach to the first canvas
    Viewer viewer = new Viewer(c);

    // rotate and position the first Viewer above the environment
    Transform3D t3d = new Transform3D();
    t3d.rotX(Math.PI / 2.0);
    t3d.setTranslation(new Vector3d(0, 0, -40));
    t3d.invert();

    MultiTransformGroup mtg = vp.getMultiTransformGroup();
    mtg.getTransformGroup(0).setTransform(t3d);

    // create a SimpleUniverse from the ViewingPlatform and Viewer
    SimpleUniverse u = new SimpleUniverse(vp, viewer);

    // add the geometry to the scenegraph
    u.addBranchGraph(scene);

    // add two more Viewers to the scenegraph
    u.getLocale().addBranchGraph(createViewer(c2, "Jim", new Color3f(0.1f, 1.0f, 1.0f), -5, 8));
    u.getLocale().addBranchGraph(createViewer(c3, "Dan", new Color3f(1.0f, 0.1f, 0.1f), 2, -8));

}

From source file:TexCoordTest.java

public TransformGroup[] getViewTransformGroupArray() {
    TransformGroup[] tgArray = new TransformGroup[1];
    tgArray[0] = new TransformGroup();

    // move the camera BACK a little...
    // note that we have to invert the matrix as
    // we are moving the viewer
    Transform3D t3d = new Transform3D();

    t3d.rotX(0.4);//from   ww w .j  a  v a2 s .  c  om
    t3d.setScale(getScale());
    t3d.setTranslation(new Vector3d(0.0, 0, -20.0));
    t3d.invert();
    tgArray[0].setTransform(t3d);

    return tgArray;
}

From source file:KeyNavigateTest.java

public TransformGroup[] getViewTransformGroupArray() {
    TransformGroup[] tgArray = new TransformGroup[2];
    tgArray[0] = new TransformGroup();
    tgArray[1] = new TransformGroup();

    Transform3D t3d = new Transform3D();
    t3d.setScale(getScale());/*from ww w .j  a v a 2s  .co m*/
    t3d.invert();
    tgArray[0].setTransform(t3d);

    // ensure the Behavior can access the TG
    tgArray[1].setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);

    // create the KeyBehavior and attach
    KeyCollisionBehavior keyBehavior = new KeyCollisionBehavior(tgArray[1], this);
    keyBehavior.setSchedulingBounds(getApplicationBounds());
    keyBehavior.setMovementRate(0.7);
    tgArray[1].addChild(keyBehavior);

    return tgArray;
}

From source file:SplineInterpolatorTest.java

public TransformGroup[] getViewTransformGroupArray() {
    TransformGroup[] tgArray = new TransformGroup[2];
    tgArray[0] = new TransformGroup();
    tgArray[1] = new TransformGroup();

    Transform3D t3d = new Transform3D();
    t3d.setScale(getScale());//from  ww w  .j a  va 2 s . c o  m
    t3d.invert();
    tgArray[0].setTransform(t3d);

    // create an Alpha object for the Interpolator
    Alpha alpha = new Alpha(-1, Alpha.INCREASING_ENABLE | Alpha.DECREASING_ENABLE, 0, 0, 25000, 4000, 100,
            20000, 5000, 50);

    // ensure the Interpolator can access the TG
    tgArray[1].setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);

    try {
        // create the Interpolator and load the keyframes from disk
        RotPosScaleTCBSplinePathInterpolator splineInterpolator = Utils.createSplinePathInterpolator(
                new UiAlpha(alpha), tgArray[1], new Transform3D(),
                new URL(getWorkingDirectory(), "rotate_viewer_spline.xls"));

        // set the scheduling bounds and attach to the scenegraph
        splineInterpolator.setSchedulingBounds(getApplicationBounds());
        tgArray[1].addChild(splineInterpolator);
    } catch (Exception e) {
        System.err.println(e.toString());
    }

    return tgArray;
}

From source file:ucar.unidata.idv.flythrough.Flythrough.java

/**
 * _more_//from w  w  w .ja v a2s .  co m
 *
 * @param pt1 _more_
 * @param xyz1 _more_
 * @param xyz2 _more_
 * @param actualPoint _more_
 * @param animateMove _more_
 */
protected void goTo(FlythroughPoint pt1, double[] xyz1, double[] xyz2, double[] actualPoint,
        boolean animateMove) {

    currentHeading = 180;
    if (actualPoint == null) {
        actualPoint = xyz2;
    }
    NavigatedDisplay navDisplay = viewManager.getNavigatedDisplay();
    MouseBehavior mouseBehavior = navDisplay.getMouseBehavior();
    double[] currentMatrix = navDisplay.getProjectionMatrix();
    double[] aspect = navDisplay.getDisplayAspect();
    try {

        if (pt1.getDescription() != null) {
            getHtmlView().setText(pt1.getDescription());
        } else {
            getHtmlView().setText("");
        }

        processReadout(pt1);

        float x1 = (float) xyz1[0];
        float y1 = (float) xyz1[1];
        float z1 = (float) xyz1[2];

        float x2 = (float) xyz2[0];
        float y2 = (float) xyz2[1];
        float z2 = (float) xyz2[2];

        double zoom = (pt1.hasZoom() ? pt1.getZoom() : getZoom());
        if (zoom == 0) {
            zoom = 0.1;
        }

        double tiltx = (pt1.hasTiltX() ? pt1.getTiltX() : tilt[0]);
        double tilty = (pt1.hasTiltY() ? pt1.getTiltY() : tilt[1]);
        double tiltz = (pt1.hasTiltZ() ? pt1.getTiltZ() : tilt[2]);

        //Check for nans
        if ((x2 != x2) || (y2 != y2) || (z2 != z2)) {
            return;
        }

        if ((x1 != x1) || (y1 != y1) || (z1 != z1)) {
            return;
        }

        double[] m = pt1.getMatrix();
        if (m == null) {
            m = new double[16];

            Transform3D t = new Transform3D();
            if (orientation.equals(ORIENT_UP)) {
                y2 = y1 + 100;
                x2 = x1;
            } else if (orientation.equals(ORIENT_DOWN)) {
                y2 = y1 - 100;
                x2 = x1;
            } else if (orientation.equals(ORIENT_LEFT)) {
                x2 = x1 - 100;
                y2 = y1;
            } else if (orientation.equals(ORIENT_RIGHT)) {
                x2 = x1 + 100;
                y2 = y1;
            }

            if ((x1 == x2) && (y1 == y2) && (z1 == z2)) {
                return;
            }

            Vector3d upVector;
            if (doGlobe()) {
                upVector = new Vector3d(x1, y1, z1);
            } else {
                upVector = new Vector3d(0, 0, 1);
            }

            //Keep flat in z for non globe
            Point3d p1 = new Point3d(x1, y1, z1);
            Point3d p2 = new Point3d(x2, y2, ((!getUseFixedZ() || doGlobe()) ? z2 : z1));
            t.lookAt(p1, p2, upVector);

            t.get(m);

            EarthLocation el1 = navDisplay.getEarthLocation(p1.x, p1.y, p1.z, false);
            EarthLocation el2 = navDisplay.getEarthLocation(p2.x, p2.y, p2.z, false);
            Bearing bearing = Bearing.calculateBearing(new LatLonPointImpl(getLat(el1), getLon(el1)),
                    new LatLonPointImpl(getLat(el2), getLon(el2)), null);
            currentHeading = bearing.getAngle();

            double[] tiltMatrix = mouseBehavior.make_matrix(tiltx, tilty, tiltz, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0);
            m = mouseBehavior.multiply_matrix(tiltMatrix, m);
            if (aspect != null) {
                double[] aspectMatrix = mouseBehavior.make_matrix(0.0, 0.0, 0.0, aspect[0], aspect[1],
                        aspect[2], 0.0, 0.0, 0.0);
                //                    m = mouseBehavior.multiply_matrix(aspectMatrix, m);
            }

            double[] scaleMatrix = mouseBehavior.make_matrix(0.0, 0.0, 0.0, zoom, 0.0, 0.0, 0.0);

            m = mouseBehavior.multiply_matrix(scaleMatrix, m);
        }

        currentPoint = pt1;
        location = currentPoint.getEarthLocation();

        if (doGlobe()) {
            setPts(locationLine, 0, x1 * 2, 0, y1 * 2, 0, z1 * 2);
            //                setPts(locationLine2, 0, x2 * 2, 0, y2 * 2, 0, z2 * 2);
        } else {
            setPts(locationLine, x1, x1, y1, y1, 1, -1);
        }

        RealTuple markerLocation = new RealTuple(RealTupleType.SpatialCartesian3DTuple,
                new double[] { x1, y1, z1 });

        if (xyz1[0] != xyz2[0]) {
            Transform3D rotTransform;
            VisADGeometryArray marker = (VisADGeometryArray) getMarker().clone();
            double rotx = 0;
            double roty = 0;
            double rotz = 0;
            rotz = -Math.toDegrees(Math.atan2(actualPoint[1] - xyz1[1], actualPoint[0] - xyz1[0])) + 90;

            if (doGlobe()) {
                Vector3d upVector = new Vector3d(x1, y1, z1);
                rotTransform = new Transform3D();
                rotTransform.lookAt(new Point3d(x1, y1, z1), new Point3d(x2, y2, z2), upVector);
                Matrix3d m3d = new Matrix3d();
                rotTransform.get(m3d);
                rotTransform = new Transform3D(m3d, new Vector3d(0, 0, 0), 1);
                rotTransform.invert();
                //                    ShapeUtility.rotate(marker, rotTransform,(float)x1,(float)y1,(float)z1);
                ShapeUtility.rotate(marker, rotTransform);

            } else {
                double[] markerM = navDisplay.getMouseBehavior().make_matrix(rotx, roty, rotz, 1.0, 0.0, 0.0,
                        0.0);
                rotTransform = new Transform3D(markerM);
                ShapeUtility.rotate(marker, rotTransform);
            }

            locationMarker.setPoint(markerLocation, marker);
        } else {
            locationMarker.setPoint(markerLocation);
        }

        locationLine.setVisible(showLine);
        //            locationLine2.setVisible(showLine);
        locationMarker.setVisible(showMarker);

        if (hasTimes && getShowTimes()) {
            DateTime dttm = pt1.getDateTime();
            if (dttm != null) {
                viewManager.getAnimationWidget().setTimeFromUser(dttm);
            }

        }

        if (changeViewpointCbx.isSelected()) {
            if (animateMove) {
                navDisplay.animateMatrix(m, animationSpeed);
            } else {
                navDisplay.setProjectionMatrix(m);
            }
        }

        if (!Misc.equals(lastLocation, pt1.getEarthLocation())) {
            lastLocation = pt1.getEarthLocation();
            EarthLocationTuple tuplePosition = new EarthLocationTuple(lastLocation.getLatitude(),
                    lastLocation.getLongitude(), lastLocation.getAltitude());
            doShare(ucar.unidata.idv.control.ProbeControl.SHARE_POSITION, tuplePosition);
        }

    } catch (NumberFormatException exc) {
        logException("Error parsing number:" + exc, exc);
    } catch (javax.media.j3d.BadTransformException bte) {
        try {
            navDisplay.setProjectionMatrix(currentMatrix);
        } catch (Exception ignore) {
        }
    } catch (Exception exc) {
        logException("Error", exc);
        if (animationWidget != null) {
            animationWidget.setRunning(false);
        }
        return;
    }

}