2024-05-29 15:56:50 +02:00
2 changed files with 30 additions and 6 deletions

View File

@@ -25,6 +25,7 @@ import org.joml.Vector4f;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;
@@ -49,9 +50,12 @@ public class PersonalMotionPreviewElement extends View {
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 final Vector4f objectPosition = new Vector4f(0, 0, -2, 1); // The location of the object in 3D space.
private ConcurrentLinkedQueue<Vector2f> vectors = new ConcurrentLinkedQueue<>();
private Vector2f[] axisVectors;
private static final String[] USER_PHRASES = {
"Veel success met de oefening!",
@@ -100,6 +104,17 @@ public class PersonalMotionPreviewElement extends View {
this.exercise = exercise;
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()
@@ -189,6 +204,11 @@ public class PersonalMotionPreviewElement extends View {
if (this.exercise == null)
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)
{
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 org.jetbrains.annotations.NotNull;
import org.joml.Matrix3d;
import org.joml.Vector3d;
import org.joml.Vector3f;
import java.util.ArrayList;
@@ -24,7 +26,7 @@ public class MotionProcessor {
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 WebServer server;
@@ -164,12 +166,14 @@ public class MotionProcessor {
// 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.
// s = 1/2 * a * t^2
// Step 2: Create rotation matrices for each axis
// Step 4: Rotate the acceleration vector
return motionData.acceleration
.rotateX(-motionData.rotation.x)
.rotateY(-motionData.rotation.y)
.rotateZ(-motionData.rotation.z)
.div(2)
.mul(sampleRate * sampleRate);
.rotateY(-motionData.rotation.y)
.rotateX(-motionData.rotation.x)
.mul(sampleRate * sampleRate / 2);
}
/**