public void setOrientation(Position eyePosition, Position centerPosition) { if (eyePosition == null || centerPosition == null) { String message = Logging.getMessage("nullValue.PositionIsNull"); Logging.logger().severe(message); throw new ArgumentException(message); } if (this.globe == null) { String message = Logging.getMessage("nullValue.DrawingContextGlobeIsNull"); Logging.logger().severe(message); throw new IllegalStateException(message); } Vec4 newEyePoint = this.globe.computePointFromPosition(eyePosition); Vec4 newCenterPoint = this.globe.computePointFromPosition(centerPosition); if (newEyePoint == null || newCenterPoint == null) { String message = Logging.getMessage("View.ErrorSettingOrientation", eyePosition, centerPosition); Logging.logger().severe(message); throw new ArgumentException(message); } // If eye lat/lon != center lat/lon, then the surface normal at the center point will be a good value // for the up direction. Vec4 up = this.globe.computeSurfaceNormalAtPoint(newCenterPoint); // Otherwise, estimate the up direction by using the *current* heading with the new center position. Vec4 forward = newCenterPoint.subtract3(newEyePoint).normalize3(); if (forward.cross3(up).getLength3() < 0.001) { Matrix modelview = ViewUtil.computeTransformMatrix(this.globe, eyePosition, this.heading, Angle.ZERO, Angle.ZERO); if (modelview != null) { Matrix modelviewInv = modelview.getInverse(); if (modelviewInv != null) { up = Vec4.UNIT_Y.transformBy4(modelviewInv); } } } if (up == null) { String message = Logging.getMessage("View.ErrorSettingOrientation", eyePosition, centerPosition); Logging.logger().severe(message); throw new ArgumentException(message); } ViewUtil.ViewState modelCoords = ViewUtil.computeViewState( this.globe, newEyePoint, newCenterPoint, up); setViewState(modelCoords); this.updateModelViewStateID(); }
protected void setViewState(ViewUtil.ViewState modelCoords) { if (modelCoords != null) { if (modelCoords.getPosition() != null) { this.eyePosition = ViewUtil.normalizedEyePosition(modelCoords.getPosition()); } if (modelCoords.getHeading() != null) { this.heading = ViewUtil.normalizedHeading(modelCoords.getHeading()); } if (modelCoords.getPitch() != null) { this.pitch = ViewUtil.normalizedPitch(modelCoords.getPitch()); } if (modelCoords.getRoll() != null) { this.roll = ViewUtil.normalizedRoll(modelCoords.getRoll()); } } }