Changes
Co-authored-by: Reifonas <211114984+Reifonas@users.noreply.github.com>
This commit is contained in:
@@ -86,6 +86,28 @@ 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) {
|
||||||
|
// Drag mode → panel rigidly follows right controller using captured offset.
|
||||||
|
if (dragging) {
|
||||||
|
const ctrlObj = rightCtrl?.object;
|
||||||
|
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 fwd = new THREE.Vector3(0, -0.05, -0.7).applyQuaternion(camera.quaternion);
|
||||||
const wantPos = new THREE.Vector3().copy(camera.position).add(fwd);
|
const wantPos = new THREE.Vector3().copy(camera.position).add(fwd);
|
||||||
const euler = new THREE.Euler().setFromQuaternion(camera.quaternion, 'YXZ');
|
const euler = new THREE.Euler().setFromQuaternion(camera.quaternion, 'YXZ');
|
||||||
@@ -105,6 +127,7 @@ export function XRHudInWorld(props: XRHudInWorldProps) {
|
|||||||
}
|
}
|
||||||
// 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
|
||||||
if (wristRef.current) {
|
if (wristRef.current) {
|
||||||
|
|||||||
Reference in New Issue
Block a user