Search in sources :

Example 86 with Vector3d

use of maspack.matrix.Vector3d in project artisynth_core by artisynth.

the class GLViewer method getZRange.

// Sanchez, July 2013:
// used to adjust selection volume, or else the orthogonal
// view scale sometimes too large to properly detect selections
protected void getZRange(Vector2d zRange) {
    if (!isOrthogonal()) {
        zRange.x = myFrustum.near;
        zRange.y = myFrustum.far;
        return;
    }
    Point3d pmin = new Point3d();
    Point3d pmax = new Point3d();
    getBounds(pmin, pmax);
    Vector3d zdir = getEyeZDirection();
    // John Lloyd, June 2016. Try to get a more robust estimate of the
    // view volume, based on the center and maximum "radius" of the
    // bounding box
    Point3d cent = new Point3d();
    Vector3d diag = new Vector3d();
    cent.add(pmax, pmin);
    cent.scale(0.5);
    diag.sub(pmax, pmin);
    cent.transform(getViewMatrix());
    double worldDist = -cent.z;
    double radius = diag.norm() / 2;
    if (radius == 0) {
        // can happen if model contains only one or more co-located points
        radius = worldDist * 0.01;
    }
    // add 20% to radius for good measure
    zRange.y = worldDist + 1.2 * radius;
    zRange.x = worldDist - 1.2 * radius;
// // find max z depth
// double worldDist = Math.abs(getEye().dot(zdir));
// double [] x = {pmin.x, pmax.x};
// double [] y = {pmin.y, pmax.y};
// double [] z = {pmin.z, pmax.z};
// double minz = Double.POSITIVE_INFINITY;
// double maxz = Double.NEGATIVE_INFINITY;
// for (int i=0; i<2; i++) {
// for (int j=0; j<2; j++) {
// for (int k=0; k<2; k++) {
// double d = x[i]*zdir.x + y[j]*zdir.y + z[k]*zdir.z;
// maxz = Math.max(maxz, d);
// minz = Math.min(minz, d);
// }
// }
// }
// // add 50% for good measure
// double d = maxz-minz;
// minz = minz-d/2;
// maxz = maxz+d/2;
// zRange.y = maxz + worldDist;
// zRange.x = 2*(minz + worldDist)-zRange.y;
}
Also used : Vector3d(maspack.matrix.Vector3d) Point3d(maspack.matrix.Point3d)

Example 87 with Vector3d

use of maspack.matrix.Vector3d in project artisynth_core by artisynth.

the class GLViewer method setAxisLength.

public void setAxisLength(double len) {
    if (len == AUTO_FIT) {
        Point3d pmin = new Point3d();
        Point3d pmax = new Point3d();
        getBounds(pmin, pmax);
        Vector3d vdiag = new Vector3d();
        vdiag.sub(pmax, pmin);
        axisLength = vdiag.norm() / 2;
    } else {
        axisLength = len;
    }
}
Also used : Vector3d(maspack.matrix.Vector3d) Point3d(maspack.matrix.Point3d)

Example 88 with Vector3d

use of maspack.matrix.Vector3d in project artisynth_core by artisynth.

the class GLViewer method setAlignedEyeOrientation.

/**
 * Adjusts the orientation the eye frame with respect to world
 * coordinates. The grid is adjusted to align with the nearest set
 * of aligned axes.
 * The distance between the center and the eye frame is unchanged.
 *
 * @param REW
 * desired rotational transform from eye to world coordinates
 */
protected void setAlignedEyeOrientation(RotationMatrix3d REW) {
    Vector3d xdir = new Vector3d();
    Vector3d ydir = new Vector3d();
    Vector3d zdir = new Vector3d();
    REW.getColumn(0, xdir);
    REW.getColumn(1, ydir);
    REW.getColumn(2, zdir);
    // new eye to world transfrom
    RigidTransform3d X = new RigidTransform3d();
    X.R.set(REW);
    double d = getEye().distance(myViewState.myCenter);
    X.p.scaledAdd(d, zdir, myViewState.myCenter);
    myViewState.myUp.set(ydir);
    setEyeToWorld(X);
    X.p.setZero();
    // adjust X.R to the nearest axis-aligned orientation
    int xmaxIdx = xdir.maxAbsIndex();
    double v = xdir.get(xmaxIdx) > 0 ? 1 : -1;
    xdir.setZero();
    xdir.set(xmaxIdx, v);
    ydir.set(xmaxIdx, 0);
    int ymaxIdx = ydir.maxAbsIndex();
    v = ydir.get(ymaxIdx) > 0 ? 1 : -1;
    ydir.setZero();
    ydir.set(ymaxIdx, v);
    X.R.setXYDirections(xdir, ydir);
    myGrid.setGridToWorld(X);
    myGrid.setUseWorldOrigin(true);
    myGrid.setLockAxesToWorld(true);
    myGrid.setXAxisColor(getAxisColor(0));
    myGrid.setYAxisColor(getAxisColor(1));
    myGrid.setZAxisColor(getAxisColor(2));
}
Also used : RigidTransform3d(maspack.matrix.RigidTransform3d) Vector3d(maspack.matrix.Vector3d)

Example 89 with Vector3d

use of maspack.matrix.Vector3d in project artisynth_core by artisynth.

the class GLViewer method autoFitOrtho.

/*
    * {@inheritDoc}
    */
public void autoFitOrtho() {
    if (hasRenderables()) {
        Point3d pcenter = new Point3d();
        double r = estimateRadiusAndCenter(pcenter);
        // if radius is zero, set default to radius 1
        if (Math.abs(r) == 0 || Double.isInfinite(r) || Double.isNaN(r)) {
            r = 1;
        }
        myViewState.myCenter.set(pcenter);
        Vector3d zdir = getEyeZDirection();
        // use sine instead of tangent since we want frustum to be tangent to
        // to the sphere implied by r
        double d = r / Math.sin(Math.toRadians(myFrustum.fov) / 2);
        Point3d eye = getEye();
        eye.scaledAdd(d, zdir, myViewState.myCenter);
        setEye(eye);
        double far = 40 * r;
        double near = far / 1000;
        setOrthogonal(2 * r, near, far);
        setGridSizeAndPosition(pcenter, r);
        if (isVisible()) {
            rerender();
        }
    }
}
Also used : Vector3d(maspack.matrix.Vector3d) Point3d(maspack.matrix.Point3d)

Example 90 with Vector3d

use of maspack.matrix.Vector3d in project artisynth_core by artisynth.

the class GL3Viewer method getLineTransform.

private RigidTransform3d getLineTransform(float[] p0, float[] p1) {
    RigidTransform3d X = new RigidTransform3d();
    Vector3d utmp = new Vector3d();
    utmp.set(p1[0] - p0[0], p1[1] - p0[1], p1[2] - p0[2]);
    X.p.set(p0[0], p0[1], p0[2]);
    X.R.setZDirection(utmp);
    return X;
}
Also used : RigidTransform3d(maspack.matrix.RigidTransform3d) Vector3d(maspack.matrix.Vector3d)

Aggregations

Vector3d (maspack.matrix.Vector3d)441 Point3d (maspack.matrix.Point3d)128 RigidTransform3d (maspack.matrix.RigidTransform3d)56 ArrayList (java.util.ArrayList)38 Matrix3d (maspack.matrix.Matrix3d)32 RotationMatrix3d (maspack.matrix.RotationMatrix3d)30 SymmetricMatrix3d (maspack.matrix.SymmetricMatrix3d)24 PolygonalMesh (maspack.geometry.PolygonalMesh)23 Vertex3d (maspack.geometry.Vertex3d)23 Face (maspack.geometry.Face)20 AxisAngle (maspack.matrix.AxisAngle)19 Vector3i (maspack.matrix.Vector3i)19 Point (artisynth.core.mechmodels.Point)18 RenderProps (maspack.render.RenderProps)17 VectorNd (maspack.matrix.VectorNd)15 AffineTransform3d (maspack.matrix.AffineTransform3d)14 IOException (java.io.IOException)13 Vector2d (maspack.matrix.Vector2d)11 Plane (maspack.matrix.Plane)10 GLViewer (maspack.render.GL.GLViewer)9