Added more logging for debugging functionality

This commit is contained in:
Luca Warmenhoven
2024-05-29 15:39:13 +02:00
parent 447a021b10
commit a6977b057c
2 changed files with 40 additions and 2 deletions

View File

@@ -22,6 +22,8 @@ import org.joml.Vector2f;
import org.joml.Vector3f;
import org.joml.Vector4f;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;
@@ -44,6 +46,11 @@ public class PersonalMotionPreviewElement extends View {
private final Paint targetPaint = new Paint();
private final Paint backgroundColor = new Paint();
private Matrix4f modelViewMatrix = new Matrix4f(); // The model 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, -1, 1); // The location of the object in 3D space.
private List<Vector2f> vectors = new ArrayList<>();
private static final String[] USER_PHRASES = {
"Veel success met de oefening!",
@@ -122,6 +129,8 @@ public class PersonalMotionPreviewElement extends View {
int progress = (int)this.motionProcessor.getError(this.paths[0], processed);
this.exerciseProgress.set(Math.min(1000, Math.max(0, progress)));
Log.i("MotionProcessor", "Processed data: " + progress + " (" + preprocessed + ")");
Vector2f parsed = projectVertex(processed, this.getWidth(), this.getHeight());
this.vectors.add(parsed);
});
saySomethingNice();
}
@@ -147,6 +156,31 @@ public class PersonalMotionPreviewElement extends View {
}
private Vector2f projectVertex(Vector3f point, int virtualWidth, int virtualHeight) {
modelViewMatrix
.identity()
.translate(-objectPosition.x, -objectPosition.y, -objectPosition.z);
// Transform the projection matrix to a perspective projection matrix
// Perspective transformation conserves the depth of the object
projectionMatrix
.identity()
.perspective((float) Math.toRadians(70), (float) virtualWidth / virtualHeight, .01f, 10000.0f);
// Convert world coordinates to screen-space using MVP matrix
Vector4f screenCoordinates = new Vector4f(point, 1.0f)
.mul(this.modelViewMatrix)
.mul(this.projectionMatrix);
// Normalize screen coordinates from (-1, 1) to (0, virtualWidth) and (0, virtualHeight)
float normalizedX = (screenCoordinates.x / screenCoordinates.w + 1.0f) * 0.5f * virtualWidth;
float normalizedY = (1.0f - screenCoordinates.y / screenCoordinates.w) * 0.5f * virtualHeight;
return new Vector2f(normalizedX, normalizedY);
}
@Override
public void onDraw(Canvas canvas) {
canvas.drawRect(0, 0, getWidth(), getHeight(), backgroundColor);
@@ -154,6 +188,11 @@ public class PersonalMotionPreviewElement extends View {
if (this.exercise == null)
return;
for ( Vector2f point : this.vectors)
{
canvas.drawRect(point.x, point.y, point.x + 5, point.y + 5, this.referencePaint);
}
/*
// Draw target circle
float targetRadius = (this.screenDimensions.x + this.screenDimensions.y) / 5.0f;
canvas.drawCircle(this.screenDimensions.x / 2, this.screenDimensions.y / 2, targetRadius, this.targetPaint);
@@ -165,7 +204,7 @@ public class PersonalMotionPreviewElement extends View {
(int)(255 * exerciseProgress.get()/1000.0f),
0
)
);
);*/
this.invalidate();

View File

@@ -108,7 +108,6 @@ public class MotionProcessor {
addMotionData(motionData);
} catch (Exception e) {
// Don't do anything ... just ignore the exception
Log.i("MotionProcessor", "Failed to parse packet data.");
}
}