diff options
Diffstat (limited to 'platform_tools/android/apps/skar_java/src/main/java/com/google/skar/examples/helloskar/app')
2 files changed, 18 insertions, 19 deletions
diff --git a/platform_tools/android/apps/skar_java/src/main/java/com/google/skar/examples/helloskar/app/FingerPainting.java b/platform_tools/android/apps/skar_java/src/main/java/com/google/skar/examples/helloskar/app/FingerPainting.java index ac97dfbf77..48b91615d4 100644 --- a/platform_tools/android/apps/skar_java/src/main/java/com/google/skar/examples/helloskar/app/FingerPainting.java +++ b/platform_tools/android/apps/skar_java/src/main/java/com/google/skar/examples/helloskar/app/FingerPainting.java @@ -84,14 +84,14 @@ public class FingerPainting { * @param holdTap ScrollEvent associated with the hit test that calls this function * @return true if point was computed and added. False otherwise. */ - public boolean computeNextPoint(float[] hitLocation, GestureHelper.ScrollEvent holdTap) { + public boolean computeNextPoint(float[] hitLocation, float[] modelMat, GestureHelper.ScrollEvent holdTap) { if (isEmpty()) { // If finger painting is empty, then first point is origin. Model matrix // of the finger painting is the model matrix of the first point addPoint(new PointF(0, 0), true); // Get model matrix of first point - setModelMatrix(modelMatrix); + setModelMatrix(modelMat); } else { // Else, construct next point given its distance from previous point float localDistanceScale = 1000; @@ -111,7 +111,7 @@ public class FingerPainting { addPoint(p, holdTap.isStartOfScroll); } previousGlobalPoint[0] = hitLocation[0]; - previousGlobalPoint[1] = hitLocation[1]; + previousGlobalPoint[1] = hitLocation[2]; return true; } @@ -230,6 +230,8 @@ public class FingerPainting { if (nbPts == 2) { p.moveTo(points.get(start).x, points.get(start).y); p.lineTo(points.get(start + 1).x, points.get(start + 1).y); + BuiltPath bp = new BuiltPath(p, c); + paths.add(bp); } else if (nbPts >= 3) { // Else (3 pts +), essentially run deCasteljau p.moveTo(points.get(start).x, points.get(start).y); @@ -243,10 +245,9 @@ public class FingerPainting { } p.lineTo(points.get(finish - 1).x, points.get(finish - 1).y); + BuiltPath bp = new BuiltPath(p, c); + paths.add(bp); } - - BuiltPath bp = new BuiltPath(p, c); - paths.add(bp); } private boolean isEmpty() { return points.isEmpty(); } diff --git a/platform_tools/android/apps/skar_java/src/main/java/com/google/skar/examples/helloskar/app/HelloCanvasAR.java b/platform_tools/android/apps/skar_java/src/main/java/com/google/skar/examples/helloskar/app/HelloCanvasAR.java index 10527c79de..56480f671a 100644 --- a/platform_tools/android/apps/skar_java/src/main/java/com/google/skar/examples/helloskar/app/HelloCanvasAR.java +++ b/platform_tools/android/apps/skar_java/src/main/java/com/google/skar/examples/helloskar/app/HelloCanvasAR.java @@ -133,12 +133,14 @@ public class HelloCanvasAR extends AppCompatActivity implements GLSurfaceView.Re // Canvas Surface View set up arSurfaceView = findViewById(R.id.canvas_surfaceview); + glSurfaceView = findViewById(R.id.gl_surfaceview); arSurfaceView.bringToFront(); arSurfaceView.setLayerType(View.LAYER_TYPE_HARDWARE, null); holder = arSurfaceView.getHolder(); // Set up tap listener. tapHelper = new GestureHelper(this); + glSurfaceView.setOnTouchListener(tapHelper); // Set up renderer. @@ -308,7 +310,6 @@ public class HelloCanvasAR extends AppCompatActivity implements GLSurfaceView.Re @Override public void onDrawFrame(GL10 gl) { Canvas canvas = null; - holder = null; // Clear screen to notify driver it should not load any pixels from previous frame. GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT); @@ -392,7 +393,7 @@ public class HelloCanvasAR extends AppCompatActivity implements GLSurfaceView.Re } } catch (Throwable t) { // Avoid crashing the application due to unhandled exceptions. - if (holder != null && canvas != null) { + if (canvas != null) { holder.unlockCanvasAndPost(canvas); } Log.e(TAG, "Exception on the OpenGL thread", t); @@ -461,7 +462,7 @@ public class HelloCanvasAR extends AppCompatActivity implements GLSurfaceView.Re Matrix.multiplyMV(hitLocation, 0, modelMatrix, 0, hitLocation, 0); - if (! drawManager.fingerPainting.computeNextPoint(hitLocation, holdTap)) { + if (! drawManager.fingerPainting.computeNextPoint(hitLocation, modelMatrix, holdTap)) { // Try to add the next point to the finger painting. If return value // is false, then keep looping continue; @@ -523,19 +524,16 @@ public class HelloCanvasAR extends AppCompatActivity implements GLSurfaceView.Re public boolean onCreateOptionsMenu(Menu menu) { MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.main_menu, menu); + + menu.setGroupCheckable(R.id.menu_drawables, true, true); return true; } public boolean onOptionsItemSelected(MenuItem item) { + item.setChecked(!item.isChecked()); switch (item.getItemId()) { - case R.id.reset_paint: - drawManager.fingerPainting.reset(); - return true; case R.id.smooth_paint: - drawManager.drawSmoothPainting = true; - return true; - case R.id.rough_paint: - drawManager.drawSmoothPainting = false; + drawManager.drawSmoothPainting = item.isChecked(); return true; case R.id.draw_circle: drawManager.currentDrawabletype = DrawManager.DrawingType.circle; @@ -543,12 +541,12 @@ public class HelloCanvasAR extends AppCompatActivity implements GLSurfaceView.Re case R.id.draw_rect: drawManager.currentDrawabletype = DrawManager.DrawingType.rect; return true; - case R.id.draw_animation: - drawManager.currentDrawabletype = DrawManager.DrawingType.animation; - return true; case R.id.draw_text: drawManager.currentDrawabletype = DrawManager.DrawingType.text; return true; + case R.id.draw_animation: + drawManager.currentDrawabletype = DrawManager.DrawingType.animation; + return true; default: return super.onOptionsItemSelected(item); } |