Fix look-ahead and euler angle ordering issues

This commit is contained in:
wheaney 2025-07-22 22:43:14 -07:00
parent f1e9bdccb7
commit fafa579eb2
2 changed files with 10 additions and 15 deletions

View File

@ -245,10 +245,11 @@ void BreezyDesktopEffect::updateImuRotation() {
return; 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)); 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 // set imuRotations to the last two rotations, leave out the elapsed time
m_imuRotations.clear(); m_imuRotations.clear();

View File

@ -6,7 +6,6 @@ Item {
required property Camera camera required property Camera camera
property vector3d rotation: Qt.vector3d(0, 0, 0)
property real radius: 2000 property real radius: 2000
property real speed: 1 property real speed: 1
@ -16,17 +15,16 @@ Item {
implicitWidth: parent.width implicitWidth: parent.width
implicitHeight: parent.height implicitHeight: parent.height
onRotationChanged: root.updateCamera(); // onRadiusChanged: root.updateCamera();
onRadiusChanged: root.updateCamera();
function updateCamera() { function updateCamera(rotation) {
const theta = 90 * Math.PI / 180; const theta = 90 * Math.PI / 180;
const phi = 0.0; const phi = 0.0;
camera.position = Qt.vector3d(radius * Math.sin(phi) * Math.sin(theta), camera.position = Qt.vector3d(radius * Math.sin(phi) * Math.sin(theta),
radius * Math.cos(theta), radius * Math.cos(theta),
radius * Math.cos(phi) * Math.sin(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 // 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) { function applyLookAhead(quatT0, quatT1, elapsedTimeMs, lookAheadMs) {
console.log(`Applying look-ahead with ${elapsedTimeMs} and ${lookAheadMs}`);
// convert both quats to euler angles // convert both quats to euler angles
const eulerT0 = quatT0.toEulerAngles(); const eulerT0 = quatT0.toEulerAngles();
const eulerT1 = quatT1.toEulerAngles(); const eulerT1 = quatT1.toEulerAngles();
@ -51,11 +48,10 @@ Item {
// how much of the delta to apply based on the look-ahead time // how much of the delta to apply based on the look-ahead time
const timeConstant = lookAheadMs / elapsedTimeMs; 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( return Qt.vector3d(
-eulerT0.y + deltaY * timeConstant, eulerT0.x + deltaX * timeConstant,
eulerT0.y + deltaY * timeConstant,
eulerT0.z + deltaZ * timeConstant, eulerT0.z + deltaZ * timeConstant,
-eulerT0.x + deltaX * timeConstant
); );
} }
@ -69,15 +65,13 @@ Item {
FrameAnimation { FrameAnimation {
running: true running: true
onTriggered: { onTriggered: {
console.log("FrameAnimation triggered, updating camera rotation");
if (root.useImuRotation && root.imuRotations && root.imuRotations.length > 0) { if (root.useImuRotation && root.imuRotations && root.imuRotations.length > 0) {
console.log("Using IMU rotation for camera control"); updateCamera(applyLookAhead(
root.rotation = applyLookAhead(
root.imuRotations[0], root.imuRotations[0],
root.imuRotations[1], root.imuRotations[1],
root.imuTimeElapsedMs, root.imuTimeElapsedMs,
lookAheadMS(root.imuTimestamp, root.lookAheadConstant, -1) lookAheadMS(root.imuTimestamp, root.lookAheadConstant, -1)
); ));
} }
} }
} }