コード例 #1
0
        public static ViewState computeViewState(Globe globe, Vec4 eyePoint, Vec4 centerPoint, Vec4 up)
        {
            if (globe == null)
            {
                String message = Logging.getMessage("nullValue.GlobeIsNull");
                Logging.logger().severe(message);
                throw new ArgumentException(message);
            }
            if (eyePoint == null)
            {
                String message = "nullValue.EyePointIsNull";
                Logging.logger().severe(message);
                throw new ArgumentException(message);
            }
            if (centerPoint == null)
            {
                String message = "nullValue.CenterPointIsNull";
                Logging.logger().severe(message);
                throw new ArgumentException(message);
            }
            if (up == null)
            {
                up = ViewUtil.getUpVector(globe, centerPoint);
            }

            Matrix modelview = Matrix.fromViewLookAt(eyePoint, centerPoint, up);

            return(ViewUtil.computeModelCoordinates(globe, modelview, centerPoint,
                                                    eyePoint));
        }
コード例 #2
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 = 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();
        }
コード例 #3
0
        protected double computeHorizonDistance(Position eyePosition)
        {
            if (this.globe != null && eyePosition != null)
            {
                double elevation             = eyePosition.getElevation();
                double elevationAboveSurface = ViewUtil.computeElevationAboveSurface(this.dc, eyePosition);
                return(ViewUtil.computeHorizonDistance(this.globe, Math.Max(elevation, elevationAboveSurface)));
            }

            return(0);
        }
コード例 #4
0
        public void setRoll(Angle roll)
        {
            if (roll == null)
            {
                String message = Logging.getMessage("nullValue.AngleIsNull");
                Logging.logger().severe(message);
                throw new ArgumentException(message);
            }

            this.roll = ViewUtil.normalizedRoll(roll);
            this.updateModelViewStateID();
        }
コード例 #5
0
        public void setHeading(Angle heading)
        {
            if (heading == null)
            {
                String message = Logging.getMessage("nullValue.AngleIsNull");
                Logging.logger().severe(message);
                throw new ArgumentException(message);
            }

            this.heading = ViewUtil.normalizedHeading(heading);
            this.heading = heading;
            this.updateModelViewStateID();
            //resolveCollisionsWithPitch();
        }
コード例 #6
0
        /**
         * Returns the most up-to-date forward vector. Unlike {@link #getForwardVector()}, this method will return the
         * View's immediate forward vector.
         *
         * @return Vec4 of the forward axis.
         */
        public Vec4 getCurrentForwardVector()
        {
            if (this.globe != null)
            {
                Matrix modelview = ViewUtil.computeTransformMatrix(this.globe, this.eyePosition,
                                                                   this.heading, this.pitch, this.roll);
                if (modelview != null)
                {
                    Matrix modelviewInv = modelview.getInverse();
                    if (modelviewInv != null)
                    {
                        return(Vec4.UNIT_NEGATIVE_Z.transformBy4(modelviewInv));
                    }
                }
            }

            return(null);
        }
コード例 #7
0
        public Vec4 getCurrentEyePoint()
        {
            if (this.globe != null)
            {
                Matrix modelview = ViewUtil.computeTransformMatrix(this.globe, this.eyePosition,
                                                                   this.heading, this.pitch, this.roll);
                if (modelview != null)
                {
                    Matrix modelviewInv = modelview.getInverse();
                    if (modelviewInv != null)
                    {
                        return(Vec4.UNIT_W.transformBy4(modelviewInv));
                    }
                }
            }

            return(Vec4.ZERO);
        }
コード例 #8
0
        public static ViewState computeModelCoordinates(Globe globe, Matrix modelTransform, Vec4 centerPoint,
                                                        Vec4 eyePoint)
        {
            if (globe == null)
            {
                String message = Logging.getMessage("nullValue.GlobeIsNull");
                Logging.logger().severe(message);
                throw new ArgumentException(message);
            }
            if (modelTransform == null)
            {
                String message = "nullValue.ModelTransformIsNull";
                Logging.logger().severe(message);
                throw new ArgumentException(message);
            }

            // Compute the center position.
            Position centerPos = globe.computePositionFromPoint(centerPoint);
            // Compute the center position transform.
            Matrix centerTransform    = ViewUtil.computePositionTransform(globe, centerPos);
            Matrix centerTransformInv = centerTransform.getInverse();

            if (centerTransformInv == null)
            {
                String message = Logging.getMessage("generic.NoninvertibleMatrix");
                Logging.logger().severe(message);
                throw new IllegalStateException(message);
            }

            // Compute the heading-pitch-zoom transform.
            Matrix hpzTransform = modelTransform.multiply(centerTransformInv);
            // Extract the heading, pitch, and zoom values from the transform.
            Angle heading = ViewUtil.computeHeading(hpzTransform);
            Angle pitch   = ViewUtil.computePitch(hpzTransform);

            if (heading == null || pitch == null)
            {
                return(null);
            }
            Position viewPosition = globe.computePositionFromPoint(eyePoint);

            return(new ViewState(viewPosition, heading, pitch, Angle.ZERO));
        }
コード例 #9
0
 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());
         }
     }
 }
コード例 #10
0
        public Position getCurrentEyePosition()
        {
            // This method is intended to compute the eye position from this view's current parameters. It can be called
            // without having previously applied this view in apply().

            if (this.globe != null)
            {
                Matrix modelview = ViewUtil.computeTransformMatrix(this.globe, this.eyePosition,
                                                                   this.heading, this.pitch, this.roll);
                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);
        }
コード例 #11
0
        protected double computeNearDistance(Position eyePosition)
        {
            // Compute the near clip distance in order to achieve a desired depth resolution at the far clip distance. This
            // computed distance is limited such that it does not intersect the terrain when possible and is never less than
            // a predetermined minimum (usually one). The computed near distance automatically scales with the resolution of
            // the OpenGL depth buffer.
            int    depthBits    = this.dc.getGLRuntimeCapabilities().getDepthBits();
            double nearDistance = ViewUtil.computePerspectiveNearDistance(this.farClipDistance, DEFAULT_DEPTH_RESOLUTION,
                                                                          depthBits);

            // Prevent the near clip plane from intersecting the terrain.
            if (eyePosition != null && this.dc != null)
            {
                double distanceToSurface = ViewUtil.computeElevationAboveSurface(this.dc, eyePosition);
                if (distanceToSurface > 0)
                {
                    double maxNearDistance = ViewUtil.computePerspectiveNearDistance(this.fieldOfView, distanceToSurface);
                    if (nearDistance > maxNearDistance)
                    {
                        nearDistance = maxNearDistance;
                    }
                }
                else
                {
                    nearDistance = MINIMUM_NEAR_DISTANCE;
                }
            }

            // Prevent the near clip plane from becoming unnecessarily small. A very small clip plane is not useful for
            // rendering the World Wind scene, and significantly reduces the depth precision in the majority of the scene.
            if (nearDistance < MINIMUM_NEAR_DISTANCE)
            {
                nearDistance = MINIMUM_NEAR_DISTANCE;
            }

            return(nearDistance);
        }
コード例 #12
0
 public double computePixelSizeAtDistance(double distance)
 {
     return(ViewUtil.computePixelSizeAtDistance(distance, this.fieldOfView, this.viewport));
 }
コード例 #13
0
 public Line computeRayFromScreenPoint(double x, double y)
 {
     return(ViewUtil.computeRayFromScreenPoint(this, x, y,
                                               this.modelview, this.projection, this.viewport));
 }