Added more logging for debugging functionality

This commit is contained in:
Luca Warmenhoven
2024-05-29 15:55:37 +02:00
parent 60a45fd510
commit bd9ace61e9
2 changed files with 31 additions and 7 deletions

View File

@@ -24,6 +24,7 @@ import org.joml.Vector4f;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicReference;
@@ -48,8 +49,11 @@ public class PersonalMotionPreviewElement extends View {
private Matrix4f modelViewMatrix = new Matrix4f(); // The model view matrix for the 3D to 2D transformation. 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 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 final Vector4f objectPosition = new Vector4f(0, 0, -2, 1); // The location of the object in 3D space.
private List<Vector2f> vectors = new ArrayList<>(); private ConcurrentLinkedQueue<Vector2f> vectors = new ConcurrentLinkedQueue<>();
private Vector2f[] axisVectors;
private static final String[] USER_PHRASES = { private static final String[] USER_PHRASES = {
@@ -99,6 +103,17 @@ public class PersonalMotionPreviewElement extends View {
this.exercise = exercise; this.exercise = exercise;
this.paths = exercise.getPath(); this.paths = exercise.getPath();
this.axisVectors = new Vector2f[] {
projectVertex(new Vector3f(-1.0f, 0, 0), getWidth(), getHeight()),
projectVertex(new Vector3f(1.0f, 0, 0), getWidth(), getHeight()),
projectVertex(new Vector3f(0, -1.0f, 0), getWidth(), getHeight()),
projectVertex(new Vector3f(0, 1.0f, 0), getWidth(), getHeight()),
projectVertex(new Vector3f(0, 0, -1.0f), getWidth(), getHeight()),
projectVertex(new Vector3f(0, 0, 1.0f), getWidth(), getHeight())
};
} }
public void onDestroy() public void onDestroy()
@@ -188,6 +203,11 @@ public class PersonalMotionPreviewElement extends View {
if (this.exercise == null) if (this.exercise == null)
return; return;
for (int i = 0; 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);
}
for ( Vector2f point : this.vectors) for ( Vector2f point : this.vectors)
{ {
canvas.drawRect(point.x, point.y, point.x + 5, point.y + 5, this.referencePaint); canvas.drawRect(point.x, point.y, point.x + 5, point.y + 5, this.referencePaint);

View File

@@ -9,6 +9,8 @@ import com.google.gson.JsonObject;
import com.google.gson.JsonParser; import com.google.gson.JsonParser;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.joml.Matrix3d;
import org.joml.Vector3d;
import org.joml.Vector3f; import org.joml.Vector3f;
import java.util.ArrayList; import java.util.ArrayList;
@@ -24,7 +26,7 @@ public class MotionProcessor {
private Vector3f ZERO = new Vector3f(0, 0, 0); private Vector3f ZERO = new Vector3f(0, 0, 0);
private final float sampleRate = 10.0F; // samples/second private final float sampleRate = 1.0f / 10.0F; // samples/second
private IMotionDataConsumer motionDataConsumer = (p1, p2, p3, p4, p5) -> { }; private IMotionDataConsumer motionDataConsumer = (p1, p2, p3, p4, p5) -> { };
private WebServer server; private WebServer server;
@@ -164,12 +166,14 @@ public class MotionProcessor {
// Rotate the acceleration vector back by the rotation vector to make it // Rotate the acceleration vector back by the rotation vector to make it
// perpendicular to the gravity vector, then apply double integration to get the relative position. // perpendicular to the gravity vector, then apply double integration to get the relative position.
// s = 1/2 * a * t^2 // s = 1/2 * a * t^2
// Step 2: Create rotation matrices for each axis
// Step 4: Rotate the acceleration vector
return motionData.acceleration return motionData.acceleration
.rotateX(-motionData.rotation.x)
.rotateY(-motionData.rotation.y)
.rotateZ(-motionData.rotation.z) .rotateZ(-motionData.rotation.z)
.div(2) .rotateY(-motionData.rotation.y)
.mul(sampleRate * sampleRate); .rotateX(-motionData.rotation.x)
.mul(sampleRate * sampleRate / 2);
} }
/** /**