summaryrefslogtreecommitdiff
path: root/VRCSDK3Avatars/Assets/Resources/GestureManager/Scripts/Extra/TransformData.cs
blob: 58d59bb81a67b84d7d88a104264199d3af4c95eb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
using UnityEngine;

namespace GestureManager.Scripts.Extra
{
    public class TransformData
    {
        private readonly Vector3 _position;
        private readonly Quaternion _rotation;
        private readonly Vector3 _localScale;

        private TransformData(Vector3 p, Quaternion r, Vector3 s)
        {
            _position = p;
            _rotation = r;
            _localScale = s;
        }

        public TransformData(Transform t) : this(t.position, t.rotation, t.localScale)
        {
        }

        public void AddTo(Transform t)
        {
            t.position += _position;
            t.rotation = _rotation * t.rotation;
            t.localScale += _localScale;
        }

        public TransformData Difference(Transform t) => new TransformData(t.position - _position, t.rotation * Quaternion.Inverse(_rotation), t.localScale - _localScale);
    }

    public static class Extensions
    {
        public static void ApplyTo(this Transform s, Transform t)
        {
            t.position = s.position;
            t.rotation = s.rotation;
            t.localScale = s.lossyScale;
        }
    }
}