From 6692e739c668080d00e48efd81d2d429cd8634a5 Mon Sep 17 00:00:00 2001 From: jessikitty Date: Wed, 8 Jul 2026 20:11:11 +1000 Subject: [PATCH] Orientation fix --- public/js/exhibit.js | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/public/js/exhibit.js b/public/js/exhibit.js index a8c3db5..3372edd 100644 --- a/public/js/exhibit.js +++ b/public/js/exhibit.js @@ -69,24 +69,19 @@ function centredCorners(m, w, h) { } // Build the marker->camera matrix (POS-IT), converting js-aruco axes to three.js. -// js-aruco POS-IT gives the marker pose in a camera frame with X right, Y up, -// Z toward viewer. Three.js's camera looks down -Z with Y up, so we convert by -// premultiplying F = diag(1,-1,-1) (flip Y and Z). This is the SAME conversion -// the working ar-head.js uses, and it is correct for pitch AND roll: tilting the -// phone up moves an anchored ghost down-screen, and rolling the phone rotates the -// ghost the same way. (An earlier F*M*F "fix" inverted both — don't reintroduce it.) -const flipYZ = new THREE.Matrix4().makeScale(1, -1, -1); - -// Convert one POS-IT (R,t) solution into a three.js marker->camera matrix. +// DERIVED FROM REAL DEVICE DATA (orient-debug log): the POS-IT rotation is already +// correct as-is. The old F=diag(1,-1,-1) premultiply was rotating the whole frame +// 180 deg about X -> pitch negated + 180 deg roll ("upside down + inverted tilt"). +// The ONLY conversion needed is on the TRANSLATION: three.js's camera looks down +// -Z (and screen Y is up), so we negate translation Y and Z. Rotation stays +// untouched, which keeps pitch/roll/yaw matching the real marker exactly. function poseToMatrix(R, t) { - const M = new THREE.Matrix4().set( - R[0][0], R[0][1], R[0][2], t[0], - R[1][0], R[1][1], R[1][2], t[1], - R[2][0], R[2][1], R[2][2], t[2], + return new THREE.Matrix4().set( + R[0][0], R[0][1], R[0][2], t[0], + R[1][0], R[1][1], R[1][2], -t[1], // flip translation Y (screen up) + R[2][0], R[2][1], R[2][2], -t[2], // flip translation Z (in front of -Z cam) 0, 0, 0, 1 ); - M.premultiply(flipYZ); // F * M (flip Y & Z: POS-IT frame -> three.js frame) - return M; } // POS-IT returns TWO solutions for a planar marker (the real pose and a mirror