RelativeTransformUtil: make vel and ang vel actually relative

This commit is contained in:
JohnCorby 2022-03-11 00:55:49 -08:00
parent 2ade7051fa
commit 46f93ee5b9

View File

@ -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();
}
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);
}