Symbol rotation (#294)
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
* Copyright 2014 Hannes Janetzek
|
||||
* Copyright 2016 devemux86
|
||||
* Copyright 2016 Erik Duisters
|
||||
* Copyright 2017 Longri
|
||||
*
|
||||
* This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
|
||||
*
|
||||
@@ -75,4 +76,9 @@ public class MarkerItem implements MarkerInterface {
|
||||
public void setMarker(MarkerSymbol marker) {
|
||||
mMarker = marker;
|
||||
}
|
||||
|
||||
public void setRotation(float rotation) {
|
||||
if (mMarker != null)
|
||||
mMarker.setRotation(rotation);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
* Copyright 2013 Hannes Janetzek
|
||||
* Copyright 2016 Stephan Leuschner
|
||||
* Copyright 2016 devemux86
|
||||
* Copyright 2017 Longri
|
||||
*
|
||||
* This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
|
||||
*
|
||||
@@ -96,6 +97,10 @@ public abstract class MarkerLayer<Item extends MarkerInterface> extends Layer {
|
||||
return mFocusedItem;
|
||||
}
|
||||
|
||||
public void update() {
|
||||
mMarkerRenderer.update();
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO
|
||||
* Interface definition for overlays that contain items that can be snapped
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
/*
|
||||
* Copyright 2013 Hannes Janetzek
|
||||
* Copyright 2016 Izumi Kawashima
|
||||
* Copyright 2017 Longri
|
||||
*
|
||||
* This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
|
||||
*
|
||||
@@ -163,9 +164,9 @@ public class MarkerRenderer extends BucketRenderer {
|
||||
|
||||
SymbolItem s = SymbolItem.pool.get();
|
||||
if (marker.isBitmap()) {
|
||||
s.set(it.x, it.y, marker.getBitmap(), true);
|
||||
s.set(it.x, it.y, marker.getBitmap(), marker.rotation, true);
|
||||
} else {
|
||||
s.set(it.x, it.y, marker.getTextureRegion(), true);
|
||||
s.set(it.x, it.y, marker.getTextureRegion(), marker.rotation, true);
|
||||
}
|
||||
s.offset = marker.getHotspot();
|
||||
s.billboard = marker.isBillboard();
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
* Copyright 2013 Hannes Janetzek
|
||||
* Copyright 2016 devemux86
|
||||
* Copyright 2016 Izumi Kawashima
|
||||
* Copyright 2017 Longri
|
||||
*
|
||||
* This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
|
||||
*
|
||||
@@ -44,6 +45,8 @@ public class MarkerSymbol {
|
||||
final PointF mOffset;
|
||||
final boolean mBillboard;
|
||||
|
||||
float rotation = 0;
|
||||
|
||||
public MarkerSymbol(TextureRegion textureRegion, float relX, float relY) {
|
||||
this(textureRegion, relX, relY, true);
|
||||
}
|
||||
@@ -180,4 +183,12 @@ public class MarkerSymbol {
|
||||
|
||||
return dx >= ox && dy >= oy && dx <= ox + w && dy <= oy + h;
|
||||
}
|
||||
|
||||
public float getRotation() {
|
||||
return this.rotation;
|
||||
}
|
||||
|
||||
public void setRotation(float rotation) {
|
||||
this.rotation = rotation;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
/*
|
||||
* Copyright 2012 Hannes Janetzek
|
||||
* Copyright 2016 devemux86
|
||||
* Copyright 2016-2017 devemux86
|
||||
* Copyright 2017 Longri
|
||||
*
|
||||
* This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
|
||||
*
|
||||
@@ -19,6 +20,7 @@ package org.oscim.renderer.bucket;
|
||||
|
||||
import org.oscim.backend.canvas.Bitmap;
|
||||
import org.oscim.core.PointF;
|
||||
import org.oscim.renderer.GLMatrix;
|
||||
import org.oscim.renderer.atlas.TextureAtlas;
|
||||
import org.oscim.utils.pool.Inlist;
|
||||
import org.slf4j.Logger;
|
||||
@@ -36,6 +38,10 @@ public final class SymbolBucket extends TextureBucket {
|
||||
private TextureItem prevTextures;
|
||||
private List<SymbolItem> mSymbols = new List<SymbolItem>();
|
||||
|
||||
private final float[] points = new float[8];
|
||||
private final GLMatrix rotationMatrix = new GLMatrix();
|
||||
private final GLMatrix translateMatrix = new GLMatrix();
|
||||
|
||||
public SymbolBucket() {
|
||||
super(RenderBucket.SYMBOL);
|
||||
fixed = true;
|
||||
@@ -120,47 +126,108 @@ public final class SymbolBucket extends TextureBucket {
|
||||
|
||||
PointF prevOffset = null;
|
||||
short x1 = 0, y1 = 0, x2 = 0, y2 = 0;
|
||||
float minX, minY, maxX, maxY;
|
||||
|
||||
/* add symbol items referencing the same bitmap */
|
||||
for (SymbolItem prev = it; it != null; it = it.next) {
|
||||
if (it.rotation == 0) { // without rotation
|
||||
if (prev.bitmap != null && prev.bitmap != it.bitmap)
|
||||
break;
|
||||
|
||||
if (prev.bitmap != null && prev.bitmap != it.bitmap)
|
||||
break;
|
||||
if (prev.texRegion != null && prev.texRegion != it.texRegion)
|
||||
break;
|
||||
|
||||
if (prev.texRegion != null && prev.texRegion != it.texRegion)
|
||||
break;
|
||||
if (it == prev || it.offset != prevOffset) {
|
||||
prevOffset = it.offset;
|
||||
if (it.offset == null) {
|
||||
float hw = width / 2f;
|
||||
float hh = height / 2f;
|
||||
|
||||
if (it == prev || it.offset != prevOffset) {
|
||||
prevOffset = it.offset;
|
||||
if (it.offset == null) {
|
||||
float hw = width / 2f;
|
||||
float hh = height / 2f;
|
||||
|
||||
x1 = (short) (SCALE * (-hw));
|
||||
x2 = (short) (SCALE * (hw));
|
||||
y1 = (short) (SCALE * (hh));
|
||||
y2 = (short) (SCALE * (-hh));
|
||||
} else {
|
||||
float hw = (float) (it.offset.x * width);
|
||||
float hh = (float) (it.offset.y * height);
|
||||
x1 = (short) (SCALE * (-hw));
|
||||
x2 = (short) (SCALE * (width - hw));
|
||||
y1 = (short) (SCALE * (height - hh));
|
||||
y2 = (short) (SCALE * (-hh));
|
||||
x1 = (short) (SCALE * (-hw));
|
||||
x2 = (short) (SCALE * (hw));
|
||||
y1 = (short) (SCALE * (hh));
|
||||
y2 = (short) (SCALE * (-hh));
|
||||
} else {
|
||||
float hw = (float) (it.offset.x * width);
|
||||
float hh = (float) (it.offset.y * height);
|
||||
x1 = (short) (SCALE * (-hw));
|
||||
x2 = (short) (SCALE * (width - hw));
|
||||
y1 = (short) (SCALE * (height - hh));
|
||||
y2 = (short) (SCALE * (-hh));
|
||||
}
|
||||
}
|
||||
|
||||
/* add vertices */
|
||||
short tx = (short) ((int) (SCALE * it.x) & LBIT_MASK
|
||||
| (it.billboard ? 1 : 0));
|
||||
|
||||
short ty = (short) (SCALE * it.y);
|
||||
|
||||
vertexItems.add(tx, ty, x1, y1, u1, v2);
|
||||
vertexItems.add(tx, ty, x1, y2, u1, v1);
|
||||
vertexItems.add(tx, ty, x2, y1, u2, v2);
|
||||
vertexItems.add(tx, ty, x2, y2, u2, v1);
|
||||
} else { // with rotation
|
||||
if (prev.bitmap != null && prev.bitmap != it.bitmap && prev.rotation != it.rotation)
|
||||
break;
|
||||
|
||||
if (prev.texRegion != null && prev.texRegion != it.texRegion && prev.rotation != it.rotation)
|
||||
break;
|
||||
|
||||
short offsetX, offsetY;
|
||||
if (it.offset == null) {
|
||||
offsetX = 0;
|
||||
offsetY = 0;
|
||||
} else {
|
||||
offsetX = (short) (((width / 2f) - (it.offset.x * width)) * SCALE);
|
||||
offsetY = (short) (((height / 2f) - (it.offset.y * height)) * SCALE);
|
||||
}
|
||||
|
||||
float hw = width / 2f;
|
||||
float hh = height / 2f;
|
||||
|
||||
minX = (SCALE * (-hw));
|
||||
maxX = (SCALE * (hw));
|
||||
minY = (SCALE * (hh));
|
||||
maxY = (SCALE * (-hh));
|
||||
|
||||
// target drawing rectangle
|
||||
{ // lower-left
|
||||
points[0] = minX;
|
||||
points[1] = minY;
|
||||
}
|
||||
|
||||
{ // upper-left
|
||||
points[2] = minX;
|
||||
points[3] = maxY;
|
||||
}
|
||||
|
||||
{ // upper-right
|
||||
points[6] = maxX;
|
||||
points[7] = maxY;
|
||||
}
|
||||
|
||||
{ // lower-right
|
||||
points[4] = maxX;
|
||||
points[5] = minY;
|
||||
}
|
||||
|
||||
if (it.rotation != 0) {
|
||||
rotationMatrix.setRotation(it.rotation, 0, 0, 1);
|
||||
rotationMatrix.prj2D(points, 0, 4);
|
||||
}
|
||||
|
||||
/* add vertices */
|
||||
short tx = (short) (((int) (SCALE * it.x) & LBIT_MASK
|
||||
| (it.billboard ? 1 : 0)) + offsetX);
|
||||
short ty = (short) ((SCALE * it.y) + offsetY);
|
||||
|
||||
vertexItems.add(tx, ty, points[0], points[1], u1, v2); // lower-left
|
||||
vertexItems.add(tx, ty, points[2], points[3], u1, v1); // upper-left
|
||||
vertexItems.add(tx, ty, points[4], points[5], u2, v2); // upper-right
|
||||
vertexItems.add(tx, ty, points[6], points[7], u2, v1); // lower-right
|
||||
}
|
||||
|
||||
/* add vertices */
|
||||
short tx = (short) ((int) (SCALE * it.x) & LBIT_MASK
|
||||
| (it.billboard ? 1 : 0));
|
||||
|
||||
short ty = (short) (SCALE * it.y);
|
||||
|
||||
vertexItems.add(tx, ty, x1, y1, u1, v2);
|
||||
vertexItems.add(tx, ty, x1, y2, u1, v1);
|
||||
vertexItems.add(tx, ty, x2, y1, u2, v2);
|
||||
vertexItems.add(tx, ty, x2, y2, u2, v1);
|
||||
|
||||
/* six elements used to draw the four vertices */
|
||||
t.indices += TextureBucket.INDICES_PER_SPRITE;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
/*
|
||||
* Copyright 2012 Hannes Janetzek
|
||||
* Copyright 2017 Longri
|
||||
*
|
||||
* This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
|
||||
*
|
||||
@@ -37,6 +38,7 @@ public class SymbolItem extends Inlist<SymbolItem> {
|
||||
it.bitmap = null;
|
||||
it.texRegion = null;
|
||||
it.offset = null;
|
||||
it.rotation = 0;
|
||||
return true;
|
||||
}
|
||||
};
|
||||
@@ -48,12 +50,24 @@ public class SymbolItem extends Inlist<SymbolItem> {
|
||||
public TextureRegion texRegion;
|
||||
public Bitmap bitmap;
|
||||
public PointF offset;
|
||||
public float rotation;
|
||||
|
||||
public void set(float x, float y, TextureRegion texture, float rotation, boolean billboard) {
|
||||
set(x, y, texture, billboard);
|
||||
this.rotation = rotation;
|
||||
}
|
||||
|
||||
public void set(float x, float y, TextureRegion texture, boolean billboard) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.texRegion = texture;
|
||||
this.billboard = billboard;
|
||||
this.rotation = 0;
|
||||
}
|
||||
|
||||
public void set(float x, float y, Bitmap bitmap, float rotation, boolean billboard) {
|
||||
set(x, y, bitmap, billboard);
|
||||
this.rotation = rotation;
|
||||
}
|
||||
|
||||
public void set(float x, float y, Bitmap bitmap, boolean billboard) {
|
||||
@@ -61,6 +75,7 @@ public class SymbolItem extends Inlist<SymbolItem> {
|
||||
this.y = y;
|
||||
this.bitmap = bitmap;
|
||||
this.billboard = billboard;
|
||||
this.rotation = 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user