@Override public boolean hit(Hitting hitting) { if (waitForReset) { // prevent NPE return false; } if (getGeoElement().getAlphaValue() < EuclidianController.MIN_VISIBLE_ALPHA_VALUE) { return false; } GeoPlane3D plane = (GeoPlane3D) getGeoElement(); // project hitting origin on plane if (hitting.isSphere()) { hitting.origin.projectPlane(plane.getCoordSys().getDrawingMatrix(), tmpCoords1, tmpCoords2); } else { hitting.origin.projectPlaneThruVIfPossible( plane.getCoordSys().getDrawingMatrix(), hitting.direction, tmpCoords1, tmpCoords2); } if (!hitting.isInsideClipping(tmpCoords1)) { return false; } double x = tmpCoords2.getX(); if (x < plane.getXmin()) { return false; } if (x > plane.getXmax()) { return false; } double y = tmpCoords2.getY(); if (y < plane.getYmin()) { return false; } if (y > plane.getYmax()) { return false; } if (hitting.isSphere()) { double d = tmpCoords1.distance(hitting.origin); double scale = getView3D().getScale(); if (d * scale <= hitting.getThreshold()) { setZPick(-d, -d); return true; } } else { double parameterOnHitting = tmpCoords2.getZ(); // TODO use other for // non-parallel // projection : // -hitting.origin.distance(project[0]); setZPick(parameterOnHitting, parameterOnHitting); return true; } return false; }
@Override public boolean hit(Hitting hitting) { if (waitForReset) { // prevent NPE return false; } if (getGeoElement().getAlphaValue() < EuclidianController.MIN_VISIBLE_ALPHA_VALUE) { return false; } GeoPolygon poly = (GeoPolygon) getGeoElement(); if (poly.getCoordSys() == null) { App.debug("" + poly); return false; } // project hitting origin on polygon plane if (globalCoords == null) { globalCoords = new Coords(4); inPlaneCoords = new Coords(4); } if (hitting.isSphere()) { hitting.origin.projectPlane(poly.getCoordSys().getMatrixOrthonormal(), globalCoords); if (hittingPointForOutline == null) { hittingPointForOutline = new GeoPoint3D(poly.getConstruction()); hittingPointForOutline.setWillingCoordsUndefined(); hittingPointForOutline.setWillingDirectionUndefined(); } // try outline hittingPointForOutline.setCoords(globalCoords); poly.pointChanged(hittingPointForOutline); Coords p3d = hittingPointForOutline.getInhomCoordsInD3(); if (project == null) { project = Coords.createInhomCoorsInD3(); } double d = p3d.distance(hitting.origin); double scale = getView3D().getScale(); if (d * scale <= poly.getLineThickness() + hitting.getThreshold()) { setZPick(-d, -d); setPickingType(PickingType.POINT_OR_CURVE); return true; } // try inside hittingPointForOutline.setCoords(globalCoords); hittingPointForOutline.setRegion(poly); poly.pointChangedForRegion(hittingPointForOutline); p3d = hittingPointForOutline.getInhomCoordsInD3(); d = p3d.distance(hitting.origin); if (d * scale <= hitting.getThreshold()) { setZPick(-d, -d); setPickingType(PickingType.SURFACE); return true; } } else { hitting.origin.projectPlaneThruVIfPossible( poly.getCoordSys().getMatrixOrthonormal(), hitting.direction, globalCoords, inPlaneCoords); if (!hitting.isInsideClipping(globalCoords)) { return false; } boolean ret = false; // check if hitting projection hits the polygon if (poly.isInRegion(inPlaneCoords.getX(), inPlaneCoords.getY())) { double parameterOnHitting = inPlaneCoords.getZ(); // TODO use // other for // non-parallel // projection // : // -hitting.origin.distance(project[0]); setZPick(parameterOnHitting, parameterOnHitting); setPickingType(PickingType.SURFACE); ret = true; } // check if hitting is on path if (!poly.wasInitLabelsCalled()) { if (hittingPointForOutline == null) { hittingPointForOutline = new GeoPoint3D(poly.getConstruction()); } hittingPointForOutline.setCoords(globalCoords); poly.pointChanged(hittingPointForOutline); Coords p3d = hittingPointForOutline.getInhomCoordsInD3(); if (hitting.isInsideClipping(p3d)) { if (project == null) { project = Coords.createInhomCoorsInD3(); } p3d.projectLine( hitting.origin, hitting.direction, project, parameters); // check distance to hitting line double d = p3d.distance(project); double scale = getView3D().getScale(); if (d * scale <= poly.getLineThickness() + hitting.getThreshold()) { double z = -parameters[0]; double dz = poly.getLineThickness() / scale; setZPick(z + dz, z - dz); setPickingType(PickingType.POINT_OR_CURVE); return true; } } } return ret; } return false; }