Exemplo n.º 1
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();
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
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);
        }