📄 basicmarkershape.java
字号:
/*Copyright (C) 2001, 2008 United States Governmentas represented by the Administrator of theNational Aeronautics and Space Administration.All Rights Reserved.*/package gov.nasa.worldwind.render.markers;import gov.nasa.worldwind.Disposable;import gov.nasa.worldwind.geom.*;import gov.nasa.worldwind.render.DrawContext;import gov.nasa.worldwind.util.Logging;import javax.media.opengl.GL;import javax.media.opengl.GLContext;import javax.media.opengl.glu.GLU;import javax.media.opengl.glu.GLUquadric;import java.util.ArrayList;/** * @author tag * @version $Id: BasicMarkerShape.java 7671 2008-11-17 00:18:14Z tgaskins $ */public class BasicMarkerShape{ public static final String SPHERE = "gov.nasa.worldwind.render.markers.Sphere"; public static final String CONE = "gov.nasa.worldwind.render.markers.Cone"; public static final String CYLINDER = "gov.nasa.worldwind.render.markers.Cylinder"; public static final String HEADING_ARROW = "gov.nasa.worldwind.render.markers.HeadingArrow"; public static final String HEADING_LINE = "gov.nasa.worldwind.render.markers.HeadingLine"; public static final String ORIENTED_SPHERE = "gov.nasa.worldwind.render.markers.DirectionalSphere"; public static final String ORIENTED_CONE = "gov.nasa.worldwind.render.markers.DirectionalCone"; public static final String ORIENTED_CYLINDER = "gov.nasa.worldwind.render.markers.DirectionalCylinder"; public static final String ORIENTED_SPHERE_LINE = "gov.nasa.worldwind.render.markers.DirectionalSphereLine"; public static final String ORIENTED_CONE_LINE = "gov.nasa.worldwind.render.markers.DirectionalConeLine"; public static final String ORIENTED_CYLINDER_LINE = "gov.nasa.worldwind.render.markers.DirectionalCylinderLine"; @SuppressWarnings({"StringEquality"}) public static MarkerShape createShapeInstance(String shapeType) { if (shapeType == null) { String message = Logging.getMessage("nullValue.ShapeType"); Logging.logger().severe(message); throw new IllegalArgumentException(message); } // String identity rather than equality is wanted here, to avoid a bunch of unnecessary string compares if (shapeType == BasicMarkerShape.SPHERE) return new Sphere(); else if (shapeType == BasicMarkerShape.CONE) return new Cone(); else if (shapeType == BasicMarkerShape.CYLINDER) return new Cylinder(); else if (shapeType == BasicMarkerShape.HEADING_ARROW) return new HeadingArrow(); else if (shapeType == BasicMarkerShape.HEADING_LINE) return new HeadingLine(); else if (shapeType == BasicMarkerShape.ORIENTED_SPHERE) return new CompoundShape(BasicMarkerShape.ORIENTED_SPHERE, "Oriented Sphere", new Sphere(), new HeadingArrow()); else if (shapeType == BasicMarkerShape.ORIENTED_CONE) return new CompoundShape(BasicMarkerShape.ORIENTED_CONE, "Oriented Cone", new Cone(), new HeadingArrow(), .6); else if (shapeType == BasicMarkerShape.ORIENTED_CYLINDER) return new CompoundShape(BasicMarkerShape.ORIENTED_CYLINDER, "Oriented Cylinder", new Cylinder(), new HeadingArrow(), .6); else if (shapeType == BasicMarkerShape.ORIENTED_SPHERE_LINE) return new CompoundShape(BasicMarkerShape.ORIENTED_SPHERE_LINE, "Oriented Sphere Line", new Sphere(), new HeadingLine(), 1); else if (shapeType == BasicMarkerShape.ORIENTED_CONE_LINE) return new CompoundShape(BasicMarkerShape.ORIENTED_CONE_LINE, "Oriented Cone Line", new Cone(), new HeadingLine(), 2); else if (shapeType == BasicMarkerShape.ORIENTED_CYLINDER_LINE) return new CompoundShape(BasicMarkerShape.ORIENTED_CYLINDER_LINE, "Oriented Cylinder Line", new Cylinder(), new HeadingLine(), 2); else return new Sphere(); } private static class CompoundShape implements MarkerShape, Disposable { protected String name; protected String shapeType; private ArrayList<MarkerShape> shapes = new ArrayList<MarkerShape>(2); private double offset = 0; public CompoundShape(String shapeType, String name, MarkerShape shape1, MarkerShape shape2) { this.name = name; this.shapes.add(shape1); this.shapes.add(shape2); } public CompoundShape(String shapeType, String name, MarkerShape shape1, MarkerShape shape2, double offset) { this.name = name; this.shapes.add(shape1); this.shapes.add(shape2); this.offset = offset; } public void dispose() { for (MarkerShape shape : this.shapes) { if (shape instanceof Disposable) ((Disposable) shape).dispose(); } } public String getName() { return name; } public String getShapeType() { return shapeType; } public void render(DrawContext dc, Marker marker, Vec4 point, double radius) { this.shapes.get(0).render(dc, marker, point, radius); if (this.offset != 0) { Position pos = dc.getGlobe().computePositionFromPoint(point); point = dc.getGlobe().computePointFromPosition(pos.getLatitude(), pos.getLongitude(), pos.getElevation() + radius * this.offset); } this.shapes.get(1).render(dc, marker, point, radius); } } protected static abstract class Shape implements MarkerShape, Disposable { protected String name; protected String shapeType; protected int glListId; protected GLUquadric quadric; protected boolean isInitialized = false; abstract protected void doRender(DrawContext dc, Marker marker, Vec4 point, double radius); protected void initialize(DrawContext dc) { this.glListId = dc.getGL().glGenLists(1); this.quadric = dc.getGLU().gluNewQuadric(); dc.getGLU().gluQuadricDrawStyle(quadric, GLU.GLU_FILL); dc.getGLU().gluQuadricNormals(quadric, GLU.GLU_SMOOTH); dc.getGLU().gluQuadricOrientation(quadric, GLU.GLU_OUTSIDE); dc.getGLU().gluQuadricTexture(quadric, false); } public void dispose() { if (this.isInitialized) { GLU glu = new GLU(); glu.gluDeleteQuadric(this.quadric); this.isInitialized = false; GLContext glc = GLContext.getCurrent(); if (glc == null) return; glc.getGL().glDeleteLists(this.glListId, 1); this.glListId = -1; } } public String getName() { return this.name; } public String getShapeType() { return this.shapeType; } public void render(DrawContext dc, Marker marker, Vec4 point, double radius) { if (!this.isInitialized) this.initialize(dc); dc.getView().pushReferenceCenter(dc, point); this.doRender(dc, marker, point, radius); dc.getView().popReferenceCenter(dc); } } private static class Sphere extends Shape { @Override protected void initialize(DrawContext dc) { super.initialize(dc); this.name = "Sphere"; this.shapeType = BasicMarkerShape.SPHERE; double radius = 1; int slices = 36; int stacks = 18; dc.getGL().glNewList(this.glListId, GL.GL_COMPILE); dc.getGLU().gluSphere(this.quadric, radius, slices, stacks); dc.getGL().glEndList(); this.isInitialized = true; } protected void doRender(DrawContext dc, Marker marker, Vec4 point, double radius) { dc.getGL().glScaled(radius, radius, radius); dc.getGL().glCallList(this.glListId); } } private static class Cone extends Shape
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -