Skip to content

Commit 3429eb3

Browse files
kalwaltclaude
andcommitted
Fix CV->GL pose conversion in updateTrackable()
Stop negating rotation columns 1 and 2 in updateTrackable(). The previous behavior applied a partial CV->GL conversion (rotation columns flipped, translation untouched), which left consumers with an inconsistent pose: the rotation was neither raw OpenCV nor a clean GL right-handed modelview, and the translation Z stayed positive — causing tracked objects to render behind the camera in OpenGL/three.js scenes (clip.w < 0, ndc.z > 1). After this change, getPoseMatrix2() / trans returns the raw OpenCV pose (rotation unmodified, translation kept at the existing 0.001 * 1.64 scale). The CV->GL handedness flip (negate Y and Z rows including translation) is applied downstream by arglCameraViewRHf when building the GL right-handed modelview (matrixGL_RH on the JS side, getGLViewMatrix() in WebARKitManager on the C++ side). Both downstream paths are now mathematically clean diag(1, -1, -1, 1) * pose conversions and produce a correct modelview that places the tracked object in front of the GL camera. Note: this is a semantic change to `pose` / `trans` for any consumer that relied on the previous partially-converted shape. Downstream consumers should use matrixGL_RH (or getGLViewMatrix) for OpenGL rendering and treat `pose` as the raw OpenCV camera pose. Refs: #34, webarkit/webarkit-testing#31 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent 891f50f commit 3429eb3

1 file changed

Lines changed: 11 additions & 5 deletions

File tree

WebARKit/WebARKitPattern.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,18 @@ void WebARKitPatternTrackingInfo::getTrackablePose(cv::Mat& pose) {
5555

5656
void WebARKitPatternTrackingInfo::updateTrackable() {
5757
if (transMat) {
58-
//visible = true;
58+
// Keep `trans` as the raw OpenCV pose (rotation unmodified, translation
59+
// scaled). The CV->GL handedness conversion (negate Y and Z rows incl.
60+
// translation) is applied downstream by arglCameraViewRHf when building
61+
// the GL right-handed modelview (matrixGL_RH / getGLViewMatrix).
62+
// Previously, rotation columns 1 and 2 were negated here but the
63+
// translation was not, producing an inconsistent partial conversion
64+
// that left tracked objects behind the camera in OpenGL renderers.
5965
for (int j = 0; j < 3; j++) {
60-
trans[j][0] = transMat[j][0];
61-
trans[j][1] = -transMat[j][1];
62-
trans[j][2] = -transMat[j][2];
63-
trans[j][3] = (transMat[j][3] * m_scale * 0.001f * 1.64f );
66+
trans[j][0] = transMat[j][0];
67+
trans[j][1] = transMat[j][1];
68+
trans[j][2] = transMat[j][2];
69+
trans[j][3] = (transMat[j][3] * m_scale * 0.001f * 1.64f);
6470
}
6571
}
6672
}

0 commit comments

Comments
 (0)