简体   繁体   English

如何在传感器四元数和3d相机四元数之间进行转换?

[英]How to convert between sensor quaternion and 3d camera quaternion?

I get a quaternion from Android's Sensor.TYPE_ROTATION_VECTOR fused sensor using getQuaternionFromVector() . 我使用getQuaternionFromVector()从Android的Sensor.TYPE_ROTATION_VECTOR融合传感器获得四元数。 I want to use that quaternion to control the camera of my Rajawali app. 我想用那个四元数控制我的Rajawali应用程序的相机。

The values (w, x, y, z) I get from the sensor are (phone in landscape, looking straight ahead): 我从传感器获得的值(w,x,y,z)是(手机在横向,直视前方):

  • North: (0.5, 0.5, -0.5, 0.5) 北:(0.5,0.5,-0.5,0.5)
  • East: (0.71, 0, -0.71, 0) 东:(0.71,0,-0.71,0)
  • South: (0.5, -0.5, -0.5, -0.5) 南:(0.5,-0.5,-0.5,-0.5)
  • West: (0, 0.71, 0, 0.71) 西:(0,0.71,0,0.71)

I need to transform this values to these correct values: 我需要将这些值转换为这些正确的值:

  • North: (1.0, 0, 0, 0) 北:(1.0,0,0,0)
  • East: (0.71, 0, 0.71, 0) 东:(0.71,0,0.71,0)
  • South: (0, 0, 1, 0) 南:(0,0,1,0)
  • West: (-0.71, 0, 0.71, 0) 西:( - 0.71,0,0.71,0)

Through some trial and error I've approached a solution, but I'm still some ways off. 通过一些试验和错误,我已经找到了解决方案,但我还有一些方法。 If I first rotate 90 deg against Y axis, and -90 deg against the X axis: 如果我首先相对于Y轴旋转90度,并且相对于X轴旋转-90度:

Quaternion a = new Quaternion(Vector3.Y, 90);
a.multiply(q);
Quaternion b = new Quaternion(Vector3.X, -90);
b.multiply(a);

The values I get are: 我得到的价值是:

  • North: (1, 0, 0, 0) 北:(1,0,0,0)
  • East: (0.71, -0.71, 0, 0) 东:(0.71,-0.71,0,0)
  • South: (0, -1, 0, 0) 南:(0,-1,0,0)
  • West: (0.71, 0.71, 0, 0) 西:(0.71,0.71,0,0)

The result is that north is correct, east is up, west is down and south is upside down. 结果是北方是正确的,向东是向上的,向西是向下的,向南是向上的。 I notice that the bearing is mixed up with pitch (I change the pitch of the device and the bearing of the camera changes, and the resevers). 我注意到轴承与螺距混合(我改变了设备的间距,相机的轴承也发生了变化,并且切换器)。

Any suggestions for how to modify the sensor quaternion to match the expected quaternion value? 有关如何修改传感器四元数以匹配预期的四元数值的任何建议? How can I change it so that sensor bearing changes the camera bearing and not the pitch? 如何更改它以使传感器轴承改变摄像机轴承而不改变俯仰?

Thanks in advance! 提前致谢!

Managed to sort it out. 管理以解决它。

public static Quaternion transform(Quaternion q) {
    Quaternion a = new Quaternion(Vector3.Y, 90).multiply(q);
    Quaternion b = new Quaternion(a.w, a.y, -a.x, -a.z);
    return b.multiply(new Quaternion(Vector3.Y, 90));
}

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

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