需要计算从Sensor.TYPE_ORIENTATION数据旋转矢量 [英] Need to calculate rotation-vector from Sensor.TYPE_ORIENTATION data

查看:470
本文介绍了需要计算从Sensor.TYPE_ORIENTATION数据旋转矢量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要计算一个旋转矢量出来,我从Sensor.TYPE_ORIENTATION获取数据的。

I need to calculate a rotation vector out of the data i get from Sensor.TYPE_ORIENTATION.

传感器数据的定义是这样的:

The sensor data is defined like this:

  • 的值必须被重新计算,成为正确的3D位置:值[0]:方位角,磁北方向和Y轴,围绕Z轴(0到359)之间的角度。 0 =北,90 =东,180 =南,270 =西
  • 在值 1 :在球场上,绕X轴(-180〜180)旋转,与正值当z轴移向Y轴。
  • 值[2]:辊,绕Y轴(-90〜90)旋转,以正值时x轴移动远离z轴
  • the values have to be recalculated to become a correct 3d position: values[0]: Azimuth, angle between the magnetic north direction and the Y axis, around the Z axis (0 to 359). 0=North, 90=East, 180=South, 270=West
  • values1: Pitch, rotation around X axis (-180 to 180), with positive values when the z-axis moves toward the y-axis.
  • values[2]: Roll, rotation around Y axis (-90 to 90), with positive values when the x-axis moves away from the z-axis

我需要像Z轴值的所有三个值(从0到360度)。我尝试了很多,但无法弄清楚如何做到这一点:/

I need all three values like the Z axis value (from 0 to 360 degree). I tried a lot but cant figure out how to do this :/

(编辑:要看到背后的思想工作中的code看一看在的 DroidAR框架那里你可以看到不同的事件类型如何处理。)

( edit: To see the idea behind in working code take a look at the class ActionWithSensorProcessing of the DroidAR framework there you can see how the different event types can be processed.)

我还试图用Sensor.TYPE_ACCELEROMETER和Sensor.TYPE_MAGNETIC_FIELD来计算自己的这个三维矢量。这里是code:

i also tried to use Sensor.TYPE_ACCELEROMETER and Sensor.TYPE_MAGNETIC_FIELD to calculate this 3d vector on my own. here is the code:

final float[] inR = new float[16];
// load inR matrix from current sensor data:
SensorManager.getRotationMatrix(inR, null, gravityValues, geomagneticValues);
float[] orientation = new float[3];
SensorManager.getOrientation(inR, orientation);
mapMagAndAcclDataToVector(orientation); //here i do some *360 stuff
orientetionChanged(orientation); //then the correct values are passed (in theorie)

但这并没有工作,我认为这是很大的复杂。 所以,我敢打赌,有一个简单的解决方案如何重计算ensor.TYPE_ORIENTATION的价值观,使他们一个三维旋转向量,但我只是不知道如何做到这一点。如果您知道答案请告诉我。

But this didn't work and i think it is much to complicated. So i bet there is a simple solution how to recalc the values of ensor.TYPE_ORIENTATION to make them a 3d rotation vector, but i just dont know how to do it. If you know the answer please tell me.

编辑: 我要补充一点,我想有值传递给OpenGL的,将其调整到轴这样的:

i should add that i want to pass there values to OpenGL to align it to the axis like this:

gl.glRotatef(values[1], 1, 0, 0);
gl.glRotatef(values[2], 0, 1, 0);
gl.glRotatef(values[0], 0, 0, 1);

但奇怪的值范围,因为我显然不能做这个。同样的问题与 从SensorManager.getOrientation的值,因为它们太翻转当你通过天际线。

but because of the strange value ranges i obviously cant do this. the same problem with the values from SensorManager.getOrientation because they flip too when you pass the horizon line..

另一种解决方案是使用INR矩阵计算的角度,但我认为必须有一个简单的解决方案(?)

another solution would be to calculate the angles using the inR matrix but i think there must be an easier solution (?)

推荐答案

确定现在我有一个解决方案,你需要做的OpenGL的轮换顺序如下:

ok now i got a solution, you have to do the openGl rotation in this order:

gl.glRotatef(values[2], 0, 1, 0);
gl.glRotatef(values[1], 1, 0, 0);
gl.glRotatef(values[0], 0, 0, 1);

使用这种结合SensorManager.getOrientation,它会工作。如果有人知道如何与Sensor.TYPE_ORIENTATION数据做到这一点,请让我知道。

use this in combination with SensorManager.getOrientation and it will work. if someone knows how to do this with the Sensor.TYPE_ORIENTATION data, please let me know.

这篇关于需要计算从Sensor.TYPE_ORIENTATION数据旋转矢量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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