Co-authored-by: Reifonas <211114984+Reifonas@users.noreply.github.com>
This commit is contained in:
gpt-engineer-app[bot]
2026-05-15 11:44:46 +00:00
parent 8540dd35ba
commit 6b0cc52c19
+39 -16
View File
@@ -86,24 +86,47 @@ export function XRHudInWorld(props: XRHudInWorldProps) {
// • If unpinned → continuously follow head with damping. // • If unpinned → continuously follow head with damping.
// • On (re)anchor request → snap target once and stop. // • On (re)anchor request → snap target once and stop.
if (panelRef.current && open) { if (panelRef.current && open) {
const fwd = new THREE.Vector3(0, -0.05, -0.7).applyQuaternion(camera.quaternion); // Drag mode → panel rigidly follows right controller using captured offset.
const wantPos = new THREE.Vector3().copy(camera.position).add(fwd); if (dragging) {
const euler = new THREE.Euler().setFromQuaternion(camera.quaternion, 'YXZ'); const ctrlObj = rightCtrl?.object;
const wantQuat = new THREE.Quaternion().setFromEuler(new THREE.Euler(0, euler.y, 0, 'YXZ')); if (ctrlObj) {
ctrlObj.updateMatrixWorld();
const cPos = new THREE.Vector3().setFromMatrixPosition(ctrlObj.matrixWorld);
const cQuat = new THREE.Quaternion().setFromRotationMatrix(ctrlObj.matrixWorld);
if (!dragInitialized.current) {
// Capture current panel pose relative to controller
const invQ = cQuat.clone().invert();
dragOffsetPos.current
.copy(panelRef.current.position).sub(cPos).applyQuaternion(invQ);
dragOffsetQuat.current.copy(invQ).multiply(panelRef.current.quaternion);
dragInitialized.current = true;
}
const newPos = dragOffsetPos.current.clone().applyQuaternion(cQuat).add(cPos);
const newQuat = cQuat.clone().multiply(dragOffsetQuat.current);
panelRef.current.position.copy(newPos);
panelRef.current.quaternion.copy(newQuat);
}
} else {
if (dragInitialized.current) dragInitialized.current = false;
const fwd = new THREE.Vector3(0, -0.05, -0.7).applyQuaternion(camera.quaternion);
const wantPos = new THREE.Vector3().copy(camera.position).add(fwd);
const euler = new THREE.Euler().setFromQuaternion(camera.quaternion, 'YXZ');
const wantQuat = new THREE.Quaternion().setFromEuler(new THREE.Euler(0, euler.y, 0, 'YXZ'));
if (reanchorRequested.current) { if (reanchorRequested.current) {
targetPos.current.copy(wantPos); targetPos.current.copy(wantPos);
targetQuat.current.copy(wantQuat); targetQuat.current.copy(wantQuat);
panelRef.current.position.copy(wantPos); panelRef.current.position.copy(wantPos);
panelRef.current.quaternion.copy(wantQuat); panelRef.current.quaternion.copy(wantQuat);
reanchorRequested.current = false; reanchorRequested.current = false;
} else if (!pinned) { } else if (!pinned) {
targetPos.current.copy(wantPos); targetPos.current.copy(wantPos);
targetQuat.current.copy(wantQuat); targetQuat.current.copy(wantQuat);
panelRef.current.position.lerp(targetPos.current, 0.12); panelRef.current.position.lerp(targetPos.current, 0.12);
panelRef.current.quaternion.slerp(targetQuat.current, 0.18); panelRef.current.quaternion.slerp(targetQuat.current, 0.18);
}
// pinned + already anchored → leave panel where it is.
} }
// pinned + already anchored → leave panel where it is.
} }
// Wrist toggle follows left controller // Wrist toggle follows left controller