Beispiel #1
0
        protected void setModelCoordinates(OrbitViewInputSupport.OrbitViewState modelCoords)
        {
            if (modelCoords != null)
            {
                if (modelCoords.getCenterPosition() != null)
                {
                    this.center = normalizedCenterPosition(modelCoords.getCenterPosition());
                    this.center = this.getOrbitViewLimits().limitCenterPosition(this, this.center);
                }
                if (modelCoords.getHeading() != null)
                {
                    this.heading = normalizedHeading(modelCoords.getHeading());
                    this.heading = this.getOrbitViewLimits().limitHeading(this, this.heading);
                }
                if (modelCoords.getPitch() != null)
                {
                    this.pitch = normalizedPitch(modelCoords.getPitch());
                    this.pitch = this.getOrbitViewLimits().limitPitch(this, this.pitch);
                }

                this.zoom = modelCoords.getZoom();
                this.zoom = this.getOrbitViewLimits().limitZoom(this, this.zoom);

                this.updateModelViewStateID();
            }
        }
Beispiel #2
0
 protected bool validateModelCoordinates(OrbitViewInputSupport.OrbitViewState modelCoords)
 {
     return(modelCoords != null &&
            modelCoords.getCenterPosition() != null &&
            modelCoords.getCenterPosition().getLatitude().degrees >= -90 &&
            modelCoords.getCenterPosition().getLatitude().degrees <= 90 &&
            modelCoords.getHeading() != null &&
            modelCoords.getPitch() != null &&
            modelCoords.getPitch().degrees >= 0 &&
            modelCoords.getPitch().degrees <= 90 &&
            modelCoords.getZoom() >= 0);
 }
Beispiel #3
0
        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);
                        }
                    }
                }
            }
        }
Beispiel #4
0
        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);
        }
Beispiel #5
0
        /** 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);
                        }
                    }
                }
            }
        }