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

📄 segmentplanerenderer.java

📁 world wind java sdk 源码
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
        ogsh.pop(gl);    }    protected boolean bindGeometryAttributes(DrawContext dc, SegmentPlane segmentPlane, Object key, boolean pickable)    {        if (dc.isPickingMode() && !pickable)            return false;        SegmentPlaneAttributes.GeometryAttributes attributes = segmentPlane.getAttributes().getGeometryAttributes(key);        if (attributes == null || !attributes.isVisible())            return false;        if (dc.isPickingMode())        {            this.bindPickableObject(dc, segmentPlane, key);        }        SegmentPlaneAttributes.applyGeometryAttributes(dc, attributes, true);        return true;    }    protected boolean bindGeometryAttributesAsLine(DrawContext dc, SegmentPlane segmentPlane, Object key,        boolean pickable)    {        if (dc.isPickingMode() && !pickable)            return false;        SegmentPlaneAttributes.GeometryAttributes attributes = segmentPlane.getAttributes().getGeometryAttributes(key);        if (attributes == null || !attributes.isVisible())            return false;        if (dc.isPickingMode())        {            this.bindPickableObject(dc, segmentPlane, key);        }        SegmentPlaneAttributes.applyGeometryAttributes(dc, attributes, false);        SegmentPlaneAttributes.applyGeometryAttributesAsLine(dc, attributes);        return true;    }    protected boolean bindLabelAttributes(DrawContext dc, SegmentPlane segmentPlane, Object key)    {        if (dc.isPickingMode())            return false;        SegmentPlaneAttributes.LabelAttributes attributes = segmentPlane.getAttributes().getLabelAttributes(key);        //noinspection RedundantIfStatement        if (attributes == null || !attributes.isVisible())            return false;        return true;    }    protected PickedObject bindPickableObject(DrawContext dc, Object userObject, Object objectId)    {        java.awt.Color pickColor = dc.getUniquePickColor();        int colorCode = pickColor.getRGB();        dc.getGL().glColor3ub((byte) pickColor.getRed(), (byte) pickColor.getGreen(), (byte) pickColor.getBlue());        PickedObject po = new PickedObject(colorCode, userObject);        po.setValue(AVKey.PICKED_OBJECT_ID, objectId);        this.pickSupport.addPickableObject(po);        return po;    }    protected PickedObject getTopPickedObject(DrawContext dc, java.awt.Point pickPoint, Object pickedObjectId)    {        PickedObject topObject = this.pickSupport.getTopObject(dc, pickPoint);        if (topObject == null)        {            return null;        }        Object id = topObject.getValue(AVKey.PICKED_OBJECT_ID);        if (id != pickedObjectId)        {            return null;        }        return topObject;    }    protected void registerPickedObject(DrawContext dc, PickedObject pickedObject, Layer layer)    {        if (layer != null)        {            pickedObject.setParentLayer(layer);        }        dc.addPickedObject(pickedObject);    }    //**************************************************************//    //********************  Plane Geometry  ************************//    //**************************************************************//    protected Position computePositionOnPlane(SectorGeometryList sgl, Globe globe, SegmentPlane segmentPlane,        double u, double v, boolean relativeToSurface)    {        double[] altitudes = segmentPlane.getPlaneAltitudes();        LatLon[] locations = segmentPlane.getPlaneLocations();        Angle heading = LatLon.rhumbAzimuth(locations[0], locations[1]);        Angle distance = LatLon.rhumbDistance(locations[0], locations[1]);        Angle d = Angle.fromDegrees(distance.degrees * u);        LatLon location = LatLon.rhumbEndPosition(locations[0], heading, d);        double altitude;        if (relativeToSurface)        {            double surfaceElevation = this.computeSurfaceElevation(sgl, globe,                location.getLatitude(), location.getLongitude());            altitude = surfaceElevation + v * (altitudes[1] - surfaceElevation);        }        else        {            altitude = altitudes[0] + v * (altitudes[1] - altitudes[0]);        }        return new Position(location, altitude);    }        protected double computeSurfaceElevation(SectorGeometryList sgl, Globe globe, Angle latitude, Angle longitude)    {        if (sgl != null)        {            Vec4 surfacePoint = sgl.getSurfacePoint(latitude, longitude);            if (surfacePoint != null)            {                Position surfacePos = globe.computePositionFromPoint(surfacePoint);                return surfacePos.getElevation();            }        }        return globe.getElevation(latitude, longitude);    }    protected void computePlaneParameterization(Globe globe, SegmentPlane segmentPlane,        int[] gridCellCounts, double[] gridCellParams)    {        double[] altitudes = segmentPlane.getPlaneAltitudes();        LatLon[] locations = segmentPlane.getPlaneLocations();        double[] gridSizes = segmentPlane.getGridCellDimensions();        double width = LatLon.rhumbDistance(locations[0], locations[1]).radians * globe.getRadius();        double height = Math.abs(altitudes[1] - altitudes[0]);        gridCellCounts[0] = (int) Math.ceil(width / gridSizes[0]);        gridCellCounts[1] = (int) Math.ceil(height / gridSizes[1]);        gridCellParams[0] = (width != 0) ? (gridSizes[0] / width) : 0;        gridCellParams[1] = (height != 0) ? (gridSizes[1] / height) : 0;    }    protected double computeObjectSize(View view, Globe globe, SegmentPlane segmentPlane, Object key, Vec4 point,        boolean usePickSize)    {        SegmentPlaneAttributes.GeometryAttributes attributes =            segmentPlane.getAttributes().getGeometryAttributes(key);        if (attributes == null)        {            return 0.0;        }        double minSize = this.getMinObjectSize();        double maxSize = this.computeMaxSizeForPixels(globe, segmentPlane);        double sizeScale = this.computeSizeForPixels(view, point, 1.0, minSize, maxSize);        return sizeScale * (usePickSize ? attributes.getPicksize() : attributes.getSize());    }    // TODO: identical to a method in MarkerRenderer; consolidate usage in a general place    protected double computeSizeForPixels(View view, Vec4 point, double pixels, double minSize, double maxSize)    {        double d = point.distanceTo3(view.getEyePoint());        double radius = pixels * view.computePixelSizeAtDistance(d);        if (radius < minSize)            radius = minSize;        else if (radius > maxSize)            radius = maxSize;        return radius;    }    protected double computeMaxSizeForPixels(Globe globe, SegmentPlane segmentPlane)    {        double[] altitudes = segmentPlane.getPlaneAltitudes();        LatLon[] locations = segmentPlane.getPlaneLocations();        Vec4[] corners = new Vec4[] {            globe.computePointFromPosition(locations[0].getLatitude(), locations[0].getLongitude(), altitudes[0]),            globe.computePointFromPosition(locations[1].getLatitude(), locations[1].getLongitude(), altitudes[0]),            globe.computePointFromPosition(locations[1].getLatitude(), locations[1].getLongitude(), altitudes[1]),            globe.computePointFromPosition(locations[0].getLatitude(), locations[0].getLongitude(), altitudes[1])};        double distance = Vec4.getAverageDistance(Arrays.asList(corners));        return distance * this.getMaxObjectSizeCoefficient();    }    //**************************************************************//    //********************  Plane Rendering  ***********************//    //**************************************************************//    protected void drawPlaneGeometry(DrawContext dc, SegmentPlane segmentPlane, RenderInfo renderInfo,        java.awt.Point pickPoint, Layer layer)    {        dc.getView().pushReferenceCenter(dc, renderInfo.planeReferenceCenter);        try        {            this.bindPlaneVertexGeometry(dc, renderInfo);            this.drawPlaneBackground(dc, segmentPlane, renderInfo, pickPoint, layer);            this.drawPlaneGrid(dc, segmentPlane, renderInfo, pickPoint, layer);            this.drawPlaneOutline(dc, segmentPlane, renderInfo, pickPoint, layer);        }        finally        {            dc.getView().popReferenceCenter(dc);        }    }    protected void drawPlaneBackground(DrawContext dc, SegmentPlane segmentPlane, RenderInfo renderInfo,        java.awt.Point pickPoint, Layer layer)    {        if (!this.bindGeometryAttributes(dc, segmentPlane, SegmentPlane.PLANE_BACKGROUND, true))            return;        this.drawPlaneFillElements(dc, renderInfo);        if (dc.isPickingMode())        {            this.resolvePlaneBackgroundPick(dc, segmentPlane, renderInfo, pickPoint, layer);        }    }    @SuppressWarnings({"UnusedDeclaration"})    protected void drawPlaneOutline(DrawContext dc, SegmentPlane segmentPlane, RenderInfo renderInfo,        java.awt.Point pickPoint, Layer layer)    {        if (!this.bindGeometryAttributesAsLine(dc, segmentPlane, SegmentPlane.PLANE_OUTLINE, false))            return;        if (!dc.isPickingMode())        {            dc.getGL().glDisable(GL.GL_LIGHTING);        }        this.drawPlaneOutlineElements(dc, renderInfo);        if (!dc.isPickingMode())        {            dc.getGL().glEnable(GL.GL_LIGHTING);        }    }    protected void drawPlaneGrid(DrawContext dc, SegmentPlane segmentPlane, RenderInfo renderInfo,        java.awt.Point pickPoint, Layer layer)    {        if (!this.bindGeometryAttributesAsLine(dc, segmentPlane, SegmentPlane.PLANE_GRID, true))            return;        if (!dc.isPickingMode())        {            dc.getGL().glDisable(GL.GL_LIGHTING);        }        this.drawPlaneGridElements(dc, renderInfo);        if (!dc.isPickingMode())        {            dc.getGL().glEnable(GL.GL_LIGHTING);        }        else        {            this.resolvePlaneGridPick(dc, segmentPlane, renderInfo, pickPoint, layer);        }    }    protected void bindPlaneVertexGeometry(DrawContext dc, RenderInfo renderInfo)    {        dc.getGL().glVertexPointer(3, GL.GL_DOUBLE, 0, renderInfo.planeVertices);        dc.getGL().glNormalPointer(GL.GL_DOUBLE, 0, renderInfo.planeNormals);    }    protected void drawPlaneFillElements(DrawContext dc, RenderInfo renderInfo)    {        dc.getGL().glEnable(GL.GL_POLYGON_OFFSET_FILL);        dc.getGL().glPolygonOffset(1f, 1f);        dc.getGL().glDrawElements(GL.GL_TRIANGLE_STRIP, renderInfo.planeFillIndexCount, GL.GL_UNSIGNED_INT,            renderInfo.planeFillIndices);        dc.getGL().glDisable(GL.GL_POLYGON_OFFSET_FILL);    }    protected void drawPlaneOutlineElements(DrawContext dc, RenderInfo renderInfo)    {        dc.getGL().glDrawElements(GL.GL_LINES, renderInfo.planeOutlineIndexCount, GL.GL_UNSIGNED_INT,            renderInfo.planeOutlineIndices);    }    protected void drawPlaneGridElements(DrawContext dc, RenderInfo renderInfo)    {        dc.getGL().glDrawElements(GL.GL_LINES, renderInfo.planeGridIndexCount, GL.GL_UNSIGNED_INT,            renderInfo.planeGridIndices);    }    @SuppressWarnings({"UnusedDeclaration"})    protected void resolvePlaneBackgroundPick(DrawContext dc, SegmentPlane segmentPlane, RenderInfo renderInfo,        java.awt.Point pickPoint, Layer layer)    {        PickedObject topObject = this.getTopPickedObject(dc, pickPoint, SegmentPlane.PLANE_BACKGROUND);        if (topObject == null)            return;        Line ray = dc.getView().computeRayFromScreenPoint(pickPoint.getX(), pickPoint.getY());        Vec4 point = this.intersectRayWithFill(ray, renderInfo);        if (point == null)            return;        Position pos = dc.getGlobe().computePositionFromPoint(point);        topObject.setPosition(pos);        this.registerPickedObject(dc, topObject, layer);    }    protected void resolvePlaneOutlinePick(DrawContext dc, SegmentPlane segmentPlane, RenderInfo renderInfo,        java.awt.Point pickPoint, Layer layer)    {        PickedObject topObject = this.getTopPickedObject(dc, pickPoint, SegmentPlane.PLANE_OUTLINE);        if (topObject == null)            return;        Line ray = dc.getView().computeRayFromScreenPoint(pickPoint.getX(), pickPoint.getY());        Plane plane = segmentPlane.computeInfinitePlane(dc.getGlobe());        if (plane == null)            return;        Vec4 point = plane.intersect(ray);        if (point == null)            return;        Vec4 outlinePoint = this.computeNearestOutlineToPoint(point, renderInfo);        if (outlinePoint == null)            return;        Position pos = dc.getGlobe().computePositionFromPoint(outlinePoint);        topObject.setPosition(pos);        this.registerPickedObject(dc, topObject, layer);

⌨️ 快捷键说明

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