Created
March 22, 2024 08:01
-
-
Save baba-s/0cfc8ea10256ab3e142db45ce9db1271 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
using UnityEngine; | |
namespace Kogane | |
{ | |
public static class TransformExtensionMethods | |
{ | |
public static Vector3 TransformPointUnscaled | |
( | |
this Transform self, | |
in Vector3 position | |
) | |
{ | |
var localToWorldMatrix = Matrix4x4.TRS | |
( | |
pos: self.position, | |
q: self.rotation, | |
s: Vector3.one | |
); | |
return localToWorldMatrix.MultiplyPoint3x4( position ); | |
} | |
public static Vector3 InverseTransformPointUnscaled | |
( | |
this Transform self, | |
in Vector3 position | |
) | |
{ | |
var worldToLocalMatrix = Matrix4x4.TRS | |
( | |
pos: self.position, | |
q: self.rotation, | |
s: Vector3.one | |
).inverse; | |
return worldToLocalMatrix.MultiplyPoint3x4( position ); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment