Packages/com.github.homuler.mediapipe/Runtime/Scripts/Unity/CoordinateSystem/RealWorldCoordinate.cs
/// <summary>
///   Convert from real world coordinates to Unity local coordinates.
///   Assume that the origin is common to the two coordinate systems.
/// </summary>
/// <param name="rectTransform">
///   <see cref="RectTransform" /> to be used for calculating local coordinates
/// </param>
/// <param name="x">X in real world coordinates</param>
/// <param name="y">Y in real world coordinates</param>
/// <param name="z">Z in real world coordinates</param>
/// <param name="scale">Ratio of real world coordinate values to local coordinate values</param>
/// <param name="imageRotation">Counterclockwise rotation angle of the input image</param>
/// <param name="isMirrored">Set to true if the original coordinates is mirrored</param>
Convert from real world coordinates to Unity local coordinates.
Assume that the origin is common to the two coordinate systems.
Convert from real world coordinates to Unity local coordinates . Assume that the origin is common to the two coordinate systems .
public static Vector3 GetLocalPosition(RectTransform rectTransform, float x, float y, float z, Vector3 scale, RotationAngle imageRotation = RotationAngle.Rotation0, bool isMirrored = false) {
      var (rx, ry) = IsInverted(imageRotation) ? (y, x) : (x, y);
      var realX = IsXReversed(imageRotation, isMirrored) ? -rx : rx;
      var realY = IsYReversed(imageRotation, isMirrored) ? -ry : ry;
      return Vector3.Scale(new Vector3(realX, realY, z), scale);
    }
public static Vector3 GetLocalPosition ( RectTransform rectTransform , float x , float y , float z , Vector3 scale , RotationAngle imageRotation = RotationAngle . Rotation0 , bool isMirrored = false ) { var ( rx , ry ) = IsInverted ( imageRotation ) ? ( y , x ) : ( x , y ) ; var realX = IsXReversed ( imageRotation , isMirrored ) ? - rx : rx ; var realY = IsYReversed ( imageRotation , isMirrored ) ? - ry : ry ; return Vector3 . Scale ( new Vector3 ( realX , realY , z ) , scale ) ; }
Convert from real world coordinates to Unity local coordinates.
Convert from real world coordinates to Unity local coordinates .
rectTransform
RectTransform
to be used for calculating local coordinates
to be used for calculating local coordinates
x
float
X in real world coordinates
X in real world coordinates
y
float
Y in real world coordinates
Y in real world coordinates
z
float
Z in real world coordinates
Z in real world coordinates
scale
Vector3
Ratio of real world coordinate values to local coordinate values
Ratio of real world coordinate values to local coordinate values
imageRotation
RotationAngle
Counterclockwise rotation angle of the input image
Counterclockwise rotation angle of the input image
isMirrored
bool
Set to true if the original coordinates is mirrored
Set to true if the original coordinates is mirrored