📄 flatglobe.java
字号:
/*
Copyright (C) 2001, 2008 United States Government
as represented by the Administrator of the
National Aeronautics and Space Administration.
All Rights Reserved.
*/
package gov.nasa.worldwind.globes;
import gov.nasa.worldwind.geom.*;
import gov.nasa.worldwind.util.*;
import gov.nasa.worldwind.render.DrawContext;
/**
* Defines a Globe represented as a projection onto a plane. The projection type is modifiable.
*
* @author Patrick Murris
* @version $Id: FlatGlobe.java 9282 2009-03-10 22:48:24Z patrickmurris $
*/
public class FlatGlobe extends EllipsoidalGlobe
{
public final static String PROJECTION_LAT_LON = "gov.nasa.worldwind.globes.projectionLatLon";
public final static String PROJECTION_MERCATOR = "gov.nasa.worldwind.globes.projectionMercator";
public final static String PROJECTION_SINUSOIDAL = "gov.nasa.worldwind.globes.projectionSinusoidal";
public final static String PROJECTION_MODIFIED_SINUSOIDAL =
"gov.nasa.worldwind.globes.projectionModifiedSinusoidal";
private String projection = PROJECTION_MERCATOR;
public FlatGlobe(double equatorialRadius, double polarRadius, double es, ElevationModel em)
{
super(equatorialRadius, polarRadius, es, em);
}
private class FlatStateKey extends StateKey
{
protected final String projection;
protected double verticalExaggeration;
public FlatStateKey(DrawContext dc)
{
super(dc);
this.projection = FlatGlobe.this.projection;
}
@SuppressWarnings({"RedundantIfStatement"})
public boolean equals(Object o)
{
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;
if (!super.equals(o))
return false;
FlatStateKey that = (FlatStateKey) o;
if (Double.compare(that.verticalExaggeration, verticalExaggeration) != 0)
return false;
if (projection != null ? !projection.equals(that.projection) : that.projection != null)
return false;
return true;
}
public int hashCode()
{
int result = super.hashCode();
long temp;
result = 31 * result + (projection != null ? projection.hashCode() : 0);
temp = verticalExaggeration != +0.0d ? Double.doubleToLongBits(verticalExaggeration) : 0L;
result = 31 * result + (int) (temp ^ (temp >>> 32));
return result;
}
}
public Object getStateKey(DrawContext dc)
{
return new FlatStateKey(dc);
}
@Override
public double getRadiusAt(Angle latitude, Angle longitude)
{
// TODO: Find a more accurate workaround than getMaximumRadius()
if (latitude == null || longitude == null)
{
String msg = Logging.getMessage("nullValue.AngleIsNull");
Logging.logger().severe(msg);
throw new IllegalArgumentException(msg);
}
return getMaximumRadius();
}
@Override
public double getRadiusAt(LatLon latLon)
{
// TODO: Find a more accurate workaround then getMaximumRadius()
if (latLon == null)
{
String msg = Logging.getMessage("nullValue.LatLonIsNull");
Logging.logger().severe(msg);
throw new IllegalArgumentException(msg);
}
return getMaximumRadius();
}
public void setProjection(String projection)
{
if (projection == null)
{
String message = Logging.getMessage("nullValue.StringIsNull");
Logging.logger().severe(message);
throw new IllegalArgumentException(message);
}
if (this.projection.equals(projection))
return;
this.projection = projection;
this.setTessellator(null);
}
public String getProjection()
{
return this.projection;
}
@Override
protected Intersection[] intersect(Line line, double equRadius, double polarRadius)
{
// Flat World Note: plane/line intersection point (OK)
// Flat World Note: extract altitude from equRadius by subtracting this.equatorialRadius (OK)
if (line == null)
{
String message = Logging.getMessage("nullValue.LineIsNull");
Logging.logger().severe(message);
throw new IllegalArgumentException(message);
}
// Intersection with world plane
Plane plane = new Plane(0, 0, 1, -(equRadius - this.equatorialRadius)); // Flat globe plane
Vec4 p = plane.intersect(line);
if (p == null)
return null;
// Check if we are in the world boundaries
Position pos = this.computePositionFromPoint(p);
if (pos == null)
return null;
if (pos.getLatitude().degrees < -90 || pos.getLatitude().degrees > 90 ||
pos.getLongitude().degrees < -180 || pos.getLongitude().degrees > 180)
return null;
return new Intersection[] {new Intersection(p, false)};
}
@Override
public boolean intersects(Line line)
{
// Flat World Note: plane/line intersection test (OK)
if (line == null)
{
String msg = Logging.getMessage("nullValue.LineIsNull");
Logging.logger().severe(msg);
throw new IllegalArgumentException(msg);
}
return this.intersect(line) != null;
}
@Override
public boolean intersects(Plane plane)
{
// Flat World Note: plane/plane intersection test (OK)
if (plane == null)
{
String msg = Logging.getMessage("nullValue.PlaneIsNull");
Logging.logger().severe(msg);
throw new IllegalArgumentException(msg);
}
return !plane.getNormal().equals(Vec4.UNIT_Z);
}
@Override
public Vec4 computeSurfaceNormalAtLocation(Angle latitude, Angle longitude)
{
// Flat World Note: return constant (OK)
if (latitude == null || longitude == null)
{
String message = Logging.getMessage("nullValue.LatitudeOrLongitudeIsNull");
Logging.logger().severe(message);
throw new IllegalArgumentException(message);
}
return Vec4.UNIT_Z;
}
@Override
public Vec4 computeSurfaceNormalAtPoint(Vec4 point)
{
// Flat World Note: return constant (OK)
if (point == null)
{
String msg = Logging.getMessage("nullValue.PointIsNull");
Logging.logger().severe(msg);
throw new IllegalArgumentException(msg);
}
return Vec4.UNIT_Z;
}
@Override
public Vec4 computeNorthPointingTangentAtLocation(Angle latitude, Angle longitude)
{
// Flat World Note: return constant (OK)
if (latitude == null || longitude == null)
{
String message = Logging.getMessage("nullValue.LatitudeOrLongitudeIsNull");
Logging.logger().severe(message);
throw new IllegalArgumentException(message);
}
return Vec4.UNIT_Y;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -