I have a sensor. This sensor return quaternion of current orientation. I’ve added reset orientation code, and it’s work perfect:
void KeyPressedHandler()
{
Quaternion CurrentQuat;
var state = this.adapter.GetState();
CurrentQuat = state.Value;
if (Input.GetKeyDown(KeyCode.R))
{
Quaternion StartPosition;
StartPosition.x = 0;
StartPosition.y = 0;
StartPosition.z = 0;
StartPosition.w = 1;
Offset = Quaternion.Inverse(CurrentQuat) * StartPosition;
}
}
void Update()
{
Quaternion CurrentQuat;
var state = this.adapter.GetState();
CurrentQuat = state.Value* Offset;
transform.Rotation = CurrentQuat;
}
But I found follow problem. If I put sensor on horizontal table, and rotate it around vertical OZ axis, model (in Unity) will rotate also around OZ axis. Then I put sensor on side edge. And if rotate around OZ axis (OZ now in horizontal plane), model will rotate in different axis, not OZ of model… why? How to save match of axises sensor and model? Regards.