📄 basicmarkershape.java
字号:
{ @Override protected void initialize(DrawContext dc) { super.initialize(dc); this.name = "Cone"; this.shapeType = BasicMarkerShape.CONE; int slices = 30; int stacks = 30; int loops = 2; dc.getGL().glNewList(this.glListId, GL.GL_COMPILE); dc.getGLU().gluQuadricOrientation(quadric, GLU.GLU_OUTSIDE); dc.getGLU().gluCylinder(quadric, 1d, 0d, 2d, slices, (int) (2 * (Math.sqrt(stacks)) + 1)); dc.getGLU().gluDisk(quadric, 0d, 1d, slices, loops); dc.getGL().glEndList(); this.isInitialized = true; } protected void doRender(DrawContext dc, Marker marker, Vec4 point, double size) { // This performs the same operation as Vec4.axisAngle() but with a "v2" of <0, 0, 1>. Vec4 normal = dc.getGlobe().computeSurfaceNormalAtPoint(point); // Compute rotation angle Angle angle = Angle.fromRadians(Math.acos(normal.z)); // Compute the direction cosine factors that define the rotation axis double A = -normal.y; double B = normal.x; double L = Math.sqrt(A * A + B * B); dc.getGL().glRotated(angle.degrees, A / L, B / L, 0); // shape normal to the globe dc.getGL().glScaled(size, size, size); // scale dc.getGL().glCallList(this.glListId); // draw } } protected static class Cylinder extends Shape { @Override protected void initialize(DrawContext dc) { super.initialize(dc); this.name = "Cylinder"; this.shapeType = BasicMarkerShape.CYLINDER; int slices = 30; int stacks = 1; int loops = 1; dc.getGL().glNewList(this.glListId, GL.GL_COMPILE); dc.getGLU().gluCylinder(quadric, 1d, 1d, 2d, slices, (int) (2 * (Math.sqrt(stacks)) + 1)); dc.getGLU().gluDisk(quadric, 0d, 1d, slices, loops); dc.getGL().glTranslated(0, 0, 2); dc.getGLU().gluDisk(quadric, 0d, 1d, slices, loops); dc.getGL().glTranslated(0, 0, -2); dc.getGL().glEndList(); this.isInitialized = true; } protected void doRender(DrawContext dc, Marker marker, Vec4 point, double size) { // This performs the same operation as Vec4.axisAngle() but with a "v2" of <0, 0, 1>. Vec4 normal = dc.getGlobe().computeSurfaceNormalAtPoint(point); // Compute rotation angle Angle angle = Angle.fromRadians(Math.acos(normal.z)); // Compute the direction cosine factors that define the rotation axis double A = -normal.y; double B = normal.x; double L = Math.sqrt(A * A + B * B); dc.getGL().glRotated(angle.degrees, A / L, B / L, 0); // shape normal to the globe dc.getGL().glScaled(size, size, size); // scale dc.getGL().glCallList(this.glListId); // draw } } protected static class HeadingLine extends Shape { @Override protected void initialize(DrawContext dc) { super.initialize(dc); this.name = "Heading Line"; this.shapeType = BasicMarkerShape.HEADING_LINE; dc.getGL().glNewList(this.glListId, GL.GL_COMPILE); dc.getGL().glBegin(GL.GL_LINE_STRIP); dc.getGL().glNormal3f(0f, 1f, 0f); dc.getGL().glVertex3d(0, 0, 0); dc.getGL().glVertex3d(0, 0, 1); dc.getGL().glEnd(); dc.getGL().glEndList(); this.isInitialized = true; } protected void doRender(DrawContext dc, Marker marker, Vec4 point, double size) { GL gl = dc.getGL(); MarkerAttributes attrs = marker.getAttributes(); if (marker.getHeading() == null) return; // Apply heading material if different from marker's if (!dc.isPickingMode() && attrs.getHeadingMaterial() != null && !attrs.getHeadingMaterial().equals(attrs.getMaterial())) { if (attrs.getOpacity() < 1) attrs.getHeadingMaterial().apply(dc.getGL(), GL.GL_FRONT, (float) attrs.getOpacity()); else attrs.getHeadingMaterial().apply(dc.getGL(), GL.GL_FRONT); } // To compute rotation of the line axis toward the proper heading, find a second point in that direction. Position pos = dc.getGlobe().computePositionFromPoint(point); LatLon p2ll = LatLon.greatCircleEndPosition(pos, marker.getHeading(), Angle.fromDegrees(.1)); Vec4 p2 = dc.getGlobe().computePointFromPosition(p2ll.getLatitude(), p2ll.getLongitude(), pos.getElevation()); // This method then performs the same operation as Vec4.axisAngle() but with a "v2" of <0, 0, 1>. Vec4 p1p2 = p2.subtract3(point).normalize3(); // Compute rotation angle Angle directionAngle = Angle.fromRadians(Math.acos(p1p2.z)); // Compute the direction cosine factors that define the rotation axis double A = -p1p2.y; double B = p1p2.x; double L = Math.sqrt(A * A + B * B); gl.glRotated(directionAngle.degrees, A / L, B / L, 0); // point line toward p2 double scale = attrs.getHeadingScale() * size; gl.glScaled(scale, scale, scale); // scale dc.getGL().glCallList(this.glListId); // draw // Restore the marker material if the heading material was applied if (!dc.isPickingMode() && attrs.getHeadingMaterial() != null && !attrs.getHeadingMaterial().equals(attrs.getMaterial())) attrs.apply(dc); } } protected static class HeadingArrow extends Shape { @Override protected void initialize(DrawContext dc) { super.initialize(dc); this.name = "Heading Arrow"; this.shapeType = BasicMarkerShape.HEADING_ARROW; dc.getGL().glNewList(this.glListId, GL.GL_COMPILE); dc.getGL().glBegin(GL.GL_POLYGON); dc.getGL().glNormal3f(0f, 1f, 0f); dc.getGL().glVertex3d(-.5, 0, 0); dc.getGL().glVertex3d(0, 0, 1); dc.getGL().glVertex3d(.5, 0, 0); dc.getGL().glVertex3d(-.5, 0, 0); dc.getGL().glEnd(); dc.getGL().glEndList(); this.isInitialized = true; } protected void doRender(DrawContext dc, Marker marker, Vec4 point, double size) { GL gl = dc.getGL(); MarkerAttributes attrs = marker.getAttributes(); if (marker.getHeading() == null) return; // Apply heading material if different from marker's if (!dc.isPickingMode() && attrs.getHeadingMaterial() != null && !attrs.getHeadingMaterial().equals(attrs.getMaterial())) { if (attrs.getOpacity() < 1) attrs.getHeadingMaterial().apply(dc.getGL(), GL.GL_FRONT, (float) attrs.getOpacity()); else attrs.getHeadingMaterial().apply(dc.getGL(), GL.GL_FRONT); } // To compute rotation of the arrow axis toward the proper heading, find a second point in that direction. Position pos = dc.getGlobe().computePositionFromPoint(point); LatLon p2ll = LatLon.greatCircleEndPosition(pos, marker.getHeading(), Angle.fromDegrees(.1)); Vec4 p2 = dc.getGlobe().computePointFromPosition(p2ll.getLatitude(), p2ll.getLongitude(), pos.getElevation()); // This method then performs the same operation as Vec4.axisAngle() but with a "v2" of <0, 0, 1>. Vec4 p1p2 = p2.subtract3(point).normalize3(); // Compute rotation angle Angle directionAngle = Angle.fromRadians(Math.acos(p1p2.z)); // Compute the direction cosine factors that define the rotation axis double A = -p1p2.y; double B = p1p2.x; double L = Math.sqrt(A * A + B * B); // Compute rotation angle on z (roll) to keep the arrow plane parallel to the ground Vec4 horizontalVector = dc.getGlobe().computeSurfaceNormalAtPoint(point).cross3(p1p2); Vec4 rotatedX = Vec4.UNIT_X.transformBy3(Matrix.fromAxisAngle(directionAngle, A / L, B / L, 0)); Angle rollAngle = rotatedX.angleBetween3(horizontalVector); // Find out which way to do the roll double rollDirection = Math.signum(-horizontalVector.cross3(rotatedX).dot3(p1p2)); gl.glRotated(directionAngle.degrees, A / L, B / L, 0); // point arrow toward p2 gl.glRotated(rollAngle.degrees, 0, 0, rollDirection); // roll arrow to keep it parallel to the ground double scale = attrs.getHeadingScale() * size; gl.glScaled(scale, scale, scale); // scale dc.getGL().glCallList(this.glListId); // draw // Restore the marker material if the heading material was applied if (!dc.isPickingMode() && attrs.getHeadingMaterial() != null && !attrs.getHeadingMaterial().equals(attrs.getMaterial())) attrs.apply(dc); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -