用于旋转 3D 立方体的 Android 方向传感器 [英] Android Orientation sensor for rotation the 3D cube

查看:45
本文介绍了用于旋转 3D 立方体的 Android 方向传感器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 Android 手机制作 3 自由度控制器,类似于 Wiimote.使用加速度计识别控制器的方向(使用 getOrientation() 方法进行计算)

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)

我正在通过使用这些值来旋转 PC 中由 opengl 绘制的立方体来测试方向值.问题是,它似乎不起作用.如果手机旋转超过特定旋转,则立方体会旋转到某个奇怪的方向.

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.

在没有计算机图形学知识的情况下,我发现参考文献说在欧拉旋转中,3D 对象的最终图形取决于每个轴上的旋转顺序.和问题有关系吗??如果是这样,正确的顺序是什么?当前顺序是yaw->pitch->roll"

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.

推荐答案

不推荐使用方向传感器.获取可靠传感器值的最佳方法是使用旋转矢量传感器.它是一种基于软件的传感器,可从基于加速度计和磁力计硬件的传感器中获取数据.

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.

旋转向量将设备的方向表示为角度和轴的组合,其中设备围绕轴(x、y 或 z)旋转了角度 θ.以下代码向您展示了如何获取默认旋转矢量传感器的实例.请参阅 Android 开发者站点中的有关此传感器的信息.

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:

public void onSensorChanged(SensorEvent event) {
       if(sensor.getType()==Sensor.TYPE_ROTATION_VECTOR){
           float[] rotationMatrix = new float[16];
           SensorManager.getRotationMatrixFromVector(rotationMatrix, event.values);
           SensorManager.getOrientation(rotationMatrix, mOrientValues);
           for(int i=0; i<3; i++)
              mOrientValues[i]=(float)
                  Math.toDegrees(mOrientValues[i])+180.0f;//orientation in degrees
}

这篇关于用于旋转 3D 立方体的 Android 方向传感器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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