Created
April 8, 2025 07:30
-
-
Save neon-izm/e98ef7c45963309f1ce119a190b43aab to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static Quaternion ConvertRosToUnity(Quaternion q) | |
{ | |
return new Quaternion(-q.y, q.z, q.x, -q.w); | |
} | |
public static Quaternion ConvertUnityToRos(Quaternion q) | |
{ | |
return new Quaternion(q.z, -q.x, q.y, -q.w); | |
} | |
public static Vector3 ConvertUnityToRos(Vector3 pos) | |
{ | |
return new Vector3(pos.z, -pos.x, pos.y); | |
} | |
public static Vector3 ConvertRosToUnity(Vector3 pos) | |
{ | |
return new Vector3(-pos.y, pos.z, pos.x); | |
} | |
public static Quaternion ConvertMayaRotationToUnity(Vector3 mayaEulerAngleDegree) { | |
Vector3 flippedRotation = new Vector3(mayaEulerAngleDegree.x, -mayaEulerAngleDegree.y, -mayaEulerAngleDegree.z); // flip Y and Z axis for right->left handed conversion | |
// convert XYZ to ZYX | |
var qx = Quaternion.AngleAxis(flippedRotation.x, Vector3.right); | |
var qy = Quaternion.AngleAxis(flippedRotation.y, Vector3.up); | |
var qz = Quaternion.AngleAxis(flippedRotation.z, Vector3.forward); | |
var qq = qz * qy * qx; // exact order! | |
return qq; | |
} | |
public static Quaternion ConvertHoudiniToUnityRotation(Vector3 houdiniEulerAngleDegree) | |
{ | |
var qx = Quaternion.Euler(houdiniEulerAngleDegree.x, 0, 0); | |
var qy = Quaternion.Euler(0, houdiniEulerAngleDegree.y, 0); | |
var qz = Quaternion.Euler(0, 0, houdiniEulerAngleDegree.z); | |
var qq = qz * qy * qx; | |
return new Quaternion(-qq.x, qq.y, qq.z, -qq.w); | |
} | |
/// <summary> | |
/// Android Gyro Quaternion(RightHand) to Unity(LeftHand) Quaternion | |
/// </summary> | |
/// <param name="rightHandedQuaternion"></param> | |
/// <returns></returns> | |
public static Quaternion ConvertRightHandedToLeftHandedQuaternion (Quaternion rightHandedQuaternion) | |
{ | |
return new Quaternion (- rightHandedQuaternion.x, | |
- rightHandedQuaternion.z, | |
- rightHandedQuaternion.y, | |
rightHandedQuaternion.w); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment