简体   繁体   English

Three.js设备方向控件:限制或禁用XY旋转

[英]Three.js Device Orientation Controls: Limit or disable XY rotations

I'm using DeviceOrientationControls to attach to and rotate an Object in Three.js 我正在使用DeviceOrientationControls附加并旋转Three.js中的对象

By default, these controls will rotate the object on all three of the XYZ axes. 默认情况下,这些控件将在所有三个XYZ轴上旋转对象。

Is there any way to disable rotation on the X and Y axes, so that the object only responds to rotation on the Z axis? 有什么方法可以禁用X和Y轴上的旋转,从而使对象仅响应Z轴上的旋转吗?

Hope that's clear enough, let me know if you need an example. 希望这很清楚,如果您需要一个例子,请告诉我。 Thanks. 谢谢。

For anyone interested, I was able to achieve this without using the Three DeviceOrientationControls library. 对于任何有兴趣的人,我无需使用Three DeviceOrientationControls库就可以实现此目的。

You can just add an event listener for 'deviceorientation' and feed the gamma rotation into the object rotation, like this: 您可以只为'deviceorientation'添加一个事件监听器,并将gamma旋转输入到对象旋转中,如下所示:

window.addEventListener('deviceorientation', function(e) {
  var gammaRotation = e.gamma ? e.gamma * (Math.PI / 180) : 0;
  bottleGroup.rotation.y = gammaRotation;
});

You can alternate DeviceOrientationControls js by adding the below line behind setObjectQuaternion( scope.object.quaternion, alpha, beta, gamma, orient ); 您可以通过在setObjectQuaternion(scope.object.quaternion,alpha,beta,gamma,orient);之后添加以下行来替换DeviceOrientationControls js; in this.update function: 在this.update函数中:

this.object.rotation.x = 0;
this.object.rotation.z = 0;

Then you got camera motion only in y direction. 然后,您只能使相机在y方向上运动。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM