Search in sources :

Example 1 with Line

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

the class ConstrainedTranslator3d method checkComponentSelection.

private boolean checkComponentSelection(Line ray, double distancePerPixel) {
    Line draggerRay = new Line(ray);
    draggerRay.inverseTransform(myXDraggerToWorld);
    double lineDist = 5 * distancePerPixel;
    double l;
    Point3d p = new Point3d();
    // check axes first
    l = xAxis.nearestPoint(p, draggerRay);
    if (l >= -mySize && l <= mySize) {
        if (draggerRay.distance(p) < lineDist) {
            return true;
        }
    }
    l = yAxis.nearestPoint(p, draggerRay);
    if (l >= -mySize && l <= mySize) {
        if (draggerRay.distance(p) < lineDist) {
            return true;
        }
    }
    l = zAxis.nearestPoint(p, draggerRay);
    if (l >= -mySize && l <= mySize) {
        if (draggerRay.distance(p) < lineDist) {
            return true;
        }
    }
    return false;
}
Also used : Line(maspack.matrix.Line) Point3d(maspack.matrix.Point3d)

Example 2 with Line

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

the class MouseRayEvent method create.

public static MouseRayEvent create(MouseEvent e, GLViewer viewer) {
    MouseRayEvent de = new MouseRayEvent((Component) e.getSource(), e.getID(), e.getWhen(), e.getModifiersEx(), e.getX(), e.getY(), e.getClickCount(), e.isPopupTrigger());
    de.myScreenWidth = viewer.getScreenWidth();
    de.myScreenHeight = viewer.getScreenHeight();
    double vph = viewer.getViewPlaneHeight();
    double vpw = viewer.getViewPlaneWidth();
    de.myViewPlaneHeight = vph;
    de.myViewPlaneWidth = vpw;
    de.myViewPlaneDistance = viewer.getViewPlaneDistance();
    // vx and vy give the current cursor location in the viewplane
    double vx = vpw * (-0.5 + de.getX() / (double) de.myScreenWidth);
    double vy = vph * (0.5 - de.getY() / (double) de.myScreenHeight);
    if (viewer.isOrthogonal()) {
        de.myRay = new Line(vx, vy, de.myViewPlaneDistance, 0, 0, -1);
    } else {
        de.myRay = new Line(0, 0, 0, vx, vy, -de.myViewPlaneDistance);
    }
    RigidTransform3d XWorldToBase = new RigidTransform3d();
    viewer.getViewMatrix(XWorldToBase);
    de.myRay.inverseTransform(XWorldToBase);
    de.myViewer = viewer;
    return de;
}
Also used : Line(maspack.matrix.Line) RigidTransform3d(maspack.matrix.RigidTransform3d)

Example 3 with Line

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

the class Transrotator3d method intersectRayAndFixture.

protected void intersectRayAndFixture(Point3d p, Line ray) {
    Line draggerRay = new Line(ray);
    draggerRay.inverseTransform(myXDraggerToWorld);
    switch(mySelectedComponent) {
        case X_AXIS:
            {
                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 4 with Line

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

the class RigidBodyConnectorList method handleLocationEvent.

@Override
public void handleLocationEvent(GLViewer viewer, MouseRayEvent rayEvent) {
    Point3d origin = new Point3d();
    Line ray = rayEvent.getRay();
    ray.nearestPoint(origin, myBodyA.getPose().p);
    System.out.println("origin=" + origin);
    createAndAddConnector(origin);
}
Also used : Line(maspack.matrix.Line) Point3d(maspack.matrix.Point3d)

Example 5 with Line

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

the class Jack3d method checkComponentSelection.

private int checkComponentSelection(MouseRayEvent e) {
    Line draggerRay = new Line(e.getRay());
    draggerRay.inverseTransform(myXDraggerToWorld);
    // double distancePerPixel = e.distancePerPixel (myXDraggerToWorld.p);
    // double lineDist = 5*distancePerPixel; // was 0.05*mySize
    double lineDist = 5 * e.distancePerPixel(myXDraggerToWorld.p);
    double minDist = Double.POSITIVE_INFINITY;
    double l, d, tempDist;
    int resultAxisOrPlane = NONE;
    RigidTransform3d draggerToEye = new RigidTransform3d();
    draggerToEye.mul(e.getViewer().getViewMatrix(), myXDraggerToWorld);
    // Line resultAxis = new Line (0, 0, 0, 0, 0, 0);
    Point3d p = new Point3d();
    // check axes first
    l = xAxis.nearestPoint(p, draggerRay);
    tempDist = draggerRay.distance(p);
    if (l >= -mySize && l <= mySize && tempDist < lineDist) {
        resultAxisOrPlane = X_AXIS;
        minDist = tempDist;
    }
    l = yAxis.nearestPoint(p, draggerRay);
    tempDist = draggerRay.distance(p);
    if (l >= -mySize && l <= mySize && tempDist < lineDist && tempDist < minDist) {
        resultAxisOrPlane = Y_AXIS;
        minDist = tempDist;
    }
    l = zAxis.nearestPoint(p, draggerRay);
    tempDist = draggerRay.distance(p);
    if (l >= -mySize && l <= mySize && tempDist < lineDist && tempDist < minDist) {
        resultAxisOrPlane = Z_AXIS;
        minDist = tempDist;
    }
    if (resultAxisOrPlane != NONE) {
        return resultAxisOrPlane;
    }
    // now check rotators, and if there is any that are selected and
    // closer to the mouse than any of the axes, then select it.
    double len = mySize;
    d = draggerRay.intersectPlane(p, yzPlane);
    tempDist = Math.abs(p.norm() - mySize);
    if (rotationSelectCheck(d, tempDist, lineDist, minDist)) {
        resultAxisOrPlane = X_ROTATE;
        minDist = tempDist;
    }
    d = draggerRay.intersectPlane(p, zxPlane);
    tempDist = Math.abs(p.norm() - mySize);
    if (rotationSelectCheck(d, tempDist, lineDist, minDist)) {
        resultAxisOrPlane = Y_ROTATE;
        minDist = tempDist;
    }
    d = draggerRay.intersectPlane(p, xyPlane);
    tempDist = Math.abs(p.norm() - mySize);
    if (rotationSelectCheck(d, tempDist, lineDist, minDist)) {
        resultAxisOrPlane = Z_ROTATE;
    }
    // return the axis or rotator that the mouse is closest to.
    if (resultAxisOrPlane != NONE) {
        return resultAxisOrPlane;
    }
    return resultAxisOrPlane;
}
Also used : Line(maspack.matrix.Line) RigidTransform3d(maspack.matrix.RigidTransform3d) Point3d(maspack.matrix.Point3d)

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