orbit.java
来自「world wind java sdk 源码」· Java 代码 · 共 827 行 · 第 1/3 页
JAVA
827 行
{ String message = Logging.getMessage("generic.ArgumentOutOfRange", "lengthSlices=" + lengthSlices); Logging.logger().severe(message); throw new IllegalArgumentException(message); } this.lengthSlices = lengthSlices; } protected int getStacks() { return this.stacks; } protected int getLoops() { return this.loops; } protected void setLoops(int loops) { if (loops < 0) { String message = Logging.getMessage("generic.ArgumentOutOfRange", "loops=" + loops); Logging.logger().severe(message); throw new IllegalArgumentException(message); } this.loops = loops; } //**************************************************************// //******************** Geometry Rendering ********************// //**************************************************************// protected Vec4 computeReferenceCenter(DrawContext dc) { if (dc == null) { String message = Logging.getMessage("nullValue.DrawContextIsNull"); Logging.logger().severe(message); throw new IllegalArgumentException(message); } if (dc.getGlobe() == null) { String message = Logging.getMessage("nullValue.DrawingContextGlobeIsNull"); Logging.logger().severe(message); throw new IllegalArgumentException(message); } Globe globe = dc.getGlobe(); double[] altitudes = this.getAltitudes(dc.getVerticalExaggeration()); Vec4 point1 = globe.computePointFromPosition( this.location1.getLatitude(), this.location1.getLongitude(), altitudes[0]); Vec4 point2 = globe.computePointFromPosition( this.location2.getLatitude(), this.location2.getLongitude(), altitudes[0]); Vec4 centerPoint = Vec4.mix3(0.5, point1, point2); Position centerPos = globe.computePositionFromPoint(centerPoint); return globe.computePointFromPosition(centerPos.getLatitude(), centerPos.getLongitude(), altitudes[0]); } protected Matrix computeTransform(DrawContext dc) { if (dc == null) { String message = Logging.getMessage("nullValue.DrawContextIsNull"); Logging.logger().severe(message); throw new IllegalArgumentException(message); } if (dc.getGlobe() == null) { String message = Logging.getMessage("nullValue.DrawingContextGlobeIsNull"); Logging.logger().severe(message); throw new IllegalArgumentException(message); } Globe globe = dc.getGlobe(); double[] altitudes = this.getAltitudes(dc.getVerticalExaggeration()); double radius = this.width / 2.0; Vec4 point1 = globe.computePointFromPosition( this.location1.getLatitude(), this.location1.getLongitude(), altitudes[0]); Vec4 point2 = globe.computePointFromPosition( this.location2.getLatitude(), this.location2.getLongitude(), altitudes[0]); Vec4 centerPoint = Vec4.mix3(0.5, point1, point2); Vec4 upVec = globe.computeSurfaceNormalAtPoint(centerPoint); Vec4 axis = point2.subtract3(point1); axis = axis.normalize3(); Matrix transform = Matrix.fromModelLookAt(point1, point1.add3(upVec), axis); if (OrbitType.LEFT.equals(this.orbitType)) transform = transform.multiply(Matrix.fromTranslation(-radius, 0.0, 0.0)); else if (OrbitType.RIGHT.equals(this.orbitType)) transform = transform.multiply(Matrix.fromTranslation(radius, 0.0, 0.0)); return transform; } protected Extent doComputeExtent(DrawContext dc) { if (dc == null) { String message = Logging.getMessage("nullValue.DrawContextIsNull"); Logging.logger().severe(message); throw new IllegalArgumentException(message); } if (dc.getGlobe() == null) { String message = Logging.getMessage("nullValue.DrawingContextGlobeIsNull"); Logging.logger().severe(message); throw new IllegalArgumentException(message); } Globe globe = dc.getGlobe(); Matrix transform = this.computeTransform(dc); Vec4 point1 = globe.computePointFromPosition(this.location1.getLatitude(), this.location1.getLongitude(), 0.0); Vec4 point2 = globe.computePointFromPosition(this.location2.getLatitude(), this.location2.getLongitude(), 0.0); double radius = this.width / 2.0; double length = point1.distanceTo3(point2); GeometryBuilder gb = this.getGeometryBuilder(); int count = gb.getLongCylinderVertexCount(4, 4, 0); int numCoords = 3 * count; float[] verts = new float[numCoords]; gb.makeLongCylinderVertices((float) radius, (float) length, 0.0f, 4, 4, 0, verts); List<LatLon> locations = new ArrayList<LatLon>(); for (int i = 0; i < numCoords; i += 3) { Vec4 v = new Vec4(verts[i], verts[i + 1], verts[i + 2]); v = v.transformBy4(transform); locations.add(globe.computePositionFromPoint(v)); } return this.computeBoundingCylinder(dc, locations); } protected void doRenderGeometry(DrawContext dc, String drawStyle) { if (dc == null) { String message = Logging.getMessage("nullValue.DrawContextIsNull"); Logging.logger().severe(message); throw new IllegalArgumentException(message); } if (dc.getGL() == null) { String message = Logging.getMessage("nullValue.DrawingContextGLIsNull"); Logging.logger().severe(message); throw new IllegalArgumentException(message); } if (dc.getGlobe() == null) { String message = Logging.getMessage("nullValue.DrawingContextGlobeIsNull"); Logging.logger().severe(message); throw new IllegalArgumentException(message); } double[] altitudes = this.getAltitudes(dc.getVerticalExaggeration()); boolean[] terrainConformant = this.isTerrainConforming(); double[] radii = new double[] {0.0, this.width / 2}; String type = this.orbitType; int arcSlices = this.arcSlices; int lengthSlices = this.lengthSlices; int stacks = this.stacks; int loops = this.loops; Globe globe = dc.getGlobe(); Vec4 point1 = globe.computePointFromPosition( this.location1.getLatitude(), this.location1.getLongitude(), altitudes[0]); Vec4 point2 = globe.computePointFromPosition( this.location2.getLatitude(), this.location2.getLongitude(), altitudes[0]); double length = point1.distanceTo3(point2); if (this.isEnableLevelOfDetail()) { DetailLevel level = this.computeDetailLevel(dc); Object o = level.getValue(ARC_SLICES); if (o != null && o instanceof Integer) arcSlices = (Integer) o; o = level.getValue(LENGTH_SLICES); if (o != null && o instanceof Integer) lengthSlices = (Integer) o; o = level.getValue(STACKS); if (o != null && o instanceof Integer) stacks = (Integer) o; o = level.getValue(LOOPS); if (o != null && o instanceof Integer) loops = (Integer) o; o = level.getValue(DISABLE_TERRAIN_CONFORMANCE); if (o != null && o instanceof Boolean && ((Boolean) o)) terrainConformant[0] = terrainConformant[1] = false; } Vec4 referenceCenter = this.computeReferenceCenter(dc); this.setExpiryTime(this.nextExpiryTime(dc, terrainConformant)); this.clearElevationMap(); GL gl = dc.getGL(); dc.getView().pushReferenceCenter(dc, referenceCenter); if (Airspace.DRAW_STYLE_OUTLINE.equals(drawStyle)) { this.drawLongCylinderOutline(dc, radii[1], length, altitudes, terrainConformant, type, arcSlices, lengthSlices, stacks, GeometryBuilder.OUTSIDE, referenceCenter); } else if (Airspace.DRAW_STYLE_FILL.equals(drawStyle)) { if (this.enableCaps) { gl.glPushAttrib(GL.GL_POLYGON_BIT); gl.glEnable(GL.GL_CULL_FACE); gl.glFrontFace(GL.GL_CCW); } if (this.enableCaps) { // Caps aren't rendered if radii are equal. if (radii[0] != radii[1]) { this.drawLongDisk(dc, radii, length, altitudes[1], terrainConformant[1], type, arcSlices, lengthSlices, loops, GeometryBuilder.OUTSIDE, referenceCenter); // Bottom cap isn't rendered if airspace is collapsed. if (!this.isAirspaceCollapsed()) { this.drawLongDisk(dc, radii, length, altitudes[0], terrainConformant[0], type, arcSlices, lengthSlices, loops, GeometryBuilder.INSIDE, referenceCenter); } } } // Long cylinder isn't rendered if airspace is collapsed. if (!this.isAirspaceCollapsed()) { this.drawLongCylinder(dc, radii[1], length, altitudes, terrainConformant, type, arcSlices, lengthSlices, stacks, GeometryBuilder.OUTSIDE, referenceCenter); } if (this.enableCaps) { gl.glPopAttrib(); } } dc.getView().popReferenceCenter(dc); } //**************************************************************// //******************** Long Cylinder ********************// //**************************************************************// private void drawLongCylinder(DrawContext dc, double radius, double length, double[] altitudes, boolean[] terrainConformant, String type, int arcSlices, int lengthSlices, int stacks, int orientation, Vec4 referenceCenter) { Geometry vertexGeom = createLongCylinderVertexGeometry(dc, radius, length, altitudes, terrainConformant, type, arcSlices, lengthSlices, stacks, orientation, referenceCenter); Object cacheKey = new Geometry.CacheKey(this.getClass(), "LongCylinder.Indices", arcSlices, lengthSlices, stacks, orientation); Geometry indexGeom = (Geometry) this.getGeometryCache().getObject(cacheKey); if (indexGeom == null) { indexGeom = new Geometry(); this.makeLongCylinderIndices(arcSlices, lengthSlices, stacks, orientation, indexGeom); this.getGeometryCache().add(cacheKey, indexGeom); }
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?