Updated PersonalMotionPreviewElement

This commit is contained in:
Luca Warmenhoven
2024-05-29 16:18:48 +02:00
parent 2426e7b2e2
commit 2e8feb686b

View File

@@ -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<Vector2f> 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)