From 2e8feb686b3badbb6b87ba78a6e861d49e05f917 Mon Sep 17 00:00:00 2001 From: Luca Warmenhoven Date: Wed, 29 May 2024 16:18:48 +0200 Subject: [PATCH] Updated PersonalMotionPreviewElement --- .../components/PersonalMotionPreviewElement.java | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/code/src/Fitbot/app/src/main/java/com/example/fitbot/ui/components/PersonalMotionPreviewElement.java b/code/src/Fitbot/app/src/main/java/com/example/fitbot/ui/components/PersonalMotionPreviewElement.java index 141b0bc..0a087ef 100644 --- a/code/src/Fitbot/app/src/main/java/com/example/fitbot/ui/components/PersonalMotionPreviewElement.java +++ b/code/src/Fitbot/app/src/main/java/com/example/fitbot/ui/components/PersonalMotionPreviewElement.java @@ -42,8 +42,7 @@ public class PersonalMotionPreviewElement extends View { private final Paint backgroundColor = new Paint(); private Matrix4f modelMatrix = new Matrix4f(); // The model view matrix for the 3D to 2D transformation. - private Matrix4f viewMatrix = new Matrix4f() - .lookAt(new Vector3f(4, 4, 4), new Vector3f(0, 0, 0), new Vector3f(0, 1, 0)); // The view matrix for the 3D to 2D transformation. + private Matrix4f viewMatrix = new Matrix4f(); // The view matrix for the 3D to 2D transformation. private Matrix4f projectionMatrix = new Matrix4f(); // The projection matrix for the 3D to 2D transformation. private final Vector4f objectPosition = new Vector4f(0, 0, 0, 1); // The location of the object in 3D space. private ConcurrentLinkedQueue vectors = new ConcurrentLinkedQueue<>(); @@ -171,9 +170,9 @@ public class PersonalMotionPreviewElement extends View { private Vector2f projectVertex(Vector3f point, int virtualWidth, int virtualHeight) { - modelMatrix + viewMatrix .identity() - .translate(-objectPosition.x, -objectPosition.y, -objectPosition.z); + .lookAt(new Vector3f(0, 0, -5), new Vector3f(0, 0, 0), new Vector3f(0, 1, 0)); // Transform the projection matrix to a perspective projection matrix // Perspective transformation conserves the depth of the object @@ -202,9 +201,13 @@ public class PersonalMotionPreviewElement extends View { if (this.exercise == null) return; - for (int i = 0; i < axisVectors.length/2; i++) + for (int i = 0, startX, endX, startY, endY; i < axisVectors.length/2; i++) { - canvas.drawLine(axisVectors[i*2].x, axisVectors[i*2].y, axisVectors[i*2+1].x, axisVectors[i*2+1].y, this.targetPaint); + startX = (int)Math.max(0, Math.min(this.screenDimensions.x, (int)axisVectors[i*2].x)); + endX = (int)Math.max(0, Math.min(this.screenDimensions.x, (int)axisVectors[i*2+1].x)); + startY = (int)Math.max(0, Math.min(this.screenDimensions.y, (int)axisVectors[i*2].y)); + endY = (int)Math.max(0, Math.min(this.screenDimensions.y, (int)axisVectors[i*2+1].y)); + canvas.drawLine(startX, startY, endX, endY, this.targetPaint); } for ( Vector2f point : this.vectors)