⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 orbitviewinputsupport.java

📁 world wind java sdk 源码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*
Copyright (C) 2001, 2007 United States Government as represented by
the Administrator of the National Aeronautics and Space Administration.
All Rights Reserved.
*/
package gov.nasa.worldwind.awt;

import gov.nasa.worldwind.avlist.AVKey;
import gov.nasa.worldwind.geom.*;
import gov.nasa.worldwind.util.Logging;
import gov.nasa.worldwind.view.*;

/**
 * @author dcollins
 * @version $Id: OrbitViewInputSupport.java 9587 2009-03-20 20:58:58Z dcollins $
 */
class OrbitViewInputSupport
{
    // OrbitView that will receive value changes.
    private boolean viewChanged;
    private boolean viewOutOfFocus;
    private boolean targetStopped;
    // Target OrbitView values.
    private Position centerTarget; // Initially, do not change OrbitView's center position.
    private Angle headingTarget; // Initially, do not change OrbitView's heading.
    private Angle pitchTarget; // Initially, do not change OrbitView's pitch.
    private double zoomTarget = -1; // Initially, do not change OrbitView's zoom.
    // OrbitView value error thresholds.
    private double centerMinEpsilon;
    private double headingMinEpsilon;
    private double pitchMinEpsilon;
    private double zoomMinEpsilon;
    // OrbitView value smoothing coefficients.
    private double centerSmoothing;
    private double headingSmoothing;
    private double pitchSmoothing;
    private double zoomSmoothing;

    OrbitViewInputSupport()
    {
        loadConfigurationValues();
        // We don't know what state the view is in, so we assume it is "out of focus".
        setViewOutOfFocus(true);
    }

    private void loadConfigurationValues()
    {
        // No configuration keys exist for these values yet (they may never).
        setCenterMinEpsilon(1e-9);
        setHeadingMinEpsilon(1e-4);
        setPitchMinEpsilon(1e-4);
        setZoomMinEpsilon(1e-3);

        // No configuration keys exist for these values yet (they may never).
        setCenterSmoothing(0.4);
        setHeadingSmoothing(0.7);
        setPitchSmoothing(0.7);
        setZoomSmoothing(0.9);
    }

    public void onViewStopped()
    {
        this.clearTargets();
    }

    public void onViewCenterStopped()
    {
        this.centerTarget = null;
        this.setViewOutOfFocus(false);
    }

    private boolean isViewChanged()
    {
        boolean result = this.viewChanged;
        this.viewChanged = false;
        return result;
    }

    private void flagViewChanged()
    {
        this.viewChanged = true;
    }

    private void refreshView(OrbitView view)
    {
        if (isViewChanged())
            view.firePropertyChange(AVKey.VIEW, null, this);
    }

    private boolean isViewOutOfFocus()
    {
        return this.viewOutOfFocus;
    }

    private void setViewOutOfFocus(boolean b)
    {
        this.viewOutOfFocus = b;
    }

    private void focusView(OrbitView view)
    {
        if (view == null)
            return;
        
        try
        {
            // Update the View's focus.
            if (view.canFocusOnViewportCenter())
            {
                view.focusOnViewportCenter();
                setViewOutOfFocus(false);
                flagViewChanged();
            }
        }
        catch (Exception e)
        {
            String message = Logging.getMessage("generic.ExceptionWhileChangingView");
            Logging.logger().log(java.util.logging.Level.SEVERE, message, e);
            // If updating the View's focus failed, raise the flag again.
            setViewOutOfFocus(true);
        }
    }

    private boolean isTargetStopped()
    {
        boolean result = this.targetStopped;
        this.targetStopped = false;
        return result;
    }

    private void flagTargetStopped()
    {
        this.targetStopped = true;
    }

    public Position getCenterTarget()
    {
        return this.centerTarget;
    }

    public void setCenterTarget(OrbitView view, Position centerTarget)
    {
        OrbitViewLimits viewLimits = (view != null) ? view.getOrbitViewLimits() : null;

        Position newTarget = limitCenterPosition(centerTarget, viewLimits);

        // If smoothing is disabled, and centerTarget != null, then set center position directly.
        if (this.centerSmoothing == 0 && newTarget != null && view != null)
        {
            this.centerTarget = null;
            view.setCenterPosition(newTarget);
            flagViewChanged();
            setViewOutOfFocus(true);
        }
        // Otherwise, just set the target.
        else
        {
            this.centerTarget = newTarget;
        }

        // Cancel heading, pitch, and zoom targets.
        if (newTarget != null)
        {
            this.headingTarget = null;
            this.pitchTarget = null;
            this.zoomTarget = -1;
        }

        refreshView(view);
    }

    public Angle getHeadingTarget()
    {
        return this.headingTarget;
    }

    public void setHeadingTarget(OrbitView view, Angle headingTarget)
    {
        OrbitViewLimits viewLimits = (view != null) ? view.getOrbitViewLimits() : null;

        Angle newTarget = limitHeading(headingTarget, viewLimits);

        if (isViewOutOfFocus())
            focusView(view);

        // If smoothing is disabled, and headingTarget != null, then set heading directly.
        if (this.headingSmoothing == 0 && newTarget != null && view != null)
        {
            this.headingTarget = null;
            view.setHeading(newTarget);
            flagViewChanged();
        }
        // Otherwise, just set the target.
        else
        {
            this.headingTarget = newTarget;
        }

        // Cancel center and zoom targets.
        if (newTarget != null)
        {
            this.centerTarget = null;
            this.zoomTarget = -1;
        }

        refreshView(view);
    }

    public Angle getPitchTarget()
    {
        return this.pitchTarget;
    }

    public void setPitchTarget(OrbitView view, Angle pitchTarget)
    {
        OrbitViewLimits viewLimits = (view != null) ? view.getOrbitViewLimits() : null;

        Angle newTarget = limitPitch(pitchTarget, viewLimits);

        if (isViewOutOfFocus())
            focusView(view);

        // If smoothing is disabled, and pitchTarget != null, then set pitch directly.
        if (this.pitchSmoothing == 0 && newTarget != null && view != null)
        {
            this.pitchTarget = null;
            view.setPitch(newTarget);
            flagViewChanged();
        }
        // Otherwise, just set the target.
        else
        {
            this.pitchTarget = newTarget;
        }

        // Cancel center and zoom targets,
        if (newTarget != null)
        {
            this.centerTarget = null;
            this.zoomTarget = -1;
        }

        refreshView(view);
    }

    public double getZoomTarget()
    {
        return this.zoomTarget;
    }

    public void setZoomTarget(OrbitView view, double zoomTarget)
    {
        OrbitViewLimits viewLimits = (view != null) ? view.getOrbitViewLimits() : null;

        double newTarget = limitZoom(zoomTarget, viewLimits);

        if (isViewOutOfFocus() && view != null)
        {
            double beforeFocus, afterFocus;
            beforeFocus = view.getZoom();
            focusView(view);
            afterFocus = view.getZoom();
            newTarget = limitZoom(newTarget + (afterFocus - beforeFocus), viewLimits);
        }

        // If smoothing is disabled, and zoomTarget >= 0, then set zoom directly.
        if (this.zoomSmoothing == 0 && newTarget >= 0 && view != null)
        {
            this.zoomTarget = -1;
            view.setZoom(newTarget);
            flagViewChanged();
        }
        // Otherwise, just set the target.
        else
        {
            this.zoomTarget = newTarget;
        }

        // Cancel center, heading, and pitch targets.
        if (newTarget >= 0)
        {
            this.centerTarget = null;
            this.headingTarget = null;
            this.pitchTarget = null;
        }

        refreshView(view);
    }

    public boolean hasTargets()
    {
        return this.centerTarget != null
            || this.headingTarget != null
            || this.pitchTarget != null
            || this.zoomTarget >= 0;
    }

    public void clearTargets()
    {
        this.centerTarget = null;
        this.headingTarget = null;
        this.pitchTarget = null;
        this.zoomTarget = -1;
        // Clear viewing flags.
        this.viewChanged = false;
        setViewOutOfFocus(false);
        this.targetStopped = false;
    }

    private static Position limitCenterPosition(Position position, OrbitViewLimits viewLimits)
    {
        if (position == null)
            return null;

        position = BasicOrbitView.normalizedCenterPosition(position);
        position = BasicOrbitViewLimits.limitCenterPosition(position, viewLimits);
        return position;
    }

    private static Angle limitHeading(Angle heading, OrbitViewLimits viewLimits)
    {
        if (heading == null)
            return null;

        heading = BasicOrbitView.normalizedHeading(heading);
        heading = BasicOrbitViewLimits.limitHeading(heading, viewLimits);
        return heading;
    }

    private static Angle limitPitch(Angle pitch, OrbitViewLimits viewLimits)
    {
        if (pitch == null)
            return null;

        pitch = BasicOrbitView.normalizedPitch(pitch);
        pitch = BasicOrbitViewLimits.limitPitch(pitch, viewLimits);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -