使用相机旋转计算平面上的 x z 运动
Calculate x z movement on plane with camera rotation
我在 AR space 中使用 HammerJS 移动 3D 对象。
只要我不移动我的 phone(即相机)就可以正常工作...
const newTranslation = new THREE.Vector3(this._initTranslation.x + e.deltaX, this._initTranslation.y, this._initTranslation.z + e.deltaY);
init... 是 Object3D 的原始部分
当我四处移动时,运动仍然在我开始的 x z 轴上。 (我在 phone 上向上移动手指(向后移动对象(在 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);
}
我在 AR space 中使用 HammerJS 移动 3D 对象。
只要我不移动我的 phone(即相机)就可以正常工作...
const newTranslation = new THREE.Vector3(this._initTranslation.x + e.deltaX, this._initTranslation.y, this._initTranslation.z + e.deltaY);
init... 是 Object3D 的原始部分
当我四处移动时,运动仍然在我开始的 x z 轴上。 (我在 phone 上向上移动手指(向后移动对象(在 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);
}