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

📄 segmentplaneeditor.java

📁 world wind java sdk 源码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        if (planeObject != null)
        {
            return planeObject.getPosition();
        }

        return null;
    }

    protected Position computeNewPositionFromPlaneIntersection(WorldWindow wwd, Point mousePoint)
    {
        View view = wwd.getView();
        Globe globe = wwd.getModel().getGlobe();
        
        Line ray = view.computeRayFromScreenPoint(mousePoint.getX(), mousePoint.getY());
        Plane plane = this.getSegmentPlane().computeInfinitePlane(globe);
        if (plane == null)
        {
            return null;
        }

        Vec4 newPoint = plane.intersect(ray);
        if (newPoint == null)
        {
            return null;
        }

        return globe.computePositionFromPoint(newPoint);
    }

    protected Position resizeSegmentPlaneToFitPosition(WorldWindow wwd, Position position)
    {
        Globe globe = wwd.getModel().getGlobe();
        double[] altitudes = this.getSegmentPlane().getPlaneAltitudes();
        double[] gridSizes = this.getSegmentPlane().getGridCellDimensions();
        LatLon[] locations = this.getSegmentPlane().getPlaneLocations();

        if (position.getElevation() < altitudes[0])
        {
            altitudes[0] = altitudes[0] + this.getNextGridStep(position.getElevation(), altitudes[0], gridSizes[1]);
        }
        if (position.getElevation() > altitudes[1])
        {
            altitudes[1] = altitudes[0] + this.getNextGridStep(position.getElevation(), altitudes[0], gridSizes[1]);
        }

        Vec4[] segment = new Vec4[2];
        segment[0] = globe.computePointFromPosition(locations[0].getLatitude(), locations[0].getLongitude(), altitudes[0]);
        segment[1] = globe.computePointFromPosition(locations[1].getLatitude(), locations[1].getLongitude(), altitudes[0]);
        Vec4 n = segment[1].subtract3(segment[0]).normalize3();
        double length = segment[0].distanceTo3(segment[1]);

        Vec4 point = globe.computePointFromPosition(position);
        Vec4 p = point.subtract3(segment[0]);
        double dot = p.dot3(n);

        // Resize only in the positive direction.
        if (dot > length)
        {
            double nextLength = this.getNextGridStep(dot, 0.0, gridSizes[0]);
            Vec4 nextPoint = segment[0].add3(n.multiply3(nextLength));
            locations[1] = new LatLon(globe.computePositionFromPoint(nextPoint));
        }
        if (dot < 0.0)
        {
            position = new Position(locations[0], position.getElevation());
        }
        
        this.getSegmentPlane().setPlaneAltitudes(altitudes[0], altitudes[1]);
        this.getSegmentPlane().setPlaneLocations(locations[0], locations[1]);

        return position;
    }

    //**************************************************************//
    //********************  Segment Plane Orientation/Length  ******//
    //**************************************************************//

    @SuppressWarnings({"UnusedDeclaration"})
    protected void doMoveLateralControlPoint(WorldWindow wwd, PickedObject pickedObject,
        Point mousePoint, Point previousMousePoint)
    {
        View view = wwd.getView();
        Globe globe = wwd.getModel().getGlobe();
        double[] altitudes = this.getSegmentPlane().getPlaneAltitudes();
        LatLon[] locations = this.getSegmentPlane().getPlaneLocations();

        Position pos = pickedObject.getPosition();
        Line ray = view.computeRayFromScreenPoint(mousePoint.getX(), mousePoint.getY());
        Intersection[] intersection = globe.intersect(ray, pos.getElevation());
        if (intersection == null || intersection.length < 0)
            return;

        Vec4 newPoint = intersection[0].getIntersectionPoint();
        LatLon newLatLon = new LatLon(globe.computePositionFromPoint(newPoint));

        Object id = pickedObject.getValue(AVKey.PICKED_OBJECT_ID);
        if (id.equals(SegmentPlane.CONTROL_POINT_LOWER_RIGHT)
            ||id.equals(SegmentPlane.CONTROL_POINT_UPPER_RIGHT))
        {
            locations[1] = newLatLon;
            this.moveSegmentLocationWithPlane(locations, SEGMENT_END_INDEX);
        }

        this.getSegmentPlane().setPlaneLocations(locations[0], locations[1]);
    }

    //**************************************************************//
    //********************  Segment Plane Height  ******************//
    //**************************************************************//

    @SuppressWarnings({"UnusedDeclaration"})
    protected void doMoveVerticalControlPoint(WorldWindow wwd, PickedObject pickedObject,
        Point mousePoint, Point previousMousePoint)
    {
        View view = wwd.getView();
        Globe globe = wwd.getModel().getGlobe();
        double[] altitudes = this.getSegmentPlane().getPlaneAltitudes();
        Position[] segmentPositions = this.getSegmentPlane().getSegmentPositions();

        Position pos = pickedObject.getPosition();
        Vec4 point = globe.computePointFromPosition(pos);

        Vec4 surfaceNormal = globe.computeSurfaceNormalAtPoint(point);
        Line verticalRay = new Line(point, surfaceNormal);
        Line screenRay = view.computeRayFromScreenPoint(mousePoint.getX(), mousePoint.getY());

        Vec4 pointOnLine = AirspaceEditorUtil.nearestPointOnLine(verticalRay, screenRay);
        Position newPos = globe.computePositionFromPoint(pointOnLine);

        altitudes[1] = newPos.getElevation();
        if (altitudes[1] < altitudes[0])
            altitudes[1] = altitudes[0];

        Position newBeginPosition = this.moveSegmentAltitudeWithPlane(segmentPositions[SEGMENT_BEGIN_INDEX], altitudes);
        Position newEndPosition = this.moveSegmentAltitudeWithPlane(segmentPositions[SEGMENT_END_INDEX], altitudes);

        if (newBeginPosition != null)
            this.getSegmentPlane().setSegmentBeginPosition(newBeginPosition);

        if (newEndPosition != null)
            this.getSegmentPlane().setSegmentEndPosition(newEndPosition);
        
        this.getSegmentPlane().setPlaneAltitudes(altitudes[0], altitudes[1]);
    }

    //**************************************************************//
    //********************  Segment Plane Length  ******************//
    //**************************************************************//

    @SuppressWarnings({"UnusedDeclaration"})
    protected void doMoveHorizontalControlPoint(WorldWindow wwd, PickedObject pickedObject, 
        Point mousePoint, Point previousMousePoint)
    {
        View view = wwd.getView();
        Globe globe = wwd.getModel().getGlobe();
        LatLon[] locations = this.getSegmentPlane().getPlaneLocations();

        Position pos = pickedObject.getPosition();
        Line ray = view.computeRayFromScreenPoint(mousePoint.getX(), mousePoint.getY());
        Intersection[] intersection = globe.intersect(ray, pos.getElevation());
        if (intersection == null || intersection.length < 0)
            return;

        Vec4 newPoint = intersection[0].getIntersectionPoint();
        LatLon newLatLon = new LatLon(globe.computePositionFromPoint(newPoint));

        Angle heading = LatLon.rhumbAzimuth(locations[0], locations[1]);
        Angle distance = LatLon.rhumbDistance(locations[0], newLatLon);

        locations[SEGMENT_END_INDEX] = LatLon.rhumbEndPosition(locations[0], heading, distance);

        this.moveSegmentLocationWithPlane(locations, SEGMENT_END_INDEX);
        this.getSegmentPlane().setPlaneLocations(locations[0], locations[1]);
    }

    //**************************************************************//
    //********************  Utility Methods  ***********************//
    //**************************************************************//

    protected Position moveSegmentAltitudeWithPlane(Position position, double[] minAndMaxElevation)
    {
        double elevation = position.getElevation();
        if (elevation >= minAndMaxElevation[0] && elevation <= minAndMaxElevation[1])
        {
            return null;
        }

        if (elevation < minAndMaxElevation[0])
            elevation = minAndMaxElevation[0];
        if (elevation > minAndMaxElevation[1])
            elevation = minAndMaxElevation[1];

        return new Position(position, elevation);
    }
    
    protected void moveSegmentLocationWithPlane(LatLon[] newPlaneLocations, int segmentPositionIndex)
    {
        LatLon[] planeLocations = this.getSegmentPlane().getPlaneLocations();
        Position segmentPosition = this.getSegmentPlane().getSegmentPositions()[segmentPositionIndex];

        if (segmentPositionIndex == SEGMENT_BEGIN_INDEX)
        {
            Position newSegmentPosition = new Position(newPlaneLocations[0], segmentPosition.getElevation());
            this.getSegmentPlane().setSegmentBeginPosition(newSegmentPosition);
        }
        else if (segmentPositionIndex == SEGMENT_END_INDEX)
        {
            Angle newHeading = LatLon.rhumbAzimuth(newPlaneLocations[0], newPlaneLocations[1]);

            Angle distance = LatLon.rhumbDistance(planeLocations[0], segmentPosition);
            Angle maxDistance = LatLon.rhumbDistance(newPlaneLocations[0], newPlaneLocations[1]);
            if (distance.compareTo(maxDistance) > 0)
                distance = maxDistance;

            LatLon newLatLon = LatLon.rhumbEndPosition(newPlaneLocations[0], newHeading, distance);
            Position newSegmentPosition = new Position(newLatLon, segmentPosition.getElevation());

            this.getSegmentPlane().setSegmentEndPosition(newSegmentPosition);
        }
    }

    protected PickedObject getPickedSegmentPlaneObject(WorldWindow wwd, Object pickedObjectId)
    {
        if (wwd.getSceneController().getPickedObjectList() == null)
        {
            return null;
        }

        for (PickedObject po : wwd.getSceneController().getPickedObjectList())
        {
            if (po != null && po.getObject() == this.getSegmentPlane())
            {
                Object id = po.getValue(AVKey.PICKED_OBJECT_ID);
                if (id == pickedObjectId)
                {
                    return po;
                }
            }
        }

        return null;
    }

    protected Position computePositionOnOrAboveSurface(WorldWindow wwd, Position position)
    {
        if (wwd.getSceneController().getTerrain() != null)
        {
            Vec4 point = wwd.getSceneController().getTerrain().getSurfacePoint(
                position.getLatitude(), position.getLongitude());
            if (point != null)
            {
                Position pos = wwd.getModel().getGlobe().computePositionFromPoint(point);
                if (position.getElevation() < pos.getElevation())
                    return new Position(position, pos.getElevation());
                return position;
            }
        }

        double elev = wwd.getModel().getGlobe().getElevation(position.getLatitude(), position.getLongitude());
        if (position.getElevation() < elev)
            return new Position(position, elev);

        return position;
    }

    protected double getNextGridStep(double value, double origin, double gridSize)
    {
        double x = Math.ceil((value - origin) / gridSize);
        return gridSize * x;
    }
}

⌨️ 快捷键说明

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