From 76ac3fcf55b5896a4b3a12df009909757251f202 Mon Sep 17 00:00:00 2001 From: ButterscotchVanilla Date: Wed, 1 Dec 2021 23:50:47 -0500 Subject: [PATCH] Fix angle calculations --- .../java/dev/slimevr/posestreamer/BVHFileStream.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/java/dev/slimevr/posestreamer/BVHFileStream.java b/src/main/java/dev/slimevr/posestreamer/BVHFileStream.java index 930614f03..50a3b7481 100644 --- a/src/main/java/dev/slimevr/posestreamer/BVHFileStream.java +++ b/src/main/java/dev/slimevr/posestreamer/BVHFileStream.java @@ -169,19 +169,19 @@ public class BVHFileStream extends PoseDataStream { float w = q.getW(); // Roll (X) - float sinrCosp = 2f * (w * x + y * z); - float cosrCosp = 1f - 2f * (x * x + y * y); + float sinrCosp = -2f * (x * y - w * z); + float cosrCosp = w * w - x * x + y * y - z * z; angles[0] = FastMath.atan2(sinrCosp, cosrCosp); // Pitch (Y) - float sinp = 2f * (w * y - z * x); + float sinp = 2f * (y * z + w * x); // Use 90 degrees if out of range angles[1] = FastMath.abs(sinp) >= 1f ? FastMath.copysign(FastMath.PI / 2f, sinp) : FastMath.asin(sinp); // Yaw (Z) - float sinyCosp = 2f * (w * z + x * y); - float cosyCosp = 1f - 2f * (y * y + z * z); - angles[2] = -FastMath.atan2(sinyCosp, cosyCosp); + float sinyCosp = -2f * (x * z - w * y); + float cosyCosp = w * w - x * x - y * y + z * z; + angles[2] = FastMath.atan2(sinyCosp, cosyCosp); return angles; }