public void focusOnTerrainCenter() { if (this.dc == null) { String message = Logging.getMessage("nullValue.DrawContextIsNull"); Logging.logger().severe(message); throw new IllegalStateException(message); } if (this.globe == null) { String message = Logging.getMessage("nullValue.DrawingContextGlobeIsNull"); Logging.logger().severe(message); throw new IllegalStateException(message); } if (this.dc.getSurfaceGeometry() == null) { return; } if (isAnimating()) { return; } Matrix modelview = OrbitViewInputSupport.computeTransformMatrix(this.globe, this.center, this.heading, this.pitch, this.roll, this.zoom); if (modelview != null) { Matrix modelviewInv = modelview.getInverse(); if (modelviewInv != null) { // The change in focus must happen seamlessly; we can't move the eye or the forward vector // (only the center position and zoom should change). Vec4 eyePoint = Vec4.UNIT_W.transformBy4(modelviewInv); Vec4 forward = Vec4.UNIT_NEGATIVE_Z.transformBy4(modelviewInv); Intersection[] intersections = this.dc.getSurfaceGeometry().intersect(new Line(eyePoint, forward)); if (intersections != null && intersections.Length > 0) { Vec4 viewportCenterPoint = intersections[0].getIntersectionPoint(); OrbitViewInputSupport.OrbitViewState modelCoords = OrbitViewInputSupport.computeOrbitViewState( this.globe, modelview, viewportCenterPoint); if (validateModelCoordinates(modelCoords)) { setModelCoordinates(modelCoords); } } } } }
private Matrix getModelviewInverse(Globe globe, Position centerPosition, Angle heading, Angle pitch, Angle roll, double zoom) { if (globe != null && centerPosition != null && heading != null && pitch != null) { Matrix modelview = OrbitViewInputSupport.computeTransformMatrix(globe, centerPosition, heading, pitch, roll, zoom); if (modelview != null) { return(modelview.getInverse()); } } return(null); }
public Vec4 getCurrentEyePoint() { if (this.globe != null) { Matrix modelview = OrbitViewInputSupport.computeTransformMatrix(this.globe, this.center, this.heading, this.pitch, this.roll, this.zoom); if (modelview != null) { Matrix modelviewInv = modelview.getInverse(); if (modelviewInv != null) { return(Vec4.UNIT_W.transformBy4(modelviewInv)); } } } return(Vec4.ZERO); }
public Position getCurrentEyePosition() { if (this.globe != null) { Matrix modelview = OrbitViewInputSupport.computeTransformMatrix(this.globe, this.center, this.heading, this.pitch, this.roll, this.zoom); if (modelview != null) { Matrix modelviewInv = modelview.getInverse(); if (modelviewInv != null) { Vec4 eyePoint = Vec4.UNIT_W.transformBy4(modelviewInv); return(this.globe.computePositionFromPoint(eyePoint)); } } } return(Position.ZERO); }
protected void doApply(DrawContext dc) { if (dc == null) { String message = Logging.getMessage("nullValue.DrawContextIsNull"); Logging.logger().severe(message); throw new ArgumentException(message); } if (dc.getGL() == null) { String message = Logging.getMessage("nullValue.DrawingContextGLIsNull"); Logging.logger().severe(message); throw new ArgumentException(message); } if (dc.getGlobe() == null) { String message = Logging.getMessage("nullValue.DrawingContextGlobeIsNull"); Logging.logger().severe(message); throw new ArgumentException(message); } // Update the draw context and the globe, then re-apply the current view property limits. Apply view property // limits after updating the globe so that globe-specific property limits are applied correctly. this.dc = dc; this.globe = this.dc.getGlobe(); this.center = this.getOrbitViewLimits().limitCenterPosition(this, this.center); this.heading = this.getOrbitViewLimits().limitHeading(this, this.heading); this.pitch = this.getOrbitViewLimits().limitPitch(this, this.pitch); this.roll = this.getOrbitViewLimits().limitRoll(this, this.roll); this.zoom = this.getOrbitViewLimits().limitZoom(this, this.zoom); //========== modelview matrix state ==========// // Compute the current modelview matrix. this.modelview = OrbitViewInputSupport.computeTransformMatrix(this.globe, this.center, this.heading, this.pitch, this.roll, this.zoom); if (this.modelview == null) { this.modelview = Matrix.IDENTITY; } // Compute the current inverse-modelview matrix. this.modelviewInv = this.modelview.getInverse(); if (this.modelviewInv == null) { this.modelviewInv = Matrix.IDENTITY; } //========== projection matrix state ==========// // Get the current OpenGL viewport state. int[] viewportArray = new int[4]; this.dc.getGL().gl2.GetInteger(OpenGL.GL_VIEWPORT, 0, viewportArray); // this.dc.getGL().glGetIntegerv(OpenGL.GL_VIEWPORT, viewportArray, 0); this.viewport = new Rectangle(viewportArray[0], viewportArray[1], viewportArray[2], viewportArray[3]); // Compute the current clip plane distances. The near distance depends on the far distance, so we must compute // the far distance first. this.farClipDistance = computeFarClipDistance(); this.nearClipDistance = computeNearClipDistance(); // Compute the current viewport dimensions. double viewportWidth = this.viewport.getWidth() <= 0.0 ? 1.0 : this.viewport.getWidth(); double viewportHeight = this.viewport.getHeight() <= 0.0 ? 1.0 : this.viewport.getHeight(); // Compute the current projection matrix. this.projection = Matrix.fromPerspective(this.fieldOfView, viewportWidth, viewportHeight, this.nearClipDistance, this.farClipDistance); // Compute the current frustum. this.frustum = Frustum.fromPerspective(this.fieldOfView, (int)viewportWidth, (int)viewportHeight, this.nearClipDistance, this.farClipDistance); //========== load GL matrix state ==========// loadGLViewState(dc, this.modelview, this.projection); //========== after apply (GL matrix state) ==========// afterDoApply(); }
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 = OrbitViewInputSupport.computeTransformMatrix( this.globe, centerPosition, this.heading, Angle.ZERO, Angle.ZERO, 1); 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); } OrbitViewInputSupport.OrbitViewState modelCoords = OrbitViewInputSupport.computeOrbitViewState( this.globe, newEyePoint, newCenterPoint, up); if (!validateModelCoordinates(modelCoords)) { String message = Logging.getMessage("View.ErrorSettingOrientation", eyePosition, centerPosition); Logging.logger().severe(message); throw new ArgumentException(message); } setModelCoordinates(modelCoords); }
/** Sets the point of rotation for heading and pitch changes to the surface position at the viewport center. */ public void focusOnViewportCenter() { if (this.isAnimating()) { return; } if (this.dc == null) { String message = Logging.getMessage("nullValue.DrawContextIsNull"); Logging.logger().severe(message); throw new IllegalStateException(message); } if (this.globe == null) { String message = Logging.getMessage("nullValue.DrawingContextGlobeIsNull"); Logging.logger().severe(message); throw new IllegalStateException(message); } Position viewportCenterPos = this.dc.getViewportCenterPosition(); if (viewportCenterPos == null) { String message = Logging.getMessage("nullValue.DrawingContextViewportCenterIsNull"); Logging.logger().severe(message); throw new IllegalStateException(message); } // We want the actual "geometric point" here, which must be adjusted for vertical exaggeration. Vec4 viewportCenterPoint = this.globe.computePointFromPosition( viewportCenterPos.getLatitude(), viewportCenterPos.getLongitude(), this.globe.getElevation(viewportCenterPos.getLatitude(), viewportCenterPos.getLongitude()) * dc.getVerticalExaggeration()); if (viewportCenterPoint != null) { Matrix modelview = OrbitViewInputSupport.computeTransformMatrix(this.globe, this.center, this.heading, this.pitch, this.roll, this.zoom); if (modelview != null) { Matrix modelviewInv = modelview.getInverse(); if (modelviewInv != null) { // The change in focus must happen seamlessly; we can't move the eye or the forward vector // (only the center position and zoom should change). Therefore we pick a point along the // forward vector, and *near* the viewportCenterPoint, but not necessarily at the // viewportCenterPoint itself. Vec4 eyePoint = Vec4.UNIT_W.transformBy4(modelviewInv); Vec4 forward = Vec4.UNIT_NEGATIVE_Z.transformBy4(modelviewInv); double distance = eyePoint.distanceTo3(viewportCenterPoint); Vec4 newCenterPoint = Vec4.fromLine3(eyePoint, distance, forward); OrbitViewInputSupport.OrbitViewState modelCoords = OrbitViewInputSupport.computeOrbitViewState( this.globe, modelview, newCenterPoint); if (validateModelCoordinates(modelCoords)) { setModelCoordinates(modelCoords); } } } } }