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

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

问题描述

我正在尝试使用类似于Wiimote的Android手机制作3-dof控制器.使用加速度计识别控制器的方向(使用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.

在没有计算机图形知识的情况下,我发现参考文献说,在Euler旋转中,3D对象的最终图形取决于每个轴上的旋转顺序.与问题有关吗?如果是这样,正确的顺序是什么?当前顺序为偏航->俯仰->侧倾"

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
}

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

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