Esempio n. 1
0
        public static Vector3 InverseTransformDirection(this ImmutableTransform t, Vector3 direction)
        {
            //            var matrix = Matrix4x4.TRS(t.Position, t.Rotation, t.Scale).inverse;
            //            return matrix.MultiplyVector(direction);

            return(Quaternion.Inverse(t.Rotation) * direction);
        }
Esempio n. 2
0
        public static Vector3 TransformDirection(this ImmutableTransform t, Vector3 direction)
        {
//            var matrix = Matrix4x4.TRS(t.Position, t.Rotation, t.Scale);
//            return matrix.MultiplyVector(direction);

            return(t.Rotation * direction);
        }
 public static ImmutableTransform Add(this ImmutableTransform source, ImmutableTransform other)
 {
     return(source
            .Translate(other.Position)
            .Rotate(other.Rotation)
            .Scale(other.Scale));
 }
 public static ImmutableTransform Subtract(this ImmutableTransform source, ImmutableTransform other)
 {
     return(source
            .Translate(-other.Position)
            .Rotate(Quaternion.Inverse(other.Rotation))
            .UpdateScale(source.Scale.Divide(other.Scale)));
 }
Esempio n. 5
0
        public static ImmutableTransform LookAt(this ImmutableTransform t, Vector3 lookTarget, Vector3 up)
        {
            var relativePosition = lookTarget - t.Position;

            t.Rotation = Quaternion.LookRotation(relativePosition, up);
            return(t);
        }
 public static GameObject SetTransform(this GameObject go, ImmutableTransform t)
 {
     if (go != null)
     {
         go.transform.Set(t);
     }
     return(go);
 }
Esempio n. 7
0
        public static ImmutableTransform UpdatePosition(this ImmutableTransform t, float?x = null, float?y = null, float?z = null)
        {
            var position = t.Position;

            position.x = x ?? position.x;
            position.y = y ?? position.y;
            position.z = z ?? position.z;
            t.Position = position;
            return(t);
        }
Esempio n. 8
0
        public static ImmutableTransform UpdateRotation(this ImmutableTransform t, float?x = null, float?y = null, float?z = null)
        {
            var angles = t.Rotation.eulerAngles;

            angles.x   = x ?? angles.x;
            angles.y   = y ?? angles.y;
            angles.z   = z ?? angles.z;
            t.Rotation = Quaternion.Euler(angles);
            return(t);
        }
Esempio n. 9
0
        public static ImmutableTransform RotateAround(this ImmutableTransform t, Vector3 center, Vector3 axis, float angle)
        {
            var desiredRotation = Quaternion.AngleAxis(angle, axis); // get the desired rotation

            var directionToCenter = t.Position - center;             // find current direction relative to center

            directionToCenter = desiredRotation * directionToCenter; // rotate the direction
            t.Position        = center + directionToCenter;          // define new position

            // rotate object to keep looking at the center:
            t.Rotation *= Quaternion.Inverse(t.Rotation) * desiredRotation * t.Rotation;

            return(t);
        }
 public static ImmutableTransform RotateWorld(this ImmutableTransform t, Vector3 rotation)
 {
     return(t.RotateWorld(Quaternion.Euler(rotation)));
 }
 public static ImmutableTransform RotateWorld(this ImmutableTransform t, Quaternion rotation)
 {
     return(t.UpdateRotation(rotation * t.Rotation));
 }
 public static ImmutableTransform Translate(this ImmutableTransform t, Vector3 translation,
                                            Quaternion rotation)
 {
     return(t.UpdatePosition(t.Position + (rotation * translation)));
 }
 public static ImmutableTransform TranslateLocally(this ImmutableTransform t, Vector3 translation)
 {
     return(t.Translate(translation, t.Rotation));
 }
Esempio n. 14
0
 public static ImmutableTransform TranslateLocally(this ImmutableTransform t, float x = 0f, float y = 0f, float z = 0f)
 {
     return(t.Translate(new Vector3(x, y, z), t.Rotation));
 }
 public static ImmutableTransform LookAt(this ImmutableTransform t, Vector3 lookTarget)
 {
     return(t.LookAt(lookTarget, up: Vector3.up));
 }
 public static void SetLocal(this Transform target, ImmutableTransform t)
 {
     target.localPosition = t.Position;
     target.localRotation = t.Rotation;
     target.localScale    = t.Scale;
 }
Esempio n. 17
0
 public static ImmutableTransform ToWorldSpace(this ImmutableTransform t, ImmutableTransform local)
 {
     return(t
            .TranslateLocally(-local.Position)
            .Rotate(Quaternion.Inverse(local.Rotation)));
 }
Esempio n. 18
0
 public static ImmutableTransform ToLocalSpace(this ImmutableTransform t, ImmutableTransform local)
 {
     return(t
            .Rotate(local.Rotation)
            .TranslateLocally(local.Position));
 }
Esempio n. 19
0
        public static Vector3 InverseTransformPoint(this ImmutableTransform t, Vector3 point)
        {
            var matrix = Matrix4x4.TRS(t.Position, t.Rotation, t.Scale).inverse;

            return(matrix.MultiplyPoint(point));
        }
Esempio n. 20
0
 public static ImmutableTransform RotateWorld(this ImmutableTransform t, Quaternion rotation)
 {
     t.Rotation = rotation * t.Rotation;
     return(t);
 }
Esempio n. 21
0
 public static ImmutableTransform RotateWorld(this ImmutableTransform t, float x = 0f, float y = 0f, float z = 0f)
 {
     return(t.RotateWorld(Quaternion.Euler(x, y, z)));
 }
 public static ImmutableTransform RotateAround(this ImmutableTransform t, Vector3 axis, float angle)
 {
     return(t.Rotate(Quaternion.AngleAxis(angle, axis)));
 }
 public static ImmutableTransform Scale(this ImmutableTransform t, Vector3 scaleFactor)
 {
     return(t.UpdateScale(Vector3.Scale(t.Scale, scaleFactor)));
 }
 public static ImmutableTransform UpdateScale(this ImmutableTransform t, Vector3 scale)
 {
     t.Scale = scale;
     return(t);
 }
Esempio n. 25
0
 public static ImmutableTransform Translate(this ImmutableTransform t, Vector3 translation,
                                            Quaternion rotation)
 {
     t.Position = t.Position + (rotation * translation);
     return(t);
 }
 public static ImmutableTransform Translate(this ImmutableTransform t, Vector3 translation)
 {
     return(t.Translate(translation, Quaternion.identity));
 }
 public static ImmutableTransform UpdateRotation(this ImmutableTransform t, Vector3 eulerAngles)
 {
     t.Rotation = Quaternion.Euler(eulerAngles);
     return(t);
 }
Esempio n. 28
0
 public static ImmutableTransform Scale(this ImmutableTransform t, Vector3 scaleFactor)
 {
     t.Scale = Vector3.Scale(t.Scale, scaleFactor);
     return(t);
 }
 public static ImmutableTransform UpdatePosition(this ImmutableTransform t, Vector3 position)
 {
     t.Position = position;
     return(t);
 }
 public static ImmutableTransform UpdateRotation(this ImmutableTransform t, Quaternion rotation)
 {
     t.Rotation = rotation;
     return(t);
 }