Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Surface Shapes and Sample project #7

Open
wants to merge 2 commits into
base: kedzie-master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions WorldWindAndroid/library.iml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
<excludeFolder url="file://$MODULE_DIR$/bin/generated-sources/combined-assets" />
<excludeFolder url="file://$MODULE_DIR$/bin/generated-sources/combined-resources" />
<excludeFolder url="file://$MODULE_DIR$/bin/generated-sources/extracted-dependencies" />
<excludeFolder url="file://$MODULE_DIR$/bin/maven-archiver" />
</content>
<orderEntry type="jdk" jdkName="Maven Android API 19 Platform" jdkType="Android SDK" />
<orderEntry type="sourceFolder" forTests="false" />
Expand Down
3 changes: 0 additions & 3 deletions WorldWindAndroid/src/gov/nasa/worldwind/SceneController.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ public class SceneController extends WWObjectImpl {

protected Set<String> perFrameStatisticsKeys = new HashSet<String>();
protected final Map<String, PerformanceStatistic> perFrameStatistics = Collections.synchronizedMap(new ConcurrentHashMap<String, PerformanceStatistic>());
protected GLRuntimeCapabilities glRuntimeCaps = new GLRuntimeCapabilities();

/** Support class used to build the composite representation of surface objects as a list of SurfaceTiles. */
protected SurfaceObjectTileBuilder surfaceObjectTileBuilder;
Expand Down Expand Up @@ -270,7 +269,6 @@ public void drawFrame(double deltaTime, int viewportWidth, int viewportHeight) {

// perFrameStatistics.clear();
this.surfaceObjectTiles.clear(); // Clear the surface object tiles generated during the last frame.
this.glRuntimeCaps.initialize();
// Prepare the drawing context for a new frame then cause this scene controller to draw its content. There is no
// need to explicitly swap the front and back buffers here, as the owner WorldWindow does this for us. In the
// case of WorldWindowGLSurfaceView, the GLSurfaceView automatically swaps the front and back buffers for us.
Expand Down Expand Up @@ -325,7 +323,6 @@ protected void doDrawFrame(DrawContext dc) {
protected void initializeDrawContext(DrawContext dc, int viewportWidth, int viewportHeight) {
dc.initialize(viewportWidth, viewportHeight);
dc.setFrameTimeStamp(SystemClock.elapsedRealtime());
dc.setGLRuntimeCapabilities(glRuntimeCaps);
dc.setModel(this.model);
dc.setView(this.view);
dc.setVerticalExaggeration(this.verticalExaggeration);
Expand Down
31 changes: 15 additions & 16 deletions WorldWindAndroid/src/gov/nasa/worldwind/geom/Matrix.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
*/
package gov.nasa.worldwind.geom;

import gov.nasa.worldwind.avlist.AVList;
import gov.nasa.worldwind.avlist.AVListImpl;
import android.graphics.PointF;
import gov.nasa.worldwind.terrain.Terrain;
import gov.nasa.worldwind.util.Logging;

Expand Down Expand Up @@ -572,7 +571,7 @@ public static Matrix fromImageToGeographic(int imageWidth, int imageHeight, Sect
* @throws IllegalArgumentException if either <code>imagePoints</code> or <code>geoPoints</code> is null or have
* length less than 3.
*/
public static Matrix fromImageToGeographic(java.awt.geom.Point2D[] imagePoints, LatLon[] geoPoints)
public static Matrix fromImageToGeographic(PointF[] imagePoints, LatLon[] geoPoints)
{
if (imagePoints == null)
{
Expand Down Expand Up @@ -635,12 +634,12 @@ public static Matrix fromImageToGeographic(java.awt.geom.Point2D[] imagePoints,
double lon2 = geoPoints[1].getLongitude().degrees;
double lon3 = geoPoints[2].getLongitude().degrees;

double x1 = imagePoints[0].getX();
double x2 = imagePoints[1].getX();
double x3 = imagePoints[2].getX();
double y1 = imagePoints[0].getY();
double y2 = imagePoints[1].getY();
double y3 = imagePoints[2].getY();
double x1 = imagePoints[0].x;
double x2 = imagePoints[1].x;
double x3 = imagePoints[2].x;
double y1 = imagePoints[0].y;
double y2 = imagePoints[1].y;
double y3 = imagePoints[2].y;

double a0 = (x3 - x1) - (x2 - x1) * (y3 - y1) / (y2 - y1);
double a = (1 / a0) * ((lon3 - lon1) - (lon2 - lon1) * (y3 - y1) / (y2 - y1));
Expand All @@ -659,7 +658,7 @@ public static Matrix fromImageToGeographic(java.awt.geom.Point2D[] imagePoints,
0.0, 0.0, 0.0, 0.0);
}

public static Matrix fromGeographicToImage(java.awt.geom.Point2D[] imagePoints, LatLon[] geoPoints)
public static Matrix fromGeographicToImage(PointF[] imagePoints, LatLon[] geoPoints)
{
if (imagePoints == null)
{
Expand Down Expand Up @@ -722,12 +721,12 @@ public static Matrix fromGeographicToImage(java.awt.geom.Point2D[] imagePoints,
double lon2 = geoPoints[1].getLongitude().degrees;
double lon3 = geoPoints[2].getLongitude().degrees;

double x1 = imagePoints[0].getX();
double x2 = imagePoints[1].getX();
double x3 = imagePoints[2].getX();
double y1 = imagePoints[0].getY();
double y2 = imagePoints[1].getY();
double y3 = imagePoints[2].getY();
double x1 = imagePoints[0].x;
double x2 = imagePoints[1].x;
double x3 = imagePoints[2].x;
double y1 = imagePoints[0].y;
double y2 = imagePoints[1].y;
double y3 = imagePoints[2].y;

double a0 = (lon3 - lon1) - (lon2 - lon1) * (lat3 - lat1) / (lat2 - lat1);
double a = (1 / a0) * ((x3 - x1) - (x2 - x1) * (lat3 - lat1) / (lat2 - lat1));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public PickPointFrustum(Frustum frustum, android.graphics.Rect rect)
// ============== Intersection Functions ======================= //

/**
* Returns true if the specified 2D screen {@link java.awt.Rectangle} intersects the space enclosed by this view
* Returns true if the specified 2D screen {@link android.graphics.Rect} intersects the space enclosed by this view
* aligned frustums screen rectangle.
*
* @param rect the rectangle to test
Expand Down
3 changes: 3 additions & 0 deletions WorldWindAndroid/src/gov/nasa/worldwind/geom/Sector.java
Original file line number Diff line number Diff line change
Expand Up @@ -776,6 +776,9 @@ public double distanceTo(DrawContext dc, Vec4 point)
throw new IllegalArgumentException(message);
}
Vec4[] corners = new Vec4[4];
for(int i=0; i<corners.length; i++) {
corners[i] = new Vec4();
}
this.computeCornerPoints(dc.getGlobe(), dc.getVerticalExaggeration(), corners);
Vec4 centerPoint = new Vec4();
this.computeCentroidPoint(dc.getGlobe(), dc.getVerticalExaggeration(), centerPoint);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,20 @@
package gov.nasa.worldwind.render;

import android.opengl.GLES20;
import android.opengl.GLU;
import gov.nasa.worldwind.Movable;
import gov.nasa.worldwind.R;
import gov.nasa.worldwind.WorldWindowImpl;
import gov.nasa.worldwind.avlist.AVKey;
import gov.nasa.worldwind.exception.WWRuntimeException;
import gov.nasa.worldwind.geom.*;
import gov.nasa.worldwind.globes.Globe;
import gov.nasa.worldwind.layers.Layer;
import gov.nasa.worldwind.util.*;
import gov.nasa.worldwind.util.measure.AreaMeasurer;

import java.nio.FloatBuffer;
import java.util.*;
import java.util.List;

import static gov.nasa.worldwind.WorldWindowImpl.glCheckError;
import static android.opengl.GLES20.*;
import static gov.nasa.worldwind.util.OGLStackHandler.*;
import static gov.nasa.worldwind.util.OGLStackHandler.GL_POLYGON_BIT;

/**
* Common superclass for surface conforming shapes such as {@link gov.nasa.worldwind.render.SurfacePolygon}, {@link
Expand Down Expand Up @@ -648,10 +643,10 @@ protected void doDrawGeographic(DrawContext dc, SurfaceTileDrawContext sdc)
{
this.determineActiveGeometry(dc, sdc);

if (this.getActiveAttributes(). isEnableInterior() && this.getActiveAttributes().getInteriorColor().a > 0)
if (this.getActiveAttributes(). isEnableInterior() && this.getActiveAttributes().getInteriorOpacity() > 0)
this.drawInterior(dc, sdc);

if (this.getActiveAttributes().isEnableOutline() && this.getActiveAttributes().getOutlineColor().a > 0)
if (this.getActiveAttributes().isEnableOutline() && this.getActiveAttributes().getOutlineOpacity() > 0)
this.drawOutline(dc, sdc);
}

Expand All @@ -670,7 +665,7 @@ protected void applyModelviewTransform(DrawContext dc, SurfaceTileDrawContext sd
}
Matrix mvp = Matrix.fromIdentity();
mvp.multiplyAndSet(sdc.getProjectionMatrix(), modelview);
dc.getCurrentProgram().loadUniformMatrix("mvp", mvp);
dc.getCurrentProgram().loadUniformMatrix("mvpMatrix", mvp);
}

/** Determines which attributes -- normal, highlight or default -- to use each frame. */
Expand Down Expand Up @@ -1071,8 +1066,8 @@ protected Object createGeometryKey(DrawContext dc, SurfaceTileDrawContext sdc)
protected double computeEdgeIntervalsPerDegree(SurfaceTileDrawContext sdc)
{
double texelsPerDegree = Math.max(
sdc.getViewport().width / sdc.getSector().getDeltaLonDegrees(),
sdc.getViewport().getHeight() / sdc.getSector().getDeltaLatDegrees());
sdc.getViewport().width() / sdc.getSector().getDeltaLonDegrees(),
sdc.getViewport().height() / sdc.getSector().getDeltaLatDegrees());
double intervalsPerTexel = 1.0 / this.getTexelsPerEdgeInterval();

return intervalsPerTexel * texelsPerDegree;
Expand Down Expand Up @@ -1155,7 +1150,7 @@ protected void applyInteriorTextureState(DrawContext dc, SurfaceTileDrawContext
transform = Matrix.fromScale(cosLat / scale, 1d / scale, 1d).multiply(transform);
// To maintain the pattern apparent size, we scale it so that one texture pixel match one draw tile pixel.
double regionPixelSize = dc.getGlobe().getRadius() * sdc.getSector().getDeltaLatRadians()
/ sdc.getViewport().height;
/ sdc.getViewport().height();
double texturePixelSize = dc.getGlobe().getRadius() * Angle.fromDegrees(1).radians / texture.getHeight();
double drawScale = texturePixelSize / regionPixelSize;
transform = Matrix.fromScale(drawScale, drawScale, 1d).multiply(transform); // Pre multiply
Expand Down Expand Up @@ -1272,8 +1267,7 @@ protected Integer tessellateInterior(DrawContext dc)

try
{
return null;
// return this.doTessellateInterior(dc);
return this.doTessellateInterior(dc);
}
catch (OutOfMemoryError e)
{
Expand All @@ -1283,12 +1277,51 @@ protected Integer tessellateInterior(DrawContext dc)
//noinspection ThrowableInstanceNeverThrown
// throw new WWRuntimeException(message, e);
this.handleUnsuccessfulInteriorTessellation(dc);


return null;
}
}

protected Integer doTessellateInterior(DrawContext dc) {
int numBytes = 0;

Position referencePos = this.getReferencePosition();
if (referencePos == null)
return null;

for (List<LatLon> drawLocations : this.getActiveGeometry())
{
if (vertexBuffer == null || vertexBuffer.capacity() < 2 * drawLocations.size())
vertexBuffer = BufferUtil.newFloatBuffer(2 * (drawLocations.size()+2));
vertexBuffer.clear();

LatLon firstPoint = drawLocations.get(0);

//calculate center and draw triangle fan all around it
LatLon centerPoint = LatLon.interpolate(.5f, firstPoint, drawLocations.get(drawLocations.size()/2));

vertexBuffer.put((float) (centerPoint.getLongitude().degrees - referencePos.getLongitude().degrees));
vertexBuffer.put((float) (centerPoint.getLatitude().degrees - referencePos.getLatitude().degrees));
numBytes += 2 * 8; // 3 coords of 8 bytes each

for (LatLon ll : drawLocations)
{
vertexBuffer.put((float) (ll.getLongitude().degrees - referencePos.getLongitude().degrees));
vertexBuffer.put((float) (ll.getLatitude().degrees - referencePos.getLatitude().degrees));
numBytes += 2 * 8; // 3 coords of 8 bytes each
}
//Add first point again
vertexBuffer.put((float) (firstPoint.getLongitude().degrees - referencePos.getLongitude().degrees));
vertexBuffer.put((float) (firstPoint.getLatitude().degrees - referencePos.getLatitude().degrees));
numBytes += 2 * 8; // 3 coords of 8 bytes each
vertexBuffer.flip();

dc.getCurrentProgram().vertexAttribPointer("vertexPoint", 2, GL_FLOAT, false, 0, vertexBuffer);
glDrawArrays(GL_TRIANGLE_FAN, 0, drawLocations.size());
}

return numBytes;
}

// protected Integer doTessellateInterior(DrawContext dc)
// {
//
Expand Down
18 changes: 0 additions & 18 deletions WorldWindAndroid/src/gov/nasa/worldwind/render/DrawContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,24 +92,6 @@ public int compareTo(OrderedRenderableEntry that) {

protected Set<String> perFrameStatisticsKeys;
protected Map<String, PerformanceStatistic> perFrameStatistics;
protected GLRuntimeCapabilities glRuntimeCaps;

public GLRuntimeCapabilities getGLRuntimeCapabilities()
{
return this.glRuntimeCaps;
}

public void setGLRuntimeCapabilities(GLRuntimeCapabilities capabilities)
{
if (capabilities == null)
{
String message = Logging.getMessage("nullValue.GLRuntimeCapabilitiesIsNull");
Logging.error(message);
throw new IllegalArgumentException(message);
}

this.glRuntimeCaps = capabilities;
}

/**
* Initializes this <code>DrawContext</code>. This method should be called at the beginning of each frame to prepare
Expand Down
9 changes: 7 additions & 2 deletions WorldWindAndroid/src/gov/nasa/worldwind/render/Path.java
Original file line number Diff line number Diff line change
Expand Up @@ -1168,7 +1168,12 @@ protected void beginDrawing(DrawContext dc) {
// each shape.
program.enableVertexAttribute("vertexPoint");

program.loadUniform1f("uOpacity", dc.isPickingMode() ? 1f : this.layer.getOpacity());
double opacity = 1d;
if(this.layer!=null)
opacity = layer.getOpacity();
else if(dc.getCurrentLayer()!=null)
opacity = dc.getCurrentLayer().getOpacity();
program.loadUniform1f("uOpacity", dc.isPickingMode() ? 1f : opacity);

// Set the OpenGL state that this shape depends on.
GLES20.glDisable(GLES20.GL_CULL_FACE);
Expand Down Expand Up @@ -1268,7 +1273,7 @@ protected void doDrawOutlineVBO(DrawContext dc, int[] vboIds, PathData pathData)
if (this.isShowPositions())
{
this.drawPointsVBO(dc, vboIds, pathData);
drawPointLabels(dc, pathData, false);
drawPointLabels(dc, pathData, true);
}
}

Expand Down
Loading