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

📄 viewinputhandler.java

📁 world wind java sdk 源码
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
                if (!(isKeyEventTrigger = this.handleKeyZoom(keys, target)))                {                    isKeyEventTrigger = this.handleKeyPan(keys, target);                }            }        }        return isKeyEventTrigger;    }    protected boolean handleKeyPan(KeyEventState keys, String target)    {        double forwardInput = 0;        double sideInput = 0;        if (keys.isKeyDown(KeyEvent.VK_LEFT))            sideInput += -1;        if (keys.isKeyDown(KeyEvent.VK_RIGHT))            sideInput += 1;        if (keys.isKeyDown(KeyEvent.VK_UP))            forwardInput += 1;        if (keys.isKeyDown(KeyEvent.VK_DOWN))            forwardInput += -1;        if (forwardInput == 0 && sideInput == 0)        {            return false;        }        //noinspection StringEquality        if (target == GENERATE_EVENTS)        {            // Normalize the forward and right magnitudes.            double length = Math.sqrt(forwardInput * forwardInput + sideInput * sideInput);            if (length > 0.0)            {                forwardInput /= length;                sideInput /= length;            }            boolean isSlowEnabled = (keys.getModifiersEx() & KeyEvent.ALT_DOWN_MASK) != 0;            ViewInputAttributes.DeviceAttributes deviceAttributes =                this.attributes.getDeviceAttributes(ViewInputAttributes.DEVICE_KEYBOARD);            ViewInputAttributes.ActionAttributes actionAttributes =                this.attributes.getActionAttributes(ViewInputAttributes.DEVICE_KEYBOARD,                    isSlowEnabled? ViewInputAttributes.VIEW_PAN_SLOW : ViewInputAttributes.VIEW_PAN);            Angle forwardChange = Angle.fromDegrees(                this.rawInputToChangeInValue(forwardInput, deviceAttributes, actionAttributes, SCALE_FUNC_ZOOM_EXP));            Angle sideChange = Angle.fromDegrees(                this.rawInputToChangeInValue(sideInput, deviceAttributes, actionAttributes, SCALE_FUNC_ZOOM_EXP));            this.onPanViewRelative(forwardChange, sideChange, actionAttributes);        }        return true;    }    protected boolean handleKeyRotate(KeyEventState keys, String target)    {        double headingInput = 0;        double pitchInput = 0;        if ((keys.getModifiersEx() & KeyEvent.SHIFT_DOWN_MASK) != 0)        {            if (keys.isKeyDown(KeyEvent.VK_LEFT))                headingInput += -1;            if (keys.isKeyDown(KeyEvent.VK_RIGHT))                headingInput += 1;            if (keys.isKeyDown(KeyEvent.VK_UP))                pitchInput += -1;            if (keys.isKeyDown(KeyEvent.VK_DOWN))                pitchInput += 1;        }        else        {            if (keys.isKeyDown(KeyEvent.VK_PAGE_DOWN))                pitchInput += 1;            if (keys.isKeyDown(KeyEvent.VK_PAGE_UP))                pitchInput += -1;        }        if (headingInput == 0 && pitchInput == 0)        {            return false;        }        //noinspection StringEquality        if (target == GENERATE_EVENTS)        {            // Normalize the heading and pitch magnitudes.            double length = Math.sqrt(headingInput * headingInput + pitchInput * pitchInput);            if (length > 0.0)            {                headingInput /= length;                pitchInput /= length;            }            boolean isSlowEnabled = (keys.getModifiersEx() & KeyEvent.ALT_DOWN_MASK) != 0;            ViewInputAttributes.DeviceAttributes deviceAttributes =                this.attributes.getDeviceAttributes(ViewInputAttributes.DEVICE_KEYBOARD);            ViewInputAttributes.ActionAttributes actionAttributes =                this.attributes.getActionAttributes(ViewInputAttributes.DEVICE_KEYBOARD,                    isSlowEnabled ? ViewInputAttributes.VIEW_ROTATE_SLOW : ViewInputAttributes.VIEW_ROTATE);            Angle headingChange = Angle.fromDegrees(                this.rawInputToChangeInValue(headingInput, deviceAttributes, actionAttributes, SCALE_FUNC_ZOOM));            Angle pitchChange = Angle.fromDegrees(                this.rawInputToChangeInValue(pitchInput, deviceAttributes, actionAttributes, SCALE_FUNC_ZOOM));            this.onRotateView(headingChange, pitchChange, actionAttributes);        }        return true;    }    protected boolean handleKeyZoom(KeyEventState keys, String target)    {        double zoomInput = 0;        if ((keys.getModifiersEx() & (KeyEvent.CTRL_DOWN_MASK | KeyEvent.META_DOWN_MASK)) != 0)        {            if (keys.isKeyDown(KeyEvent.VK_UP))                zoomInput += -1;            if (keys.isKeyDown(KeyEvent.VK_DOWN))                zoomInput += 1;        }        else        {            if (keys.isKeyDown(KeyEvent.VK_ADD) || keys.isKeyDown(KeyEvent.VK_EQUALS))                zoomInput += -1;            if (keys.isKeyDown(KeyEvent.VK_SUBTRACT) || keys.isKeyDown(KeyEvent.VK_MINUS))                zoomInput += 1;        }        if (zoomInput == 0)        {            return false;        }        //noinspection StringEquality        if (target == GENERATE_EVENTS)        {            boolean isSlowEnabled = (keys.getModifiersEx() & KeyEvent.ALT_DOWN_MASK) != 0;            ViewInputAttributes.DeviceAttributes deviceAttributes =                this.attributes.getDeviceAttributes(ViewInputAttributes.DEVICE_KEYBOARD);            ViewInputAttributes.ActionAttributes actionAttributes =                this.attributes.getActionAttributes(ViewInputAttributes.DEVICE_KEYBOARD,                    isSlowEnabled ? ViewInputAttributes.VIEW_ZOOM_SLOW : ViewInputAttributes.VIEW_ZOOM);            double zoomChange = this.rawInputToChangeInValue(zoomInput, deviceAttributes, actionAttributes,                SCALE_FUNC_ZOOM);            this.onZoomView(zoomChange, actionAttributes);        }        return true;    }    //**************************************************************//    //********************  Property Change Events  ****************//    //**************************************************************//    public void propertyChange(java.beans.PropertyChangeEvent e)    {        if (this.wwd == null) // include this test to ensure any derived implementation performs it        {            return;        }        if (e == null) // include this test to ensure any derived implementation performs it        {            return;        }        //noinspection StringEquality        if (e.getPropertyName() == View.VIEW_STOPPED)        {            this.handleViewStopped();        }        else //noinspection StringEquality            if (e.getPropertyName() == OrbitView.CENTER_STOPPED)        {            this.handleOrbitViewCenterStopped();        }    }    protected void handleViewStopped()    {        this.orbitViewInputSupport.onViewStopped();    }    protected void handleOrbitViewCenterStopped()    {        this.orbitViewInputSupport.onViewCenterStopped();    }    //**************************************************************//    //********************  Raw Input Transformation  **************//    //**************************************************************//    // Translates raw user input into a change in value, according to the specified device and action attributes.    // The input is scaled by the action attribute range (depending on eye position), then scaled by the device    // sensitivity.    protected double rawInputToChangeInValue(double rawInput,        ViewInputAttributes.DeviceAttributes deviceAttributes, ViewInputAttributes.ActionAttributes actionAttributes,        String scaleFunc)    {        double value = rawInput;        double[] range = actionAttributes.getValues();        value *= this.getScaledValue(range[0], range[1], scaleFunc);        value *= deviceAttributes.getSensitivity();        return value;    }    protected double getScaledValue(double minValue, double maxValue, String scaleFunc)    {        if (scaleFunc == null)        {            return minValue;        }        double t = 0.0;        if (scaleFunc.startsWith(SCALE_FUNC_EYE_ALTITUDE))        {            t = this.evaluateScaleFuncEyeAltitude();        }        else if (scaleFunc.startsWith(SCALE_FUNC_ZOOM))        {            t = this.evaluateScaleFuncZoom();        }        if (scaleFunc.toLowerCase().endsWith("exp"))        {            t = Math.pow(2.0, t) - 1.0;        }                return minValue * (1.0 - t) + maxValue * t;    }    protected double evaluateScaleFuncEyeAltitude()    {        View view = this.getView();        if (view == null)        {            return 0.0;        }        Position eyePos = view.getEyePosition();        double radius = this.wwd.getModel().getGlobe().getRadius();        double surfaceElevation = this.wwd.getModel().getGlobe().getElevation(eyePos.getLatitude(), eyePos.getLongitude());        double t = (eyePos.getElevation() - surfaceElevation) / (3.0 * radius);        return (t < 0 ? 0 : (t > 1 ? 1 : t));    }    protected double evaluateScaleFuncZoom()    {        View view = this.getView();        if (view == null)        {            return 0.0;        }        double radius = this.wwd.getModel().getGlobe().getRadius();        double t = ((OrbitView) view).getZoom() / (3.0 * radius);        return (t < 0 ? 0 : (t > 1 ? 1 : t));    }    //**************************************************************//    //********************  View State Change Utilities  ***********//    //**************************************************************//    protected void setCenterPosition(OrbitView view, Position position, ViewInputAttributes.ActionAttributes attrib)    {        // Stop ViewStateIterators, so we are the only one affecting the view.        if (view.hasStateIterator())            view.stopStateIterators();        double smoothing = attrib.getSmoothingValue();        if (!(attrib.isEnableSmoothing() && this.isEnableSmoothing()))            smoothing = 0.0;        if (smoothing != 0.0 && this.orbitViewInputSupport.getCenterTarget() != null)        {            Position target = this.orbitViewInputSupport.getCenterTarget();            Position cur = view.getCenterPosition();            position = new Position(                target.getLatitude().add(position.getLatitude()).subtract(cur.getLatitude()),                target.getLongitude().add(position.getLongitude()).subtract(cur.getLongitude()),                target.getElevation() + position.getElevation() - cur.getElevation());        }        this.orbitViewInputSupport.setCenterSmoothing(smoothing);        this.orbitViewInputSupport.setCenterTarget(view, position);        view.firePropertyChange(AVKey.VIEW, null, view);    }    protected void changeHeading(OrbitView view, Angle change, ViewInputAttributes.ActionAttributes attrib)    {        // Stop ViewStateIterators, so we are the only one affecting the view.        if (view.hasStateIterator())            view.stopStateIterators();        double smoothing = attrib.getSmoothingValue();        if (!(attrib.isEnableSmoothing() && this.isEnableSmoothing()))            smoothing = 0.0;        Angle newHeading;        if (smoothing != 0.0 && this.orbitViewInputSupport.getHeadingTarget() != null)        {            newHeading = this.orbitViewInputSupport.getHeadingTarget().add(change);        }        else        {            newHeading = view.getHeading().add(change);        }        this.orbitViewInputSupport.setHeadingSmoothing(smoothing);        this.orbitViewInputSupport.setHeadingTarget(view, newHeading);        view.firePropertyChange(AVKey.VIEW, null, view);    }    protected void changePitch(OrbitView view, Angle change, ViewInputAttributes.ActionAttributes attrib)    {        // Stop ViewStateIterators, so we are the only one affecting the view.        if (view.hasStateIterator())            view.stopStateIterators();        double smoothing = attrib.getSmoothingValue();        if (!(attrib.isEnableSmoothing() && this.isEnableSmoothing()))            smoothing = 0.0;        Angle newPitch;        if (smoothing != 0.0 && this.orbitViewInputSupport.getPitchTarget() != null)        {            newPitch = this.orbitViewInputSupport.getPitchTarget().add(change);        }        else        {            newPitch = view.getPitch().add(change);        }        this.orbitViewInputSupport.setPitchSmoothing(smoothing);        this.orbitViewInputSupport.setPitchTarget(view, newPitch);        view.firePropertyChange(AVKey.VIEW, null, view);    }    protected void changeZoom(OrbitView view, double change, ViewInputAttributes.ActionAttributes attrib)    {        // Stop ViewStateIterators, so we are the only one affecting the view.        if (view.hasStateIterator())            view.stopStateIterators();        double smoothing = attrib.getSmoothingValue();        if (!(attrib.isEnableSmoothing() && this.isEnableSmoothing()))            smoothing = 0.0;                double newZoom;        if (smoothing != 0.0 && this.orbitViewInputSupport.getZoomTarget() >= 0)        {            newZoom = computeNewZoomTarget(this.orbitViewInputSupport.getZoomTarget(), change);        }        else        {            newZoom = computeNewZoomTarget(view.getZoom(), change);        }        this.orbitViewInputSupport.setZoomSmoothing(smoothing);        this.orbitViewInputSupport.setZoomTarget(view, newZoom);        view.firePropertyChange(AVKey.VIEW, null, view);    }    protected static double computeNewZoomTarget(double curZoom, double change)    {        double logCurZoom = curZoom != 0 ? Math.log(curZoom) : 0;        return Math.exp(logCurZoom + change);    }}

⌨️ 快捷键说明

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