public static void setEyePoint(Globe globe, BasicOrbitView view, Vec4 newEyePoint)
        {
            if (globe == null)
            {
                var msg = Logging.getMessage("nullValue.GlobeIsNull");
                Logging.logger().severe(msg);
                throw new ArgumentException(msg);
            }

            if (view == null)
            {
                var msg = Logging.getMessage("nullValue.ViewIsNull");
                Logging.logger().severe(msg);
                throw new ArgumentException(msg);
            }

            if (newEyePoint == null)
            {
                var msg = Logging.getMessage("nullValue.PointIsNull");
                Logging.logger().severe(msg);
                throw new ArgumentException(msg);
            }

            // Translate the view's modelview matrix to the specified new eye point, and compute the new center point by
            // assuming that the view's zoom distance does not change.
            var translation = view.getModelviewMatrix().extractEyePoint().subtract3(newEyePoint);
            var modelview   = view.getModelviewMatrix().multiply(Matrix.fromTranslation(translation));
            var eyePoint    = modelview.extractEyePoint();
            var forward     = modelview.extractForwardVector();
            var centerPoint = eyePoint.add3(forward.multiply3(view.getZoom()));

            // Set the view's properties from the new modelview matrix.
            var parameters = modelview.extractViewingParameters(centerPoint, view.getRoll(), globe);

            view.setCenterPosition((Position)parameters.getValue(AVKey.ORIGIN));
            view.setHeading((Angle)parameters.getValue(AVKey.HEADING));
            view.setPitch((Angle)parameters.getValue(AVKey.TILT));
            view.setRoll((Angle)parameters.getValue(AVKey.ROLL));
            view.setZoom((double)parameters.getValue(AVKey.RANGE));
            view.setViewOutOfFocus(true);
        }
Example #2
0
        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);
        }
Example #3
0
        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);
        }