Mapping outside quaternions to Unity

2019-05-31 13:56发布

I'm trying to map rotations from a sensor into Unity using Quaternions, and I cannot seem to figure out why rotations do not map correctly.

I'm using the Adafruit BNO055 to pull absolute orientation in the form of Quaternions. The source for their Quaternion implementation can be found here. From what I understand about Quaternions, which is almost nothing, I should be able to pull a Quaternion out of the sensor and pump it into any GameObject inside Unity so that they share the same orientation. If I had a loop set up that read the Quaternion data from the sensor and pumped it into Unity, the GameObject should rotate exactly like the sensor in the physical world. Unfortunately, this is not happening.

An example of the data sent from the sensor to Unity

w: 0.903564
x: 0.012207
y: 0.009094
z: -0.428223

Is the Quaternion sent from the sensor not equal to the Quaternions used in Unity? If not, how would I go about getting these mapped correctly?

Thanks in advance for any help!

2条回答
再贱就再见
2楼-- · 2019-05-31 14:22

When I have created a Quaternion from an external sensor in a comma separated list, this works for me:

parts = SensorReceivedText.Split(',');
float x = Convert.ToSingle(parts[0]);
float y = Convert.ToSingle(parts[1]);
float z = Convert.ToSingle(parts[2]);
float w = Convert.ToSingle(parts[3]);
Quaternion rotation = new Quaternion(x, y, z, w);
查看更多
爷、活的狠高调
3楼-- · 2019-05-31 14:27

Just for example of diffrent conversions (including Unity and OpenGL) https://developers.google.com/project-tango/overview/coordinate-systems

I don't know your device and coordinates notation, but you can recover it making some experiments with orientation.

The main problem of conversion, that conversion matrix may contain MIRRORING (-1 matrix component). And can't be solved just rearanging rotation axes.

查看更多
登录 后发表回答