Android 方向传感器用于旋转 3D 立方体
我正在尝试使用 Android 手机制作 3 自由度控制器,类似于 Wiimote。使用加速度计来识别控制器的方向(使用 getOrientation() 方法进行计算)
我正在通过使用这些值来旋转 PC 中 opengl 绘制的立方体来测试方向值。问题是,它似乎不起作用。如果手机旋转超过特定的旋转,立方体就会旋转到某个奇怪的方向。
在没有计算机图形学知识的情况下,我发现参考文献说在欧拉旋转中,3D对象的最终图形取决于每个轴上的旋转顺序。和问题有关系吗??如果是这样,正确的顺序是什么?当前的顺序是“偏航->俯仰->滚动”
我不认为这是因为所谓的校准问题,因为值变化很大。
I'm trying to make 3-dof controller using Android phone, similar to Wiimote. Uses Accelerometer for recognizing the controller's orientation (used getOrientation() method for calculation)
I'm testing the orientation values by using those values to rotate the cube drawn by opengl in PC. The problem is, it doesn't seem working. If the phone is rotated over the specific rotation, the cube is rotated to some weird direction.
Without knowledge of computer graphics, I found the reference saying that in Euler rotation, the final figure of 3D object depends on the order of rotation on each axes. Is it related to the problem?? If so, what is the correct order? Current order is "yaw->pitch->roll"
I don't think it's because of the so-called calibration issue, as the value changes are significant.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
方向传感器已弃用。获取可靠传感器值的最佳方法是使用旋转矢量传感器。它是一种基于软件的传感器,从基于加速度计和磁力计硬件的传感器中获取数据。
旋转矢量将设备的方向表示为角度和轴的组合,其中设备绕轴(x、y 或 z)旋转了角度 θ。以下代码向您展示如何获取默认旋转矢量传感器的实例。请参阅 Android 开发网站中的有关此传感器的信息。
这是如何使用旋转向量获取可靠值的示例:
The Orientation sensor is deprecated. The best way to acquire reliable sensor values is using the rotation vector sensor. It is a software-based sensor that derives the data from the accelerometer and magnetometer hardware-based sensors.
The rotation vector represents the orientation of the device as a combination of an angle and an axis, in which the device has rotated through an angle θ around an axis (x, y, or z). The following code shows you how to get an instance of the default rotation vector sensor. See the info about this sensor in the Android Dev Site.
This is an example of how to use the rotation vector to get reliable values:
当手机接近垂直位置并且没有校准帮助时,我遇到了类似的问题
getOrientation()
返回奇怪的结果。简单的解决方案是使用这个传感器:
显然这个传感器在较新的平台中已被弃用,但无论如何它都可以正常工作。
I had similar problem with
getOrientation()
returning weird results when phone approaches vertical position and no calibration helps.The easy solution is to use this sensor:
Apparently this sensor is deprecated in newer platforms but it works just fine anyway.