testing 'tessellate' jni
This commit is contained in:
@@ -15,16 +15,65 @@
|
||||
package org.oscim.renderer.sublayers;
|
||||
|
||||
import java.nio.ShortBuffer;
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.oscim.core.GeometryBuffer;
|
||||
import org.oscim.core.Tile;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
public class MeshLayer extends Layer {
|
||||
GeometryBuffer mGeom = new GeometryBuffer(10,10);
|
||||
|
||||
public MeshLayer() {
|
||||
GeometryBuffer e = mGeom;
|
||||
|
||||
int size = Tile.SIZE;
|
||||
|
||||
float x1 = -1;
|
||||
float y1 = -1;
|
||||
float x2 = size + 1;
|
||||
float y2 = size + 1;
|
||||
|
||||
// always clear geometry before starting
|
||||
// a different type.
|
||||
e.clear();
|
||||
e.startPolygon();
|
||||
e.addPoint(x1, y1);
|
||||
e.addPoint(x2, y1);
|
||||
e.addPoint(x2, y2);
|
||||
e.addPoint(x1, y2);
|
||||
|
||||
y1 = 5;
|
||||
y2 = size - 5;
|
||||
x1 = 5;
|
||||
x2 = size - 5;
|
||||
|
||||
e.startHole();
|
||||
e.addPoint(x1, y1);
|
||||
e.addPoint(x2, y1);
|
||||
e.addPoint(x2, y2);
|
||||
e.addPoint(x1, y2);
|
||||
|
||||
addMesh(e);
|
||||
}
|
||||
|
||||
public void addMesh(GeometryBuffer geom){
|
||||
int numRings = 2;
|
||||
|
||||
for (int i = 0, n = geom.points.length; i < n; i++){
|
||||
long ctx = tessellate(geom.points, 0, geom.index, 0, numRings);
|
||||
|
||||
short[] coordinates = new short[100];
|
||||
|
||||
while (tessGetCoordinates(ctx, coordinates, 2) > 0){
|
||||
Log.d("..", Arrays.toString(coordinates));
|
||||
}
|
||||
|
||||
while (tessGetIndices(ctx, coordinates) > 0){
|
||||
Log.d("..", Arrays.toString(coordinates));
|
||||
}
|
||||
|
||||
tessFinish(ctx);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -37,4 +86,25 @@ public class MeshLayer extends Layer {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param points an array of x,y coordinates
|
||||
* @param pos position in points array
|
||||
* @param index geom indices
|
||||
* @param ipos position in index array
|
||||
* @param numRings number of rings in polygon == outer(1) + inner rings
|
||||
* @return number of triangles in io buffer
|
||||
*/
|
||||
public static native int tessellate(float[] points, int pos,
|
||||
short[] index, int ipos, int numRings);
|
||||
|
||||
public static native void tessFinish(long ctx);
|
||||
|
||||
public static native int tessGetCoordinates(long ctx, short[] coordinates, float scale);
|
||||
|
||||
public static native int tessGetIndices(long ctx, short[] indices);
|
||||
|
||||
|
||||
static {
|
||||
System.loadLibrary("tessellate");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user