Search in sources :

Example 11 with Line

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

the class Rotator3d method checkComponentSelection.

private int checkComponentSelection(MouseRayEvent e) {
    Line draggerRay = new Line(e.getRay());
    draggerRay.inverseTransform(myXDraggerToWorld);
    // double lineDist = 5*distancePerPixel; // 0.05*mySize;
    double lineDist = 5 * e.distancePerPixel(myXDraggerToWorld.p);
    double minDist = Double.POSITIVE_INFINITY;
    double d, tempDist;
    Point3d p = new Point3d();
    // check if the mouse is selecting a rotator, and return
    // the closest rotator if it is.
    int axis = NONE;
    d = draggerRay.intersectPlane(p, yzPlane);
    tempDist = Math.abs(p.norm() - mySize);
    if (rotationSelectCheck(d, tempDist, lineDist, minDist)) {
        axis = X_AXIS;
        minDist = tempDist;
    }
    d = draggerRay.intersectPlane(p, zxPlane);
    tempDist = Math.abs(p.norm() - mySize);
    if (rotationSelectCheck(d, tempDist, lineDist, minDist)) {
        axis = Y_AXIS;
        minDist = tempDist;
    }
    d = draggerRay.intersectPlane(p, xyPlane);
    tempDist = Math.abs(p.norm() - mySize);
    if (rotationSelectCheck(d, tempDist, lineDist, minDist)) {
        axis = Z_AXIS;
    }
    return axis;
}
Also used : Line(maspack.matrix.Line) Point3d(maspack.matrix.Point3d)

Example 12 with Line

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

the class Rotator3d method findRotation.

private void findRotation(RotationMatrix3d R, Point3d p, Line ray) {
    Line draggerRay = new Line(ray);
    draggerRay.inverseTransform(myXDraggerToWorld0);
    switch(mySelectedComponent) {
        case X_AXIS:
            {
                draggerRay.intersectPlane(p, yzPlane);
                R.setAxisAngle(xAxis.getDirection(), Math.atan2(p.z, p.y));
                break;
            }
        case Y_AXIS:
            {
                draggerRay.intersectPlane(p, zxPlane);
                R.setAxisAngle(yAxis.getDirection(), Math.atan2(p.x, p.z));
                break;
            }
        case Z_AXIS:
            {
                draggerRay.intersectPlane(p, xyPlane);
                R.setAxisAngle(zAxis.getDirection(), Math.atan2(p.y, p.x));
                break;
            }
        case OUTER_SPHERE:
            {
                break;
            }
        default:
            {
                throw new InternalErrorException("unexpected case " + mySelectedComponent);
            }
    }
    double mag = p.norm();
    if (mag != 0) {
        p.scale(mySize / mag);
    }
}
Also used : Line(maspack.matrix.Line) InternalErrorException(maspack.util.InternalErrorException)

Example 13 with Line

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

the class Scaler3d method checkComponentSelection.

private int checkComponentSelection(Line ray, double distancePerPixel) {
    Line draggerRay = new Line(ray);
    draggerRay.inverseTransform(myXDraggerToWorld);
    double lineDist = 5 * distancePerPixel;
    double l, d;
    Point3d p = new Point3d();
    // check axes first
    l = xAxis.nearestPoint(p, draggerRay);
    if (l >= 0 && l <= mySize) {
        if (draggerRay.distance(p) < lineDist) {
            return X_AXIS;
        }
    }
    l = yAxis.nearestPoint(p, draggerRay);
    if (l >= 0 && l <= mySize) {
        if (draggerRay.distance(p) < lineDist) {
            return Y_AXIS;
        }
    }
    l = zAxis.nearestPoint(p, draggerRay);
    if (l >= 0 && l <= mySize) {
        if (draggerRay.distance(p) < lineDist) {
            return Z_AXIS;
        }
    }
    // now check planes
    double len = myPlaneBoxRelativeSize * mySize;
    d = draggerRay.intersectPlane(p, xyPlane);
    if (d != inf && p.x >= 0 && p.x <= len && p.y >= 0 && p.y <= len) {
        return XY_PLANE;
    }
    d = draggerRay.intersectPlane(p, yzPlane);
    if (d != inf && p.y >= 0 && p.y <= len && p.z >= 0 && p.z <= len) {
        return YZ_PLANE;
    }
    d = draggerRay.intersectPlane(p, zxPlane);
    if (d != inf && p.z >= 0 && p.z <= len && p.x >= 0 && p.x <= len) {
        return ZX_PLANE;
    }
    return NONE;
}
Also used : Line(maspack.matrix.Line) Point3d(maspack.matrix.Point3d)

Example 14 with Line

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

the class Scaler3d method intersectRayAndFixture.

private void intersectRayAndFixture(Point3d p, Line ray) {
    Line draggerRay = new Line(ray);
    draggerRay.inverseTransform(myXDraggerToWorld);
    switch(mySelectedComponent) {
        case X_AXIS:
            {
                double l = xAxis.nearestPoint(p, draggerRay);
                p.y = p.z = 0;
                break;
            }
        case Y_AXIS:
            {
                yAxis.nearestPoint(p, draggerRay);
                p.x = p.z = 0;
                break;
            }
        case Z_AXIS:
            {
                zAxis.nearestPoint(p, draggerRay);
                p.x = p.y = 0;
                break;
            }
        case XY_PLANE:
            {
                draggerRay.intersectPlane(p, xyPlane);
                p.z = 0;
                break;
            }
        case YZ_PLANE:
            {
                draggerRay.intersectPlane(p, yzPlane);
                p.x = 0;
                break;
            }
        case ZX_PLANE:
            {
                draggerRay.intersectPlane(p, zxPlane);
                p.y = 0;
                break;
            }
        default:
            {
                throw new InternalErrorException("unexpected case " + mySelectedComponent);
            }
    }
}
Also used : Line(maspack.matrix.Line) InternalErrorException(maspack.util.InternalErrorException)

Example 15 with Line

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

the class ConstrainedTranslator3d method updateLocation.

private void updateLocation(MouseRayEvent e) {
    if (mesh == null) {
        return;
    }
    Line ray = e.getRay();
    Point3d origin = ray.getOrigin();
    Vector3d direction = ray.getDirection();
    // face = obbt.intersect (origin, direction, duv, intersector);
    face = query.nearestFaceAlongRay(null, duv, mesh, origin, direction);
    if (face != null) {
        myXDraggerToWorld.p.scaledAdd(duv.x, direction, origin);
    } else {
        Renderer renderer = e.getViewer();
        Point3d location = new Point3d(myXDraggerToWorld.p);
        RigidTransform3d EyeToWorld = renderer.getViewMatrix();
        EyeToWorld.invert();
        EyeToWorld.R.getColumn(2, planeNormal);
        plane.set(planeNormal, location);
        plane.intersectRay(planeLocation, direction, origin);
        face = query.nearestFaceToPoint(location, coords, mesh, planeLocation);
        duv.x = myXDraggerToWorld.p.distance(EyeToWorld.p);
        duv.y = coords.x;
        duv.z = coords.y;
        myXDraggerToWorld.p.set(location);
    }
    myIncrementalTransform.p.set(transform.p);
    transform.p.sub(myXDraggerToWorld.p, firstLocation);
    myIncrementalTransform.p.sub(transform.p, myIncrementalTransform.p);
}
Also used : Line(maspack.matrix.Line) RigidTransform3d(maspack.matrix.RigidTransform3d) Vector3d(maspack.matrix.Vector3d) Point3d(maspack.matrix.Point3d) Renderer(maspack.render.Renderer)

Aggregations

Line (maspack.matrix.Line)15 Point3d (maspack.matrix.Point3d)8 InternalErrorException (maspack.util.InternalErrorException)6 RigidTransform3d (maspack.matrix.RigidTransform3d)5 Vector3d (maspack.matrix.Vector3d)1 Renderer (maspack.render.Renderer)1