public Position computeCenterPositionToResolveCollision(BasicOrbitView orbitView, double nearDistance, DrawContext dc) { if (orbitView == null) { String message = Logging.getMessage("nullValue.OrbitViewIsNull"); Logging.logger().severe(message); throw new ArgumentException(message); } if (nearDistance < 0) { String message = Logging.getMessage("generic.ArgumentOutOfRange", nearDistance); Logging.logger().severe(message); throw new ArgumentException(message); } if (dc == null) { String message = Logging.getMessage("nullValue.DrawContextIsNull"); Logging.logger().severe(message); throw new ArgumentException(message); } Globe globe = dc.getGlobe(); if (globe == null) { String message = Logging.getMessage("nullValue.DrawingContextGlobeIsNull"); Logging.logger().severe(message); throw new ArgumentException(message); } Position newCenter = null; for (int i = 0; i < this.numIterations; i++) { Matrix modelviewInv = getModelviewInverse(globe, newCenter != null ? newCenter : orbitView.getCenterPosition(), orbitView.getHeading(), orbitView.getPitch(), orbitView.getRoll(), orbitView.getZoom()); if (modelviewInv != null) { double heightAboveSurface = computeViewHeightAboveSurface(dc, modelviewInv, orbitView.getFieldOfView(), orbitView.getViewport(), nearDistance); double adjustedHeight = heightAboveSurface - this.collisionThreshold; if (adjustedHeight < 0) { newCenter = new Position( newCenter != null ? newCenter : orbitView.getCenterPosition(), (newCenter != null ? newCenter.getElevation() : orbitView.getCenterPosition().getElevation()) - adjustedHeight); } } } return(newCenter); }
public Angle computePitchToResolveCollision(BasicOrbitView orbitView, double nearDistance, DrawContext dc) { if (orbitView == null) { String message = Logging.getMessage("nullValue.OrbitViewIsNull"); Logging.logger().severe(message); throw new ArgumentException(message); } if (nearDistance < 0) { String message = Logging.getMessage("generic.ArgumentOutOfRange", nearDistance); Logging.logger().severe(message); throw new ArgumentException(message); } if (dc == null) { String message = Logging.getMessage("nullValue.DrawContextIsNull"); Logging.logger().severe(message); throw new ArgumentException(message); } Globe globe = dc.getGlobe(); if (globe == null) { String message = Logging.getMessage("nullValue.DrawingContextGlobeIsNull"); Logging.logger().severe(message); throw new ArgumentException(message); } Angle newPitch = null; for (int i = 0; i < this.numIterations; i++) { Matrix modelviewInv = getModelviewInverse(globe, orbitView.getCenterPosition(), orbitView.getHeading(), newPitch != null ? newPitch : orbitView.getPitch(), orbitView.getRoll(), orbitView.getZoom()); if (modelviewInv != null) { double heightAboveSurface = computeViewHeightAboveSurface(dc, modelviewInv, orbitView.getFieldOfView(), orbitView.getViewport(), nearDistance); double adjustedHeight = heightAboveSurface - this.collisionThreshold; if (adjustedHeight < 0) { Vec4 eyePoint = getEyePoint(modelviewInv); Vec4 centerPoint = globe.computePointFromPosition(orbitView.getCenterPosition()); if (eyePoint != null && centerPoint != null) { Position eyePos = globe.computePositionFromPoint(eyePoint); // Compute the eye point required to resolve the collision. Vec4 newEyePoint = globe.computePointFromPosition(eyePos.getLatitude(), eyePos.getLongitude(), eyePos.getElevation() - adjustedHeight); // Compute the pitch that corresponds with the elevation of the eye point // (but not necessarily the latitude and longitude). Vec4 normalAtCenter = globe.computeSurfaceNormalAtPoint(centerPoint); Vec4 newEye_sub_center = newEyePoint.subtract3(centerPoint).normalize3(); double dot = normalAtCenter.dot3(newEye_sub_center); if (dot >= -1 || dot <= 1) { double angle = Math.Acos(dot); newPitch = Angle.fromRadians(angle); } } } } } return(newPitch); }