问题
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!
回答1:
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.
回答2:
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);
来源:https://stackoverflow.com/questions/32982459/mapping-outside-quaternions-to-unity