aboutsummaryrefslogtreecommitdiffhomepage
path: root/platform_tools
diff options
context:
space:
mode:
Diffstat (limited to 'platform_tools')
-rw-r--r--platform_tools/android/apps/skar_java/src/main/java/com/google/ar/core/examples/java/helloskar/DrawManager.java57
1 files changed, 30 insertions, 27 deletions
diff --git a/platform_tools/android/apps/skar_java/src/main/java/com/google/ar/core/examples/java/helloskar/DrawManager.java b/platform_tools/android/apps/skar_java/src/main/java/com/google/ar/core/examples/java/helloskar/DrawManager.java
index c448ffeb42..7e5ac29384 100644
--- a/platform_tools/android/apps/skar_java/src/main/java/com/google/ar/core/examples/java/helloskar/DrawManager.java
+++ b/platform_tools/android/apps/skar_java/src/main/java/com/google/ar/core/examples/java/helloskar/DrawManager.java
@@ -39,7 +39,6 @@ public class DrawManager {
private float viewportHeight;
private ColorFilter lightFilter;
private BitmapShader planeShader;
- private Bitmap planeTexture;
public ArrayList<float[]> modelMatrices = new ArrayList<>();
public void updateViewport(float width, float height) {
@@ -178,7 +177,6 @@ public class DrawManager {
continue;
}
-
// Get plane model matrix
float[] model = new float[16];
plane.getCenterPose().toMatrix(model, 0);
@@ -186,58 +184,63 @@ public class DrawManager {
// Initial rotation
float[] initRot = SkARMatrix.createXYtoXZRotationMatrix();
- float[] initScale = new float[16];
- Matrix.setIdentityM(initScale, 0);
- Matrix.scaleM(initScale, 0, 1f, 1f, 1f);
- android.graphics.Matrix scale = SkARMatrix.createMatrixFrom4x4(SkARMatrix.multiplyMatrices4x4(new float[][] {initScale}));
-
// Matrix = mvpv
float[][] matrices = {initRot, model, viewMatrix, projectionMatrix, SkARMatrix.createViewportMatrix(viewportWidth, viewportHeight)};
android.graphics.Matrix mvpv = SkARMatrix.createMatrixFrom4x4(SkARMatrix.multiplyMatrices4x4(matrices));
- canvas.save();
-
- canvas.setMatrix(mvpv);
-
- drawPlaneAsPath(canvas, plane);
- canvas.restore();
+ if (Build.VERSION.SDK_INT > Build.VERSION_CODES.O_MR1) {
+ // Android version P and higher
+ drawPlane(canvas, mvpv, plane);
+ } else {
+ drawPlaneAsPath(canvas, mvpv, plane);
+ }
}
}
// Helper function that draws an AR plane using a path
- private void drawPlaneAsPath(Canvas canvas, Plane plane) {
+ private void drawPlaneAsPath(Canvas canvas, android.graphics.Matrix mvpv, Plane plane) {
int vertsSize = plane.getPolygon().limit() / 2;
FloatBuffer polygon = plane.getPolygon();
polygon.rewind();
- Path path = new Path();
- path.moveTo(polygon.get(0), polygon.get(1));
+ // Build source path from polygon data
+ Path pathSrc = new Path();
+ pathSrc.moveTo(polygon.get(0), polygon.get(1));
for (int i = 1; i < vertsSize; i++) {
- path.lineTo(polygon.get(i * 2), polygon.get(i * 2 + 1));
+ pathSrc.lineTo(polygon.get(i * 2), polygon.get(i * 2 + 1));
}
- path.close();
+ pathSrc.close();
+ // Set up paint
Paint p = new Paint();
p.setShader(planeShader);
- p.setColorFilter(new PorterDuffColorFilter(Color.argb(0.4f, 1, 0, 0), PorterDuff.Mode.SRC_ATOP));
+ p.setColorFilter(new PorterDuffColorFilter(Color.argb(0.4f, 1, 0, 0),
+ PorterDuff.Mode.SRC_ATOP));
p.setAlpha(120);
- //canvas.drawPath(path, p); TODO: enable this when path is drawn on GPU
+ // Build destination path by transforming source path
+ Path pathDst = new Path();
+ pathSrc.transform(mvpv, pathDst);
+
+ // Shader local matrix
+ android.graphics.Matrix lm = new android.graphics.Matrix();
+ lm.setScale(0.0005f, 0.0005f);
+ lm.postConcat(mvpv);
+ planeShader.setLocalMatrix(lm);
- RectF r = new RectF();
- path.computeBounds(r, true);
- canvas.drawRect(r, p);
+ // Draw dest path
+ canvas.save();
+ canvas.setMatrix(new android.graphics.Matrix());
+ canvas.drawPath(pathDst, p);
+ canvas.restore();
}
public void initializePlaneShader(Context context, String gridDistanceTextureName) throws IOException {
// Read the texture.
- planeTexture =
+ Bitmap planeTexture =
BitmapFactory.decodeStream(context.getAssets().open(gridDistanceTextureName));
// Set up the shader
planeShader = new BitmapShader(planeTexture, Shader.TileMode.REPEAT, Shader.TileMode.REPEAT);
- android.graphics.Matrix m = new android.graphics.Matrix();
- m.setScale(0.0005f, 0.0005f);
- planeShader.setLocalMatrix(m);
}
private float[] getTextScaleMatrix(float size) {