在three.js中向DeviceOrientationControls添加偏移量 [英] Add offset to DeviceOrientationControls in three.js

查看:1271
本文介绍了在three.js中向DeviceOrientationControls添加偏移量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 deviceControls.update(); 命令后向相机添加偏移量。我使用了 DeviceOrientationControls ,如第一个例子所示。

I'm trying to add an offset to the camera after deviceControls.update(); command. I used DeviceOrientationControls as shown in this first example.

偏移量将是拖动手势的结果,如这个例子。

The offset will be the result of a drag gesture, as presents in this example.

当我乘以2个四元数(我尝试过axb和bxa)时,最终结果不正确。

When I multiply the 2 quaternions (I have tried a x b and b x a), the final result is not correct.

这是我的操作:

const m1 = new THREE.Matrix4();
m1.lookAt(new THREE.Vector3(), camera.target, THREE.Object3D.DefaultUp.clone());

const quater = new THREE.Quaternion();
quater.setFromRotationMatrix(m1);

const finalQuater = new THREE.Quaternion();
finalQuater.multiplyQuaternions(quater, camera.quaternion);

camera.quaternion.copy(finalQuater);

camera.target 是我的最终拖动目标(Vector3)和 camera.quaternion 已由 deviceControls.update()设置,并且等于相机方向,根据设备陀螺仪。

camera.target is my final drag target (Vector3), and camera.quaternion has been set by deviceControls.update() and is equals to the camera orientation, according to the device gyroscope.

感谢您的帮助

更新:我试图改变旋转顺序, 同样的问题。我认为这是由于设备方向更新后的原点更改,但找不到如何解决。

Update : I have tried to changer rotate order, same problem. I think it is due to the origin change after the device orientation update, but can't find how to solve.

推荐答案

DeviceOrientationControls 现在有一个属性 alphaOffsetAngle ,还有一个方法

DeviceOrientationControls now has a property alphaOffsetAngle, and a method

controls.updateAlphaOffsetAngle( angle ); // angle is in radians

将围绕three.js'Y'轴旋转场景。

that will rotate the scene around the three.js 'Y' axis.

three.js r.77

three.js r.77

这篇关于在three.js中向DeviceOrientationControls添加偏移量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆