From fafa579eb29cd1cca4c63e689916cf903a4e886f Mon Sep 17 00:00:00 2001 From: wheaney <42350981+wheaney@users.noreply.github.com> Date: Tue, 22 Jul 2025 22:43:14 -0700 Subject: [PATCH] Fix look-ahead and euler angle ordering issues --- kwin/src/breezydesktopeffect.cpp | 5 +++-- kwin/src/qml/CameraController.qml | 20 +++++++------------- 2 files changed, 10 insertions(+), 15 deletions(-) diff --git a/kwin/src/breezydesktopeffect.cpp b/kwin/src/breezydesktopeffect.cpp index d298cf9..a9a5f30 100644 --- a/kwin/src/breezydesktopeffect.cpp +++ b/kwin/src/breezydesktopeffect.cpp @@ -245,10 +245,11 @@ void BreezyDesktopEffect::updateImuRotation() { return; } - QQuaternion quatT0(imuData[3], imuData[0], imuData[1], imuData[2]); + // convert NWU to EUS by passing root.rotation values: -y, z, -x + QQuaternion quatT0(imuData[3], -imuData[1], imuData[2], -imuData[0]); memcpy(imuData, data + 109 + sizeof(imuData), sizeof(imuData)); - QQuaternion quatT1(imuData[3], imuData[0], imuData[1], imuData[2]); + QQuaternion quatT1(imuData[3], -imuData[1], imuData[2], -imuData[0]); // set imuRotations to the last two rotations, leave out the elapsed time m_imuRotations.clear(); diff --git a/kwin/src/qml/CameraController.qml b/kwin/src/qml/CameraController.qml index 9eea8c4..033f56e 100644 --- a/kwin/src/qml/CameraController.qml +++ b/kwin/src/qml/CameraController.qml @@ -6,7 +6,6 @@ Item { required property Camera camera - property vector3d rotation: Qt.vector3d(0, 0, 0) property real radius: 2000 property real speed: 1 @@ -16,17 +15,16 @@ Item { implicitWidth: parent.width implicitHeight: parent.height - onRotationChanged: root.updateCamera(); - onRadiusChanged: root.updateCamera(); + // onRadiusChanged: root.updateCamera(); - function updateCamera() { + function updateCamera(rotation) { const theta = 90 * Math.PI / 180; const phi = 0.0; camera.position = Qt.vector3d(radius * Math.sin(phi) * Math.sin(theta), radius * Math.cos(theta), radius * Math.cos(phi) * Math.sin(theta)); - camera.eulerRotation = root.rotation; + camera.eulerRotation = rotation; } // how far to look ahead is how old the IMU data is plus a constant that is either the default for this device or an override @@ -38,7 +36,6 @@ Item { } function applyLookAhead(quatT0, quatT1, elapsedTimeMs, lookAheadMs) { - console.log(`Applying look-ahead with ${elapsedTimeMs} and ${lookAheadMs}`); // convert both quats to euler angles const eulerT0 = quatT0.toEulerAngles(); const eulerT1 = quatT1.toEulerAngles(); @@ -51,11 +48,10 @@ Item { // how much of the delta to apply based on the look-ahead time const timeConstant = lookAheadMs / elapsedTimeMs; - // compute the look-ahead angles and convert NWU to EUS by passing root.rotation values: -y, z, -x return Qt.vector3d( - -eulerT0.y + deltaY * timeConstant, + eulerT0.x + deltaX * timeConstant, + eulerT0.y + deltaY * timeConstant, eulerT0.z + deltaZ * timeConstant, - -eulerT0.x + deltaX * timeConstant ); } @@ -69,15 +65,13 @@ Item { FrameAnimation { running: true onTriggered: { - console.log("FrameAnimation triggered, updating camera rotation"); if (root.useImuRotation && root.imuRotations && root.imuRotations.length > 0) { - console.log("Using IMU rotation for camera control"); - root.rotation = applyLookAhead( + updateCamera(applyLookAhead( root.imuRotations[0], root.imuRotations[1], root.imuTimeElapsedMs, lookAheadMS(root.imuTimestamp, root.lookAheadConstant, -1) - ); + )); } } }