I created two objects in Unity3D, representing an upperarm (parent) and a lowerarm (child), joined with a character joint. The rotation of these objects is driven by 2 quaternions which i gather from an IMU located on the upperarm and lowerarm. I calibrate both quaternions. My objective is to visualize an elbow flexion/extension.
Q in the name indicates it is a Quaternion. QImu indicates it is the Quaternion from the IMU. Qstart indicates it is the initial starting orientation of the IMU.
// upperarm script attached to upperarm object
if (Input.GetKeyDown(KeyCode.Space))
{
QstartUpperArm = QimuUpperArm;
}
transform.localRotation = QstartUpperArm * Quaternion.Inverse(QimuUpperArm);
// lowerarm script attached to lowerarm object
if (Input.GetKeyDown(KeyCode.Space))
{
QstartLowerArm = QimuLowerArm;
}
QimuLowerArm = QstartLowerArm * Quaternion.Inverse(QimuLowerArm);
transform.localrotation = Quaternion.Inverse(Qstart2 * Quaternion.Inverse(Qimu2)) * Qimu1new;
The Upperarm object is rotating exactly as expected. The lowerarm object however has one the y-axis reversed. All other axis are fine. How can i change the sign of this one axis using the Quaternion?
Quaternion reversedY = Quaternion.Inverse(Qstart2 * Quaternion.Inverse(Qimu2)) * Qimu1new;transform.localrotation = Quaternion.Euler(Vector3.Scale(reversedY, new Vector3(1f, -1f, 1f) ) );Vector3 myEulerAngles = QimuLowerArm.eulerAngles; Quaternion invertedRotation = Quaternion.Euler(myEulerAngles.x, -myEulerAngles.y, myEulerAngles.z); transform.localRotation = invertedRotation;So i guess your soluiton is kind of similar.