我在一个AR空间中使用HammerJS移动一个Object 3D。
只要我不移动手机(相机),它就能正常工作......
const newTranslation = new THREE.Vector3(this._initTranslation.x + e.deltaX, this._initTranslation.y, this._initTranslation.z + e.deltaY);
init ...是Object3D的原始版本
当我四处移动时,我仍然在x z轴上开始。 (我在手机上向上移动手指(向后移动物体(在z轴上))而不是从左向右移动
我知道我必须将相机旋转到计数中,从相机转换到世界但不知道如何做到这一点。
在此先感谢您的帮助。
我把它修好了。这是我的解决方案,以防有人需要它:
我现在用我的相机旋转角度旋转点:
const movePoint = new THREE.Vector2(e.deltaX, e.deltaY);
movePoint.rotateAround(new THREE.Vector2(0, 0), this.getCameraAngle());
const newTranslation = new THREE.Vector3(this._initTranslation.x + movePoint.x,
this._initTranslation.y, this._initTranslation.z + movePoint.y);
对于摄像机角度:
public getCameraAngle (): number {
const cameraDir = new THREE.Vector3();
this._arCamera.getWorldDirection(cameraDir);
cameraDir.setY(0);
cameraDir.normalize();
return Math.atan2(cameraDir.z, cameraDir.x) - Math.atan2(-1, 0);
}