diff --git a/QSB/Utility/RelativeTransformUtil.cs b/QSB/Utility/RelativeTransformUtil.cs index 7cd5a081..5a151cf7 100644 --- a/QSB/Utility/RelativeTransformUtil.cs +++ b/QSB/Utility/RelativeTransformUtil.cs @@ -4,12 +4,27 @@ namespace QSB.Utility; public static class RelativeTransformUtil { - public static Vector3 ToRelPos(this Transform reference, Vector3 pos) => reference.InverseTransformPoint(pos); - public static Vector3 FromRelPos(this Transform reference, Vector3 relPos) => reference.TransformPoint(relPos); - public static Quaternion ToRelRot(this Transform reference, Quaternion rot) => reference.InverseTransformRotation(rot); - public static Quaternion FromRelRot(this Transform reference, Quaternion relRot) => reference.TransformRotation(relRot); - public static Vector3 ToRelVel(this OWRigidbody reference, Vector3 vel, Vector3 pos) => vel - reference.GetPointVelocity(pos); - public static Vector3 FromRelVel(this OWRigidbody reference, Vector3 relVel, Vector3 pos) => relVel + reference.GetPointVelocity(pos); - public static Vector3 ToRelAngVel(this OWRigidbody reference, Vector3 angVel) => angVel - reference.GetAngularVelocity(); - public static Vector3 FromRelAngVel(this OWRigidbody reference, Vector3 relAngVel) => relAngVel + reference.GetAngularVelocity(); -} \ No newline at end of file + public static Vector3 ToRelPos(this Transform refTransform, Vector3 pos) => + refTransform.InverseTransformPoint(pos); + + public static Vector3 FromRelPos(this Transform refTransform, Vector3 relPos) => + refTransform.TransformPoint(relPos); + + public static Quaternion ToRelRot(this Transform refTransform, Quaternion rot) => + refTransform.InverseTransformRotation(rot); + + public static Quaternion FromRelRot(this Transform refTransform, Quaternion relRot) => + refTransform.TransformRotation(relRot); + + public static Vector3 ToRelVel(this OWRigidbody refBody, Vector3 vel, Vector3 pos) => + refBody.transform.InverseTransformDirection(vel - refBody.GetPointVelocity(pos)); + + public static Vector3 FromRelVel(this OWRigidbody refBody, Vector3 relVel, Vector3 pos) => + refBody.GetPointVelocity(pos) + refBody.transform.TransformDirection(relVel); + + public static Vector3 ToRelAngVel(this OWRigidbody refBody, Vector3 angVel) => + refBody.transform.InverseTransformDirection(angVel - refBody.GetAngularVelocity()); + + public static Vector3 FromRelAngVel(this OWRigidbody refBody, Vector3 relAngVel) => + refBody.GetAngularVelocity() + refBody.transform.TransformDirection(relAngVel); +}