📄 segmentplanerenderer.java
字号:
} protected void resolvePlaneGridPick(DrawContext dc, SegmentPlane segmentPlane, RenderInfo renderInfo, java.awt.Point pickPoint, Layer layer) { PickedObject topObject = this.getTopPickedObject(dc, pickPoint, SegmentPlane.PLANE_GRID); 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 gridPoint = this.computeNearestGridLineToPoint(point, renderInfo); if (gridPoint == null) return; Position pos = dc.getGlobe().computePositionFromPoint(gridPoint); topObject.setPosition(pos); this.registerPickedObject(dc, topObject, layer); } //**************************************************************// //******************** Border Rendering **********************// //**************************************************************// @SuppressWarnings({"UnusedDeclaration"}) protected void drawPlaneBorder(DrawContext dc, SegmentPlane segmentPlane, RenderInfo renderInfo, java.awt.Point pickPoint, Layer layer) { if (!this.bindGeometryAttributes(dc, segmentPlane, SegmentPlane.PLANE_BORDER, false)) return; SegmentPlaneAttributes.GeometryAttributes attributes = segmentPlane.getAttributes().getGeometryAttributes( SegmentPlane.PLANE_BORDER); View view = dc.getView(); Globe globe = dc.getGlobe(); double[] altitudes = segmentPlane.getPlaneAltitudes(); LatLon[] locations = segmentPlane.getPlaneLocations(); int mask = segmentPlane.getBorderMask(); Vec4 p1 = globe.computePointFromPosition(locations[0].getLatitude(), locations[0].getLongitude(), altitudes[0]); Vec4 p2 = globe.computePointFromPosition(locations[0].getLatitude(), locations[0].getLongitude(), altitudes[1]); Vec4 referencePoint = p1.add3(p2).divide3(2.0); double size = this.computeObjectSize(view, globe, segmentPlane, SegmentPlane.PLANE_BORDER, referencePoint, dc.isPickingMode()); double height = altitudes[1] - altitudes[0]; GL gl = dc.getGL(); OGLStackHandler oglsh = new OGLStackHandler(); oglsh.pushModelview(gl); try { if ((mask & SegmentPlane.LEFT) != 0) { Matrix modelview = view.getModelviewMatrix(); modelview = modelview.multiply(globe.computeTransformToPosition( locations[0].getLatitude(), locations[0].getLongitude(), altitudes[0])); this.drawBorder(dc, renderInfo, modelview, size, height); } } finally { oglsh.pop(gl); } } protected void drawBorder(DrawContext dc, RenderInfo renderInfo, Matrix modelview, double radius, double height) { GL gl = dc.getGL(); double[] compArray = new double[16]; Matrix transform = Matrix.IDENTITY; transform = transform.multiply(modelview); transform = transform.multiply(Matrix.fromScale(radius, radius, height)); transform.toArray(compArray, 0, false); gl.glLoadMatrixd(compArray, 0); this.drawBorderCylinder(dc, renderInfo); transform = Matrix.IDENTITY; transform = transform.multiply(modelview); transform = transform.multiply(Matrix.fromScale(radius)); transform.toArray(compArray, 0, false); gl.glLoadMatrixd(compArray, 0); this.drawBorderCap(dc, renderInfo); transform = Matrix.IDENTITY; transform = transform.multiply(modelview); transform = transform.multiply(Matrix.fromTranslation(0, 0, height)); transform = transform.multiply(Matrix.fromScale(radius)); transform.toArray(compArray, 0, false); gl.glLoadMatrixd(compArray, 0); this.drawBorderCap(dc, renderInfo); } protected void drawBorderCylinder(DrawContext dc, RenderInfo renderInfo) { GL gl = dc.getGL(); gl.glVertexPointer(3, GL.GL_FLOAT, 0, renderInfo.borderCylinderVertices); gl.glNormalPointer(GL.GL_FLOAT, 0, renderInfo.borderCylinderNormals); gl.glDrawElements(GL.GL_TRIANGLE_STRIP, renderInfo.borderCylinderIndexCount, GL.GL_UNSIGNED_INT, renderInfo.borderCylinderIndices); } protected void drawBorderCap(DrawContext dc, RenderInfo renderInfo) { GL gl = dc.getGL(); gl.glVertexPointer(3, GL.GL_FLOAT, 0, renderInfo.borderCapVertices); gl.glNormalPointer(GL.GL_FLOAT, 0, renderInfo.borderCapNormals); gl.glDrawElements(GL.GL_TRIANGLE_STRIP, renderInfo.borderCapIndexCount, GL.GL_UNSIGNED_INT, renderInfo.borderCapIndices); } //**************************************************************// //******************** Segment Altimeter Rendering ***********// //**************************************************************// protected void drawSegmentAltimeter(DrawContext dc, SegmentPlane segmentPlane, RenderInfo renderInfo, java.awt.Point pickPoint, Layer layer) { this.drawSegmentAltimeterGeometry(dc, segmentPlane, renderInfo, pickPoint, layer); this.drawSegmentAltimeterLabel(dc, segmentPlane, renderInfo, pickPoint, layer); } @SuppressWarnings({"UnusedDeclaration"}) protected void drawSegmentAltimeterGeometry(DrawContext dc, SegmentPlane segmentPlane, RenderInfo renderInfo, java.awt.Point pickPoint, Layer layer) { if (!this.bindGeometryAttributesAsLine(dc, segmentPlane, SegmentPlane.ALTIMETER, false)) return; Globe globe = dc.getGlobe(); Position position = segmentPlane.getSegmentPositions()[1]; double surfaceElevation = this.computeSurfaceElevation(dc.getSurfaceGeometry(), globe, position.getLatitude(), position.getLongitude()); Vec4 v1 = globe.computePointFromPosition(position.getLatitude(), position.getLongitude(), position.getElevation()); Vec4 v2 = globe.computePointFromPosition(position.getLatitude(), position.getLongitude(), surfaceElevation); Vec4 referenceCenter = v1; v1 = v1.subtract3(referenceCenter); v2 = v2.subtract3(referenceCenter); if (!dc.isPickingMode()) { dc.getGL().glDisable(GL.GL_LIGHTING); } GL gl = dc.getGL(); OGLStackHandler oglsh = new OGLStackHandler(); // Modify the projection transform to shift the depth values slightly toward the camera in order to // ensure the lines are selected during depth buffering. double[] pm = new double[16]; gl.glGetDoublev(GL.GL_PROJECTION_MATRIX, pm, 0); pm[10] *= 0.99; // TODO: See Lengyel 2 ed. Section 9.1.2 to compute optimal/minimal offset oglsh.pushProjectionIdentity(gl); gl.glLoadMatrixd(pm, 0); dc.getView().pushReferenceCenter(dc, referenceCenter); gl.glBegin(GL.GL_LINES); try { gl.glVertex3d(v1.x, v1.y, v1.z); gl.glVertex3d(v2.x, v2.y, v2.z); } finally { gl.glEnd(); dc.getView().popReferenceCenter(dc); oglsh.pop(gl); } if (!dc.isPickingMode()) { dc.getGL().glEnable(GL.GL_LIGHTING); } } @SuppressWarnings({"UnusedDeclaration"}) protected void drawSegmentAltimeterLabel(DrawContext dc, SegmentPlane segmentPlane, RenderInfo renderInfo, java.awt.Point pickPoint, Layer layer) { if (!this.bindLabelAttributes(dc, segmentPlane, SegmentPlane.ALTIMETER)) return; SectorGeometryList sgl = dc.getSurfaceGeometry(); Globe globe = dc.getGlobe(); Position position = segmentPlane.getSegmentPositions()[1]; double surfaceElevation = this.computeSurfaceElevation(sgl, globe, position.getLatitude(), position.getLongitude()); double height = position.getElevation() - surfaceElevation; Position centerPos = new Position(position, surfaceElevation + (height / 2.0)); AVList values = new AVListImpl(); values.setValue(AVKey.HEIGHT, height); this.drawLabel(dc, segmentPlane, centerPos, values, SegmentPlane.ALTIMETER); } //**************************************************************// //******************** Control Point Rendering ***************// //**************************************************************// protected void drawControlPoints(DrawContext dc, SegmentPlane segmentPlane, RenderInfo renderInfo, java.awt.Point pickPoint, Layer layer) { SectorGeometryList sgl = dc.getSurfaceGeometry(); Globe globe = dc.getGlobe(); // Draw user-defined control points. for (SegmentPlane.ControlPoint controlPoint : segmentPlane.getControlPoints()) { Position pos = this.computeControlPointPosition(sgl, globe, segmentPlane, controlPoint); if (pos != null) { this.drawControlPoint(dc, segmentPlane, controlPoint, pos, renderInfo.controlPointShape); } } // Draw segment begin/end control points. Object[] keys = new Object[] {SegmentPlane.SEGMENT_BEGIN, SegmentPlane.SEGMENT_END}; Position[] positions = segmentPlane.getSegmentPositions(); for (int i = 0; i < 2; i++) { SegmentPlane.ControlPoint controlPoint = new SegmentPlane.ControlPoint(segmentPlane, keys[i], -1, -1, false); this.drawControlPoint(dc, segmentPlane, controlPoint, positions[i], renderInfo.controlPointShape); } if (dc.isPickingMode()) { this.resolveControlPointPick(dc, segmentPlane, renderInfo, pickPoint, layer); } } protected void drawControlPoint(DrawContext dc, SegmentPlane segmentPlane, SegmentPlane.ControlPoint controlPoint, Position position, MarkerShape shape) { ControlPointInfo controlPointInfo = new ControlPointInfo(controlPoint, position, shape); this.drawControlPointGeometry(dc, segmentPlane, controlPointInfo); this.drawControlPointLabel(dc, segmentPlane, controlPoint, position); } protected void drawControlPointGeometry(DrawContext dc, SegmentPlane segmentPlane, ControlPointInfo controlPointInfo) { Object key = controlPointInfo.controlPoint.getKey(); if (!this.bindGeometryAttributes(dc, segmentPlane, key, true)) return; SegmentPlaneAttributes.GeometryAttributes attributes = segmentPlane.getAttributes().getGeometryAttributes(key); if (attributes == null || !attributes.isVisible()) return; GL gl = dc.getGL(); View view = dc.getView(); Globe globe = dc.getGlobe(); Vec4 point = globe.computePointFromPosition(controlPointInfo.position); double minSize = this.getMinObjectSize(); double maxSize = this.computeMaxSizeForPixels(globe, segmentPlane); double sizeScale = this.computeSizeForPixels(view, point, 1.0, minSize, maxSize); // Apply the control point offset in the local coordinate system at the control point's position. Treat offset // coordinates as pixel sizes, so the final coordinate must also be scaled by the eye distance. Use the // original point to compute the scale factor, so that the offset doesn't change the control point's size. Matrix transformToPosition = globe.computeTransformToPosition(controlPointInfo.position); Vec4 offset = attributes.getOffset(); offset = offset.multiply3(sizeScale); offset = offset.transformBy3(transformToPosition); // Add the adjusted offset to the Cartesian point, and recompute the control point's offset geographic position. point = point.add3(offset); controlPointInfo.position = globe.computePositionFromPoint(point); if (dc.isPickingMode()) { PickedObject po = this.bindPickableObject(dc, controlPointInfo.controlPoint, controlPointInfo.controlPoint.getKey()); po.setPosition(controlPointInfo.position); } OGLStackHandler ogsh = new OGLStackHandler(); ogsh.pushModelview(gl); try { double size = sizeScale * (dc.isPickingMode() ? attributes.getPicksize() : attributes.getSize()); controlPointInfo.shape.render(dc, null, point, size); } finally { ogsh.pop(gl); } } protected void drawControlPointLabel(DrawContext dc, SegmentPlane segmentPlane, SegmentPlane.ControlPoint controlPoint, Position position) { if (!this.bindLabelAttributes(dc, segmentPlane, controlPoint.getKey())) return; double surfaceElevation = this.computeSurfaceElevation(dc.getSurfaceGeometry(), dc.getGlobe(), position.getLatitude(), position.getLongitude()); double height = position.getElevation() - surfaceElevation; AVList values = new AVListImpl(); values.setValue(AVKey.HEIGHT, height); this.drawLabel(dc, segmentPlane, position, values, controlPoint.getKey()); } @SuppressWarnings({"UnusedDeclaration"}) protected void resolveControlPointPick(DrawContext dc, SegmentPlane segmentPlane, RenderInfo renderInfo, java.awt.Point pickPoint, Layer layer) { PickedObject topObject = null; // Pick user-defined control points. for (SegmentPlane.ControlPoint controlPoint : segmentPlane.getControlPoints()) { if ((topObject = this.getTopPickedObject(dc, pickPoint, controlPoint.getKey())) != null) { break; } } if (topObject == null) { // Pick segment begin/end control points. Object[] keys = new Object[] {SegmentPlane.SEGMENT_BEGIN, SegmentPlane.SEGMENT_END}; for (Object key : keys) { if ((topObject = this.getTopPickedObject(dc, pickPoint, key)) != null) { break;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -