Improve code / xml formatting, closes #54

This commit is contained in:
Emux
2016-07-09 19:45:22 +03:00
parent 7919d0ab9c
commit e793e8851b
458 changed files with 58405 additions and 63062 deletions

View File

@@ -31,44 +31,44 @@ import org.oscim.tiling.source.oscimap4.OSciMap4TileSource;
public class MapzenTest extends GdxMap {
@Override
protected boolean onKeyDown(int keycode) {
if (keycode == Input.Keys.A) {
loadTheme();
}
@Override
protected boolean onKeyDown(int keycode) {
if (keycode == Input.Keys.A) {
loadTheme();
}
return super.onKeyDown(keycode);
}
return super.onKeyDown(keycode);
}
@Override
public void createLayers() {
UrlTileSource tileSource = OSciMap4TileSource.builder()
.url("https://vector.mapzen.com/osm/v0.8/all")
.apiKey("vector-tiles-xxxxxxx") // Put a proper API key
.zoomMax(18)
.httpFactory(new OkHttpEngine.OkHttpFactory())
.build();
@Override
public void createLayers() {
UrlTileSource tileSource = OSciMap4TileSource.builder()
.url("https://vector.mapzen.com/osm/v0.8/all")
.apiKey("vector-tiles-xxxxxxx") // Put a proper API key
.zoomMax(18)
.httpFactory(new OkHttpEngine.OkHttpFactory())
.build();
VectorTileLayer l = mMap.setBaseMap(tileSource);
VectorTileLayer l = mMap.setBaseMap(tileSource);
loadTheme();
loadTheme();
mMap.layers().add(new BuildingLayer(mMap, l));
mMap.layers().add(new LabelLayer(mMap, l));
mMap.layers().add(new BuildingLayer(mMap, l));
mMap.layers().add(new LabelLayer(mMap, l));
mMap.setMapPosition(53.08, 8.82, 1 << 17);
}
mMap.setMapPosition(53.08, 8.82, 1 << 17);
}
private void loadTheme() {
try {
mMap.setTheme(ThemeLoader.load(getClass().getResourceAsStream("/assets/styles/mapzen.xml")));
} catch (ThemeException e) {
e.printStackTrace();
}
}
private void loadTheme() {
try {
mMap.setTheme(ThemeLoader.load(getClass().getResourceAsStream("/assets/styles/mapzen.xml")));
} catch (ThemeException e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
GdxMapApp.init();
GdxMapApp.run(new MapzenTest(), null, 400);
}
public static void main(String[] args) {
GdxMapApp.init();
GdxMapApp.run(new MapzenTest(), null, 400);
}
}

View File

@@ -1,5 +1,7 @@
package org.oscim.test;
import com.badlogic.gdx.Input;
import org.oscim.core.BoundingBox;
import org.oscim.gdx.GdxMap;
import org.oscim.gdx.GdxMapApp;
@@ -7,32 +9,30 @@ import org.oscim.renderer.MapRenderer;
import org.oscim.tiling.TileSource;
import org.oscim.tiling.source.oscimap4.OSciMap4TileSource;
import com.badlogic.gdx.Input;
public class AnimatorTest extends GdxMap {
@Override
public void createLayers() {
MapRenderer.setBackgroundColor(0xff000000);
@Override
public void createLayers() {
MapRenderer.setBackgroundColor(0xff000000);
TileSource ts = new OSciMap4TileSource();
initDefaultLayers(ts, false, false, false);
TileSource ts = new OSciMap4TileSource();
initDefaultLayers(ts, false, false, false);
mMap.setMapPosition(0, 0, 1 << 4);
mMap.setMapPosition(0, 0, 1 << 4);
}
}
@Override
protected boolean onKeyDown(int keycode) {
if (keycode == Input.Keys.NUM_1) {
mMap.animator().animateTo(new BoundingBox(53.1, 8.8, 53.2, 8.9));
return true;
}
return false;
}
@Override
protected boolean onKeyDown(int keycode) {
if (keycode == Input.Keys.NUM_1) {
mMap.animator().animateTo(new BoundingBox(53.1, 8.8, 53.2, 8.9));
return true;
}
return false;
}
public static void main(String[] args) {
GdxMapApp.init();
GdxMapApp.run(new AnimatorTest(), null, 256);
}
public static void main(String[] args) {
GdxMapApp.init();
GdxMapApp.run(new AnimatorTest(), null, 256);
}
}

View File

@@ -1,9 +1,6 @@
package org.oscim.test;
import static org.oscim.tiling.source.bitmap.DefaultSources.HD_HILLSHADE;
import static org.oscim.tiling.source.bitmap.DefaultSources.OPENSTREETMAP;
import static org.oscim.tiling.source.bitmap.DefaultSources.STAMEN_TONER;
import static org.oscim.tiling.source.bitmap.DefaultSources.STAMEN_WATERCOLOR;
import com.badlogic.gdx.Input;
import org.oscim.gdx.GdxMap;
import org.oscim.gdx.GdxMapApp;
@@ -12,53 +9,56 @@ import org.oscim.renderer.MapRenderer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.badlogic.gdx.Input;
import static org.oscim.tiling.source.bitmap.DefaultSources.HD_HILLSHADE;
import static org.oscim.tiling.source.bitmap.DefaultSources.OPENSTREETMAP;
import static org.oscim.tiling.source.bitmap.DefaultSources.STAMEN_TONER;
import static org.oscim.tiling.source.bitmap.DefaultSources.STAMEN_WATERCOLOR;
public class BitmapLayerTest extends GdxMap {
final Logger log = LoggerFactory.getLogger(BitmapTileLayer.class);
final Logger log = LoggerFactory.getLogger(BitmapTileLayer.class);
BitmapTileLayer mLayer = null;
BitmapTileLayer mShaded = null;
BitmapTileLayer mLayer = null;
BitmapTileLayer mShaded = null;
@Override
protected boolean onKeyDown(int keycode) {
if (keycode == Input.Keys.NUM_1) {
mMap.layers().remove(mLayer);
mLayer = new BitmapTileLayer(mMap, OPENSTREETMAP.build());
mMap.layers().add(mLayer);
return true;
} else if (keycode == Input.Keys.NUM_2) {
mMap.layers().remove(mLayer);
mLayer = new BitmapTileLayer(mMap, STAMEN_WATERCOLOR.build());
mMap.layers().add(mLayer);
return true;
} else if (keycode == Input.Keys.NUM_3) {
if (mShaded != null) {
mMap.layers().remove(mShaded);
mShaded = null;
} else {
mShaded = new BitmapTileLayer(mMap, HD_HILLSHADE.build());
mMap.layers().add(mShaded);
}
return true;
}
@Override
protected boolean onKeyDown(int keycode) {
if (keycode == Input.Keys.NUM_1) {
mMap.layers().remove(mLayer);
mLayer = new BitmapTileLayer(mMap, OPENSTREETMAP.build());
mMap.layers().add(mLayer);
return true;
} else if (keycode == Input.Keys.NUM_2) {
mMap.layers().remove(mLayer);
mLayer = new BitmapTileLayer(mMap, STAMEN_WATERCOLOR.build());
mMap.layers().add(mLayer);
return true;
} else if (keycode == Input.Keys.NUM_3) {
if (mShaded != null) {
mMap.layers().remove(mShaded);
mShaded = null;
} else {
mShaded = new BitmapTileLayer(mMap, HD_HILLSHADE.build());
mMap.layers().add(mShaded);
}
return true;
}
return false;
}
return false;
}
@Override
public void createLayers() {
MapRenderer.setBackgroundColor(0xff888888);
@Override
public void createLayers() {
MapRenderer.setBackgroundColor(0xff888888);
mLayer = new BitmapTileLayer(mMap, STAMEN_TONER.build());
mMap.layers().add(mLayer);
mLayer = new BitmapTileLayer(mMap, STAMEN_TONER.build());
mMap.layers().add(mLayer);
}
}
public static void main(String[] args) {
public static void main(String[] args) {
GdxMapApp.init();
GdxMapApp.run(new BitmapLayerTest(), null, 256);
}
GdxMapApp.init();
GdxMapApp.run(new BitmapLayerTest(), null, 256);
}
}

View File

@@ -1,6 +1,6 @@
package org.oscim.test;
import java.io.FileNotFoundException;
import com.badlogic.gdx.Input;
import org.oscim.gdx.GdxMap;
import org.oscim.gdx.GdxMapApp;
@@ -11,72 +11,72 @@ import org.oscim.theme.IRenderTheme;
import org.oscim.theme.ThemeLoader;
import org.oscim.tiling.source.mapfile.MapFileTileSource;
import com.badlogic.gdx.Input;
import java.io.FileNotFoundException;
public class ExternalRenderThemeTest extends GdxMap {
VectorTileLayer mapLayer;
VectorTileLayer mapLayer;
@Override
protected boolean onKeyDown(int keycode) {
String name = null;
if (keycode == Input.Keys.NUM_1)
name = "themes/freizeitkarte/theme.xml";
if (keycode == Input.Keys.NUM_2)
name = "themes/elevate/theme.xml";
if (keycode == Input.Keys.NUM_3)
name = "themes/vmap/theme.xml";
@Override
protected boolean onKeyDown(int keycode) {
String name = null;
if (keycode == Input.Keys.NUM_1)
name = "themes/freizeitkarte/theme.xml";
if (keycode == Input.Keys.NUM_2)
name = "themes/elevate/theme.xml";
if (keycode == Input.Keys.NUM_3)
name = "themes/vmap/theme.xml";
if (name == null)
return false;
if (name == null)
return false;
try {
IRenderTheme theme = ThemeLoader.load(name);
mapLayer.setRenderTheme(theme);
MapRenderer.setBackgroundColor(theme.getMapBackground());
} catch (FileNotFoundException e) {
e.printStackTrace();
}
try {
IRenderTheme theme = ThemeLoader.load(name);
mapLayer.setRenderTheme(theme);
MapRenderer.setBackgroundColor(theme.getMapBackground());
} catch (FileNotFoundException e) {
e.printStackTrace();
}
mMap.clearMap();
mMap.updateMap(true);
return true;
}
mMap.clearMap();
mMap.updateMap(true);
return true;
}
@Override
public void createLayers() {
mMap.setMapPosition(53.08, 8.83, 1 << 14);
@Override
public void createLayers() {
mMap.setMapPosition(53.08, 8.83, 1 << 14);
// TileSource tileSource = new OSciMap4TileSource();
// TileSource tileSource = new OSciMap4TileSource();
MapFileTileSource tileSource = new MapFileTileSource();
// tileSource.setMapFile("/home/jeff/src/vtm/Freizeitkarte_DEU_NW.map");
tileSource.setMapFile("/home/jeff/germany.map");
MapFileTileSource tileSource = new MapFileTileSource();
// tileSource.setMapFile("/home/jeff/src/vtm/Freizeitkarte_DEU_NW.map");
tileSource.setMapFile("/home/jeff/germany.map");
VectorTileLayer l = mMap.setBaseMap(tileSource);
mapLayer = l;
VectorTileLayer l = mMap.setBaseMap(tileSource);
mapLayer = l;
// mMap.getLayers().add(new BuildingLayer(mMap, l.getTileLayer()));
mMap.layers().add(new LabelLayer(mMap, l));
// mMap.getLayers().add(new BuildingLayer(mMap, l.getTileLayer()));
mMap.layers().add(new LabelLayer(mMap, l));
try {
IRenderTheme theme = ThemeLoader
.load("themes/freizeitkarte/theme.xml");
// IRenderTheme theme =
// ThemeLoader.load("themes/elevate/theme.xml");
// IRenderTheme theme = ThemeLoader.load("themes/vmap/theme.xml");
l.setRenderTheme(theme);
MapRenderer.setBackgroundColor(theme.getMapBackground());
} catch (FileNotFoundException e) {
e.printStackTrace();
}
try {
IRenderTheme theme = ThemeLoader
.load("themes/freizeitkarte/theme.xml");
// IRenderTheme theme =
// ThemeLoader.load("themes/elevate/theme.xml");
// IRenderTheme theme = ThemeLoader.load("themes/vmap/theme.xml");
l.setRenderTheme(theme);
MapRenderer.setBackgroundColor(theme.getMapBackground());
} catch (FileNotFoundException e) {
e.printStackTrace();
}
// mMap.getLayers().add(new GenericLayer(mMap, new MeshRenderer()));
// mMap.getLayers().add(new GenericLayer(mMap, new GridRenderer()));
}
// mMap.getLayers().add(new GenericLayer(mMap, new MeshRenderer()));
// mMap.getLayers().add(new GenericLayer(mMap, new GridRenderer()));
}
public static void main(String[] args) {
GdxMapApp.init();
GdxMapApp.run(new ExternalRenderThemeTest(), null, 256);
}
public static void main(String[] args) {
GdxMapApp.init();
GdxMapApp.run(new ExternalRenderThemeTest(), null, 256);
}
}

View File

@@ -18,98 +18,98 @@ import org.oscim.theme.styles.LineStyle.LineBuilder;
public class HairLineTest extends GdxMap {
static GeometryBuffer createLine(float r) {
GeometryBuffer in = new GeometryBuffer(100, 2);
static GeometryBuffer createLine(float r) {
GeometryBuffer in = new GeometryBuffer(100, 2);
for (int j = 0; j <= 12; j += 3) {
in.startLine();
for (int i = 0; i <= 120; i++) {
double rad = Math.toRadians(i * 3);
in.addPoint((float) (Math.cos(rad) * (r + j)), (float) (Math.sin(rad) * (r + j)));
}
}
return in;
}
for (int j = 0; j <= 12; j += 3) {
in.startLine();
for (int i = 0; i <= 120; i++) {
double rad = Math.toRadians(i * 3);
in.addPoint((float) (Math.cos(rad) * (r + j)), (float) (Math.sin(rad) * (r + j)));
}
}
return in;
}
static class Renderer extends BucketRenderer {
boolean init;
LineBuilder<?> l = LineStyle.builder()
.color(Color.WHITE)
.strokeWidth(1.5f)
.cap(Cap.ROUND);
static class Renderer extends BucketRenderer {
boolean init;
LineBuilder<?> l = LineStyle.builder()
.color(Color.WHITE)
.strokeWidth(1.5f)
.cap(Cap.ROUND);
HairLineBucket ll = buckets.addHairLineBucket(1, l.build());
HairLineBucket ll = buckets.addHairLineBucket(1, l.build());
//LineLayer ll = layers.addLineLayer(1, new LineStyle(Color.fade(Color.CYAN, 0.6f), 2.5f));
LineStyle style = new LineStyle(Color.fade(Color.MAGENTA, 0.6f), 2.5f);
//LineLayer ll = layers.addLineLayer(1, new LineStyle(Color.fade(Color.CYAN, 0.6f), 2.5f));
LineStyle style = new LineStyle(Color.fade(Color.MAGENTA, 0.6f), 2.5f);
HairLineBucket l1 = buckets.addHairLineBucket(2, style);
HairLineBucket l1 = buckets.addHairLineBucket(2, style);
//style = new LineStyle(Color.fade(Color.LTGRAY, 0.8f), 1.5f);
LineBucket l2 = buckets.addLineBucket(3, style);
//style = new LineStyle(Color.fade(Color.LTGRAY, 0.8f), 1.5f);
LineBucket l2 = buckets.addLineBucket(3, style);
PolygonBucket pl = buckets.addPolygonBucket(4, AreaStyle.builder()
.color(Color.BLUE)
//.outline(Color.CYAN, 1)
.build());
PolygonBucket pl = buckets.addPolygonBucket(4, AreaStyle.builder()
.color(Color.BLUE)
//.outline(Color.CYAN, 1)
.build());
@Override
public boolean setup() {
//ll.roundCap = true;
return super.setup();
}
@Override
public boolean setup() {
//ll.roundCap = true;
return super.setup();
}
@Override
public void update(GLViewport v) {
if (!init) {
mMapPosition.copy(v.pos);
init = true;
GeometryBuffer g;
@Override
public void update(GLViewport v) {
if (!init) {
mMapPosition.copy(v.pos);
init = true;
GeometryBuffer g;
for (int i = 105; i < 160; i += 30) {
for (int i = 105; i < 160; i += 30) {
g = createLine(i);
g = createLine(i);
ll.addLine(g);
ll.addLine(g);
//g.translate(10, 10);
//l1.addLine(g);
//g.translate(10, 10);
//l1.addLine(g);
// int o = 0;
// for (int k = 0; k < g.index.length && g.index[k] >= 0; k++) {
//
// for (int j = 0; j < g.index[k];)
// ll.addPoint(g.points[o + j++], g.points[o + j++]);
//
// o += g.index[k];
// }
}
g = new GeometryBuffer(4, 2);
g.clear();
g.startPolygon();
g.addPoint(-100, -100);
g.addPoint(100, -100);
g.addPoint(100, 100);
g.addPoint(-100, 100);
g.translate(100, 100);
l2.addLine(g);
pl.addPolygon(g);
// int o = 0;
// for (int k = 0; k < g.index.length && g.index[k] >= 0; k++) {
//
// for (int j = 0; j < g.index[k];)
// ll.addPoint(g.points[o + j++], g.points[o + j++]);
//
// o += g.index[k];
// }
}
g = new GeometryBuffer(4, 2);
g.clear();
g.startPolygon();
g.addPoint(-100, -100);
g.addPoint(100, -100);
g.addPoint(100, 100);
g.addPoint(-100, 100);
g.translate(100, 100);
l2.addLine(g);
pl.addPolygon(g);
compile();
}
}
}
compile();
}
}
}
@Override
protected void createLayers() {
MapRenderer.setBackgroundColor(Color.BLACK);
mMap.layers().add(new GenericLayer(mMap, new Renderer()));
@Override
protected void createLayers() {
MapRenderer.setBackgroundColor(Color.BLACK);
mMap.layers().add(new GenericLayer(mMap, new Renderer()));
}
}
public static void main(String[] args) {
GdxMapApp.init();
GdxMapApp.run(new HairLineTest(), null, 400);
public static void main(String[] args) {
GdxMapApp.init();
GdxMapApp.run(new HairLineTest(), null, 400);
}
}
}

View File

@@ -16,6 +16,8 @@
*/
package org.oscim.test;
import com.badlogic.gdx.Input;
import org.oscim.backend.canvas.Color;
import org.oscim.backend.canvas.Paint.Cap;
import org.oscim.core.GeometryBuffer;
@@ -29,198 +31,196 @@ import org.oscim.renderer.bucket.LineBucket;
import org.oscim.renderer.bucket.LineTexBucket;
import org.oscim.theme.styles.LineStyle;
import com.badlogic.gdx.Input;
public class LineRenderTest extends GdxMap {
GeometryBuffer mGeom = new GeometryBuffer(2, 1);
GeometryBuffer mLine = new GeometryBuffer(2, 1);
GeometryBuffer mGeom = new GeometryBuffer(2, 1);
GeometryBuffer mLine = new GeometryBuffer(2, 1);
static boolean fixedLineWidth = true;
LineTest l = new LineTest();
static boolean fixedLineWidth = true;
LineTest l = new LineTest();
@Override
public void createLayers() {
MapRenderer.setBackgroundColor(0xff000000);
@Override
public void createLayers() {
MapRenderer.setBackgroundColor(0xff000000);
// TileSource ts = new OSciMap4TileSource();
// ts.setOption("url", "http://opensciencemap.org/tiles/vtm");
// initDefaultLayers(ts, false, false, false);
// TileSource ts = new OSciMap4TileSource();
// ts.setOption("url", "http://opensciencemap.org/tiles/vtm");
// initDefaultLayers(ts, false, false, false);
mMap.setMapPosition(0, 0, 1 << 4);
mMap.setMapPosition(0, 0, 1 << 4);
GeometryBuffer g = mLine;
g.startLine();
g.addPoint(-100, 0);
g.addPoint(100, 0);
GeometryBuffer g = mLine;
g.startLine();
g.addPoint(-100, 0);
g.addPoint(100, 0);
addLines(l, 0, true, false);
addLines(l, 0, true, false);
mMap.layers().add(new GenericLayer(mMap, l));
}
mMap.layers().add(new GenericLayer(mMap, l));
}
void addLines(LineTest l, int layer, boolean addOutline, boolean fixed) {
void addLines(LineTest l, int layer, boolean addOutline, boolean fixed) {
GeometryBuffer g = mLine;
GeometryBuffer g = mLine;
LineStyle line1, line2, line3, line4;
LineStyle line1, line2, line3, line4;
if (fixed) {
line1 = new LineStyle(Color.RED, 0.5f);
line2 = new LineStyle(Color.GREEN, 1);
line3 = new LineStyle(Color.BLUE, 2);
line4 = new LineStyle(Color.LTGRAY, 3);
if (fixed) {
line1 = new LineStyle(Color.RED, 0.5f);
line2 = new LineStyle(Color.GREEN, 1);
line3 = new LineStyle(Color.BLUE, 2);
line4 = new LineStyle(Color.LTGRAY, 3);
} else {
line1 = new LineStyle(0, null, Color.fade(Color.RED, 0.5f), 4.0f,
Cap.BUTT, false, 0, 0, 0, 0, 1f, false);
} else {
line1 = new LineStyle(0, null, Color.fade(Color.RED, 0.5f), 4.0f,
Cap.BUTT, false, 0, 0, 0, 0, 1f, false);
line2 = new LineStyle(0, null, Color.GREEN, 6.0f, Cap.BUTT, true, 0, 0,
0, 0, 1f, false);
line2 = new LineStyle(0, null, Color.GREEN, 6.0f, Cap.BUTT, true, 0, 0,
0, 0, 1f, false);
line3 = new LineStyle(0, null, Color.BLUE, 2.0f, Cap.ROUND, false, 4,
Color.CYAN, 1, 0, 0, false);
line3 = new LineStyle(0, null, Color.BLUE, 2.0f, Cap.ROUND, false, 4,
Color.CYAN, 1, 0, 0, false);
line4 = new LineStyle(0, null, Color.LTGRAY, 2.0f, Cap.ROUND, false, 0,
0, 0, 0, 1f, false);
}
line4 = new LineStyle(0, null, Color.LTGRAY, 2.0f, Cap.ROUND, false, 0,
0, 0, 0, 1f, false);
}
LineStyle outline = new LineStyle(0, null, Color.BLUE, 2.0f, Cap.ROUND, false, 0,
0, 0, 0, 1f, true);
LineStyle outline = new LineStyle(0, null, Color.BLUE, 2.0f, Cap.ROUND, false, 0,
0, 0, 0, 1f, true);
LineStyle outline2 = new LineStyle(0, null, Color.RED, 2.0f, Cap.ROUND, false, 0,
0, 0, 0, 0, true);
LineStyle outline2 = new LineStyle(0, null, Color.RED, 2.0f, Cap.ROUND, false, 0,
0, 0, 0, 0, true);
LineBucket ol = l.buckets.addLineBucket(0, outline);
LineBucket ol2 = l.buckets.addLineBucket(5, outline2);
LineBucket ol = l.buckets.addLineBucket(0, outline);
LineBucket ol2 = l.buckets.addLineBucket(5, outline2);
LineBucket ll = l.buckets.addLineBucket(10, line1);
ll.addLine(g.translate(0, -20));
ll.addLine(g.translate(0, 10.5f));
addCircle(-200, -200, 100, ll);
LineBucket ll = l.buckets.addLineBucket(10, line1);
ll.addLine(g.translate(0, -20));
ll.addLine(g.translate(0, 10.5f));
addCircle(-200, -200, 100, ll);
if (addOutline)
ol.addOutline(ll);
if (addOutline)
ol.addOutline(ll);
ll = l.buckets.addLineBucket(20, line2);
ll.addLine(g.translate(0, 10.5f));
ll.addLine(g.translate(0, 10.5f));
addCircle(200, -200, 100, ll);
ll = l.buckets.addLineBucket(20, line2);
ll.addLine(g.translate(0, 10.5f));
ll.addLine(g.translate(0, 10.5f));
addCircle(200, -200, 100, ll);
if (addOutline)
ol.addOutline(ll);
if (addOutline)
ol.addOutline(ll);
LineTexBucket lt = l.buckets.getLineTexBucket(30);
lt.line = line3;
lt.width = line3.width;
lt.addLine(g.translate(0, 10.5f));
lt.addLine(g.translate(0, 10.5f));
addCircle(200, 200, 100, lt);
LineTexBucket lt = l.buckets.getLineTexBucket(30);
lt.line = line3;
lt.width = line3.width;
lt.addLine(g.translate(0, 10.5f));
lt.addLine(g.translate(0, 10.5f));
addCircle(200, 200, 100, lt);
// if (addOutline)
// ol2.addOutline(ll);
// if (addOutline)
// ol2.addOutline(ll);
ll = l.buckets.addLineBucket(40, line4);
ll.addLine(g.translate(0, 10.5f));
ll.addLine(g.translate(0, 10.5f));
addCircle(-200, 200, 100, ll);
ll = l.buckets.addLineBucket(40, line4);
ll.addLine(g.translate(0, 10.5f));
ll.addLine(g.translate(0, 10.5f));
addCircle(-200, 200, 100, ll);
if (addOutline)
ol2.addOutline(ll);
}
if (addOutline)
ol2.addOutline(ll);
}
void addCircle(float cx, float cy, float radius, LineBucket ll) {
GeometryBuffer g = mGeom;
void addCircle(float cx, float cy, float radius, LineBucket ll) {
GeometryBuffer g = mGeom;
g.clear();
g.startLine();
g.addPoint(cx, cy);
g.addPoint(cx, cy);
g.clear();
g.startLine();
g.addPoint(cx, cy);
g.addPoint(cx, cy);
for (int i = 0; i < 60; i++) {
double d = Math.toRadians(i * 6);
g.setPoint(1, cx + (float) Math.sin(d) * radius,
cy + (float) Math.cos(d) * radius);
ll.addLine(g);
}
}
for (int i = 0; i < 60; i++) {
double d = Math.toRadians(i * 6);
g.setPoint(1, cx + (float) Math.sin(d) * radius,
cy + (float) Math.cos(d) * radius);
ll.addLine(g);
}
}
void addCircle(float cx, float cy, float radius, LineTexBucket ll) {
GeometryBuffer g = mGeom;
void addCircle(float cx, float cy, float radius, LineTexBucket ll) {
GeometryBuffer g = mGeom;
g.clear();
g.startLine();
g.addPoint(cx, cy);
g.addPoint(cx, cy);
g.clear();
g.startLine();
g.addPoint(cx, cy);
g.addPoint(cx, cy);
for (int i = 0; i < 60; i++) {
double d = Math.toRadians(i * 6);
g.setPoint(1, cx + (float) Math.sin(d) * radius,
cy + (float) Math.cos(d) * radius);
ll.addLine(g);
}
}
for (int i = 0; i < 60; i++) {
double d = Math.toRadians(i * 6);
g.setPoint(1, cx + (float) Math.sin(d) * radius,
cy + (float) Math.cos(d) * radius);
ll.addLine(g);
}
}
@Override
protected boolean onKeyDown(int keycode) {
if (keycode < Input.Keys.NUM_1 || keycode > Input.Keys.NUM_4)
return false;
@Override
protected boolean onKeyDown(int keycode) {
if (keycode < Input.Keys.NUM_1 || keycode > Input.Keys.NUM_4)
return false;
synchronized (l) {
l.clear();
synchronized (l) {
l.clear();
GeometryBuffer g = mLine;
g.clear();
g.startLine();
g.addPoint(-100, 0);
g.addPoint(100, 0);
GeometryBuffer g = mLine;
g.clear();
g.startLine();
g.addPoint(-100, 0);
g.addPoint(100, 0);
if (keycode == Input.Keys.NUM_1)
addLines(l, 0, true, true);
else if (keycode == Input.Keys.NUM_2)
addLines(l, 0, true, false);
else if (keycode == Input.Keys.NUM_3)
addLines(l, 0, false, true);
else if (keycode == Input.Keys.NUM_4)
addLines(l, 0, false, false);
}
if (keycode == Input.Keys.NUM_1)
addLines(l, 0, true, true);
else if (keycode == Input.Keys.NUM_2)
addLines(l, 0, true, false);
else if (keycode == Input.Keys.NUM_3)
addLines(l, 0, false, true);
else if (keycode == Input.Keys.NUM_4)
addLines(l, 0, false, false);
}
mMap.updateMap(true);
mMap.updateMap(true);
return true;
}
return true;
}
class LineTest extends BucketRenderer {
class LineTest extends BucketRenderer {
public LineTest() {
mMapPosition.scale = 0;
}
public LineTest() {
mMapPosition.scale = 0;
}
public synchronized void clear() {
buckets.clear();
setReady(false);
}
public synchronized void clear() {
buckets.clear();
setReady(false);
}
@Override
public synchronized void update(GLViewport v) {
@Override
public synchronized void update(GLViewport v) {
if (mMapPosition.scale == 0)
mMapPosition.copy(v.pos);
if (mMapPosition.scale == 0)
mMapPosition.copy(v.pos);
if (!isReady()) {
compile();
}
}
if (!isReady()) {
compile();
}
}
// @Override
// protected void setMatrix(MapPosition pos, Matrices m, boolean
// project) {
// m.useScreenCoordinates(true, 8f);
// }
}
// @Override
// protected void setMatrix(MapPosition pos, Matrices m, boolean
// project) {
// m.useScreenCoordinates(true, 8f);
// }
}
public static void main(String[] args) {
GdxMapApp.init();
GdxMapApp.run(new LineRenderTest(), null, 256);
}
public static void main(String[] args) {
GdxMapApp.init();
GdxMapApp.run(new LineRenderTest(), null, 256);
}
}

View File

@@ -1,5 +1,8 @@
package org.oscim.test;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input;
import org.oscim.backend.canvas.Color;
import org.oscim.core.GeometryBuffer;
import org.oscim.gdx.GdxMap;
@@ -11,100 +14,97 @@ import org.oscim.renderer.MapRenderer;
import org.oscim.renderer.bucket.LineBucket;
import org.oscim.theme.styles.LineStyle;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input;
public class LineTest extends GdxMap {
@Override
protected boolean onKeyDown(int keycode) {
if (keycode == Input.Keys.NUM_1) {
angle++;
mMap.render();
return true;
@Override
protected boolean onKeyDown(int keycode) {
if (keycode == Input.Keys.NUM_1) {
angle++;
mMap.render();
return true;
}
}
if (keycode == Input.Keys.NUM_2) {
angle--;
mMap.render();
return true;
if (keycode == Input.Keys.NUM_2) {
angle--;
mMap.render();
return true;
}
return false;
}
}
return false;
}
float angle = 0;
float angle = 0;
@Override
protected void createLayers() {
mMap.layers().add(new GenericLayer(mMap, new BucketRenderer() {
boolean init;
@Override
protected void createLayers() {
mMap.layers().add(new GenericLayer(mMap, new BucketRenderer() {
boolean init;
LineBucket ll = buckets.addLineBucket(0,
new LineStyle(Color.fade(Color.CYAN, 0.5f), 1.5f));
LineBucket ll = buckets.addLineBucket(0,
new LineStyle(Color.fade(Color.CYAN, 0.5f), 1.5f));
GeometryBuffer g = new GeometryBuffer(10, 1);
GeometryBuffer g = new GeometryBuffer(10, 1);
@Override
public void update(GLViewport v) {
if (!init) {
mMapPosition.copy(v.pos);
init = true;
@Override
public void update(GLViewport v) {
if (!init) {
mMapPosition.copy(v.pos);
init = true;
// g.addPoint(0, 0);
// g.addPoint(0, 1);
// g.addPoint(0.1f, 0);
//
// g.addPoint(1, 1);
// g.addPoint(2, 0);
//
// g.addPoint(2, 1);
// g.addPoint(2, 0);
//
// g.addPoint(3, 1);
// g.addPoint(3, 0);
// g.addPoint(3, 1);
//
// for (int i = 0; i < 60; i++){
// g.startLine();
// g.addPoint(0, 0);
// g.addPoint(0, 1);
// }
//
// g.scale(100, 100);
//
// ll.addLine(g);
//
// compile();
}
// g.addPoint(0, 0);
// g.addPoint(0, 1);
// g.addPoint(0.1f, 0);
//
// g.addPoint(1, 1);
// g.addPoint(2, 0);
//
// g.addPoint(2, 1);
// g.addPoint(2, 0);
//
// g.addPoint(3, 1);
// g.addPoint(3, 0);
// g.addPoint(3, 1);
//
// for (int i = 0; i < 60; i++){
// g.startLine();
// g.addPoint(0, 0);
// g.addPoint(0, 1);
// }
//
// g.scale(100, 100);
//
// ll.addLine(g);
//
// compile();
}
buckets.clear();
buckets.set(ll);
g.clear();
//for (int i = 0; i < 60; i++) {
g.startLine();
g.addPoint(-1, 0);
g.addPoint(0, 0);
g.addPoint((float) Math.cos(Math.toRadians(angle)),
(float) Math.sin(Math.toRadians(angle)));
//}
buckets.clear();
buckets.set(ll);
g.clear();
//for (int i = 0; i < 60; i++) {
g.startLine();
g.addPoint(-1, 0);
g.addPoint(0, 0);
g.addPoint((float) Math.cos(Math.toRadians(angle)),
(float) Math.sin(Math.toRadians(angle)));
//}
g.scale(100, 100);
g.scale(100, 100);
ll.addLine(g);
ll.addLine(g);
compile();
compile();
angle = Gdx.input.getX() / 2f % 360;
angle = Gdx.input.getX() / 2f % 360;
MapRenderer.animate();
}
}));
}
MapRenderer.animate();
}
}));
}
public static void main(String[] args) {
GdxMapApp.init();
GdxMapApp.run(new LineTest(), null, 256);
}
public static void main(String[] args) {
GdxMapApp.init();
GdxMapApp.run(new LineTest(), null, 256);
}
}

View File

@@ -10,21 +10,21 @@ import org.oscim.tiling.source.oscimap4.OSciMap4TileSource;
public class MapTest extends GdxMapApp {
@Override
public void createLayers() {
Map map = getMap();
@Override
public void createLayers() {
Map map = getMap();
VectorTileLayer l = map.setBaseMap(new OSciMap4TileSource());
VectorTileLayer l = map.setBaseMap(new OSciMap4TileSource());
map.layers().add(new BuildingLayer(map, l));
map.layers().add(new LabelLayer(map, l));
map.layers().add(new BuildingLayer(map, l));
map.layers().add(new LabelLayer(map, l));
map.setTheme(VtmThemes.DEFAULT);
map.setMapPosition(53.075, 8.808, 1 << 17);
}
map.setTheme(VtmThemes.DEFAULT);
map.setMapPosition(53.075, 8.808, 1 << 17);
}
public static void main(String[] args) {
GdxMapApp.init();
GdxMapApp.run(new MapTest(), null, 400);
}
public static void main(String[] args) {
GdxMapApp.init();
GdxMapApp.run(new MapTest(), null, 400);
}
}

View File

@@ -31,46 +31,46 @@ import java.io.File;
public class MapsforgeTest extends GdxMap {
private static File mapFile;
private static File mapFile;
@Override
public void createLayers() {
MapFileTileSource tileSource = new MapFileTileSource();
tileSource.setMapFile(mapFile.getAbsolutePath());
tileSource.setPreferredLanguage("en");
@Override
public void createLayers() {
MapFileTileSource tileSource = new MapFileTileSource();
tileSource.setMapFile(mapFile.getAbsolutePath());
tileSource.setPreferredLanguage("en");
VectorTileLayer l = mMap.setBaseMap(tileSource);
mMap.setTheme(VtmThemes.DEFAULT);
VectorTileLayer l = mMap.setBaseMap(tileSource);
mMap.setTheme(VtmThemes.DEFAULT);
mMap.layers().add(new BuildingLayer(mMap, l));
mMap.layers().add(new LabelLayer(mMap, l));
mMap.layers().add(new BuildingLayer(mMap, l));
mMap.layers().add(new LabelLayer(mMap, l));
MapInfo info = tileSource.getMapInfo();
MapPosition pos = new MapPosition();
pos.setByBoundingBox(info.boundingBox, Tile.SIZE * 4, Tile.SIZE * 4);
mMap.setMapPosition(pos);
}
MapInfo info = tileSource.getMapInfo();
MapPosition pos = new MapPosition();
pos.setByBoundingBox(info.boundingBox, Tile.SIZE * 4, Tile.SIZE * 4);
mMap.setMapPosition(pos);
}
private static File getMapFile(String[] args) {
if (args.length == 0) {
throw new IllegalArgumentException("missing argument: <mapFile>");
}
private static File getMapFile(String[] args) {
if (args.length == 0) {
throw new IllegalArgumentException("missing argument: <mapFile>");
}
File file = new File(args[0]);
if (!file.exists()) {
throw new IllegalArgumentException("file does not exist: " + file);
} else if (!file.isFile()) {
throw new IllegalArgumentException("not a file: " + file);
} else if (!file.canRead()) {
throw new IllegalArgumentException("cannot read file: " + file);
}
return file;
}
File file = new File(args[0]);
if (!file.exists()) {
throw new IllegalArgumentException("file does not exist: " + file);
} else if (!file.isFile()) {
throw new IllegalArgumentException("not a file: " + file);
} else if (!file.canRead()) {
throw new IllegalArgumentException("cannot read file: " + file);
}
return file;
}
public static void main(String[] args) {
mapFile = getMapFile(args);
public static void main(String[] args) {
mapFile = getMapFile(args);
GdxMapApp.init();
GdxMapApp.run(new MapsforgeTest(), null, 400);
}
GdxMapApp.init();
GdxMapApp.run(new MapsforgeTest(), null, 400);
}
}

View File

@@ -16,9 +16,6 @@
*/
package org.oscim.test;
import java.util.ArrayList;
import java.util.List;
import org.oscim.backend.canvas.Color;
import org.oscim.core.GeoPoint;
import org.oscim.core.MapPosition;
@@ -29,74 +26,77 @@ import org.oscim.layers.tile.bitmap.BitmapTileLayer;
import org.oscim.map.Map.UpdateListener;
import org.oscim.tiling.source.bitmap.DefaultSources;
import java.util.ArrayList;
import java.util.List;
public class PathLayerTest extends GdxMapApp {
@Override
public void createLayers() {
mMap.setBaseMap(new BitmapTileLayer(mMap, DefaultSources.STAMEN_TONER.build()));
@Override
public void createLayers() {
mMap.setBaseMap(new BitmapTileLayer(mMap, DefaultSources.STAMEN_TONER.build()));
createLayers(1, true);
createLayers(1, true);
mMap.setMapPosition(0, 0, 1 << 2);
mMap.setMapPosition(0, 0, 1 << 2);
mMap.events.bind(new UpdateListener() {
@Override
public void onMapEvent(Event e, MapPosition mapPosition) {
//if (e == Map.UPDATE_EVENT) {
long t = System.currentTimeMillis();
float pos = t % 20000 / 10000f - 1f;
createLayers(pos, false);
mMap.updateMap(true);
//}
}
});
}
mMap.events.bind(new UpdateListener() {
@Override
public void onMapEvent(Event e, MapPosition mapPosition) {
//if (e == Map.UPDATE_EVENT) {
long t = System.currentTimeMillis();
float pos = t % 20000 / 10000f - 1f;
createLayers(pos, false);
mMap.updateMap(true);
//}
}
});
}
ArrayList<JtsPathLayer> mPathLayers = new ArrayList<>();
ArrayList<JtsPathLayer> mPathLayers = new ArrayList<>();
void createLayers(float pos, boolean init) {
void createLayers(float pos, boolean init) {
int i = 0;
int i = 0;
for (double lat = -90; lat <= 90; lat += 5) {
List<GeoPoint> pts = new ArrayList<>();
for (double lat = -90; lat <= 90; lat += 5) {
List<GeoPoint> pts = new ArrayList<>();
for (double lon = -180; lon <= 180; lon += 2) {
//pts.add(new GeoPoint(lat, lon));
// double longitude = lon + (pos * 180);
// if (longitude < -180)
// longitude += 360;
// if (longitude > 180)
// longitude -= 360;
double longitude = lon;
for (double lon = -180; lon <= 180; lon += 2) {
//pts.add(new GeoPoint(lat, lon));
// double longitude = lon + (pos * 180);
// if (longitude < -180)
// longitude += 360;
// if (longitude > 180)
// longitude -= 360;
double longitude = lon;
double latitude = lat + (pos * 90);
if (latitude < -90)
latitude += 180;
if (latitude > 90)
latitude -= 180;
double latitude = lat + (pos * 90);
if (latitude < -90)
latitude += 180;
if (latitude > 90)
latitude -= 180;
latitude += Math.sin((Math.abs(pos) * (lon / Math.PI)));
latitude += Math.sin((Math.abs(pos) * (lon / Math.PI)));
pts.add(new GeoPoint(latitude, longitude));
}
JtsPathLayer pathLayer;
if (init) {
int c = Color.fade(Color.rainbow((float) (lat + 90) / 180), 0.5f);
pathLayer = new JtsPathLayer(mMap, c, 6);
mMap.layers().add(pathLayer);
mPathLayers.add(pathLayer);
} else {
pathLayer = mPathLayers.get(i++);
}
pts.add(new GeoPoint(latitude, longitude));
}
JtsPathLayer pathLayer;
if (init) {
int c = Color.fade(Color.rainbow((float) (lat + 90) / 180), 0.5f);
pathLayer = new JtsPathLayer(mMap, c, 6);
mMap.layers().add(pathLayer);
mPathLayers.add(pathLayer);
} else {
pathLayer = mPathLayers.get(i++);
}
pathLayer.setPoints(pts);
}
pathLayer.setPoints(pts);
}
}
}
public static void main(String[] args) {
GdxMapApp.init();
GdxMapApp.run(new PathLayerTest(), null, 400);
}
public static void main(String[] args) {
GdxMapApp.init();
GdxMapApp.run(new PathLayerTest(), null, 400);
}
}

View File

@@ -1,6 +1,6 @@
package org.oscim.test;
import static org.oscim.utils.ColorUtil.saturate;
import com.badlogic.gdx.Input;
import org.oscim.gdx.GdxMap;
import org.oscim.gdx.GdxMapApp;
@@ -20,104 +20,104 @@ import org.oscim.tiling.source.oscimap4.OSciMap4TileSource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.badlogic.gdx.Input;
import static org.oscim.utils.ColorUtil.saturate;
public class RuleVisitorTest extends GdxMap {
final Logger log = LoggerFactory.getLogger(RuleVisitorTest.class);
RenderTheme mTheme;
double mSaturation = 1;
final Logger log = LoggerFactory.getLogger(RuleVisitorTest.class);
RenderTheme mTheme;
double mSaturation = 1;
@Override
protected boolean onKeyDown(int keycode) {
VectorTileLayer l = (VectorTileLayer) mMap.layers().get(1);
RenderTheme t = (RenderTheme) l.getTheme();
@Override
protected boolean onKeyDown(int keycode) {
VectorTileLayer l = (VectorTileLayer) mMap.layers().get(1);
RenderTheme t = (RenderTheme) l.getTheme();
if (keycode == Input.Keys.NUM_1) {
mSaturation += 0.1;
t.traverseRules(new SaturateLineStyles(mSaturation, true, true, true));
t.updateStyles();
mMap.render();
return true;
}
if (keycode == Input.Keys.NUM_2) {
mSaturation -= 0.1;
t.traverseRules(new SaturateLineStyles(mSaturation, true, true, true));
t.updateStyles();
mMap.render();
return true;
}
if (keycode == Input.Keys.NUM_1) {
mSaturation += 0.1;
t.traverseRules(new SaturateLineStyles(mSaturation, true, true, true));
t.updateStyles();
mMap.render();
return true;
}
if (keycode == Input.Keys.NUM_2) {
mSaturation -= 0.1;
t.traverseRules(new SaturateLineStyles(mSaturation, true, true, true));
t.updateStyles();
mMap.render();
return true;
}
return super.onKeyDown(keycode);
}
return super.onKeyDown(keycode);
}
@Override
public void createLayers() {
MapRenderer.setBackgroundColor(0xf0f0f0);
@Override
public void createLayers() {
MapRenderer.setBackgroundColor(0xf0f0f0);
TileSource ts = new OSciMap4TileSource();
VectorTileLayer l = mMap.setBaseMap(ts);
TileSource ts = new OSciMap4TileSource();
VectorTileLayer l = mMap.setBaseMap(ts);
mMap.setTheme(VtmThemes.DEFAULT);
RenderTheme t = (RenderTheme) l.getTheme();
mTheme = t;
//t.traverseRules(new DesaturateAreaStyles());
//t.traverseRules(new DesaturateLineStyles());
t.traverseRules(new SaturateLineStyles(0.5, true, true, true));
t.updateStyles();
mMap.setTheme(VtmThemes.DEFAULT);
RenderTheme t = (RenderTheme) l.getTheme();
mTheme = t;
//t.traverseRules(new DesaturateAreaStyles());
//t.traverseRules(new DesaturateLineStyles());
t.traverseRules(new SaturateLineStyles(0.5, true, true, true));
t.updateStyles();
//mMap.setMapPosition(7.707, 81.689, 1 << 16);
//mMap.setMapPosition(7.707, 81.689, 1 << 16);
mMap.setMapPosition(53.08, 8.82, 1 << 16);
}
mMap.setMapPosition(53.08, 8.82, 1 << 16);
}
public static void main(String[] args) {
GdxMapApp.init();
GdxMapApp.run(new RuleVisitorTest(), null, 400);
}
public static void main(String[] args) {
GdxMapApp.init();
GdxMapApp.run(new RuleVisitorTest(), null, 400);
}
static class SaturateLineStyles extends RuleVisitor {
private final LineBuilder<?> lineBuilder = LineStyle.builder();
private final AreaBuilder<?> areaBuilder = AreaStyle.builder();
static class SaturateLineStyles extends RuleVisitor {
private final LineBuilder<?> lineBuilder = LineStyle.builder();
private final AreaBuilder<?> areaBuilder = AreaStyle.builder();
private final double saturation;
private final boolean modifyArea;
private final boolean modifyLine;
private final boolean relative;
private final double saturation;
private final boolean modifyArea;
private final boolean modifyLine;
private final boolean relative;
public SaturateLineStyles(double saturation, boolean relative, boolean modArea,
boolean modLine) {
this.saturation = saturation;
this.modifyArea = modArea;
this.modifyLine = modLine;
this.relative = relative;
}
public SaturateLineStyles(double saturation, boolean relative, boolean modArea,
boolean modLine) {
this.saturation = saturation;
this.modifyArea = modArea;
this.modifyLine = modLine;
this.relative = relative;
}
@Override
public void apply(Rule r) {
for (RenderStyle style : r.styles) {
@Override
public void apply(Rule r) {
for (RenderStyle style : r.styles) {
if (modifyLine && style instanceof LineStyle) {
LineStyle s = (LineStyle) style;
if (modifyLine && style instanceof LineStyle) {
LineStyle s = (LineStyle) style;
s.set(lineBuilder.set(s)
.color(saturate(s.color, saturation, relative))
.stippleColor(saturate(s.stippleColor, saturation, relative))
.build());
continue;
}
s.set(lineBuilder.set(s)
.color(saturate(s.color, saturation, relative))
.stippleColor(saturate(s.stippleColor, saturation, relative))
.build());
continue;
}
if (modifyArea && style instanceof AreaStyle) {
AreaStyle s = (AreaStyle) style;
if (modifyArea && style instanceof AreaStyle) {
AreaStyle s = (AreaStyle) style;
s.set(areaBuilder.set(s)
.color(saturate(s.color, saturation, relative))
.blendColor(saturate(s.blendColor, saturation, relative))
.build());
}
}
s.set(areaBuilder.set(s)
.color(saturate(s.color, saturation, relative))
.blendColor(saturate(s.blendColor, saturation, relative))
.build());
}
}
super.apply(r);
}
}
super.apply(r);
}
}
}

View File

@@ -24,25 +24,25 @@ import org.oscim.tiling.source.oscimap4.OSciMap4TileSource;
public class S3DBLayerTest extends GdxMapApp {
@Override
public void createLayers() {
mMap.setBaseMap(new OSciMap4TileSource());
mMap.setTheme(VtmThemes.DEFAULT);
@Override
public void createLayers() {
mMap.setBaseMap(new OSciMap4TileSource());
mMap.setTheme(VtmThemes.DEFAULT);
TileSource ts = OSciMap4TileSource
.builder()
.url("http://opensciencemap.org/tiles/s3db")
.build();
TileSource ts = OSciMap4TileSource
.builder()
.url("http://opensciencemap.org/tiles/s3db")
.build();
S3DBLayer tl = new S3DBLayer(mMap, ts);
mMap.layers().add(tl);
S3DBLayer tl = new S3DBLayer(mMap, ts);
mMap.layers().add(tl);
mMap.setMapPosition(53.08, 8.82, 1 << 17);
mMap.setMapPosition(53.08, 8.82, 1 << 17);
}
}
public static void main(String[] args) {
init();
run(new S3DBLayerTest(), null, 400);
}
public static void main(String[] args) {
init();
run(new S3DBLayerTest(), null, 400);
}
}

View File

@@ -26,79 +26,79 @@ import org.oscim.utils.pool.Inlist;
/**
* UNUSED
* */
*/
public abstract class SpriteManager<T> {
TexturePool pool;
TexturePool pool;
public class Sprite extends Inlist<Sprite> {
public class Sprite extends Inlist<Sprite> {
public Sprite(T i, TextureAtlas a, Rect r) {
atlas = a;
rect = r;
item = i;
}
public Sprite(T i, TextureAtlas a, Rect r) {
atlas = a;
rect = r;
item = i;
}
T item;
TextureAtlas atlas;
Rect rect;
}
T item;
TextureAtlas atlas;
Rect rect;
}
TextureAtlas mAtlas;
TextureAtlas curAtlas;
TextureAtlas mAtlas;
TextureAtlas curAtlas;
Sprite items;
Sprite items;
protected final Canvas mCanvas = CanvasAdapter.newCanvas();
protected TextureItem mTexture;
protected final Canvas mCanvas = CanvasAdapter.newCanvas();
protected TextureItem mTexture;
public SpriteManager() {
//mTexture = pool.get();
public SpriteManager() {
//mTexture = pool.get();
//mTexture.ownBitmap = true;
//mTexture.ownBitmap = true;
//mAtlas = new TextureAtlas(mTexture.bitmap);
//mAtlas = new TextureAtlas(mTexture.bitmap);
//mCanvas.setBitmap(mTexture.bitmap);
}
//mCanvas.setBitmap(mTexture.bitmap);
}
public Sprite getRegion(T item) {
//return items.get(item);
for (Sprite t = items; t != null; t = t.next)
if (t.item == item)
return t;
public Sprite getRegion(T item) {
//return items.get(item);
for (Sprite t = items; t != null; t = t.next)
if (t.item == item)
return t;
return null;
}
return null;
}
public void clear() {
for (TextureItem t = mTexture; t != null; t = t.dispose());
mAtlas.clear();
items = null;
public void clear() {
for (TextureItem t = mTexture; t != null; t = t.dispose()) ;
mAtlas.clear();
items = null;
//mTexture.bitmap.eraseColor(Color.TRANSPARENT);
mTexture = pool.get();
mCanvas.setBitmap(mTexture.bitmap);
}
//mTexture.bitmap.eraseColor(Color.TRANSPARENT);
mTexture = pool.get();
mCanvas.setBitmap(mTexture.bitmap);
}
public TextureItem getTextures() {
return mTexture;
}
public TextureItem getTextures() {
return mTexture;
}
public Sprite addItem(T item, int width, int height) {
Rect r = mAtlas.getRegion(width, height);
if (r == null) {
//create new atlas
return null;
}
Sprite sprite = new Sprite(item, mAtlas, r);
public Sprite addItem(T item, int width, int height) {
Rect r = mAtlas.getRegion(width, height);
if (r == null) {
//create new atlas
return null;
}
Sprite sprite = new Sprite(item, mAtlas, r);
items = Inlist.appendItem(items, sprite);
items = Inlist.appendItem(items, sprite);
draw(item, r);
draw(item, r);
return sprite;
}
return sprite;
}
abstract void draw(T item, Rect r);
abstract void draw(T item, Rect r);
}

View File

@@ -1,8 +1,5 @@
package org.oscim.test;
import java.util.ArrayList;
import java.util.Stack;
import org.oscim.theme.RenderTheme;
import org.oscim.theme.rule.Rule;
import org.oscim.theme.rule.Rule.Element;
@@ -16,114 +13,119 @@ import org.oscim.theme.styles.RenderStyle;
import org.oscim.theme.styles.TextStyle;
import org.oscim.theme.styles.TextStyle.TextBuilder;
import java.util.ArrayList;
import java.util.Stack;
public class ThemeBuilder {
protected final ArrayList<RuleBuilder> mRulesList = new ArrayList<RuleBuilder>();
protected final Stack<RuleBuilder> mRuleStack = new Stack<RuleBuilder>();
protected final ArrayList<RuleBuilder> mRulesList = new ArrayList<RuleBuilder>();
protected final Stack<RuleBuilder> mRuleStack = new Stack<RuleBuilder>();
protected int mLevels = 0;
protected int mMapBackground = 0xffffffff;
protected float mBaseTextSize = 1;
protected int mLevels = 0;
protected int mMapBackground = 0xffffffff;
protected float mBaseTextSize = 1;
protected RuleBuilder mCurrentRule;
protected RuleBuilder mCurrentRule;
public RenderTheme build() {
int[] layer = new int[1];
public RenderTheme build() {
int[] layer = new int[1];
Rule[] rules = new Rule[mRulesList.size()];
for (int i = 0, n = rules.length; i < n; i++)
rules[i] = mRulesList.get(i).onComplete(layer);
Rule[] rules = new Rule[mRulesList.size()];
for (int i = 0, n = rules.length; i < n; i++)
rules[i] = mRulesList.get(i).onComplete(layer);
RenderTheme theme = new RenderTheme(mMapBackground, mBaseTextSize, rules, mLevels);
RenderTheme theme = new RenderTheme(mMapBackground, mBaseTextSize, rules, mLevels);
mRulesList.clear();
mRuleStack.clear();
mRulesList.clear();
mRuleStack.clear();
return theme;
}
return theme;
}
public ThemeBuilder pop() {
public ThemeBuilder pop() {
mRuleStack.pop();
if (mRuleStack.empty()) {
mRulesList.add(mCurrentRule);
} else {
mCurrentRule = mRuleStack.peek();
}
return this;
}
mRuleStack.pop();
if (mRuleStack.empty()) {
mRulesList.add(mCurrentRule);
} else {
mCurrentRule = mRuleStack.peek();
}
return this;
}
public ThemeBuilder push(RuleBuilder rule) {
if (!mRuleStack.empty())
mCurrentRule.addSubRule(rule);
public ThemeBuilder push(RuleBuilder rule) {
if (!mRuleStack.empty())
mCurrentRule.addSubRule(rule);
mCurrentRule = rule;
mRuleStack.push(mCurrentRule);
mCurrentRule = rule;
mRuleStack.push(mCurrentRule);
return this;
}
return this;
}
public ThemeBuilder rules(RuleBuilder... rb) {
for (RuleBuilder r : rb) {
mRulesList.add(r);
}
return this;
}
public ThemeBuilder rules(RuleBuilder... rb) {
for (RuleBuilder r : rb) {
mRulesList.add(r);
}
return this;
}
public RuleBuilder pushParse(String keys, String values) {
public RuleBuilder pushParse(String keys, String values) {
return RuleBuilder.create(keys, values)
.zoom(~0)
.element(Element.ANY);
}
return RuleBuilder.create(keys, values)
.zoom(~0)
.element(Element.ANY);
}
public ThemeBuilder addStyle(RenderStyle style) {
mCurrentRule.addStyle(style);
return this;
}
public ThemeBuilder addStyle(RenderStyle style) {
mCurrentRule.addStyle(style);
return this;
}
protected void rules() {
protected void rules() {
};
}
public static LineBuilder<?> line(int color, float width) {
return LineStyle.builder()
.color(color)
.strokeWidth(width);
}
;
public static AreaBuilder<?> area(int color) {
return AreaStyle.builder()
.color(color);
}
public static LineBuilder<?> line(int color, float width) {
return LineStyle.builder()
.color(color)
.strokeWidth(width);
}
public static TextBuilder<?> wayText(float size, int color) {
return TextStyle.builder()
.fontSize(size)
.color(color);
}
public static AreaBuilder<?> area(int color) {
return AreaStyle.builder()
.color(color);
}
public static TextBuilder<?> nodeText(float size, int color) {
return TextStyle.builder()
.fontSize(size)
.color(color)
.isCaption(true);
}
public static TextBuilder<?> wayText(float size, int color) {
return TextStyle.builder()
.fontSize(size)
.color(color);
}
public static RuleBuilder matchKey(String key) {
return new RuleBuilder(RuleType.POSITIVE,
new String[] { key },
new String[] {});
}
public static TextBuilder<?> nodeText(float size, int color) {
return TextStyle.builder()
.fontSize(size)
.color(color)
.isCaption(true);
}
public static RuleBuilder matchValue(String value) {
return new RuleBuilder(RuleType.POSITIVE,
new String[] {},
new String[] { value });
}
public static RuleBuilder matchKey(String key) {
return new RuleBuilder(RuleType.POSITIVE,
new String[]{key},
new String[]{});
}
public static RuleBuilder matchKeyValue(String key, String value) {
return new RuleBuilder(RuleType.POSITIVE,
new String[] { key },
new String[] { value });
}
public static RuleBuilder matchValue(String value) {
return new RuleBuilder(RuleType.POSITIVE,
new String[]{},
new String[]{value});
}
public static RuleBuilder matchKeyValue(String key, String value) {
return new RuleBuilder(RuleType.POSITIVE,
new String[]{key},
new String[]{value});
}
}

View File

@@ -13,49 +13,49 @@ import org.slf4j.LoggerFactory;
public class ThemeBuilderTest extends GdxMap {
final Logger log = LoggerFactory.getLogger(S3DBLayerTest.class);
final Logger log = LoggerFactory.getLogger(S3DBLayerTest.class);
static class MyTheme extends ThemeBuilder {
public MyTheme() {
rules(
matchKeyValue("natural", "water")
.style(area(Color.BLUE)),
static class MyTheme extends ThemeBuilder {
public MyTheme() {
rules(
matchKeyValue("natural", "water")
.style(area(Color.BLUE)),
matchKeyValue("landuse", "forest")
.style(area(Color.GREEN)),
matchKeyValue("landuse", "forest")
.style(area(Color.GREEN)),
matchKeyValue("landuse", "residential")
.style(area(Color.LTGRAY)),
matchKeyValue("landuse", "residential")
.style(area(Color.LTGRAY)),
matchKey("highway")
.rules(matchValue("residential")
.style(line(Color.DKGRAY, 1.2f),
line(Color.WHITE, 1.1f)
.cap(Cap.ROUND)))
matchKey("highway")
.rules(matchValue("residential")
.style(line(Color.DKGRAY, 1.2f),
line(Color.WHITE, 1.1f)
.cap(Cap.ROUND)))
.style(line(Color.BLACK, 1)
.blur(0.5f)));
}
}
.style(line(Color.BLACK, 1)
.blur(0.5f)));
}
}
@Override
public void createLayers() {
@Override
public void createLayers() {
VectorTileLayer l = mMap.setBaseMap(new OSciMap4TileSource());
VectorTileLayer l = mMap.setBaseMap(new OSciMap4TileSource());
RenderTheme t = new MyTheme().build();
RenderTheme t = new MyTheme().build();
mMap.setTheme(t);
//mMap.setTheme(VtmThemes.DEFAULT);
mMap.setTheme(t);
//mMap.setTheme(VtmThemes.DEFAULT);
mMap.layers().add(new LabelLayer(mMap, l));
mMap.layers().add(new LabelLayer(mMap, l));
mMap.setMapPosition(53.08, 8.82, 1 << 17);
mMap.setMapPosition(53.08, 8.82, 1 << 17);
}
}
public static void main(String[] args) {
GdxMapApp.init();
GdxMapApp.run(new ThemeBuilderTest(), null, 400);
}
public static void main(String[] args) {
GdxMapApp.init();
GdxMapApp.run(new ThemeBuilderTest(), null, 400);
}
}

View File

@@ -1,9 +1,5 @@
package org.oscim.test;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import org.oscim.awt.AwtGraphics;
import org.oscim.backend.AssetAdapter;
import org.oscim.core.GeometryBuffer.GeometryType;
@@ -14,35 +10,39 @@ import org.oscim.theme.ThemeLoader;
import org.oscim.theme.VtmThemes;
import org.oscim.theme.styles.RenderStyle;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
public class ThemeTest {
public static void main(String[] args) {
AwtGraphics.init();
AssetAdapter.init(new AssetAdapter() {
@Override
public InputStream openFileAsStream(String name) {
try {
return new FileInputStream("/home/jeff/src/vtm/OpenScienceMap/vtm/assets/"
+ name);
} catch (FileNotFoundException e) {
e.printStackTrace();
return null;
}
}
});
public static void main(String[] args) {
AwtGraphics.init();
AssetAdapter.init(new AssetAdapter() {
@Override
public InputStream openFileAsStream(String name) {
try {
return new FileInputStream("/home/jeff/src/vtm/OpenScienceMap/vtm/assets/"
+ name);
} catch (FileNotFoundException e) {
e.printStackTrace();
return null;
}
}
});
IRenderTheme t = ThemeLoader.load(VtmThemes.DEFAULT);
IRenderTheme t = ThemeLoader.load(VtmThemes.DEFAULT);
TagSet tags = new TagSet();
tags.add(new Tag("highway", "trunk_link"));
tags.add(new Tag("brigde", "yes"));
tags.add(new Tag("oneway", "yes"));
TagSet tags = new TagSet();
tags.add(new Tag("highway", "trunk_link"));
tags.add(new Tag("brigde", "yes"));
tags.add(new Tag("oneway", "yes"));
RenderStyle[] ri = t.matchElement(GeometryType.LINE, tags, 16);
RenderStyle[] ri = t.matchElement(GeometryType.LINE, tags, 16);
for (RenderStyle r : ri) {
System.out.println("class: " + r.getClass().getName());
}
}
for (RenderStyle r : ri) {
System.out.println("class: " + r.getClass().getName());
}
}
}

View File

@@ -26,177 +26,177 @@ import org.oscim.tiling.source.oscimap4.OSciMap4TileSource;
public class TileRenderTest extends GdxMapApp {
static boolean loadOneTile = true;
// static int tileX = 34365 >> 2;
// static int tileY = 21333 >> 2;
// static byte tileZ = 14;
static boolean loadOneTile = true;
// static int tileX = 34365 >> 2;
// static int tileY = 21333 >> 2;
// static byte tileZ = 14;
static int tileX = 68747 >> 3;
static int tileY = 42648 >> 3;
static byte tileZ = 14;
static int tileX = 68747 >> 3;
static int tileY = 42648 >> 3;
static byte tileZ = 14;
@Override
public void createLayers() {
@Override
public void createLayers() {
mMap.layers().add(new TileGridLayer(mMap, Color.LTGRAY, 1.2f, 1));
mMap.layers().add(new TileGridLayer(mMap, Color.LTGRAY, 1.2f, 1));
MapTile tile = new MapTile(null, tileX, tileY, tileZ);
MapTile tile = new MapTile(null, tileX, tileY, tileZ);
double w = 1.0 / (1 << tile.zoomLevel);
double minLon = MercatorProjection.toLongitude(tile.x);
double maxLon = MercatorProjection.toLongitude(tile.x + w);
double minLat = MercatorProjection.toLatitude(tile.y + w);
double maxLat = MercatorProjection.toLatitude(tile.y);
double lat = minLat + (maxLat - minLat) / 2;
double lon = minLon + (maxLon - minLon) / 2;
double w = 1.0 / (1 << tile.zoomLevel);
double minLon = MercatorProjection.toLongitude(tile.x);
double maxLon = MercatorProjection.toLongitude(tile.x + w);
double minLat = MercatorProjection.toLatitude(tile.y + w);
double maxLat = MercatorProjection.toLatitude(tile.y);
double lat = minLat + (maxLat - minLat) / 2;
double lon = minLon + (maxLon - minLon) / 2;
MapPosition mapPosition = new MapPosition(lat, lon, 1 << tile.zoomLevel);
MapPosition mapPosition = new MapPosition(lat, lon, 1 << tile.zoomLevel);
mMap.setMapPosition(mapPosition);
mMap.setMapPosition(mapPosition);
final TileManager tileManager;
final TileManager tileManager;
if (loadOneTile) {
tile = new MapTile(new TileNode(), tileX, tileY, tileZ);
/* setup tile quad-tree, expected for locking */
tile.node.parent = tile.node;
tile.node.parent.parent = tile.node;
if (loadOneTile) {
tile = new MapTile(new TileNode(), tileX, tileY, tileZ);
/* setup tile quad-tree, expected for locking */
tile.node.parent = tile.node;
tile.node.parent.parent = tile.node;
/* setup TileSet contatining one tile */
final TileSet tiles = new TileSet();
tiles.cnt = 1;
tiles.tiles[0] = tile;
tiles.lockTiles();
final TileSet tiles = new TileSet();
tiles.cnt = 1;
tiles.tiles[0] = tile;
tiles.lockTiles();
tileManager = new TestTileManager(mMap, tiles);
} else {
/* create TileManager and calculate tiles for current position */
tileManager = new TileManager(mMap, 100);
}
tileManager = new TestTileManager(mMap, tiles);
} else {
/* create TileManager and calculate tiles for current position */
tileManager = new TileManager(mMap, 100);
}
/* get the loader created by VectorTileLayer ... */
final TestTileLoader[] tileLoader = { null };
final TestTileLoader[] tileLoader = {null};
TestVectorTileLayer tileLayer = new TestVectorTileLayer(mMap, tileManager);
tileLoader[0] = tileLayer.getTileLoader();
TestVectorTileLayer tileLayer = new TestVectorTileLayer(mMap, tileManager);
tileLoader[0] = tileLayer.getTileLoader();
TileSource tileSource = new OSciMap4TileSource();
//TileSource tileSource = new TestTileSource();
TileSource tileSource = new OSciMap4TileSource();
//TileSource tileSource = new TestTileSource();
tileLayer.setTileSource(tileSource);
tileLayer.setTileSource(tileSource);
//IRenderTheme theme = ThemeLoader.load(VtmThemes.OSMARENDER);
//tileLayer.setRenderTheme(theme);
//tileLayer.setRenderTheme(new DebugTheme());
//IRenderTheme theme = ThemeLoader.load(VtmThemes.OSMARENDER);
//tileLayer.setRenderTheme(theme);
//tileLayer.setRenderTheme(new DebugTheme());
/* need to create the labellayer here to get the tileloaded event */
LabelLayer labelLayer = new LabelLayer(mMap, tileLayer);
LabelLayer labelLayer = new LabelLayer(mMap, tileLayer);
//mMap.layers().add(tileLayer);
mMap.setBaseMap(tileLayer);
mMap.setTheme(VtmThemes.DEFAULT);
//mMap.layers().add(tileLayer);
mMap.setBaseMap(tileLayer);
mMap.setTheme(VtmThemes.DEFAULT);
log.debug("load tiles:");
if (loadOneTile) {
log.debug("load {}", tile);
log.debug("load tiles:");
if (loadOneTile) {
log.debug("load {}", tile);
tileLoader[0].loadTile(tile);
tileManager.jobCompleted(tile, QueryResult.SUCCESS);
} else {
tileManager.update(mapPosition);
MapTile t = tileManager.getTileJob();
while (t != null) {
log.debug("load {}", t);
tileLoader[0].loadTile(tile);
tileManager.jobCompleted(tile, QueryResult.SUCCESS);
} else {
tileManager.update(mapPosition);
MapTile t = tileManager.getTileJob();
while (t != null) {
log.debug("load {}", t);
tileLoader[0].loadTile(t);
tileManager.jobCompleted(t, QueryResult.SUCCESS);
tileLoader[0].loadTile(t);
tileManager.jobCompleted(t, QueryResult.SUCCESS);
t = tileManager.getTileJob();
}
}
t = tileManager.getTileJob();
}
}
mMap.layers().add(labelLayer);
mMap.layers().add(labelLayer);
MapRenderer.setBackgroundColor(0xff888888);
}
MapRenderer.setBackgroundColor(0xff888888);
}
static class TestTileLoader extends VectorTileLoader {
static class TestTileLoader extends VectorTileLoader {
public TestTileLoader(VectorTileLayer tileLayer) {
super(tileLayer);
}
public TestTileLoader(VectorTileLayer tileLayer) {
super(tileLayer);
}
@Override
public boolean loadTile(MapTile tile) {
mTile = tile;
return super.loadTile(tile);
}
@Override
public boolean loadTile(MapTile tile) {
mTile = tile;
return super.loadTile(tile);
}
@Override
public void process(MapElement element) {
/* ignore polygons for testing */
if (element.type != GeometryType.LINE)
return;
@Override
public void process(MapElement element) {
/* ignore polygons for testing */
if (element.type != GeometryType.LINE)
return;
if (element.tags.containsKey("name"))
super.process(element);
}
}
if (element.tags.containsKey("name"))
super.process(element);
}
}
static class TestVectorTileLayer extends VectorTileLayer {
final VectorTileLoader[] tileLoader = { null };
static class TestVectorTileLayer extends VectorTileLayer {
final VectorTileLoader[] tileLoader = {null};
public TestVectorTileLayer(Map map, TileManager tileManager) {
super(map, tileManager, new VectorTileRenderer());
}
public TestVectorTileLayer(Map map, TileManager tileManager) {
super(map, tileManager, new VectorTileRenderer());
}
TestTileLoader getTileLoader() {
return (TestTileLoader) mTileLoader[0];
}
TestTileLoader getTileLoader() {
return (TestTileLoader) mTileLoader[0];
}
@Override
protected int getNumLoaders() {
return 1;
}
@Override
protected int getNumLoaders() {
return 1;
}
@Override
protected void initLoader(int numLoaders) {
mTileLoader = new TileLoader[numLoaders];
for (int i = 0; i < numLoaders; i++) {
mTileLoader[i] = new TestTileLoader(this);
}
}
@Override
protected void initLoader(int numLoaders) {
mTileLoader = new TileLoader[numLoaders];
for (int i = 0; i < numLoaders; i++) {
mTileLoader[i] = new TestTileLoader(this);
}
}
@Override
public void onMapEvent(Event event, MapPosition mapPosition) {
@Override
public void onMapEvent(Event event, MapPosition mapPosition) {
/* ignore map events */
if (event != Map.CLEAR_EVENT)
return;
if (event != Map.CLEAR_EVENT)
return;
//super.onMapEvent(event, mapPosition);
}
}
//super.onMapEvent(event, mapPosition);
}
}
static class TestTileManager extends TileManager {
TileSet fixedTiles;
static class TestTileManager extends TileManager {
TileSet fixedTiles;
public TestTileManager(Map map, TileSet fixedTiles) {
super(map, 100);
this.fixedTiles = fixedTiles;
}
public TestTileManager(Map map, TileSet fixedTiles) {
super(map, 100);
this.fixedTiles = fixedTiles;
}
@Override
public boolean getActiveTiles(TileSet tileSet) {
if (tileSet == null)
tileSet = new TileSet(fixedTiles.cnt);
@Override
public boolean getActiveTiles(TileSet tileSet) {
if (tileSet == null)
tileSet = new TileSet(fixedTiles.cnt);
tileSet.setTiles(fixedTiles);
return true;
}
}
tileSet.setTiles(fixedTiles);
return true;
}
}
public static void main(String[] args) {
GdxMapApp.init();
GdxMapApp.run(new TileRenderTest(), null, 512);
}
public static void main(String[] args) {
GdxMapApp.init();
GdxMapApp.run(new TileRenderTest(), null, 512);
}
}

View File

@@ -28,67 +28,67 @@ import org.oscim.utils.ColorUtil;
public class VectorLayerTest extends GdxMapApp {
@Override
public void createLayers() {
mMap.setBaseMap(new OSciMap4TileSource());
mMap.setTheme(VtmThemes.DEFAULT);
@Override
public void createLayers() {
mMap.setBaseMap(new OSciMap4TileSource());
mMap.setTheme(VtmThemes.DEFAULT);
VectorLayer vectorLayer = new VectorLayer(mMap);
VectorLayer vectorLayer = new VectorLayer(mMap);
// vectorLayer.add(new PointDrawable(0, 180, Style.builder()
// .setBuffer(10)
// .setFillColor(Color.RED)
// .setFillAlpha(0.5)
// .build()));
//
// Geometry g = new GeomBuilder()
// .point(180, 0)
// .point()
// .buffer(6)
// .get();
//
// vectorLayer.add(new PolygonDrawable(g, defaultStyle()));
//
// vectorLayer.add(new PointDrawable(0, 180, Style.builder()
// .setBuffer(10)
// .setFillColor(Color.RED)
// .setFillAlpha(0.5)
// .build()));
//
// Geometry g = new GeomBuilder()
// .point(180, 0)
// .point()
// .buffer(6)
// .get();
//
// vectorLayer.add(new PolygonDrawable(g, defaultStyle()));
//
Style.Builder sb = Style.builder()
.buffer(0.4)
.fillColor(Color.RED)
.fillAlpha(0.2);
Style.Builder sb = Style.builder()
.buffer(0.4)
.fillColor(Color.RED)
.fillAlpha(0.2);
// int tileSize = 5;
// for (int x = -180; x < 200; x += tileSize) {
// for (int y = -90; y < 90; y += tileSize) {
// // Style style = sb.setFillAlpha(FastMath.clamp(FastMath.length(x, y) / 180, 0.2, 1))
// // .build();
//
// vectorLayer.add(new RectangleDrawable(FastMath.clamp(y, -85, 85), x,
// FastMath.clamp(y + tileSize - 0.1, -85, 85),
// x + tileSize - 0.1, style));
//
// }
// }
// int tileSize = 5;
// for (int x = -180; x < 200; x += tileSize) {
// for (int y = -90; y < 90; y += tileSize) {
// // Style style = sb.setFillAlpha(FastMath.clamp(FastMath.length(x, y) / 180, 0.2, 1))
// // .build();
//
// vectorLayer.add(new RectangleDrawable(FastMath.clamp(y, -85, 85), x,
// FastMath.clamp(y + tileSize - 0.1, -85, 85),
// x + tileSize - 0.1, style));
//
// }
// }
for (int i = 0; i < 1000; i++) {
Style style = sb.buffer(Math.random() * 1)
.fillColor(ColorUtil.setHue(Color.RED,
Math.random()))
.fillAlpha(0.5)
.build();
for (int i = 0; i < 1000; i++) {
Style style = sb.buffer(Math.random() * 1)
.fillColor(ColorUtil.setHue(Color.RED,
Math.random()))
.fillAlpha(0.5)
.build();
vectorLayer.add(new PointDrawable(Math.random() * 180 - 90,
Math.random() * 360 - 180,
style));
vectorLayer.add(new PointDrawable(Math.random() * 180 - 90,
Math.random() * 360 - 180,
style));
}
}
mMap.layers().add(vectorLayer);
mMap.layers().add(new TileGridLayer(mMap, 0xff222222, 1.2f, 1));
mMap.layers().add(vectorLayer);
mMap.layers().add(new TileGridLayer(mMap, 0xff222222, 1.2f, 1));
mMap.setMapPosition(0, 0, 1 << 2);
}
mMap.setMapPosition(0, 0, 1 << 2);
}
public static void main(String[] args) {
GdxMapApp.init();
GdxMapApp.run(new VectorLayerTest(), null, 400);
}
public static void main(String[] args) {
GdxMapApp.init();
GdxMapApp.run(new VectorLayerTest(), null, 400);
}
}

View File

@@ -12,37 +12,37 @@ import org.oscim.tiling.source.oscimap4.OSciMap4TileSource;
public class Gdx3DTest extends GdxMap {
@Override
public void createLayers() {
MapRenderer.setBackgroundColor(0xff888888);
@Override
public void createLayers() {
MapRenderer.setBackgroundColor(0xff888888);
mMap.setMapPosition(53.1, 8.8, 1 << 15);
mMap.setMapPosition(53.1, 8.8, 1 << 15);
TileSource ts = new OSciMap4TileSource();
// initDefaultLayers(ts, false, false, false);
TileSource ts = new OSciMap4TileSource();
// initDefaultLayers(ts, false, false, false);
VectorTileLayer mMapLayer = mMap.setBaseMap(ts);
mMap.setTheme(VtmThemes.DEFAULT);
// mMap.setTheme(VtmThemes.TRONRENDER);
VectorTileLayer mMapLayer = mMap.setBaseMap(ts);
mMap.setTheme(VtmThemes.DEFAULT);
// mMap.setTheme(VtmThemes.TRONRENDER);
mMap.layers().add(new BuildingLayer(mMap, mMapLayer));
mMap.layers().add(new BuildingLayer(mMap, mMapLayer));
// mMap.getLayers().add(new GenericLayer(mMap, new GridRenderer()));
// mMap.getLayers().add(new GenericLayer(mMap, new GridRenderer()));
// ts = new OSciMap4TileSource("http://opensciencemap.org/tiles/s3db");
// VectorTileLayer tl = new VectorTileLayer(mMap, 16, 16, 20);
// tl.setTileSource(ts);
// tl.setRenderTheme(ThemeLoader.load(VtmThemes.DEFAULT));
// mMap.getLayers().add(tl);
// mMap.getLayers().add(new BuildingLayer(mMap, tl.getTileLayer()));
// ts = new OSciMap4TileSource("http://opensciencemap.org/tiles/s3db");
// VectorTileLayer tl = new VectorTileLayer(mMap, 16, 16, 20);
// tl.setTileSource(ts);
// tl.setRenderTheme(ThemeLoader.load(VtmThemes.DEFAULT));
// mMap.getLayers().add(tl);
// mMap.getLayers().add(new BuildingLayer(mMap, tl.getTileLayer()));
mMap.layers().add(new Poi3DLayer(mMap, mMapLayer));
mMap.layers().add(new Poi3DLayer(mMap, mMapLayer));
mMap.layers().add(new LabelLayer(mMap, mMapLayer));
}
mMap.layers().add(new LabelLayer(mMap, mMapLayer));
}
public static void main(String[] args) {
GdxMapApp.init();
GdxMapApp.run(new Gdx3DTest(), null, 320);
}
public static void main(String[] args) {
GdxMapApp.init();
GdxMapApp.run(new Gdx3DTest(), null, 320);
}
}

View File

@@ -1,5 +1,9 @@
package org.oscim.test.gdx.poi3d;
import com.badlogic.gdx.assets.AssetManager;
import com.badlogic.gdx.graphics.g3d.Model;
import com.badlogic.gdx.graphics.g3d.model.Node;
import org.oscim.core.MapPosition;
import org.oscim.event.Event;
import org.oscim.layers.Layer;
@@ -7,231 +11,227 @@ import org.oscim.map.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.badlogic.gdx.assets.AssetManager;
import com.badlogic.gdx.graphics.g3d.Model;
import com.badlogic.gdx.graphics.g3d.model.Node;
public class GdxModelLayer extends Layer implements Map.UpdateListener {
static final Logger log = LoggerFactory.getLogger(GdxModelLayer.class);
static final Logger log = LoggerFactory.getLogger(GdxModelLayer.class);
GdxRenderer3D g3d;
GdxRenderer3D g3d;
//VectorTileLayer mTileLayer;
//VectorTileLayer mTileLayer;
public GdxModelLayer(Map map) {
super(map);
// tileLayer.addHook(new TileLoaderProcessHook() {
//
// @Override
// public boolean process(MapTile tile, ElementLayers layers, MapElement element) {
//
// if (!element.tags.contains(TREE_TAG))
// return false;
//
// Poi3DTileData td = get(tile);
// PointF p = element.getPoint(0);
// SymbolItem s = SymbolItem.pool.get();
// s.x = p.x;
// s.y = p.y;
// td.symbols.push(s);
//
// return true;
// }
// });
//mTileLayer = tileLayer;
public GdxModelLayer(Map map) {
super(map);
// tileLayer.addHook(new TileLoaderProcessHook() {
//
// @Override
// public boolean process(MapTile tile, ElementLayers layers, MapElement element) {
//
// if (!element.tags.contains(TREE_TAG))
// return false;
//
// Poi3DTileData td = get(tile);
// PointF p = element.getPoint(0);
// SymbolItem s = SymbolItem.pool.get();
// s.x = p.x;
// s.y = p.y;
// td.symbols.push(s);
//
// return true;
// }
// });
//mTileLayer = tileLayer;
mRenderer = g3d = new GdxRenderer3D(mMap);
mRenderer = g3d = new GdxRenderer3D(mMap);
// Material mat = new
// Material(ColorAttribute.createDiffuse(Color.BLUE));
// ModelBuilder modelBuilder = new ModelBuilder();
// long attributes = Usage.Position | Usage.Normal |
// Usage.TextureCoordinates;
// Material mat = new
// Material(ColorAttribute.createDiffuse(Color.BLUE));
// ModelBuilder modelBuilder = new ModelBuilder();
// long attributes = Usage.Position | Usage.Normal |
// Usage.TextureCoordinates;
// mModel = modelBuilder.createSphere(10f, 10f, 10f, 12, 12,
// mat, attributes);
// mModel = modelBuilder.createSphere(10f, 10f, 10f, 12, 12,
// mat, attributes);
assets = new AssetManager();
assets.load("data/g3d/test.g3db", Model.class);
loading = true;
}
assets = new AssetManager();
assets.load("data/g3d/test.g3db", Model.class);
loading = true;
}
// TileSet mTileSet = new TileSet();
// TileSet mPrevTiles = new TileSet();
//
// LinkedHashMap<Tile, Array<SharedModel>> mTileMap =
// new LinkedHashMap<Tile, Array<SharedModel>>();
// TileSet mTileSet = new TileSet();
// TileSet mPrevTiles = new TileSet();
//
// LinkedHashMap<Tile, Array<SharedModel>> mTileMap =
// new LinkedHashMap<Tile, Array<SharedModel>>();
boolean loading;
Model mModel;
AssetManager assets;
boolean loading;
Model mModel;
AssetManager assets;
private void doneLoading() {
Model model = assets.get("data/g3d/test.g3db", Model.class);
for (int i = 0; i < model.nodes.size; i++) {
Node node = model.nodes.get(i);
log.debug("loader node " + node.id);
private void doneLoading() {
Model model = assets.get("data/g3d/test.g3db", Model.class);
for (int i = 0; i < model.nodes.size; i++) {
Node node = model.nodes.get(i);
log.debug("loader node " + node.id);
if (node.id.equals("test_root")) {
node = node.getChild("Building", false, false);
log.debug("loader node " + node.id);
if (node.id.equals("test_root")) {
node = node.getChild("Building", false, false);
log.debug("loader node " + node.id);
node.rotation.setFromAxis(1, 0, 0, 90);
mModel = model;
node.rotation.setFromAxis(1, 0, 0, 90);
mModel = model;
break;
}
break;
}
//}
}
//}
}
loading = false;
}
loading = false;
}
@Override
public void onMapEvent(Event ev, MapPosition pos) {
@Override
public void onMapEvent(Event ev, MapPosition pos) {
// if (ev == Map.CLEAR_EVENT) {
// mTileSet = new TileSet();
// mPrevTiles = new TileSet();
// mTileMap = new LinkedHashMap<Tile, Array<SharedModel>>();
// synchronized (g3d) {
// g3d.instances.clear();
// }
// }
//
if (loading && assets.update()) {
doneLoading();
// Renderable renderable = new Renderable();
// new SharedModel(mModel).getRenderable(renderable);
// Shader shader = new DefaultShader(renderable, true, false,
// false, false, 1, 0, 0, 0);
// if (ev == Map.CLEAR_EVENT) {
// mTileSet = new TileSet();
// mPrevTiles = new TileSet();
// mTileMap = new LinkedHashMap<Tile, Array<SharedModel>>();
// synchronized (g3d) {
// g3d.instances.clear();
// }
// }
//
if (loading && assets.update()) {
doneLoading();
// Renderable renderable = new Renderable();
// new SharedModel(mModel).getRenderable(renderable);
// Shader shader = new DefaultShader(renderable, true, false,
// false, false, 1, 0, 0, 0);
g3d.instances.add(new SharedModel(mModel));
g3d.instances.add(new SharedModel(mModel));
}
if (loading)
return;
}
if (loading)
return;
int x = 17185 << 1;
int y = 10662 << 1;
int z = 16;
double scale = 1 / (1 << z);
int x = 17185 << 1;
int y = 10662 << 1;
int z = 16;
double scale = 1 / (1 << z);
g3d.cam.setMapPosition(x * scale - pos.x, y * scale - pos.y, scale / pos.scale);
g3d.cam.setMapPosition(x * scale - pos.x, y * scale - pos.y, scale / pos.scale);
//
// // log.debug("update");
//
// mTileLayer.tileRenderer().getVisibleTiles(mTileSet);
//
// if (mTileSet.cnt == 0) {
// mTileSet.releaseTiles();
// return;
// }
//
// boolean changed = false;
//
// Array<SharedModel> added = new Array<SharedModel>();
// Array<SharedModel> removed = new Array<SharedModel>();
//
// // log.debug("update");
//
// mTileLayer.tileRenderer().getVisibleTiles(mTileSet);
//
// if (mTileSet.cnt == 0) {
// mTileSet.releaseTiles();
// return;
// }
//
// boolean changed = false;
//
// Array<SharedModel> added = new Array<SharedModel>();
// Array<SharedModel> removed = new Array<SharedModel>();
// for (int i = 0; i < mTileSet.cnt; i++) {
// MapTile t = mTileSet.tiles[i];
// if (mPrevTiles.contains(t))
// continue;
//
// Array<SharedModel> instances = new Array<SharedModel>();
//
// Poi3DTileData ld = (Poi3DTileData) t.getData(POI_DATA);
// if (ld == null)
// continue;
//
// for (SymbolItem it : ld.symbols) {
//
// SharedModel inst = new SharedModel(mModel);
// inst.userData = it;
// // float r = 0.5f + 0.5f * (float) Math.random();
// // float g = 0.5f + 0.5f * (float) Math.random();
// // float b = 0.5f + 0.5f * (float) Math.random();
//
// // inst.transform.setTranslation(new Vector3(it.x, it.y,
// // 10));
// // inst.materials.get(0).set(ColorAttribute.createDiffuse(r,
// // g, b, 0.8f));
// instances.add(inst);
// added.add(inst);
// }
//
// if (instances.size == 0)
// continue;
//
// log.debug("add " + t + " " + instances.size);
//
// changed = true;
//
// mTileMap.put(t, instances);
// }
//
// for (int i = 0; i < mPrevTiles.cnt; i++) {
// MapTile t = mPrevTiles.tiles[i];
// if (mTileSet.contains(t))
// continue;
//
// Array<SharedModel> instances = mTileMap.get(t);
// if (instances == null)
// continue;
//
// changed = true;
//
// removed.addAll(instances);
// mTileMap.remove(t);
// log.debug("remove " + t);
// }
//
// mPrevTiles.releaseTiles();
//
// int zoom = mTileSet.tiles[0].zoomLevel;
//
// TileSet tmp = mPrevTiles;
// mPrevTiles = mTileSet;
// mTileSet = tmp;
//
// if (!changed)
// return;
//
// // scale aka tree height
// float scale = (float) (1f / (1 << (17 - zoom))) * 8;
//
// double tileX = (pos.x * (Tile.SIZE << zoom));
// double tileY = (pos.y * (Tile.SIZE << zoom));
//
// synchronized (g3d) {
//
// for (Entry<Tile, Array<SharedModel>> e : mTileMap.entrySet()) {
// Tile t = e.getKey();
//
// float dx = (float) (t.tileX * Tile.SIZE - tileX);
// float dy = (float) (t.tileY * Tile.SIZE - tileY);
//
// for (SharedModel inst : e.getValue()) {
// SymbolItem it = (SymbolItem) inst.userData;
//
// // variable height
// float s = scale + (it.x * it.y) % 3;
// float r = (it.x * it.y) % 360;
//
// inst.transform.idt();
// inst.transform.scale(s, s, s);
// inst.transform.translate((dx + it.x) / s, (dy + it.y) / s, 0);
// inst.transform.rotate(0, 0, 1, r);
//
// // inst.transform.setToTranslationAndScaling((dx +
// // it.x), (dy + it.y),
// // 0, s, s, s);
//
// }
// }
// for (int i = 0; i < mTileSet.cnt; i++) {
// MapTile t = mTileSet.tiles[i];
// if (mPrevTiles.contains(t))
// continue;
//
// Array<SharedModel> instances = new Array<SharedModel>();
//
// Poi3DTileData ld = (Poi3DTileData) t.getData(POI_DATA);
// if (ld == null)
// continue;
//
// for (SymbolItem it : ld.symbols) {
//
// SharedModel inst = new SharedModel(mModel);
// inst.userData = it;
// // float r = 0.5f + 0.5f * (float) Math.random();
// // float g = 0.5f + 0.5f * (float) Math.random();
// // float b = 0.5f + 0.5f * (float) Math.random();
//
// // inst.transform.setTranslation(new Vector3(it.x, it.y,
// // 10));
// // inst.materials.get(0).set(ColorAttribute.createDiffuse(r,
// // g, b, 0.8f));
// instances.add(inst);
// added.add(inst);
// }
//
// if (instances.size == 0)
// continue;
//
// log.debug("add " + t + " " + instances.size);
//
// changed = true;
//
// mTileMap.put(t, instances);
// }
//
// for (int i = 0; i < mPrevTiles.cnt; i++) {
// MapTile t = mPrevTiles.tiles[i];
// if (mTileSet.contains(t))
// continue;
//
// Array<SharedModel> instances = mTileMap.get(t);
// if (instances == null)
// continue;
//
// changed = true;
//
// removed.addAll(instances);
// mTileMap.remove(t);
// log.debug("remove " + t);
// }
//
// mPrevTiles.releaseTiles();
//
// int zoom = mTileSet.tiles[0].zoomLevel;
//
// TileSet tmp = mPrevTiles;
// mPrevTiles = mTileSet;
// mTileSet = tmp;
//
// if (!changed)
// return;
//
// // scale aka tree height
// float scale = (float) (1f / (1 << (17 - zoom))) * 8;
//
// double tileX = (pos.x * (Tile.SIZE << zoom));
// double tileY = (pos.y * (Tile.SIZE << zoom));
//
// synchronized (g3d) {
//
// for (Entry<Tile, Array<SharedModel>> e : mTileMap.entrySet()) {
// Tile t = e.getKey();
//
// float dx = (float) (t.tileX * Tile.SIZE - tileX);
// float dy = (float) (t.tileY * Tile.SIZE - tileY);
//
// for (SharedModel inst : e.getValue()) {
// SymbolItem it = (SymbolItem) inst.userData;
//
// // variable height
// float s = scale + (it.x * it.y) % 3;
// float r = (it.x * it.y) % 360;
//
// inst.transform.idt();
// inst.transform.scale(s, s, s);
// inst.transform.translate((dx + it.x) / s, (dy + it.y) / s, 0);
// inst.transform.rotate(0, 0, 1, r);
//
// // inst.transform.setToTranslationAndScaling((dx +
// // it.x), (dy + it.y),
// // 0, s, s, s);
//
// }
// }
}
}
}

View File

@@ -1,17 +1,5 @@
package org.oscim.test.gdx.poi3d;
import static org.oscim.backend.GLAdapter.gl;
import org.oscim.backend.GL;
import org.oscim.core.Tile;
import org.oscim.map.Map;
import org.oscim.map.Viewport;
import org.oscim.renderer.GLState;
import org.oscim.renderer.GLViewport;
import org.oscim.renderer.LayerRenderer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.badlogic.gdx.graphics.g3d.Environment;
import com.badlogic.gdx.graphics.g3d.Model;
import com.badlogic.gdx.graphics.g3d.ModelBatch;
@@ -25,162 +13,174 @@ import com.badlogic.gdx.graphics.g3d.utils.RenderContext;
import com.badlogic.gdx.math.Vector3;
import com.badlogic.gdx.utils.Array;
import org.oscim.backend.GL;
import org.oscim.core.Tile;
import org.oscim.map.Map;
import org.oscim.map.Viewport;
import org.oscim.renderer.GLState;
import org.oscim.renderer.GLViewport;
import org.oscim.renderer.LayerRenderer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import static org.oscim.backend.GLAdapter.gl;
public class GdxModelRenderer extends LayerRenderer {
static final Logger log = LoggerFactory.getLogger(GdxModelRenderer.class);
static final Logger log = LoggerFactory.getLogger(GdxModelRenderer.class);
ModelBatch modelBatch;
public MapCamera cam;
Map mMap;
ModelBatch modelBatch;
public MapCamera cam;
Map mMap;
boolean loading;
boolean loading;
public Environment lights;
public Environment lights;
public Array<SharedModel> instances = new Array<SharedModel>();
public Array<SharedModel> instances = new Array<SharedModel>();
public Shader shader;
public RenderContext renderContext;
public Model model;
private ModelBatch mBatch = new ModelBatch();
public Shader shader;
public RenderContext renderContext;
public Model model;
private ModelBatch mBatch = new ModelBatch();
public GdxModelRenderer(Map map) {
mMap = map;
}
public GdxModelRenderer(Map map) {
mMap = map;
}
@Override
public boolean setup() {
@Override
public boolean setup() {
modelBatch = new ModelBatch(new DefaultShaderProvider());
modelBatch = new ModelBatch(new DefaultShaderProvider());
lights = new Environment();
lights.set(new ColorAttribute(ColorAttribute.AmbientLight, 1.0f, 1.0f, 1.0f, 1.f));
lights.add(new DirectionalLight().set(0.3f, 0.3f, 0.3f, 0, 1, -0.2f));
lights = new Environment();
lights.set(new ColorAttribute(ColorAttribute.AmbientLight, 1.0f, 1.0f, 1.0f, 1.f));
lights.add(new DirectionalLight().set(0.3f, 0.3f, 0.3f, 0, 1, -0.2f));
cam = new MapCamera(mMap);
cam = new MapCamera(mMap);
renderContext =
new RenderContext(new DefaultTextureBinder(DefaultTextureBinder.WEIGHTED, 1));
renderContext =
new RenderContext(new DefaultTextureBinder(DefaultTextureBinder.WEIGHTED, 1));
// shader = new DefaultShader(renderable.material,
// renderable.mesh.getVertexAttributes(), true, false, 1, 0, 0, 0);
// shader.init();
// shader = new DefaultShader(renderable.material,
// renderable.mesh.getVertexAttributes(), true, false, 1, 0, 0, 0);
// shader.init();
return true;
}
return true;
}
@Override
public synchronized void update(GLViewport v) {
// if (loading && assets.update())
// doneLoading();
@Override
public synchronized void update(GLViewport v) {
// if (loading && assets.update())
// doneLoading();
if (!isReady()) {
cam.setPosition(v.pos);
setReady(true);
}
if (!isReady()) {
cam.setPosition(v.pos);
setReady(true);
}
// if (changed) {
// cam.update(position, matrices);
// }
}
// if (changed) {
// cam.update(position, matrices);
// }
}
Vector3 tempVector = new Vector3();
float[] mBox = new float[8];
Vector3 tempVector = new Vector3();
float[] mBox = new float[8];
Renderable r = new Renderable();
Renderable r = new Renderable();
@Override
public void render(GLViewport v) {
if (instances.size == 0)
return;
@Override
public void render(GLViewport v) {
if (instances.size == 0)
return;
// GLUtils.checkGlError(">" + TAG);
// GLUtils.checkGlError(">" + TAG);
gl.depthMask(true);
gl.depthMask(true);
if (v.pos.zoomLevel < 16)
gl.clear(GL.DEPTH_BUFFER_BIT);
if (v.pos.zoomLevel < 16)
gl.clear(GL.DEPTH_BUFFER_BIT);
gl.bindBuffer(GL.ELEMENT_ARRAY_BUFFER, 0);
gl.bindBuffer(GL.ELEMENT_ARRAY_BUFFER, 0);
// set state that is expected after modelBatch.end();
// modelBatch keeps track of its own state
GLState.enableVertexArrays(-1, -1);
GLState.bindTex2D(-1);
GLState.useProgram(-1);
GLState.test(false, false);
GLState.blend(false);
// set state that is expected after modelBatch.end();
// modelBatch keeps track of its own state
GLState.enableVertexArrays(-1, -1);
GLState.bindTex2D(-1);
GLState.useProgram(-1);
GLState.test(false, false);
GLState.blend(false);
cam.update(v);
cam.update(v);
Viewport p = mMap.viewport();
p.getMapExtents(mBox, 10);
float scale = (float) (cam.mMapPosition.scale / v.pos.scale);
Viewport p = mMap.viewport();
p.getMapExtents(mBox, 10);
float scale = (float) (cam.mMapPosition.scale / v.pos.scale);
float dx = (float) (cam.mMapPosition.x - v.pos.x)
* (Tile.SIZE << cam.mMapPosition.zoomLevel);
float dy = (float) (cam.mMapPosition.y - v.pos.y)
* (Tile.SIZE << cam.mMapPosition.zoomLevel);
float dx = (float) (cam.mMapPosition.x - v.pos.x)
* (Tile.SIZE << cam.mMapPosition.zoomLevel);
float dy = (float) (cam.mMapPosition.y - v.pos.y)
* (Tile.SIZE << cam.mMapPosition.zoomLevel);
for (int i = 0; i < 8; i += 2) {
mBox[i] *= scale;
mBox[i] -= dx;
mBox[i + 1] *= scale;
mBox[i + 1] -= dy;
}
for (int i = 0; i < 8; i += 2) {
mBox[i] *= scale;
mBox[i] -= dx;
mBox[i + 1] *= scale;
mBox[i + 1] -= dy;
}
//int w = mMap.getWidth() / 2;
//int h = mMap.getHeight() / 2;
//float sqRadius = (w * w + h * h) / scale;
//int w = mMap.getWidth() / 2;
//int h = mMap.getHeight() / 2;
//float sqRadius = (w * w + h * h) / scale;
synchronized (this) {
if (instances.size == 0)
return;
synchronized (this) {
if (instances.size == 0)
return;
//renderContext.begin();
//renderContext.begin();
// if (shader == null) {
// r = instances.get(0).getRenderable(r);
// DefaultShader.Config c = new DefaultShader.Config();
// c.numBones = 0;
// c.numDirectionalLights = 1;
// r.environment = lights;
//
// shader = new DefaultShader(r, c);
// shader.init();
// }
mBatch.begin(cam);
//shader.begin(cam, renderContext);
// if (shader == null) {
// r = instances.get(0).getRenderable(r);
// DefaultShader.Config c = new DefaultShader.Config();
// c.numBones = 0;
// c.numDirectionalLights = 1;
// r.environment = lights;
//
// shader = new DefaultShader(r, c);
// shader.init();
// }
mBatch.begin(cam);
//shader.begin(cam, renderContext);
for (SharedModel instance : instances) {
instance.transform.getTranslation(tempVector);
//instance.getRenderables(renderables, pool);
// if (tempVector.x * tempVector.x + tempVector.y * tempVector.y > sqRadius)
// continue;
// tempVector.scl(0.8f, 0.8f, 1);
// if (!GeometryUtils.pointInPoly(tempVector.x, tempVector.y, mBox, 8, 0))
// continue;
for (SharedModel instance : instances) {
instance.transform.getTranslation(tempVector);
//instance.getRenderables(renderables, pool);
// if (tempVector.x * tempVector.x + tempVector.y * tempVector.y > sqRadius)
// continue;
// tempVector.scl(0.8f, 0.8f, 1);
// if (!GeometryUtils.pointInPoly(tempVector.x, tempVector.y, mBox, 8, 0))
// continue;
mBatch.render(instance);
mBatch.render(instance);
//shader.render(r);
}
mBatch.end();
//shader.render(r);
}
mBatch.end();
//shader.end();
//renderContext.end();
}
//shader.end();
//renderContext.end();
}
gl.depthMask(false);
gl.bindBuffer(GL.ELEMENT_ARRAY_BUFFER, 0);
gl.bindBuffer(GL.ARRAY_BUFFER, 0);
}
gl.depthMask(false);
gl.bindBuffer(GL.ELEMENT_ARRAY_BUFFER, 0);
gl.bindBuffer(GL.ARRAY_BUFFER, 0);
}
// @Override
// public void dispose () {
// modelBatch.dispose();
// assets.dispose();
// assets = null;
// axesModel.dispose();
// axesModel = null;
// }
// @Override
// public void dispose () {
// modelBatch.dispose();
// assets.dispose();
// assets = null;
// axesModel.dispose();
// axesModel = null;
// }
}

View File

@@ -1,18 +1,5 @@
package org.oscim.test.gdx.poi3d;
import static org.oscim.backend.GLAdapter.gl;
import org.oscim.backend.GL;
import org.oscim.core.Tile;
import org.oscim.map.Map;
import org.oscim.map.Viewport;
import org.oscim.renderer.GLState;
import org.oscim.renderer.GLViewport;
import org.oscim.renderer.LayerRenderer;
import org.oscim.utils.geom.GeometryUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.badlogic.gdx.graphics.g3d.Environment;
import com.badlogic.gdx.graphics.g3d.Model;
import com.badlogic.gdx.graphics.g3d.ModelBatch;
@@ -27,174 +14,187 @@ import com.badlogic.gdx.graphics.g3d.utils.RenderContext;
import com.badlogic.gdx.math.Vector3;
import com.badlogic.gdx.utils.Array;
import org.oscim.backend.GL;
import org.oscim.core.Tile;
import org.oscim.map.Map;
import org.oscim.map.Viewport;
import org.oscim.renderer.GLState;
import org.oscim.renderer.GLViewport;
import org.oscim.renderer.LayerRenderer;
import org.oscim.utils.geom.GeometryUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import static org.oscim.backend.GLAdapter.gl;
public class GdxRenderer3D extends LayerRenderer {
static final Logger log = LoggerFactory.getLogger(GdxRenderer3D.class);
static final Logger log = LoggerFactory.getLogger(GdxRenderer3D.class);
ModelBatch modelBatch;
public MapCamera cam;
Map mMap;
ModelBatch modelBatch;
public MapCamera cam;
Map mMap;
boolean loading;
boolean loading;
public Environment lights;
public Environment lights;
public Array<SharedModel> instances = new Array<SharedModel>();
public Array<SharedModel> instances = new Array<SharedModel>();
public Shader shader;
public RenderContext renderContext;
public Model model;
public Shader shader;
public RenderContext renderContext;
public Model model;
public GdxRenderer3D(Map map) {
mMap = map;
}
public GdxRenderer3D(Map map) {
mMap = map;
}
@Override
public boolean setup() {
@Override
public boolean setup() {
modelBatch = new ModelBatch(new DefaultShaderProvider());
modelBatch = new ModelBatch(new DefaultShaderProvider());
lights = new Environment();
lights.set(new ColorAttribute(ColorAttribute.AmbientLight, 1.0f, 1.0f, 1.0f, 1.f));
lights.add(new DirectionalLight().set(0.3f, 0.3f, 0.3f, 0, 1, -0.2f));
lights = new Environment();
lights.set(new ColorAttribute(ColorAttribute.AmbientLight, 1.0f, 1.0f, 1.0f, 1.f));
lights.add(new DirectionalLight().set(0.3f, 0.3f, 0.3f, 0, 1, -0.2f));
cam = new MapCamera(mMap);
cam = new MapCamera(mMap);
renderContext =
new RenderContext(new DefaultTextureBinder(DefaultTextureBinder.WEIGHTED, 1));
renderContext =
new RenderContext(new DefaultTextureBinder(DefaultTextureBinder.WEIGHTED, 1));
// shader = new DefaultShader(renderable.material,
// renderable.mesh.getVertexAttributes(), true, false, 1, 0, 0, 0);
// shader.init();
// shader = new DefaultShader(renderable.material,
// renderable.mesh.getVertexAttributes(), true, false, 1, 0, 0, 0);
// shader.init();
return true;
}
return true;
}
@Override
public synchronized void update(GLViewport v) {
// if (loading && assets.update())
// doneLoading();
@Override
public synchronized void update(GLViewport v) {
// if (loading && assets.update())
// doneLoading();
if (!isReady()) {
cam.setPosition(v.pos);
setReady(true);
}
if (!isReady()) {
cam.setPosition(v.pos);
setReady(true);
}
// if (changed) {
// cam.update(position, matrices);
// }
}
// if (changed) {
// cam.update(position, matrices);
// }
}
Vector3 tempVector = new Vector3();
float[] mBox = new float[8];
Vector3 tempVector = new Vector3();
float[] mBox = new float[8];
Renderable r = new Renderable();
Renderable r = new Renderable();
@Override
public void render(GLViewport v) {
if (instances.size == 0)
return;
@Override
public void render(GLViewport v) {
if (instances.size == 0)
return;
// GLUtils.checkGlError(">" + TAG);
// GLUtils.checkGlError(">" + TAG);
gl.depthMask(true);
gl.depthMask(true);
// if (position.zoomLevel < 17)
// GL.clear(GL20.DEPTH_BUFFER_BIT);
// if (position.zoomLevel < 17)
// GL.clear(GL20.DEPTH_BUFFER_BIT);
gl.bindBuffer(GL.ELEMENT_ARRAY_BUFFER, 0);
gl.bindBuffer(GL.ELEMENT_ARRAY_BUFFER, 0);
// set state that is expected after modelBatch.end();
// modelBatch keeps track of its own state
GLState.enableVertexArrays(-1, -1);
GLState.bindTex2D(-1);
GLState.useProgram(-1);
GLState.test(false, false);
GLState.blend(false);
// set state that is expected after modelBatch.end();
// modelBatch keeps track of its own state
GLState.enableVertexArrays(-1, -1);
GLState.bindTex2D(-1);
GLState.useProgram(-1);
GLState.test(false, false);
GLState.blend(false);
cam.update(v);
long time = System.currentTimeMillis();
cam.update(v);
long time = System.currentTimeMillis();
int cnt = 0;
int rnd = 0;
int cnt = 0;
int rnd = 0;
Viewport p = mMap.viewport();
p.getMapExtents(mBox, 10);
float scale = (float) (cam.mMapPosition.scale / v.pos.scale);
Viewport p = mMap.viewport();
p.getMapExtents(mBox, 10);
float scale = (float) (cam.mMapPosition.scale / v.pos.scale);
float dx = (float) (cam.mMapPosition.x - v.pos.x)
* (Tile.SIZE << cam.mMapPosition.zoomLevel);
float dy = (float) (cam.mMapPosition.y - v.pos.y)
* (Tile.SIZE << cam.mMapPosition.zoomLevel);
float dx = (float) (cam.mMapPosition.x - v.pos.x)
* (Tile.SIZE << cam.mMapPosition.zoomLevel);
float dy = (float) (cam.mMapPosition.y - v.pos.y)
* (Tile.SIZE << cam.mMapPosition.zoomLevel);
for (int i = 0; i < 8; i += 2) {
mBox[i] *= scale;
mBox[i] -= dx;
mBox[i + 1] *= scale;
mBox[i + 1] -= dy;
}
for (int i = 0; i < 8; i += 2) {
mBox[i] *= scale;
mBox[i] -= dx;
mBox[i + 1] *= scale;
mBox[i + 1] -= dy;
}
int w = mMap.getWidth() / 2;
int h = mMap.getHeight() / 2;
int w = mMap.getWidth() / 2;
int h = mMap.getHeight() / 2;
float sqRadius = (w * w + h * h) / scale;
float sqRadius = (w * w + h * h) / scale;
synchronized (this) {
if (instances.size == 0)
return;
synchronized (this) {
if (instances.size == 0)
return;
cnt = instances.size;
cnt = instances.size;
renderContext.begin();
renderContext.begin();
if (shader == null) {
r = instances.get(0).getRenderable(r);
DefaultShader.Config c = new DefaultShader.Config();
c.numBones = 0;
c.numDirectionalLights = 1;
r.environment = lights;
// shader = new DefaultShader(r, true, false, false, false, 1,
// 0, 0, 0);
shader = new DefaultShader(r, c);
shader.init();
}
if (shader == null) {
r = instances.get(0).getRenderable(r);
DefaultShader.Config c = new DefaultShader.Config();
c.numBones = 0;
c.numDirectionalLights = 1;
r.environment = lights;
// shader = new DefaultShader(r, true, false, false, false, 1,
// 0, 0, 0);
shader = new DefaultShader(r, c);
shader.init();
}
shader.begin(cam, renderContext);
shader.begin(cam, renderContext);
for (SharedModel instance : instances) {
instance.transform.getTranslation(tempVector);
for (SharedModel instance : instances) {
instance.transform.getTranslation(tempVector);
if (tempVector.x * tempVector.x + tempVector.y * tempVector.y > sqRadius)
continue;
if (tempVector.x * tempVector.x + tempVector.y * tempVector.y > sqRadius)
continue;
tempVector.scl(0.8f, 0.8f, 1);
tempVector.scl(0.8f, 0.8f, 1);
if (!GeometryUtils.pointInPoly(tempVector.x, tempVector.y, mBox, 8, 0))
continue;
if (!GeometryUtils.pointInPoly(tempVector.x, tempVector.y, mBox, 8, 0))
continue;
instance.getRenderable(r);
// r.lights = lights;
// r.environment = lights;
shader.render(r);
instance.getRenderable(r);
// r.lights = lights;
// r.environment = lights;
shader.render(r);
rnd++;
}
rnd++;
}
shader.end();
renderContext.end();
}
log.debug(">>> " + (System.currentTimeMillis() - time) + " " + cnt + "/" + rnd);
shader.end();
renderContext.end();
}
log.debug(">>> " + (System.currentTimeMillis() - time) + " " + cnt + "/" + rnd);
gl.depthMask(false);
gl.bindBuffer(GL.ELEMENT_ARRAY_BUFFER, 0);
gl.bindBuffer(GL.ARRAY_BUFFER, 0);
}
gl.depthMask(false);
gl.bindBuffer(GL.ELEMENT_ARRAY_BUFFER, 0);
gl.bindBuffer(GL.ARRAY_BUFFER, 0);
}
// @Override
// public void dispose () {
// modelBatch.dispose();
// assets.dispose();
// assets = null;
// axesModel.dispose();
// axesModel = null;
// }
// @Override
// public void dispose () {
// modelBatch.dispose();
// assets.dispose();
// assets = null;
// axesModel.dispose();
// axesModel = null;
// }
}

View File

@@ -1,6 +1,11 @@
package org.oscim.test.gdx.poi3d;
import static org.oscim.backend.GLAdapter.gl;
import com.badlogic.gdx.graphics.g3d.Environment;
import com.badlogic.gdx.graphics.g3d.ModelBatch;
import com.badlogic.gdx.graphics.g3d.environment.DirectionalLight;
import com.badlogic.gdx.graphics.g3d.utils.DefaultShaderProvider;
import com.badlogic.gdx.math.Vector3;
import com.badlogic.gdx.utils.Array;
import org.oscim.backend.GL;
import org.oscim.core.Tile;
@@ -13,154 +18,149 @@ import org.oscim.utils.geom.GeometryUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.badlogic.gdx.graphics.g3d.Environment;
import com.badlogic.gdx.graphics.g3d.ModelBatch;
import com.badlogic.gdx.graphics.g3d.environment.DirectionalLight;
import com.badlogic.gdx.graphics.g3d.utils.DefaultShaderProvider;
import com.badlogic.gdx.math.Vector3;
import com.badlogic.gdx.utils.Array;
import static org.oscim.backend.GLAdapter.gl;
public class GdxRenderer3D2 extends LayerRenderer {
static final Logger log = LoggerFactory.getLogger(GdxRenderer3D2.class);
static final Logger log = LoggerFactory.getLogger(GdxRenderer3D2.class);
ModelBatch modelBatch;
public MapCamera cam;
Map mMap;
ModelBatch modelBatch;
public MapCamera cam;
Map mMap;
boolean loading;
boolean loading;
public Environment lights;
public Environment lights;
public Array<SharedModel> instances = new Array<SharedModel>();
public Array<SharedModel> instances = new Array<SharedModel>();
public GdxRenderer3D2(Map map) {
mMap = map;
}
public GdxRenderer3D2(Map map) {
mMap = map;
}
@Override
public boolean setup() {
@Override
public boolean setup() {
// if (assets == null)
// assets = new AssetManager();
// if (assets == null)
// assets = new AssetManager();
// assets.load("data/g3d/invaders.g3dj", Model.class);
// loading = true;
// assets.load("data/g3d/invaders.g3dj", Model.class);
// loading = true;
modelBatch = new ModelBatch(new DefaultShaderProvider());
modelBatch = new ModelBatch(new DefaultShaderProvider());
lights = new Environment();
// lights.ambientLight.set(1.0f, 1.0f, 1.0f, 1f);
// lights.ambientLight.set(215 / 255f,
// 240 / 255f,
// 51 / 255f, 1f);
lights = new Environment();
// lights.ambientLight.set(1.0f, 1.0f, 1.0f, 1f);
// lights.ambientLight.set(215 / 255f,
// 240 / 255f,
// 51 / 255f, 1f);
lights.add(new DirectionalLight().set(0.9f, 0.9f, 0.9f, 0, 1, -0.2f));
lights.add(new DirectionalLight().set(0.9f, 0.9f, 0.9f, 0, 1, -0.2f));
cam = new MapCamera(mMap);
cam = new MapCamera(mMap);
return true;
}
return true;
}
@Override
public synchronized void update(GLViewport v) {
// if (loading && assets.update())
// doneLoading();
@Override
public synchronized void update(GLViewport v) {
// if (loading && assets.update())
// doneLoading();
if (!isReady()) {
cam.setPosition(v.pos);
setReady(true);
}
if (!isReady()) {
cam.setPosition(v.pos);
setReady(true);
}
// if (changed) {
// cam.update(position, matrices);
// }
}
// if (changed) {
// cam.update(position, matrices);
// }
}
Vector3 tempVector = new Vector3();
float[] mBox = new float[8];
Vector3 tempVector = new Vector3();
float[] mBox = new float[8];
@Override
public void render(GLViewport v) {
if (instances.size == 0)
return;
@Override
public void render(GLViewport v) {
if (instances.size == 0)
return;
// GLUtils.checkGlError(">" + TAG);
// GLUtils.checkGlError(">" + TAG);
gl.depthMask(true);
gl.depthMask(true);
if (v.pos.zoomLevel < 17)
gl.clear(GL.DEPTH_BUFFER_BIT);
if (v.pos.zoomLevel < 17)
gl.clear(GL.DEPTH_BUFFER_BIT);
gl.bindBuffer(GL.ELEMENT_ARRAY_BUFFER, 0);
gl.bindBuffer(GL.ELEMENT_ARRAY_BUFFER, 0);
// set state that is expected after modelBatch.end();
// modelBatch keeps track of its own state
GLState.enableVertexArrays(-1, -1);
GLState.bindTex2D(-1);
GLState.useProgram(-1);
GLState.test(false, false);
GLState.blend(false);
// set state that is expected after modelBatch.end();
// modelBatch keeps track of its own state
GLState.enableVertexArrays(-1, -1);
GLState.bindTex2D(-1);
GLState.useProgram(-1);
GLState.test(false, false);
GLState.blend(false);
// GL.cullFace(GL20.BACK);
// GL.frontFace(GL20.CW);
// GL.cullFace(GL20.BACK);
// GL.frontFace(GL20.CW);
cam.update(v);
long time = System.currentTimeMillis();
cam.update(v);
long time = System.currentTimeMillis();
int cnt = 0;
int rnd = 0;
int cnt = 0;
int rnd = 0;
Viewport p = mMap.viewport();
p.getMapExtents(mBox, 10);
float scale = (float) (cam.mMapPosition.scale / v.pos.scale);
Viewport p = mMap.viewport();
p.getMapExtents(mBox, 10);
float scale = (float) (cam.mMapPosition.scale / v.pos.scale);
float dx =
(float) (cam.mMapPosition.x - v.pos.x)
* (Tile.SIZE << cam.mMapPosition.zoomLevel);
float dy =
(float) (cam.mMapPosition.y - v.pos.y)
* (Tile.SIZE << cam.mMapPosition.zoomLevel);
float dx =
(float) (cam.mMapPosition.x - v.pos.x)
* (Tile.SIZE << cam.mMapPosition.zoomLevel);
float dy =
(float) (cam.mMapPosition.y - v.pos.y)
* (Tile.SIZE << cam.mMapPosition.zoomLevel);
for (int i = 0; i < 8; i += 2) {
mBox[i] *= scale;
mBox[i] -= dx;
mBox[i + 1] *= scale;
mBox[i + 1] -= dy;
}
for (int i = 0; i < 8; i += 2) {
mBox[i] *= scale;
mBox[i] -= dx;
mBox[i + 1] *= scale;
mBox[i + 1] -= dy;
}
synchronized (this) {
modelBatch.begin(cam);
cnt = instances.size;
synchronized (this) {
modelBatch.begin(cam);
cnt = instances.size;
for (SharedModel instance : instances) {
instance.transform.getTranslation(tempVector);
tempVector.scl(0.9f, 0.9f, 1);
if (!GeometryUtils.pointInPoly(tempVector.x, tempVector.y, mBox, 8, 0))
continue;
for (SharedModel instance : instances) {
instance.transform.getTranslation(tempVector);
tempVector.scl(0.9f, 0.9f, 1);
if (!GeometryUtils.pointInPoly(tempVector.x, tempVector.y, mBox, 8, 0))
continue;
modelBatch.render(instance);
rnd++;
}
modelBatch.end();
}
log.debug(">>> " + (System.currentTimeMillis() - time) + " " + cnt + "/" + rnd);
modelBatch.render(instance);
rnd++;
}
modelBatch.end();
}
log.debug(">>> " + (System.currentTimeMillis() - time) + " " + cnt + "/" + rnd);
// GLUtils.checkGlError("<" + TAG);
// GLUtils.checkGlError("<" + TAG);
gl.depthMask(false);
gl.bindBuffer(GL.ELEMENT_ARRAY_BUFFER, 0);
gl.bindBuffer(GL.ARRAY_BUFFER, 0);
gl.depthMask(false);
gl.bindBuffer(GL.ELEMENT_ARRAY_BUFFER, 0);
gl.bindBuffer(GL.ARRAY_BUFFER, 0);
// GLState.bindTex2D(-1);
// GLState.useProgram(-1);
}
// GLState.bindTex2D(-1);
// GLState.useProgram(-1);
}
// @Override
// public void dispose () {
// modelBatch.dispose();
// assets.dispose();
// assets = null;
// axesModel.dispose();
// axesModel = null;
// }
// @Override
// public void dispose () {
// modelBatch.dispose();
// assets.dispose();
// assets = null;
// axesModel.dispose();
// axesModel = null;
// }
}

View File

@@ -1,70 +1,70 @@
package org.oscim.test.gdx.poi3d;
import com.badlogic.gdx.graphics.Camera;
import com.badlogic.gdx.math.Matrix4;
import org.oscim.core.MapPosition;
import org.oscim.core.Tile;
import org.oscim.map.Map;
import org.oscim.renderer.GLViewport;
import com.badlogic.gdx.graphics.Camera;
import com.badlogic.gdx.math.Matrix4;
public class MapCamera extends Camera {
private final Map mMap;
private final Map mMap;
public MapCamera(Map map) {
mMap = map;
public MapCamera(Map map) {
mMap = map;
this.near = 1;
this.far = 8;
}
this.near = 1;
this.far = 8;
}
MapPosition mMapPosition = new MapPosition();
MapPosition mMapPosition = new MapPosition();
public void setPosition(MapPosition pos) {
mMapPosition.copy(pos);
public void setPosition(MapPosition pos) {
mMapPosition.copy(pos);
this.viewportWidth = mMap.getWidth();
this.viewportHeight = mMap.getHeight();
}
this.viewportWidth = mMap.getWidth();
this.viewportHeight = mMap.getHeight();
}
public void setMapPosition(double x, double y, double scale) {
mMapPosition.setScale(scale);
mMapPosition.x = x;
mMapPosition.y = y;
}
public void setMapPosition(double x, double y, double scale) {
mMapPosition.setScale(scale);
mMapPosition.x = x;
mMapPosition.y = y;
}
public void update(GLViewport v) {
double scale = (v.pos.scale * Tile.SIZE);
public void update(GLViewport v) {
double scale = (v.pos.scale * Tile.SIZE);
float x = (float) ((mMapPosition.x - v.pos.x) * scale);
float y = (float) ((mMapPosition.y - v.pos.y) * scale);
float z = (float) (v.pos.scale / mMapPosition.scale);
float x = (float) ((mMapPosition.x - v.pos.x) * scale);
float y = (float) ((mMapPosition.y - v.pos.y) * scale);
float z = (float) (v.pos.scale / mMapPosition.scale);
v.proj.get(projection.getValues());
v.mvp.setTransScale(x, y, z);
v.mvp.setValue(10, z);
v.mvp.multiplyLhs(v.view);
v.mvp.get(view.getValues());
v.proj.get(projection.getValues());
v.mvp.setTransScale(x, y, z);
v.mvp.setValue(10, z);
v.mvp.multiplyLhs(v.view);
v.mvp.get(view.getValues());
combined.set(projection);
combined.set(projection);
Matrix4.mul(combined.val, view.val);
Matrix4.mul(combined.val, view.val);
//if (updateFrustum) {
invProjectionView.set(combined);
Matrix4.inv(invProjectionView.val);
frustum.update(invProjectionView);
//}
}
//if (updateFrustum) {
invProjectionView.set(combined);
Matrix4.inv(invProjectionView.val);
frustum.update(invProjectionView);
//}
}
@Override
public void update() {
}
@Override
public void update() {
}
@Override
public void update(boolean updateFrustum) {
@Override
public void update(boolean updateFrustum) {
}
}
}

View File

@@ -1,7 +1,9 @@
package org.oscim.test.gdx.poi3d;
import java.util.LinkedHashMap;
import java.util.Map.Entry;
import com.badlogic.gdx.assets.AssetManager;
import com.badlogic.gdx.graphics.g3d.Model;
import com.badlogic.gdx.graphics.g3d.model.Node;
import com.badlogic.gdx.utils.Array;
import org.oscim.core.MapElement;
import org.oscim.core.MapPosition;
@@ -21,242 +23,240 @@ import org.oscim.renderer.bucket.SymbolItem;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.badlogic.gdx.assets.AssetManager;
import com.badlogic.gdx.graphics.g3d.Model;
import com.badlogic.gdx.graphics.g3d.model.Node;
import com.badlogic.gdx.utils.Array;
import java.util.LinkedHashMap;
import java.util.Map.Entry;
public class Poi3DLayer extends Layer implements Map.UpdateListener {
static final Logger log = LoggerFactory.getLogger(Poi3DLayer.class);
static final Logger log = LoggerFactory.getLogger(Poi3DLayer.class);
static class Poi3DTileData extends TileData {
public final List<SymbolItem> symbols = new List<SymbolItem>();
static class Poi3DTileData extends TileData {
public final List<SymbolItem> symbols = new List<SymbolItem>();
@Override
protected void dispose() {
SymbolItem.pool.releaseAll(symbols.clear());
}
}
@Override
protected void dispose() {
SymbolItem.pool.releaseAll(symbols.clear());
}
}
final static String POI_DATA = Poi3DLayer.class.getSimpleName();
final static Tag TREE_TAG = new Tag("natural", "tree");
final static String POI_DATA = Poi3DLayer.class.getSimpleName();
final static Tag TREE_TAG = new Tag("natural", "tree");
private Poi3DTileData get(MapTile tile) {
Poi3DTileData ld = (Poi3DTileData) tile.getData(POI_DATA);
if (ld == null) {
ld = new Poi3DTileData();
tile.addData(POI_DATA, ld);
}
return ld;
}
private Poi3DTileData get(MapTile tile) {
Poi3DTileData ld = (Poi3DTileData) tile.getData(POI_DATA);
if (ld == null) {
ld = new Poi3DTileData();
tile.addData(POI_DATA, ld);
}
return ld;
}
GdxRenderer3D g3d;
VectorTileLayer mTileLayer;
GdxRenderer3D g3d;
VectorTileLayer mTileLayer;
public Poi3DLayer(Map map, VectorTileLayer tileLayer) {
super(map);
tileLayer.addHook(new TileLoaderProcessHook() {
public Poi3DLayer(Map map, VectorTileLayer tileLayer) {
super(map);
tileLayer.addHook(new TileLoaderProcessHook() {
@Override
public boolean process(MapTile tile, RenderBuckets buckets, MapElement element) {
@Override
public boolean process(MapTile tile, RenderBuckets buckets, MapElement element) {
if (!element.tags.contains(TREE_TAG))
return false;
if (!element.tags.contains(TREE_TAG))
return false;
Poi3DTileData td = get(tile);
PointF p = element.getPoint(0);
SymbolItem s = SymbolItem.pool.get();
s.x = p.x;
s.y = p.y;
td.symbols.push(s);
Poi3DTileData td = get(tile);
PointF p = element.getPoint(0);
SymbolItem s = SymbolItem.pool.get();
s.x = p.x;
s.y = p.y;
td.symbols.push(s);
return true;
}
return true;
}
@Override
public void complete(MapTile tile, boolean success) {
}
});
mTileLayer = tileLayer;
@Override
public void complete(MapTile tile, boolean success) {
}
});
mTileLayer = tileLayer;
mRenderer = g3d = new GdxRenderer3D(mMap);
mRenderer = g3d = new GdxRenderer3D(mMap);
// Material mat = new
// Material(ColorAttribute.createDiffuse(Color.BLUE));
// ModelBuilder modelBuilder = new ModelBuilder();
// long attributes = Usage.Position | Usage.Normal |
// Usage.TextureCoordinates;
// Material mat = new
// Material(ColorAttribute.createDiffuse(Color.BLUE));
// ModelBuilder modelBuilder = new ModelBuilder();
// long attributes = Usage.Position | Usage.Normal |
// Usage.TextureCoordinates;
// mModel = modelBuilder.createSphere(10f, 10f, 10f, 12, 12,
// mat, attributes);
// mModel = modelBuilder.createSphere(10f, 10f, 10f, 12, 12,
// mat, attributes);
assets = new AssetManager();
assets.load("data/g3d/treeA.g3dj", Model.class);
loading = true;
}
assets = new AssetManager();
assets.load("data/g3d/treeA.g3dj", Model.class);
loading = true;
}
TileSet mTileSet = new TileSet();
TileSet mPrevTiles = new TileSet();
TileSet mTileSet = new TileSet();
TileSet mPrevTiles = new TileSet();
LinkedHashMap<Tile, Array<SharedModel>> mTileMap =
new LinkedHashMap<Tile, Array<SharedModel>>();
LinkedHashMap<Tile, Array<SharedModel>> mTileMap =
new LinkedHashMap<Tile, Array<SharedModel>>();
boolean loading;
Model mModel;
AssetManager assets;
boolean loading;
Model mModel;
AssetManager assets;
private void doneLoading() {
Model model = assets.get("data/g3d/treeA.g3dj", Model.class);
for (int i = 0; i < model.nodes.size; i++) {
Node node = model.nodes.get(i);
private void doneLoading() {
Model model = assets.get("data/g3d/treeA.g3dj", Model.class);
for (int i = 0; i < model.nodes.size; i++) {
Node node = model.nodes.get(i);
if (node.id.equals("treeA_root")) {
node.rotation.setFromAxis(1, 0, 0, 90);
mModel = model;
if (node.id.equals("treeA_root")) {
node.rotation.setFromAxis(1, 0, 0, 90);
mModel = model;
}
}
}
}
loading = false;
}
loading = false;
}
@Override
public void onMapEvent(Event ev, MapPosition pos) {
@Override
public void onMapEvent(Event ev, MapPosition pos) {
if (ev == Map.CLEAR_EVENT) {
mTileSet = new TileSet();
mPrevTiles = new TileSet();
mTileMap = new LinkedHashMap<Tile, Array<SharedModel>>();
synchronized (g3d) {
g3d.instances.clear();
}
}
if (ev == Map.CLEAR_EVENT) {
mTileSet = new TileSet();
mPrevTiles = new TileSet();
mTileMap = new LinkedHashMap<Tile, Array<SharedModel>>();
synchronized (g3d) {
g3d.instances.clear();
}
}
if (loading && assets.update()) {
doneLoading();
// Renderable renderable = new Renderable();
// new SharedModel(mModel).getRenderable(renderable);
// Shader shader = new DefaultShader(renderable, true, false,
// false, false, 1, 0, 0, 0);
}
if (loading)
return;
if (loading && assets.update()) {
doneLoading();
// Renderable renderable = new Renderable();
// new SharedModel(mModel).getRenderable(renderable);
// Shader shader = new DefaultShader(renderable, true, false,
// false, false, 1, 0, 0, 0);
}
if (loading)
return;
// log.debug("update");
// log.debug("update");
mTileLayer.tileRenderer().getVisibleTiles(mTileSet);
mTileLayer.tileRenderer().getVisibleTiles(mTileSet);
if (mTileSet.cnt == 0) {
mTileSet.releaseTiles();
return;
}
if (mTileSet.cnt == 0) {
mTileSet.releaseTiles();
return;
}
boolean changed = false;
boolean changed = false;
Array<SharedModel> added = new Array<SharedModel>();
Array<SharedModel> removed = new Array<SharedModel>();
Array<SharedModel> added = new Array<SharedModel>();
Array<SharedModel> removed = new Array<SharedModel>();
for (int i = 0; i < mTileSet.cnt; i++) {
MapTile t = mTileSet.tiles[i];
if (mPrevTiles.contains(t))
continue;
for (int i = 0; i < mTileSet.cnt; i++) {
MapTile t = mTileSet.tiles[i];
if (mPrevTiles.contains(t))
continue;
Array<SharedModel> instances = new Array<SharedModel>();
Array<SharedModel> instances = new Array<SharedModel>();
Poi3DTileData ld = (Poi3DTileData) t.getData(POI_DATA);
if (ld == null)
continue;
Poi3DTileData ld = (Poi3DTileData) t.getData(POI_DATA);
if (ld == null)
continue;
for (SymbolItem it : ld.symbols) {
for (SymbolItem it : ld.symbols) {
SharedModel inst = new SharedModel(mModel);
inst.userData = it;
// float r = 0.5f + 0.5f * (float) Math.random();
// float g = 0.5f + 0.5f * (float) Math.random();
// float b = 0.5f + 0.5f * (float) Math.random();
SharedModel inst = new SharedModel(mModel);
inst.userData = it;
// float r = 0.5f + 0.5f * (float) Math.random();
// float g = 0.5f + 0.5f * (float) Math.random();
// float b = 0.5f + 0.5f * (float) Math.random();
// inst.transform.setTranslation(new Vector3(it.x, it.y,
// 10));
// inst.materials.get(0).set(ColorAttribute.createDiffuse(r,
// g, b, 0.8f));
instances.add(inst);
added.add(inst);
}
// inst.transform.setTranslation(new Vector3(it.x, it.y,
// 10));
// inst.materials.get(0).set(ColorAttribute.createDiffuse(r,
// g, b, 0.8f));
instances.add(inst);
added.add(inst);
}
if (instances.size == 0)
continue;
if (instances.size == 0)
continue;
log.debug("add " + t + " " + instances.size);
log.debug("add " + t + " " + instances.size);
changed = true;
changed = true;
mTileMap.put(t, instances);
}
mTileMap.put(t, instances);
}
for (int i = 0; i < mPrevTiles.cnt; i++) {
MapTile t = mPrevTiles.tiles[i];
if (mTileSet.contains(t))
continue;
for (int i = 0; i < mPrevTiles.cnt; i++) {
MapTile t = mPrevTiles.tiles[i];
if (mTileSet.contains(t))
continue;
Array<SharedModel> instances = mTileMap.get(t);
if (instances == null)
continue;
Array<SharedModel> instances = mTileMap.get(t);
if (instances == null)
continue;
changed = true;
changed = true;
removed.addAll(instances);
mTileMap.remove(t);
log.debug("remove " + t);
}
removed.addAll(instances);
mTileMap.remove(t);
log.debug("remove " + t);
}
mPrevTiles.releaseTiles();
mPrevTiles.releaseTiles();
int zoom = mTileSet.tiles[0].zoomLevel;
int zoom = mTileSet.tiles[0].zoomLevel;
TileSet tmp = mPrevTiles;
mPrevTiles = mTileSet;
mTileSet = tmp;
TileSet tmp = mPrevTiles;
mPrevTiles = mTileSet;
mTileSet = tmp;
if (!changed)
return;
if (!changed)
return;
// scale aka tree height
float scale = (float) (1f / (1 << (17 - zoom))) * 8;
// scale aka tree height
float scale = (float) (1f / (1 << (17 - zoom))) * 8;
double tileX = (pos.x * (Tile.SIZE << zoom));
double tileY = (pos.y * (Tile.SIZE << zoom));
double tileX = (pos.x * (Tile.SIZE << zoom));
double tileY = (pos.y * (Tile.SIZE << zoom));
synchronized (g3d) {
synchronized (g3d) {
for (Entry<Tile, Array<SharedModel>> e : mTileMap.entrySet()) {
Tile t = e.getKey();
for (Entry<Tile, Array<SharedModel>> e : mTileMap.entrySet()) {
Tile t = e.getKey();
float dx = (float) (t.tileX * Tile.SIZE - tileX);
float dy = (float) (t.tileY * Tile.SIZE - tileY);
float dx = (float) (t.tileX * Tile.SIZE - tileX);
float dy = (float) (t.tileY * Tile.SIZE - tileY);
for (SharedModel inst : e.getValue()) {
SymbolItem it = (SymbolItem) inst.userData;
for (SharedModel inst : e.getValue()) {
SymbolItem it = (SymbolItem) inst.userData;
// variable height
float s = scale + (it.x * it.y) % 3;
float r = (it.x * it.y) % 360;
// variable height
float s = scale + (it.x * it.y) % 3;
float r = (it.x * it.y) % 360;
inst.transform.idt();
inst.transform.scale(s, s, s);
inst.transform.translate((dx + it.x) / s, (dy + it.y) / s, 0);
inst.transform.rotate(0, 0, 1, r);
inst.transform.idt();
inst.transform.scale(s, s, s);
inst.transform.translate((dx + it.x) / s, (dy + it.y) / s, 0);
inst.transform.rotate(0, 0, 1, r);
// inst.transform.setToTranslationAndScaling((dx +
// it.x), (dy + it.y),
// 0, s, s, s);
// inst.transform.setToTranslationAndScaling((dx +
// it.x), (dy + it.y),
// 0, s, s, s);
}
}
}
}
g3d.instances.removeAll(removed, true);
g3d.instances.addAll(added);
g3d.cam.setMapPosition(pos.x, pos.y, 1 << zoom);
}
}
g3d.instances.removeAll(removed, true);
g3d.instances.addAll(added);
g3d.cam.setMapPosition(pos.x, pos.y, 1 << zoom);
}
}
}

View File

@@ -20,420 +20,488 @@ import com.badlogic.gdx.utils.ArrayMap;
import com.badlogic.gdx.utils.ObjectMap;
import com.badlogic.gdx.utils.Pool;
/** An instance of a {@link Model}, allows to specify global transform and modify the materials, as it
* has a copy of the model's materials. Multiple instances can be created from the same Model,
* all sharing the meshes and textures of the Model. The Model owns the meshes and textures, to
/**
* An instance of a {@link Model}, allows to specify global transform and modify the materials, as it
* has a copy of the model's materials. Multiple instances can be created from the same Model,
* all sharing the meshes and textures of the Model. The Model owns the meshes and textures, to
* dispose of these, the Model has to be disposed. Therefor, the Model must outlive all its ModelInstances</p>
*
* <p/>
* The ModelInstance creates a full copy of all materials, nodes and animations.
* @author badlogic, xoppa */
*
* @author badlogic, xoppa
*/
public class SharedModel implements RenderableProvider {
/** the materials of the model, used by nodes that have a graphical representation FIXME not sure if superfluous, allows modification of materials without having to traverse the nodes **/
public final Array<Material> materials = new Array<Material>();
/** root nodes of the model **/
public final Array<Node> nodes = new Array<Node>();
/** animations of the model, modifying node transformations **/
public final Array<Animation> animations = new Array<Animation>();
/** the {@link Model} this instances derives from **/
public final Model model;
/** the world transform **/
public Matrix4 transform;
/** user definable value, which is passed to the shader. */
public Object userData;
/** Constructs a new ModelInstance with all nodes and materials of the given model.
* @param model The {@link Model} to create an instance of. */
public SharedModel(final Model model) {
this(model, (String[])null);
}
/** @param model The source {@link Model}
* @param nodeId The ID of the root {@link Node} of the {@link Model} for the instance to contain
* @param mergeTransform True to apply the source node transform to the instance transform, resetting the node transform. */
public SharedModel(final Model model, final String nodeId, boolean mergeTransform) {
this(model, null, nodeId, false, false, mergeTransform);
}
/** @param model The source {@link Model}
* @param transform The {@link Matrix4} instance for this ModelInstance to reference or null to create a new matrix.
* @param nodeId The ID of the root {@link Node} of the {@link Model} for the instance to contain
* @param mergeTransform True to apply the source node transform to the instance transform, resetting the node transform. */
public SharedModel(final Model model, final Matrix4 transform, final String nodeId, boolean mergeTransform) {
this(model, transform, nodeId, false, false, mergeTransform);
}
/**
* the materials of the model, used by nodes that have a graphical representation FIXME not sure if superfluous, allows modification of materials without having to traverse the nodes
**/
public final Array<Material> materials = new Array<Material>();
/**
* root nodes of the model
**/
public final Array<Node> nodes = new Array<Node>();
/**
* animations of the model, modifying node transformations
**/
public final Array<Animation> animations = new Array<Animation>();
/**
* the {@link Model} this instances derives from
**/
public final Model model;
/**
* the world transform
**/
public Matrix4 transform;
/**
* user definable value, which is passed to the shader.
*/
public Object userData;
/** Recursively searches the mode for the specified node.
* @param model The source {@link Model}
* @param nodeId The ID of the {@link Node} within the {@link Model} for the instance to contain
* @param parentTransform True to apply the parent's node transform to the instance (only applicable if recursive is true).
* @param mergeTransform True to apply the source node transform to the instance transform, resetting the node transform. */
public SharedModel(final Model model, final String nodeId, boolean parentTransform, boolean mergeTransform) {
this(model, null, nodeId, true, parentTransform, mergeTransform);
}
/** Recursively searches the mode for the specified node.
* @param model The source {@link Model}
* @param transform The {@link Matrix4} instance for this ModelInstance to reference or null to create a new matrix.
* @param nodeId The ID of the {@link Node} within the {@link Model} for the instance to contain
* @param parentTransform True to apply the parent's node transform to the instance (only applicable if recursive is true).
* @param mergeTransform True to apply the source node transform to the instance transform, resetting the node transform. */
public SharedModel(final Model model, final Matrix4 transform, final String nodeId, boolean parentTransform, boolean mergeTransform) {
this(model, transform, nodeId, true, parentTransform, mergeTransform);
}
/** @param model The source {@link Model}
* @param nodeId The ID of the {@link Node} within the {@link Model} for the instance to contain
* @param recursive True to recursively search the Model's node tree, false to only search for a root node
* @param parentTransform True to apply the parent's node transform to the instance (only applicable if recursive is true).
* @param mergeTransform True to apply the source node transform to the instance transform, resetting the node transform. */
public SharedModel(final Model model, final String nodeId, boolean recursive, boolean parentTransform, boolean mergeTransform) {
this(model, null, nodeId, recursive, parentTransform, mergeTransform);
}
/** @param model The source {@link Model}
* @param transform The {@link Matrix4} instance for this ModelInstance to reference or null to create a new matrix.
* @param nodeId The ID of the {@link Node} within the {@link Model} for the instance to contain
* @param recursive True to recursively search the Model's node tree, false to only search for a root node
* @param parentTransform True to apply the parent's node transform to the instance (only applicable if recursive is true).
* @param mergeTransform True to apply the source node transform to the instance transform, resetting the node transform. */
public SharedModel(final Model model, final Matrix4 transform, final String nodeId, boolean recursive, boolean parentTransform, boolean mergeTransform) {
this.model = model;
this.transform = transform == null ? new Matrix4() : transform;
nodePartBones.clear();
Node copy, node = model.getNode(nodeId, recursive);
this.nodes.add(copy = copyNode(node));
if (mergeTransform) {
this.transform.mul(parentTransform ? node.globalTransform : node.localTransform);
copy.translation.set(0,0,0);
copy.rotation.idt();
copy.scale.set(1,1,1);
} else if (parentTransform && copy.hasParent())
this.transform.mul(node.getParent().globalTransform);
setBones();
copyAnimations(model.animations);
calculateTransforms();
}
/** Constructs a new ModelInstance with only the specified nodes and materials of the given model. */
public SharedModel(final Model model, final String... rootNodeIds) {
this(model, null, rootNodeIds);
}
/** Constructs a new ModelInstance with only the specified nodes and materials of the given model. */
public SharedModel(final Model model, final Matrix4 transform, final String... rootNodeIds) {
this.model = model;
this.transform = transform == null ? new Matrix4() : transform;
if (rootNodeIds == null)
copyNodes(model.nodes);
else
copyNodes(model.nodes, rootNodeIds);
copyAnimations(model.animations);
calculateTransforms();
}
/** Constructs a new ModelInstance with only the specified nodes and materials of the given model. */
public SharedModel(final Model model, final Array<String> rootNodeIds) {
this(model, null, rootNodeIds);
}
/** Constructs a new ModelInstance with only the specified nodes and materials of the given model. */
public SharedModel(final Model model, final Matrix4 transform, final Array<String> rootNodeIds) {
this.model = model;
this.transform = transform == null ? new Matrix4() : transform;
copyNodes(model.nodes, rootNodeIds);
copyAnimations(model.animations);
calculateTransforms();
}
/** Constructs a new ModelInstance at the specified position. */
public SharedModel(final Model model, Vector3 position) {
this(model);
this.transform.setToTranslation(position);
}
/** Constructs a new ModelInstance at the specified position. */
public SharedModel(final Model model, float x, float y, float z) {
this(model);
this.transform.setToTranslation(x, y, z);
}
/** Constructs a new ModelInstance with the specified transform. */
public SharedModel(final Model model, Matrix4 transform) {
this(model, transform, (String[])null);
}
/** Constructs a new ModelInstance which is an copy of the specified ModelInstance. */
public SharedModel(SharedModel copyFrom) {
this(copyFrom, copyFrom.transform.cpy());
}
/** Constructs a new ModelInstance which is an copy of the specified ModelInstance. */
public SharedModel(SharedModel copyFrom, final Matrix4 transform) {
this.model = copyFrom.model;
this.transform = transform == null ? new Matrix4() : transform;
copyNodes(copyFrom.nodes);
copyAnimations(copyFrom.animations);
calculateTransforms();
}
/** @return A newly created ModelInstance which is a copy of this ModelInstance */
public SharedModel copy() {
return new SharedModel(this);
}
/**
* Constructs a new ModelInstance with all nodes and materials of the given model.
*
* @param model The {@link Model} to create an instance of.
*/
public SharedModel(final Model model) {
this(model, (String[]) null);
}
/**
* @param model The source {@link Model}
* @param nodeId The ID of the root {@link Node} of the {@link Model} for the instance to contain
* @param mergeTransform True to apply the source node transform to the instance transform, resetting the node transform.
*/
public SharedModel(final Model model, final String nodeId, boolean mergeTransform) {
this(model, null, nodeId, false, false, mergeTransform);
}
/**
* @param model The source {@link Model}
* @param transform The {@link Matrix4} instance for this ModelInstance to reference or null to create a new matrix.
* @param nodeId The ID of the root {@link Node} of the {@link Model} for the instance to contain
* @param mergeTransform True to apply the source node transform to the instance transform, resetting the node transform.
*/
public SharedModel(final Model model, final Matrix4 transform, final String nodeId, boolean mergeTransform) {
this(model, transform, nodeId, false, false, mergeTransform);
}
/**
* Recursively searches the mode for the specified node.
*
* @param model The source {@link Model}
* @param nodeId The ID of the {@link Node} within the {@link Model} for the instance to contain
* @param parentTransform True to apply the parent's node transform to the instance (only applicable if recursive is true).
* @param mergeTransform True to apply the source node transform to the instance transform, resetting the node transform.
*/
public SharedModel(final Model model, final String nodeId, boolean parentTransform, boolean mergeTransform) {
this(model, null, nodeId, true, parentTransform, mergeTransform);
}
/**
* Recursively searches the mode for the specified node.
*
* @param model The source {@link Model}
* @param transform The {@link Matrix4} instance for this ModelInstance to reference or null to create a new matrix.
* @param nodeId The ID of the {@link Node} within the {@link Model} for the instance to contain
* @param parentTransform True to apply the parent's node transform to the instance (only applicable if recursive is true).
* @param mergeTransform True to apply the source node transform to the instance transform, resetting the node transform.
*/
public SharedModel(final Model model, final Matrix4 transform, final String nodeId, boolean parentTransform, boolean mergeTransform) {
this(model, transform, nodeId, true, parentTransform, mergeTransform);
}
/**
* @param model The source {@link Model}
* @param nodeId The ID of the {@link Node} within the {@link Model} for the instance to contain
* @param recursive True to recursively search the Model's node tree, false to only search for a root node
* @param parentTransform True to apply the parent's node transform to the instance (only applicable if recursive is true).
* @param mergeTransform True to apply the source node transform to the instance transform, resetting the node transform.
*/
public SharedModel(final Model model, final String nodeId, boolean recursive, boolean parentTransform, boolean mergeTransform) {
this(model, null, nodeId, recursive, parentTransform, mergeTransform);
}
/**
* @param model The source {@link Model}
* @param transform The {@link Matrix4} instance for this ModelInstance to reference or null to create a new matrix.
* @param nodeId The ID of the {@link Node} within the {@link Model} for the instance to contain
* @param recursive True to recursively search the Model's node tree, false to only search for a root node
* @param parentTransform True to apply the parent's node transform to the instance (only applicable if recursive is true).
* @param mergeTransform True to apply the source node transform to the instance transform, resetting the node transform.
*/
public SharedModel(final Model model, final Matrix4 transform, final String nodeId, boolean recursive, boolean parentTransform, boolean mergeTransform) {
this.model = model;
this.transform = transform == null ? new Matrix4() : transform;
nodePartBones.clear();
Node copy, node = model.getNode(nodeId, recursive);
this.nodes.add(copy = copyNode(node));
if (mergeTransform) {
this.transform.mul(parentTransform ? node.globalTransform : node.localTransform);
copy.translation.set(0, 0, 0);
copy.rotation.idt();
copy.scale.set(1, 1, 1);
} else if (parentTransform && copy.hasParent())
this.transform.mul(node.getParent().globalTransform);
setBones();
copyAnimations(model.animations);
calculateTransforms();
}
/**
* Constructs a new ModelInstance with only the specified nodes and materials of the given model.
*/
public SharedModel(final Model model, final String... rootNodeIds) {
this(model, null, rootNodeIds);
}
/**
* Constructs a new ModelInstance with only the specified nodes and materials of the given model.
*/
public SharedModel(final Model model, final Matrix4 transform, final String... rootNodeIds) {
this.model = model;
this.transform = transform == null ? new Matrix4() : transform;
if (rootNodeIds == null)
copyNodes(model.nodes);
else
copyNodes(model.nodes, rootNodeIds);
copyAnimations(model.animations);
calculateTransforms();
}
/**
* Constructs a new ModelInstance with only the specified nodes and materials of the given model.
*/
public SharedModel(final Model model, final Array<String> rootNodeIds) {
this(model, null, rootNodeIds);
}
/**
* Constructs a new ModelInstance with only the specified nodes and materials of the given model.
*/
public SharedModel(final Model model, final Matrix4 transform, final Array<String> rootNodeIds) {
this.model = model;
this.transform = transform == null ? new Matrix4() : transform;
copyNodes(model.nodes, rootNodeIds);
copyAnimations(model.animations);
calculateTransforms();
}
/**
* Constructs a new ModelInstance at the specified position.
*/
public SharedModel(final Model model, Vector3 position) {
this(model);
this.transform.setToTranslation(position);
}
/**
* Constructs a new ModelInstance at the specified position.
*/
public SharedModel(final Model model, float x, float y, float z) {
this(model);
this.transform.setToTranslation(x, y, z);
}
/**
* Constructs a new ModelInstance with the specified transform.
*/
public SharedModel(final Model model, Matrix4 transform) {
this(model, transform, (String[]) null);
}
/**
* Constructs a new ModelInstance which is an copy of the specified ModelInstance.
*/
public SharedModel(SharedModel copyFrom) {
this(copyFrom, copyFrom.transform.cpy());
}
/**
* Constructs a new ModelInstance which is an copy of the specified ModelInstance.
*/
public SharedModel(SharedModel copyFrom, final Matrix4 transform) {
this.model = copyFrom.model;
this.transform = transform == null ? new Matrix4() : transform;
copyNodes(copyFrom.nodes);
copyAnimations(copyFrom.animations);
calculateTransforms();
}
/**
* @return A newly created ModelInstance which is a copy of this ModelInstance
*/
public SharedModel copy() {
return new SharedModel(this);
}
private ObjectMap<NodePart, ArrayMap<Node, Matrix4>> nodePartBones = new ObjectMap<NodePart, ArrayMap<Node, Matrix4>>();
private void copyNodes(Array<Node> nodes) {
nodePartBones.clear();
for (int i = 0, n = nodes.size; i < n; ++i) {
final Node node = nodes.get(i);
this.nodes.add(copyNode(node));
}
setBones();
}
private void copyNodes(Array<Node> nodes, final String... nodeIds) {
nodePartBones.clear();
for (int i = 0, n = nodes.size; i < n; ++i) {
final Node node = nodes.get(i);
for (final String nodeId : nodeIds) {
if (nodeId.equals(node.id)) {
this.nodes.add(copyNode(node));
break;
}
}
}
setBones();
}
private void copyNodes(Array<Node> nodes, final Array<String> nodeIds) {
nodePartBones.clear();
for (int i = 0, n = nodes.size; i < n; ++i) {
final Node node = nodes.get(i);
for (final String nodeId : nodeIds) {
if (nodeId.equals(node.id)) {
this.nodes.add(copyNode(node));
break;
}
}
}
setBones();
}
private void setBones() {
for (ObjectMap.Entry<NodePart, ArrayMap<Node, Matrix4>> e : nodePartBones.entries()) {
if (e.key.invBoneBindTransforms == null)
e.key.invBoneBindTransforms = new ArrayMap<Node, Matrix4>(true, e.value.size, Node.class, Matrix4.class);
e.key.invBoneBindTransforms.clear();
for (final ObjectMap.Entry<Node, Matrix4> b : e.value.entries())
e.key.invBoneBindTransforms.put(getNode(b.key.id), b.value); // Share the inv bind matrix with the model
e.key.bones = new Matrix4[e.value.size];
for (int i = 0; i < e.key.bones.length; i++)
e.key.bones[i] = new Matrix4();
}
}
private Node copyNode(Node node) {
Node copy = new Node();
copy.id = node.id;
copy.inheritTransform = node.inheritTransform;
copy.translation.set(node.translation);
copy.rotation.set(node.rotation);
copy.scale.set(node.scale);
copy.localTransform.set(node.localTransform);
copy.globalTransform.set(node.globalTransform);
for (NodePart nodePart : node.parts) {
copy.parts.add(copyNodePart(nodePart));
}
for (Node child : node.getChildren()) {
copy.addChild(copyNode(child));
}
return copy;
}
private NodePart copyNodePart(NodePart nodePart) {
NodePart copy = new NodePart();
copy.meshPart = new MeshPart();
copy.meshPart.id = nodePart.meshPart.id;
copy.meshPart.offset = nodePart.meshPart.offset;
copy.meshPart.size = nodePart.meshPart.size;
copy.meshPart.primitiveType = nodePart.meshPart.primitiveType;
copy.meshPart.mesh = nodePart.meshPart.mesh;
if (nodePart.invBoneBindTransforms != null)
nodePartBones.put(copy, nodePart.invBoneBindTransforms);
private ObjectMap<NodePart, ArrayMap<Node, Matrix4>> nodePartBones = new ObjectMap<NodePart, ArrayMap<Node, Matrix4>>();
private void copyNodes (Array<Node> nodes) {
nodePartBones.clear();
for(int i = 0, n = nodes.size; i<n; ++i) {
final Node node = nodes.get(i);
this.nodes.add(copyNode(node));
}
setBones();
}
private void copyNodes (Array<Node> nodes, final String... nodeIds) {
nodePartBones.clear();
for(int i = 0, n = nodes.size; i<n; ++i) {
final Node node = nodes.get(i);
for (final String nodeId : nodeIds) {
if (nodeId.equals(node.id)) {
this.nodes.add(copyNode(node));
break;
}
}
}
setBones();
}
private void copyNodes (Array<Node> nodes, final Array<String> nodeIds) {
nodePartBones.clear();
for(int i = 0, n = nodes.size; i<n; ++i) {
final Node node = nodes.get(i);
for (final String nodeId : nodeIds) {
if (nodeId.equals(node.id)) {
this.nodes.add(copyNode(node));
break;
}
}
}
setBones();
}
private void setBones() {
for (ObjectMap.Entry<NodePart,ArrayMap<Node, Matrix4>> e : nodePartBones.entries()) {
if (e.key.invBoneBindTransforms == null)
e.key.invBoneBindTransforms = new ArrayMap<Node, Matrix4>(true, e.value.size, Node.class, Matrix4.class);
e.key.invBoneBindTransforms.clear();
for (final ObjectMap.Entry<Node, Matrix4> b : e.value.entries())
e.key.invBoneBindTransforms.put(getNode(b.key.id), b.value); // Share the inv bind matrix with the model
e.key.bones = new Matrix4[e.value.size];
for (int i = 0; i < e.key.bones.length; i++)
e.key.bones[i] = new Matrix4();
}
}
private Node copyNode(Node node) {
Node copy = new Node();
copy.id = node.id;
copy.inheritTransform = node.inheritTransform;
copy.translation.set(node.translation);
copy.rotation.set(node.rotation);
copy.scale.set(node.scale);
copy.localTransform.set(node.localTransform);
copy.globalTransform.set(node.globalTransform);
for(NodePart nodePart: node.parts) {
copy.parts.add(copyNodePart(nodePart));
}
for(Node child: node.getChildren()) {
copy.addChild(copyNode(child));
}
return copy;
}
private NodePart copyNodePart (NodePart nodePart) {
NodePart copy = new NodePart();
copy.meshPart = new MeshPart();
copy.meshPart.id = nodePart.meshPart.id;
copy.meshPart.offset = nodePart.meshPart.offset;
copy.meshPart.size = nodePart.meshPart.size;
copy.meshPart.primitiveType = nodePart.meshPart.primitiveType;
copy.meshPart.mesh = nodePart.meshPart.mesh;
if (nodePart.invBoneBindTransforms != null)
nodePartBones.put(copy, nodePart.invBoneBindTransforms);
// final int index = materials.indexOf(nodePart.material, false);
// if (index < 0)
// materials.add(copy.material = nodePart.material.copy());
// else
// copy.material = materials.get(index);
//
copy.material = nodePart.material;
return copy;
}
private void copyAnimations (final Iterable<Animation> source) {
for (final Animation anim : source) {
Animation animation = new Animation();
animation.id = anim.id;
for (final NodeAnimation nanim : anim.nodeAnimations) {
final Node node = getNode(nanim.node.id);
if (node == null)
continue;
NodeAnimation nodeAnim = new NodeAnimation();
nodeAnim.node = node;
if (nanim.rotation != null) {
nodeAnim.rotation = new Array<NodeKeyframe<Quaternion>>();
nodeAnim.rotation.ensureCapacity(nanim.rotation.size);
for (final NodeKeyframe<Quaternion> kf : nanim.rotation) {
if (kf.keytime > animation.duration)
animation.duration = kf.keytime;
nodeAnim.rotation.add(new NodeKeyframe<Quaternion>(kf.keytime, new Quaternion(kf.value == null ? node.rotation : kf.value)));
}
}
if (nanim.scaling != null) {
nodeAnim.scaling = new Array<NodeKeyframe<Vector3>>();
nodeAnim.scaling.ensureCapacity(nanim.scaling.size);
for (final NodeKeyframe<Vector3> kf : nanim.scaling) {
if (kf.keytime > animation.duration)
animation.duration = kf.keytime;
nodeAnim.scaling.add(new NodeKeyframe<Vector3>(kf.keytime, new Vector3(kf.value == null ? node.scale : kf.value)));
}
}
if (nanim.translation != null) {
nodeAnim.translation = new Array<NodeKeyframe<Vector3>>();
nodeAnim.translation.ensureCapacity(nanim.translation.size);
for (final NodeKeyframe<Vector3> kf : nanim.translation) {
if (kf.keytime > animation.duration)
animation.duration = kf.keytime;
nodeAnim.translation.add(new NodeKeyframe<Vector3>(kf.keytime, new Vector3(kf.value == null ? node.translation : kf.value)));
}
}
if ((nodeAnim.rotation != null && nodeAnim.rotation.size > 0)
|| (nodeAnim.scaling != null && nodeAnim.scaling.size > 0)
|| (nodeAnim.translation != null && nodeAnim.translation.size > 0))
animation.nodeAnimations.add(nodeAnim);
}
if (animation.nodeAnimations.size > 0)
animations.add(animation);
}
}
/**
* Traverses the Node hierarchy and collects {@link Renderable} instances for every
* node with a graphical representation. Renderables are obtained from the provided
* pool. The resulting array can be rendered via a {@link ModelBatch}.
*
* @param renderables the output array
* @param pool the pool to obtain Renderables from
*/
public void getRenderables(Array<Renderable> renderables, Pool<Renderable> pool) {
for(Node node: nodes) {
getRenderables(node, renderables, pool);
}
}
copy.material = nodePart.material;
/** @return The renderable of the first node's first part. */
public Renderable getRenderable(final Renderable out) {
return getRenderable(out, nodes.get(0));
}
/** @return The renderable of the node's first part. */
public Renderable getRenderable(final Renderable out, final Node node) {
return getRenderable(out, node, node.parts.get(0));
}
public Renderable getRenderable(final Renderable out, final Node node, final NodePart nodePart) {
nodePart.setRenderable(out);
if (nodePart.bones == null && transform != null)
out.worldTransform.set(transform).mul(node.globalTransform);
else if (transform != null)
out.worldTransform.set(transform);
else
out.worldTransform.idt();
out.userData = userData;
return out;
}
protected void getRenderables(Node node, Array<Renderable> renderables, Pool<Renderable> pool) {
if(node.parts.size > 0) {
for(NodePart nodePart: node.parts) {
renderables.add(getRenderable(pool.obtain(), node, nodePart));
}
}
for(Node child: node.getChildren()) {
getRenderables(child, renderables, pool);
}
}
/** Calculates the local and world transform of all {@link Node} instances in this model, recursively.
* First each {@link Node#localTransform} transform is calculated based on the translation, rotation and
* scale of each Node. Then each {@link Node#calculateWorldTransform()}
* is calculated, based on the parent's world transform and the local transform of each Node.
* Finally, the animation bone matrices are updated accordingly.</p>
*
* This method can be used to recalculate all transforms if any of the Node's local properties (translation, rotation, scale)
* was modified.
*/
public void calculateTransforms() {
final int n = nodes.size;
for(int i = 0; i < n; i++) {
nodes.get(i).calculateTransforms(true);
}
for(int i = 0; i < n; i++) {
nodes.get(i).calculateBoneTransforms(true);
}
}
/** Calculate the bounding box of this model instance.
* This is a potential slow operation, it is advised to cache the result.
* @param out the {@link BoundingBox} that will be set with the bounds.
* @return the out parameter for chaining */
public BoundingBox calculateBoundingBox(final BoundingBox out) {
out.inf();
return extendBoundingBox(out);
}
/** Extends the bounding box with the bounds of this model instance.
* This is a potential slow operation, it is advised to cache the result.
* @param out the {@link BoundingBox} that will be extended with the bounds.
* @return the out parameter for chaining */
public BoundingBox extendBoundingBox(final BoundingBox out) {
final int n = nodes.size;
for(int i = 0; i < n; i++)
nodes.get(i).extendBoundingBox(out);
return out;
}
return copy;
}
private void copyAnimations(final Iterable<Animation> source) {
for (final Animation anim : source) {
Animation animation = new Animation();
animation.id = anim.id;
for (final NodeAnimation nanim : anim.nodeAnimations) {
final Node node = getNode(nanim.node.id);
if (node == null)
continue;
NodeAnimation nodeAnim = new NodeAnimation();
nodeAnim.node = node;
if (nanim.rotation != null) {
nodeAnim.rotation = new Array<NodeKeyframe<Quaternion>>();
nodeAnim.rotation.ensureCapacity(nanim.rotation.size);
for (final NodeKeyframe<Quaternion> kf : nanim.rotation) {
if (kf.keytime > animation.duration)
animation.duration = kf.keytime;
nodeAnim.rotation.add(new NodeKeyframe<Quaternion>(kf.keytime, new Quaternion(kf.value == null ? node.rotation : kf.value)));
}
}
if (nanim.scaling != null) {
nodeAnim.scaling = new Array<NodeKeyframe<Vector3>>();
nodeAnim.scaling.ensureCapacity(nanim.scaling.size);
for (final NodeKeyframe<Vector3> kf : nanim.scaling) {
if (kf.keytime > animation.duration)
animation.duration = kf.keytime;
nodeAnim.scaling.add(new NodeKeyframe<Vector3>(kf.keytime, new Vector3(kf.value == null ? node.scale : kf.value)));
}
}
if (nanim.translation != null) {
nodeAnim.translation = new Array<NodeKeyframe<Vector3>>();
nodeAnim.translation.ensureCapacity(nanim.translation.size);
for (final NodeKeyframe<Vector3> kf : nanim.translation) {
if (kf.keytime > animation.duration)
animation.duration = kf.keytime;
nodeAnim.translation.add(new NodeKeyframe<Vector3>(kf.keytime, new Vector3(kf.value == null ? node.translation : kf.value)));
}
}
if ((nodeAnim.rotation != null && nodeAnim.rotation.size > 0)
|| (nodeAnim.scaling != null && nodeAnim.scaling.size > 0)
|| (nodeAnim.translation != null && nodeAnim.translation.size > 0))
animation.nodeAnimations.add(nodeAnim);
}
if (animation.nodeAnimations.size > 0)
animations.add(animation);
}
}
/**
* Traverses the Node hierarchy and collects {@link Renderable} instances for every
* node with a graphical representation. Renderables are obtained from the provided
* pool. The resulting array can be rendered via a {@link ModelBatch}.
*
* @param renderables the output array
* @param pool the pool to obtain Renderables from
*/
public void getRenderables(Array<Renderable> renderables, Pool<Renderable> pool) {
for (Node node : nodes) {
getRenderables(node, renderables, pool);
}
}
/**
* @return The renderable of the first node's first part.
*/
public Renderable getRenderable(final Renderable out) {
return getRenderable(out, nodes.get(0));
}
/**
* @return The renderable of the node's first part.
*/
public Renderable getRenderable(final Renderable out, final Node node) {
return getRenderable(out, node, node.parts.get(0));
}
public Renderable getRenderable(final Renderable out, final Node node, final NodePart nodePart) {
nodePart.setRenderable(out);
if (nodePart.bones == null && transform != null)
out.worldTransform.set(transform).mul(node.globalTransform);
else if (transform != null)
out.worldTransform.set(transform);
else
out.worldTransform.idt();
out.userData = userData;
return out;
}
protected void getRenderables(Node node, Array<Renderable> renderables, Pool<Renderable> pool) {
if (node.parts.size > 0) {
for (NodePart nodePart : node.parts) {
renderables.add(getRenderable(pool.obtain(), node, nodePart));
}
}
for (Node child : node.getChildren()) {
getRenderables(child, renderables, pool);
}
}
/**
* Calculates the local and world transform of all {@link Node} instances in this model, recursively.
* First each {@link Node#localTransform} transform is calculated based on the translation, rotation and
* scale of each Node. Then each {@link Node#calculateWorldTransform()}
* is calculated, based on the parent's world transform and the local transform of each Node.
* Finally, the animation bone matrices are updated accordingly.</p>
* <p/>
* This method can be used to recalculate all transforms if any of the Node's local properties (translation, rotation, scale)
* was modified.
*/
public void calculateTransforms() {
final int n = nodes.size;
for (int i = 0; i < n; i++) {
nodes.get(i).calculateTransforms(true);
}
for (int i = 0; i < n; i++) {
nodes.get(i).calculateBoneTransforms(true);
}
}
/**
* Calculate the bounding box of this model instance.
* This is a potential slow operation, it is advised to cache the result.
*
* @param out the {@link BoundingBox} that will be set with the bounds.
* @return the out parameter for chaining
*/
public BoundingBox calculateBoundingBox(final BoundingBox out) {
out.inf();
return extendBoundingBox(out);
}
/**
* Extends the bounding box with the bounds of this model instance.
* This is a potential slow operation, it is advised to cache the result.
*
* @param out the {@link BoundingBox} that will be extended with the bounds.
* @return the out parameter for chaining
*/
public BoundingBox extendBoundingBox(final BoundingBox out) {
final int n = nodes.size;
for (int i = 0; i < n; i++)
nodes.get(i).extendBoundingBox(out);
return out;
}
/**
* @param id The ID of the animation to fetch (case sensitive).
* @return The {@link Animation} with the specified id, or null if not available.
*/
public Animation getAnimation(final String id) {
return getAnimation(id, true);
}
/**
* @param id The ID of the animation to fetch.
* @param ignoreCase whether to use case sensitivity when comparing the animation id.
* @return The {@link Animation} with the specified id, or null if not available.
*/
public Animation getAnimation(final String id, boolean ignoreCase) {
final int n = animations.size;
Animation animation;
if (ignoreCase) {
for (int i = 0; i < n; i++)
if ((animation = animations.get(i)).id.equalsIgnoreCase(id))
return animation;
} else {
for (int i = 0; i < n; i++)
if ((animation = animations.get(i)).id.equals(id))
return animation;
}
return null;
}
/** @param id The ID of the animation to fetch (case sensitive).
* @return The {@link Animation} with the specified id, or null if not available. */
public Animation getAnimation(final String id) {
return getAnimation(id, true);
}
/** @param id The ID of the animation to fetch.
* @param ignoreCase whether to use case sensitivity when comparing the animation id.
* @return The {@link Animation} with the specified id, or null if not available. */
public Animation getAnimation(final String id, boolean ignoreCase) {
final int n = animations.size;
Animation animation;
if (ignoreCase) {
for (int i = 0; i < n; i++)
if ((animation = animations.get(i)).id.equalsIgnoreCase(id))
return animation;
} else {
for (int i = 0; i < n; i++)
if ((animation = animations.get(i)).id.equals(id))
return animation;
}
return null;
}
// /** @param id The ID of the material to fetch.
// * @return The {@link Material} with the specified id, or null if not available. */
// public Material getMaterial(final String id) {
@@ -457,25 +525,31 @@ public class SharedModel implements RenderableProvider {
// }
// return null;
// }
/** @param id The ID of the node to fetch.
* @return The {@link Node} with the specified id, or null if not found. */
public Node getNode(final String id) {
return getNode(id, true);
}
/** @param id The ID of the node to fetch.
* @param recursive false to fetch a root node only, true to search the entire node tree for the specified node.
* @return The {@link Node} with the specified id, or null if not found. */
public Node getNode(final String id, boolean recursive) {
return getNode(id, recursive, false);
}
/** @param id The ID of the node to fetch.
* @param recursive false to fetch a root node only, true to search the entire node tree for the specified node.
* @param ignoreCase whether to use case sensitivity when comparing the node id.
* @return The {@link Node} with the specified id, or null if not found. */
public Node getNode(final String id, boolean recursive, boolean ignoreCase) {
return Node.getNode(nodes, id, recursive, ignoreCase);
}
/**
* @param id The ID of the node to fetch.
* @return The {@link Node} with the specified id, or null if not found.
*/
public Node getNode(final String id) {
return getNode(id, true);
}
/**
* @param id The ID of the node to fetch.
* @param recursive false to fetch a root node only, true to search the entire node tree for the specified node.
* @return The {@link Node} with the specified id, or null if not found.
*/
public Node getNode(final String id, boolean recursive) {
return getNode(id, recursive, false);
}
/**
* @param id The ID of the node to fetch.
* @param recursive false to fetch a root node only, true to search the entire node tree for the specified node.
* @param ignoreCase whether to use case sensitivity when comparing the node id.
* @return The {@link Node} with the specified id, or null if not found.
*/
public Node getNode(final String id, boolean recursive, boolean ignoreCase) {
return Node.getNode(nodes, id, recursive, ignoreCase);
}
}

View File

@@ -16,15 +16,8 @@
*/
package org.oscim.test.jeo;
import static org.oscim.tiling.source.bitmap.DefaultSources.STAMEN_TONER;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;
import org.jeo.vector.VectorDataset;
import org.jeo.map.Style;
import org.jeo.vector.VectorDataset;
import org.oscim.gdx.GdxMap;
import org.oscim.gdx.GdxMapApp;
import org.oscim.layers.JeoVectorLayer;
@@ -33,54 +26,61 @@ import org.oscim.layers.TileGridLayer;
import org.oscim.layers.tile.bitmap.BitmapTileLayer;
import org.oscim.test.JeoTest;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;
import static org.oscim.tiling.source.bitmap.DefaultSources.STAMEN_TONER;
public class LayerTest extends GdxMap {
String PATH = "https://gist.github.com/anonymous/8960337/raw/overpass.geojson";
String PATH = "https://gist.github.com/anonymous/8960337/raw/overpass.geojson";
OSMIndoorLayer mIndoorLayer;
OSMIndoorLayer mIndoorLayer;
@Override
public void createLayers() {
mMap.setBaseMap(new BitmapTileLayer(mMap, STAMEN_TONER.build()));
mMap.layers().add(new TileGridLayer(mMap));
@Override
public void createLayers() {
mMap.setBaseMap(new BitmapTileLayer(mMap, STAMEN_TONER.build()));
mMap.layers().add(new TileGridLayer(mMap));
mMap.addTask(new Runnable() {
@Override
public void run() {
try {
URL url = new URL(PATH);
URLConnection conn = url.openConnection();
InputStream is = conn.getInputStream();
mMap.addTask(new Runnable() {
@Override
public void run() {
try {
URL url = new URL(PATH);
URLConnection conn = url.openConnection();
InputStream is = conn.getInputStream();
VectorDataset data = JeoTest.readGeoJson(is);
Style style = JeoTest.getStyle();
mIndoorLayer = new OSMIndoorLayer(mMap, data, style);
mIndoorLayer.activeLevels[0] = true;
mIndoorLayer.activeLevels[1] = true;
mIndoorLayer.activeLevels[2] = true;
mIndoorLayer.activeLevels[3] = true;
VectorDataset data = JeoTest.readGeoJson(is);
Style style = JeoTest.getStyle();
mIndoorLayer = new OSMIndoorLayer(mMap, data, style);
mIndoorLayer.activeLevels[0] = true;
mIndoorLayer.activeLevels[1] = true;
mIndoorLayer.activeLevels[2] = true;
mIndoorLayer.activeLevels[3] = true;
mMap.layers().add(new JeoVectorLayer(mMap, data, style));
mMap.layers().add(mIndoorLayer);
mMap.layers().add(new JeoVectorLayer(mMap, data, style));
mMap.layers().add(mIndoorLayer);
mMap.updateMap(true);
mMap.updateMap(true);
} catch (IOException e) {
e.printStackTrace();
}
}
});
} catch (IOException e) {
e.printStackTrace();
}
}
});
mMap.setMapPosition(53.5620092, 9.9866457, 1 << 16);
mMap.setMapPosition(53.5620092, 9.9866457, 1 << 16);
//VectorDataset data = (VectorDataset) JeoTest.getJsonData("states.json", true);
//Style style = JeoTest.getStyle();
//mMap.layers().add(new JeoVectorLayer(mMap, data, style));
//VectorDataset data = (VectorDataset) JeoTest.getJsonData("states.json", true);
//Style style = JeoTest.getStyle();
//mMap.layers().add(new JeoVectorLayer(mMap, data, style));
}
}
public static void main(String[] args) {
GdxMapApp.init();
GdxMapApp.run(new LayerTest(), null, 256);
}
public static void main(String[] args) {
GdxMapApp.init();
GdxMapApp.run(new LayerTest(), null, 256);
}
}

View File

@@ -10,25 +10,25 @@ import org.oscim.tiling.source.oscimap4.OSciMap4TileSource;
public class ThemeTest extends GdxMapApp {
public static void main(String[] args) {
GdxMapApp.init();
GdxMapApp.run(new ThemeTest(), null, 256);
}
public static void main(String[] args) {
GdxMapApp.init();
GdxMapApp.run(new ThemeTest(), null, 256);
}
@Override
public void createLayers() {
UrlTileSource ts = new OSciMap4TileSource();
@Override
public void createLayers() {
UrlTileSource ts = new OSciMap4TileSource();
VectorTileLayer l = mMap.setBaseMap(ts);
VectorTileLayer l = mMap.setBaseMap(ts);
l.setRenderTheme(new RenderTheme());
l.setRenderTheme(new RenderTheme());
MapRenderer.setBackgroundColor(0xffcccccc);
MapRenderer.setBackgroundColor(0xffcccccc);
// mMap.getLayers().add(new LabelLayer(mMap,
// mMapLayer.getTileLayer()));
// mMap.getLayers().add(new JeoMapLayer(mMap));
// mMap.getLayers().add(new LabelLayer(mMap,
// mMapLayer.getTileLayer()));
// mMap.getLayers().add(new JeoMapLayer(mMap));
mMap.layers().add(new TileGridLayer(mMap));
}
mMap.layers().add(new TileGridLayer(mMap));
}
}

View File

@@ -1,7 +1,5 @@
package org.oscim.test.renderer;
import java.util.Arrays;
import org.oscim.backend.canvas.Color;
import org.oscim.backend.canvas.Paint.Cap;
import org.oscim.gdx.GdxMap;
@@ -20,123 +18,125 @@ import org.oscim.theme.styles.TextStyle;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Arrays;
public class AtlasTest extends GdxMap {
@Override
protected void createLayers() {
mMap.setMapPosition(0, 0, 1 << 4);
mMap.layers().add(new GenericLayer(mMap, new AtlasRenderLayer()));
}
@Override
protected void createLayers() {
mMap.setMapPosition(0, 0, 1 << 4);
mMap.layers().add(new GenericLayer(mMap, new AtlasRenderLayer()));
}
public static void main(String[] args) {
GdxMapApp.init();
GdxMapApp.run(new AtlasTest(), null, 400);
}
public static void main(String[] args) {
GdxMapApp.init();
GdxMapApp.run(new AtlasTest(), null, 400);
}
static class AtlasRenderLayer extends BucketRenderer {
static class AtlasRenderLayer extends BucketRenderer {
Logger log = LoggerFactory.getLogger(AtlasRenderLayer.class);
Logger log = LoggerFactory.getLogger(AtlasRenderLayer.class);
public AtlasRenderLayer() {
public AtlasRenderLayer() {
TextureAtlas mAtlas = TextureAtlas.create(2048, 2048, 1);
TextureAtlas mAtlas = TextureAtlas.create(2048, 2048, 1);
TextBucket tl = new TextBucket();
TextStyle t = TextStyle.builder().fontSize(20).color(Color.BLACK).build();
buckets.set(tl);
TextBucket tl = new TextBucket();
TextStyle t = TextStyle.builder().fontSize(20).color(Color.BLACK).build();
buckets.set(tl);
LineBucket ll = buckets.getLineBucket(0);
ll.line = new LineStyle(Color.BLUE, 3, Cap.BUTT);
ll.scale = 1f;
LineBucket ll = buckets.getLineBucket(0);
ll.line = new LineStyle(Color.BLUE, 3, Cap.BUTT);
ll.scale = 1f;
LineBucket ll2 = buckets.getLineBucket(1);
ll2.line = new LineStyle(Color.RED, 3, Cap.BUTT);
ll2.scale = 1f;
LineBucket ll2 = buckets.getLineBucket(1);
ll2.line = new LineStyle(Color.RED, 3, Cap.BUTT);
ll2.scale = 1f;
LineBucket ll3 = buckets.getLineBucket(2);
ll3.line = new LineStyle(Color.GREEN, 3, Cap.BUTT);
ll3.scale = 1f;
LineBucket ll3 = buckets.getLineBucket(2);
ll3.line = new LineStyle(Color.GREEN, 3, Cap.BUTT);
ll3.scale = 1f;
float[] points = new float[10];
float[] points = new float[10];
for (int i = 0; i < 400; i++) {
int w = (int) (20 + Math.random() * 256);
int h = (int) (20 + Math.random() * 56);
Rect r = mAtlas.getRegion(w, h);
if (r == null) {
log.debug("no space left");
continue;
}
r.x += 1;
r.y += 1;
for (int i = 0; i < 400; i++) {
int w = (int) (20 + Math.random() * 256);
int h = (int) (20 + Math.random() * 56);
Rect r = mAtlas.getRegion(w, h);
if (r == null) {
log.debug("no space left");
continue;
}
r.x += 1;
r.y += 1;
points[0] = r.x;
points[1] = r.y;
points[2] = r.x + (r.w - 2);
points[3] = r.y;
points[4] = r.x + (r.w - 2);
points[5] = r.y + (r.h - 2);
points[6] = r.x;
points[7] = r.y + (r.h - 2);
points[8] = r.x;
points[9] = r.y;
ll.addLine(points, 10, false);
points[0] = r.x;
points[1] = r.y;
points[2] = r.x + (r.w - 2);
points[3] = r.y;
points[4] = r.x + (r.w - 2);
points[5] = r.y + (r.h - 2);
points[6] = r.x;
points[7] = r.y + (r.h - 2);
points[8] = r.x;
points[9] = r.y;
ll.addLine(points, 10, false);
r.x += 1;
r.y += 1;
points[0] = r.x;
points[1] = r.y;
points[2] = r.x + (w - 4);
points[3] = r.y;
points[4] = r.x + (w - 4);
points[5] = r.y + (h - 4);
points[6] = r.x;
points[7] = r.y + (h - 4);
points[8] = r.x;
points[9] = r.y;
r.x += 1;
r.y += 1;
points[0] = r.x;
points[1] = r.y;
points[2] = r.x + (w - 4);
points[3] = r.y;
points[4] = r.x + (w - 4);
points[5] = r.y + (h - 4);
points[6] = r.x;
points[7] = r.y + (h - 4);
points[8] = r.x;
points[9] = r.y;
log.debug("add region: " + Arrays.toString(points));
ll2.addLine(points, 10, false);
log.debug("add region: " + Arrays.toString(points));
ll2.addLine(points, 10, false);
TextItem ti = TextItem.pool.get();
ti.set(r.x + r.w / 2, r.y + r.h / 2, "" + i, t);
ti.x1 = 0;
ti.y1 = 1; // (short) (size / 2);
ti.x2 = 1; // (short) size;
ti.y2 = 1;
tl.addText(ti);
}
TextItem ti = TextItem.pool.get();
ti.set(r.x + r.w / 2, r.y + r.h / 2, "" + i, t);
ti.x1 = 0;
ti.y1 = 1; // (short) (size / 2);
ti.x2 = 1; // (short) size;
ti.y2 = 1;
tl.addText(ti);
}
for (Slot s = mAtlas.mSlots; s != null; s = s.next) {
points[0] = s.x;
points[1] = s.y;
points[2] = s.x + s.w;
points[3] = s.y;
points[4] = s.x + s.w;
points[5] = 2048;
points[6] = s.x;
points[7] = 2048;
points[8] = s.x;
points[9] = s.y;
for (Slot s = mAtlas.mSlots; s != null; s = s.next) {
points[0] = s.x;
points[1] = s.y;
points[2] = s.x + s.w;
points[3] = s.y;
points[4] = s.x + s.w;
points[5] = 2048;
points[6] = s.x;
points[7] = 2048;
points[8] = s.x;
points[9] = s.y;
ll3.addLine(points, 10, false);
}
ll3.addLine(points, 10, false);
}
tl.prepare();
//tl.labels = TextItem.pool.releaseAll(tl.labels);
}
tl.prepare();
//tl.labels = TextItem.pool.releaseAll(tl.labels);
}
boolean initial = true;
boolean initial = true;
@Override
public void update(GLViewport v) {
@Override
public void update(GLViewport v) {
if (initial) {
mMapPosition.copy(v.pos);
initial = false;
if (initial) {
mMapPosition.copy(v.pos);
initial = false;
compile();
}
}
}
compile();
}
}
}
}

View File

@@ -1,7 +1,5 @@
package org.oscim.test.renderer;
import java.util.List;
import org.oscim.backend.canvas.Color;
import org.oscim.core.GeometryBuffer;
import org.oscim.core.Point;
@@ -14,75 +12,77 @@ import org.oscim.renderer.bucket.LineBucket;
import org.oscim.theme.styles.LineStyle;
import org.oscim.utils.geom.BezierPath;
import java.util.List;
public class BezierTest extends GdxMap {
@Override
protected void createLayers() {
mMap.layers().add(new GenericLayer(mMap, new BezierPathLayer()));
}
@Override
protected void createLayers() {
mMap.layers().add(new GenericLayer(mMap, new BezierPathLayer()));
}
public static void main(String[] args) {
GdxMapApp.init();
GdxMapApp.run(new BezierTest(), null, 400);
}
public static void main(String[] args) {
GdxMapApp.init();
GdxMapApp.run(new BezierTest(), null, 400);
}
static class BezierPathLayer extends BucketRenderer {
static class BezierPathLayer extends BucketRenderer {
public BezierPathLayer() {
mMapPosition.scale = 0;
public BezierPathLayer() {
mMapPosition.scale = 0;
GeometryBuffer g = new GeometryBuffer(100, 1);
g.startLine();
GeometryBuffer g = new GeometryBuffer(100, 1);
g.startLine();
Point[] pts = new Point[10];
for (int i = 0; i < 10; i++) {
pts[i] = new Point(i * 3, (i * i) % 3 * 4);
pts[i].x *= 10;
pts[i].y *= 10;
// System.out.println(pts[i]);
g.addPoint(pts[i]);
}
LineBucket ll = buckets.addLineBucket(0, new LineStyle(Color.BLUE, 2f));
ll.addLine(g);
Point[] pts = new Point[10];
for (int i = 0; i < 10; i++) {
pts[i] = new Point(i * 3, (i * i) % 3 * 4);
pts[i].x *= 10;
pts[i].y *= 10;
// System.out.println(pts[i]);
g.addPoint(pts[i]);
}
LineBucket ll = buckets.addLineBucket(0, new LineStyle(Color.BLUE, 2f));
ll.addLine(g);
List<Point> ctrl = BezierPath.cubicSplineControlPoints(pts, 0.1f);
List<Point> ctrl = BezierPath.cubicSplineControlPoints(pts, 0.1f);
g.clear();
g.startLine();
Point p0 = pts[0];
g.clear();
g.startLine();
Point p0 = pts[0];
for (int j = 1, k = 0; j < pts.length; j++) {
Point p1 = ctrl.get(k++);
Point p2 = ctrl.get(k++);
Point p3 = pts[j];
System.out.println(">>> " + p1 + " " + p2);
for (int i = 0; i < 10; i++) {
double mu = (i / 10f);
Point p = BezierPath.cubicBezier(p0, p1, p2, p3, mu);
g.addPoint(p);
System.out.println(mu + " " + p);
}
p0 = p3;
}
ll = buckets.addLineBucket(1, new LineStyle(Color.CYAN, 2f));
ll.addLine(g);
for (int j = 1, k = 0; j < pts.length; j++) {
Point p1 = ctrl.get(k++);
Point p2 = ctrl.get(k++);
Point p3 = pts[j];
System.out.println(">>> " + p1 + " " + p2);
for (int i = 0; i < 10; i++) {
double mu = (i / 10f);
Point p = BezierPath.cubicBezier(p0, p1, p2, p3, mu);
g.addPoint(p);
System.out.println(mu + " " + p);
}
p0 = p3;
}
ll = buckets.addLineBucket(1, new LineStyle(Color.CYAN, 2f));
ll.addLine(g);
}
}
public synchronized void clear() {
buckets.clear();
setReady(false);
}
public synchronized void clear() {
buckets.clear();
setReady(false);
}
@Override
public synchronized void update(GLViewport v) {
@Override
public synchronized void update(GLViewport v) {
if (mMapPosition.scale == 0)
mMapPosition.copy(v.pos);
if (mMapPosition.scale == 0)
mMapPosition.copy(v.pos);
if (!isReady()) {
compile();
}
}
}
if (!isReady()) {
compile();
}
}
}
}

View File

@@ -16,12 +16,6 @@
*/
package org.oscim.test.renderer;
import static org.oscim.backend.GLAdapter.gl;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.FloatBuffer;
import org.oscim.backend.GL;
import org.oscim.core.MapPosition;
import org.oscim.map.Map;
@@ -31,6 +25,12 @@ import org.oscim.renderer.GLUtils;
import org.oscim.renderer.GLViewport;
import org.oscim.renderer.LayerRenderer;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.FloatBuffer;
import static org.oscim.backend.GLAdapter.gl;
/*
* This is an example how to integrate custom OpenGL drawing routines as map overlay
*
@@ -40,127 +40,127 @@ import org.oscim.renderer.LayerRenderer;
public class CustomRenderer extends LayerRenderer {
private final Map mMap;
private final MapPosition mMapPosition;
private final Map mMap;
private final MapPosition mMapPosition;
private int mProgramObject;
private int hVertexPosition;
private int hMatrixPosition;
private int mProgramObject;
private int hVertexPosition;
private int hMatrixPosition;
private FloatBuffer mVertices;
private final float[] mVerticesData = {
-200, -200, 1.0f,
200, 200, 0,
-200, 200, 0.5f,
200, -200, 0.5f,
};
private boolean mInitialized;
private FloatBuffer mVertices;
private final float[] mVerticesData = {
-200, -200, 1.0f,
200, 200, 0,
-200, 200, 0.5f,
200, -200, 0.5f,
};
private boolean mInitialized;
public CustomRenderer(Map map) {
mMap = map;
mMapPosition = new MapPosition();
}
public CustomRenderer(Map map) {
mMap = map;
mMapPosition = new MapPosition();
}
// ---------- everything below runs in GLRender Thread ----------
@Override
public void update(GLViewport v) {
if (!mInitialized) {
if (!init())
return;
// ---------- everything below runs in GLRender Thread ----------
@Override
public void update(GLViewport v) {
if (!mInitialized) {
if (!init())
return;
mInitialized = true;
mInitialized = true;
// fix current MapPosition
mMapPosition.copy(v.pos);
// fix current MapPosition
mMapPosition.copy(v.pos);
compile();
}
}
compile();
}
}
protected void compile() {
// modify mVerticesData and put in FloatBuffer
protected void compile() {
// modify mVerticesData and put in FloatBuffer
mVertices.clear();
mVertices.put(mVerticesData);
mVertices.flip();
mVertices.clear();
mVertices.put(mVerticesData);
mVertices.flip();
setReady(true);
}
setReady(true);
}
@Override
public void render(GLViewport v) {
@Override
public void render(GLViewport v) {
// Use the program object
GLState.useProgram(mProgramObject);
// Use the program object
GLState.useProgram(mProgramObject);
GLState.blend(true);
GLState.test(false, false);
GLState.blend(true);
GLState.test(false, false);
// unbind previously bound VBOs
gl.bindBuffer(GL.ARRAY_BUFFER, 0);
// unbind previously bound VBOs
gl.bindBuffer(GL.ARRAY_BUFFER, 0);
// Load the vertex data
//mVertices.position(0);
gl.vertexAttribPointer(hVertexPosition, 3, GL.FLOAT, false, 0, mVertices);
//mVertices.position(2);
//GL.vertexAttribPointer(hVertexPosition, 2, GL20.FLOAT, false, 4, mVertices);
// Load the vertex data
//mVertices.position(0);
gl.vertexAttribPointer(hVertexPosition, 3, GL.FLOAT, false, 0, mVertices);
//mVertices.position(2);
//GL.vertexAttribPointer(hVertexPosition, 2, GL20.FLOAT, false, 4, mVertices);
GLState.enableVertexArrays(hVertexPosition, -1);
GLState.enableVertexArrays(hVertexPosition, -1);
/* apply view and projection matrices */
// set mvp (tmp) matrix relative to mMapPosition
// i.e. fixed on the map
// set mvp (tmp) matrix relative to mMapPosition
// i.e. fixed on the map
float ratio = 1f / mMap.getWidth();
float ratio = 1f / mMap.getWidth();
v.mvp.setScale(ratio, ratio, 1);
v.mvp.multiplyLhs(v.proj);
v.mvp.setAsUniform(hMatrixPosition);
v.mvp.setScale(ratio, ratio, 1);
v.mvp.multiplyLhs(v.proj);
v.mvp.setAsUniform(hMatrixPosition);
// Draw the triangle
gl.drawArrays(GL.TRIANGLE_STRIP, 0, 4);
// Draw the triangle
gl.drawArrays(GL.TRIANGLE_STRIP, 0, 4);
GLUtils.checkGlError("...");
}
GLUtils.checkGlError("...");
}
private boolean init() {
// Load the vertex/fragment shaders
int programObject = GLShader.createProgram(vShaderStr, fShaderStr);
private boolean init() {
// Load the vertex/fragment shaders
int programObject = GLShader.createProgram(vShaderStr, fShaderStr);
if (programObject == 0)
return false;
if (programObject == 0)
return false;
// Handle for vertex position in shader
hVertexPosition = gl.getAttribLocation(programObject, "a_pos");
// Handle for vertex position in shader
hVertexPosition = gl.getAttribLocation(programObject, "a_pos");
hMatrixPosition = gl.getUniformLocation(programObject, "u_mvp");
hMatrixPosition = gl.getUniformLocation(programObject, "u_mvp");
// Store the program object
mProgramObject = programObject;
// Store the program object
mProgramObject = programObject;
mVertices = ByteBuffer.allocateDirect(mVerticesData.length * 4)
.order(ByteOrder.nativeOrder()).asFloatBuffer();
mVertices = ByteBuffer.allocateDirect(mVerticesData.length * 4)
.order(ByteOrder.nativeOrder()).asFloatBuffer();
return true;
}
return true;
}
private final static String vShaderStr = "" +
"precision mediump float;"
+ "uniform mat4 u_mvp;"
+ "attribute vec4 a_pos;"
+ "varying float alpha;"
+ "void main()"
+ "{"
+ " gl_Position = u_mvp * vec4(a_pos.xy, 0.0, 1.0);"
+ " alpha = a_pos.z;"
+ "}";
private final static String vShaderStr = "" +
"precision mediump float;"
+ "uniform mat4 u_mvp;"
+ "attribute vec4 a_pos;"
+ "varying float alpha;"
+ "void main()"
+ "{"
+ " gl_Position = u_mvp * vec4(a_pos.xy, 0.0, 1.0);"
+ " alpha = a_pos.z;"
+ "}";
private final static String fShaderStr = "" +
"precision mediump float;"
+ "varying float alpha;"
+ "void main()"
+ "{"
+ " gl_FragColor = vec4 (alpha, 1.0-alpha, 0.0, 0.7 );"
+ "}";
private final static String fShaderStr = "" +
"precision mediump float;"
+ "varying float alpha;"
+ "void main()"
+ "{"
+ " gl_FragColor = vec4 (alpha, 1.0-alpha, 0.0, 0.7 );"
+ "}";
}

View File

@@ -1,9 +1,5 @@
package org.oscim.test.renderer;
import static org.oscim.backend.GLAdapter.gl;
import java.nio.FloatBuffer;
import org.oscim.backend.GL;
import org.oscim.backend.canvas.Color;
import org.oscim.gdx.GdxMap;
@@ -18,195 +14,199 @@ import org.oscim.renderer.GLViewport;
import org.oscim.renderer.MapRenderer;
import org.oscim.utils.FastMath;
import java.nio.FloatBuffer;
import static org.oscim.backend.GLAdapter.gl;
public class HexagonRenderTest extends GdxMap {
@Override
protected void createLayers() {
mMap.setMapPosition(0, 0, 1 << 4);
mMap.layers().add(new GenericLayer(mMap, new HexagonRenderer()));
}
@Override
protected void createLayers() {
mMap.setMapPosition(0, 0, 1 << 4);
mMap.layers().add(new GenericLayer(mMap, new HexagonRenderer()));
}
public static void main(String[] args) {
GdxMapApp.init();
GdxMapApp.run(new HexagonRenderTest(), null, 400);
}
public static void main(String[] args) {
GdxMapApp.init();
GdxMapApp.run(new HexagonRenderTest(), null, 400);
}
/* This is an example how to integrate custom OpenGL drawing routines as map
* overlay
* overlay
*
* based on chapter 2 from:
* https://github.com/dalinaum/opengl-es-book-samples/tree/master/Android */
static class HexagonRenderer extends BucketRenderer {
static class HexagonRenderer extends BucketRenderer {
private int mProgramObject;
private int hVertexPosition;
private int hMatrixPosition;
private int hColorPosition;
private int hCenterPosition;
private int mProgramObject;
private int hVertexPosition;
private int hMatrixPosition;
private int hColorPosition;
private int hCenterPosition;
//private FloatBuffer mVertices;
private boolean mInitialized;
private BufferObject mVBO;
//private FloatBuffer mVertices;
private boolean mInitialized;
private BufferObject mVBO;
int mZoom = -1;
float mCellScale = 60 * MapRenderer.COORD_SCALE;
int mZoom = -1;
float mCellScale = 60 * MapRenderer.COORD_SCALE;
@Override
public void update(GLViewport v) {
if (!mInitialized) {
if (!init()) {
return;
}
mInitialized = true;
@Override
public void update(GLViewport v) {
if (!mInitialized) {
if (!init()) {
return;
}
mInitialized = true;
compile();
mMapPosition.copy(v.pos);
}
compile();
mMapPosition.copy(v.pos);
}
//if (mZoom != v.pos.zoomLevel) {
// mMapPosition.copy(v.pos);
// mZoom = v.pos.zoomLevel;
//}
}
//if (mZoom != v.pos.zoomLevel) {
// mMapPosition.copy(v.pos);
// mZoom = v.pos.zoomLevel;
//}
}
@Override
protected void compile() {
@Override
protected void compile() {
float[] vertices = new float[12];
float[] vertices = new float[12];
for (int i = 0; i < 6; i++) {
vertices[i * 2 + 0] = (float) Math.cos(Math.PI * 2 * i / 6) * mCellScale;
vertices[i * 2 + 1] = (float) Math.sin(Math.PI * 2 * i / 6) * mCellScale;
}
FloatBuffer buf = MapRenderer.getFloatBuffer(12);
buf.put(vertices);
for (int i = 0; i < 6; i++) {
vertices[i * 2 + 0] = (float) Math.cos(Math.PI * 2 * i / 6) * mCellScale;
vertices[i * 2 + 1] = (float) Math.sin(Math.PI * 2 * i / 6) * mCellScale;
}
FloatBuffer buf = MapRenderer.getFloatBuffer(12);
buf.put(vertices);
mVBO = BufferObject.get(GL.ARRAY_BUFFER, 0);
mVBO.loadBufferData(buf.flip(), 12 * 4);
mVBO = BufferObject.get(GL.ARRAY_BUFFER, 0);
mVBO.loadBufferData(buf.flip(), 12 * 4);
setReady(true);
}
setReady(true);
}
@Override
public void render(GLViewport v) {
@Override
public void render(GLViewport v) {
// Use the program object
GLState.useProgram(mProgramObject);
// Use the program object
GLState.useProgram(mProgramObject);
GLState.blend(true);
GLState.test(false, false);
GLState.blend(true);
GLState.test(false, false);
// bind VBO data
mVBO.bind();
// bind VBO data
mVBO.bind();
// set VBO vertex layout
gl.vertexAttribPointer(hVertexPosition, 2, GL.FLOAT, false, 0, 0);
// set VBO vertex layout
gl.vertexAttribPointer(hVertexPosition, 2, GL.FLOAT, false, 0, 0);
GLState.enableVertexArrays(hVertexPosition, -1);
GLState.enableVertexArrays(hVertexPosition, -1);
/* apply view and projection matrices */
// set mvp (tmp) matrix relative to mMapPosition
// i.e. fixed on the map
setMatrix(v);
v.mvp.setAsUniform(hMatrixPosition);
// set mvp (tmp) matrix relative to mMapPosition
// i.e. fixed on the map
setMatrix(v);
v.mvp.setAsUniform(hMatrixPosition);
final int offset_x = 4;
final int offset_y = 16;
final int offset_x = 4;
final int offset_y = 16;
float h = (float) (Math.sqrt(3) / 2);
for (int y = -offset_y; y < offset_y; y++) {
for (int x = -offset_x; x < offset_x; x++) {
float xx = x * 2 + (y % 2 == 0 ? 1 : 0);
float yy = y * h + h / 2;
float h = (float) (Math.sqrt(3) / 2);
for (int y = -offset_y; y < offset_y; y++) {
for (int x = -offset_x; x < offset_x; x++) {
float xx = x * 2 + (y % 2 == 0 ? 1 : 0);
float yy = y * h + h / 2;
gl.uniform2f(hCenterPosition, xx * (mCellScale * 1.5f), yy * mCellScale);
gl.uniform2f(hCenterPosition, xx * (mCellScale * 1.5f), yy * mCellScale);
//float alpha = 1 + (float) Math.log10(FastMath.clamp(
// (float) Math.sqrt(xx * xx + yy * yy) / offset_y, 0.0f, 1.0f)) * 2;
//float alpha = 1 + (float) Math.log10(FastMath.clamp(
// (float) Math.sqrt(xx * xx + yy * yy) / offset_y, 0.0f, 1.0f)) * 2;
float alpha = (float) Math.sqrt(xx * xx + yy * yy) / offset_y;
float alpha = (float) Math.sqrt(xx * xx + yy * yy) / offset_y;
float fy = (float) (y + offset_y) / (offset_y * 2);
float fx = (float) (x + offset_x) / (offset_x * 2);
float fz = FastMath.clamp(
(float) (x < 0 || y < 0 ? 1 - Math.sqrt(fx * fx + fy
* fy)
: 0),
0,
1);
float fy = (float) (y + offset_y) / (offset_y * 2);
float fx = (float) (x + offset_x) / (offset_x * 2);
float fz = FastMath.clamp(
(float) (x < 0 || y < 0 ? 1 - Math.sqrt(fx * fx + fy
* fy)
: 0),
0,
1);
int c = 0xff << 24
| (int) (0xff * fy) << 16
| (int) (0xff * fx) << 8
| (int) (0xff * fz);
int c = 0xff << 24
| (int) (0xff * fy) << 16
| (int) (0xff * fx) << 8
| (int) (0xff * fz);
GLUtils.setColor(hColorPosition, c, alpha);
GLUtils.setColor(hColorPosition, c, alpha);
gl.drawArrays(GL.TRIANGLE_FAN, 0, 6);
}
}
gl.drawArrays(GL.TRIANGLE_FAN, 0, 6);
}
}
GLUtils.setColor(hColorPosition, Color.DKGRAY, 0.3f);
GLUtils.setColor(hColorPosition, Color.DKGRAY, 0.3f);
for (int y = -offset_y; y < offset_y; y++) {
for (int x = -offset_x; x < offset_x; x++) {
float xx = x * 2 + (y % 2 == 0 ? 1 : 0);
float yy = y * h + h / 2;
for (int y = -offset_y; y < offset_y; y++) {
for (int x = -offset_x; x < offset_x; x++) {
float xx = x * 2 + (y % 2 == 0 ? 1 : 0);
float yy = y * h + h / 2;
gl.uniform2f(hCenterPosition, xx * (mCellScale * 1.5f), yy * mCellScale);
gl.drawArrays(GL.LINE_LOOP, 0, 6);
}
}
gl.uniform2f(hCenterPosition, xx * (mCellScale * 1.5f), yy * mCellScale);
gl.drawArrays(GL.LINE_LOOP, 0, 6);
}
}
GLUtils.checkGlError("...");
}
GLUtils.checkGlError("...");
}
private boolean init() {
// Load the vertex/fragment shaders
int programObject = GLShader.createProgram(vShaderStr, fShaderStr);
private boolean init() {
// Load the vertex/fragment shaders
int programObject = GLShader.createProgram(vShaderStr, fShaderStr);
if (programObject == 0)
return false;
if (programObject == 0)
return false;
// Handle for vertex position in shader
hVertexPosition = gl.getAttribLocation(programObject, "a_pos");
// Handle for vertex position in shader
hVertexPosition = gl.getAttribLocation(programObject, "a_pos");
hMatrixPosition = gl.getUniformLocation(programObject, "u_mvp");
hMatrixPosition = gl.getUniformLocation(programObject, "u_mvp");
hColorPosition = gl.getUniformLocation(programObject, "u_color");
hColorPosition = gl.getUniformLocation(programObject, "u_color");
hCenterPosition = gl.getUniformLocation(programObject, "u_center");
hCenterPosition = gl.getUniformLocation(programObject, "u_center");
// Store the program object
mProgramObject = programObject;
// Store the program object
mProgramObject = programObject;
return true;
}
return true;
}
private final static String vShaderStr = ""
+ "#ifdef GLES\n"
+ "precision mediump float;\n"
+ "#endif\n"
+ "uniform mat4 u_mvp;"
+ "uniform vec2 u_center;"
+ "attribute vec2 a_pos;"
+ "void main()"
+ "{"
+ " gl_Position = u_mvp * vec4(u_center + a_pos, 0.0, 1.0);"
+ "}";
private final static String vShaderStr = ""
+ "#ifdef GLES\n"
+ "precision mediump float;\n"
+ "#endif\n"
+ "uniform mat4 u_mvp;"
+ "uniform vec2 u_center;"
+ "attribute vec2 a_pos;"
+ "void main()"
+ "{"
+ " gl_Position = u_mvp * vec4(u_center + a_pos, 0.0, 1.0);"
+ "}";
private final static String fShaderStr = ""
+ "#ifdef GLES\n"
+ "precision mediump float;\n"
+ "#endif\n"
+ "varying float alpha;"
+ "uniform vec4 u_color;"
+ "void main()"
+ "{"
+ " gl_FragColor = u_color;"
+ "}";
private final static String fShaderStr = ""
+ "#ifdef GLES\n"
+ "precision mediump float;\n"
+ "#endif\n"
+ "varying float alpha;"
+ "uniform vec4 u_color;"
+ "void main()"
+ "{"
+ " gl_FragColor = u_color;"
+ "}";
}
}
}

View File

@@ -23,30 +23,30 @@ import org.oscim.renderer.bucket.SymbolBucket;
import org.oscim.renderer.bucket.SymbolItem;
public class SymbolRenderLayer extends BucketRenderer {
boolean initialize = true;
boolean initialize = true;
public SymbolRenderLayer() {
SymbolBucket l = new SymbolBucket();
buckets.set(l);
public SymbolRenderLayer() {
SymbolBucket l = new SymbolBucket();
buckets.set(l);
SymbolItem it = SymbolItem.pool.get();
it.billboard = false;
SymbolItem it = SymbolItem.pool.get();
it.billboard = false;
try {
it.bitmap = CanvasAdapter.getBitmapAsset("jar:symbols/cafe.png");
} catch (Exception e) {
e.printStackTrace();
try {
it.bitmap = CanvasAdapter.getBitmapAsset("jar:symbols/cafe.png");
} catch (Exception e) {
e.printStackTrace();
}
l.addSymbol(it);
}
}
l.addSymbol(it);
}
@Override
public void update(GLViewport v) {
if (initialize) {
initialize = false;
mMapPosition.copy(v.pos);
compile();
}
}
@Override
public void update(GLViewport v) {
if (initialize) {
initialize = false;
mMapPosition.copy(v.pos);
compile();
}
}
}