private void OnParentChanged()
        {
            if (_parent == null)
            {
                _localPosition3D = _position3D;
                _localRotation3D = _rotation3D;

                _localPosition2D        = _position2D;
                _localRotation2D        = _rotation2D;
                _localRotation2DDegrees = _rotation2DDegrees;
            }
            else
            {
                _localPosition3D = Quaternion.Inverse(_parent._rotation3D) * (_position3D - _parent._position3D);
                _localRotation3D = QuaternionEx.Normalize(Quaternion.Inverse(_parent._rotation3D) * _rotation3D);

                _localPosition2D        = Quaternion.Inverse(_parent._rotation2D) * (_position2D - _parent._position2D);
                _localRotation2D        = QuaternionEx.Normalize(Quaternion.Inverse(_parent._rotation2D) * _rotation2D);
                _localRotation2DDegrees = _localRotation2D.ConvertTo2DRotation();
            }

            UpdateChildTransforms3D();
            UpdateChildTransforms2D();
            OnChanged(new GizmoTransform.ChangeData(ChangeReason.ParentChange, GizmoDimension.None));
        }
Exemplo n.º 2
0
 public void SetMappedAxis(Vector2 axis)
 {
     if (!IsMapped)
     {
         return;
     }
     _transform.Rotate2D(QuaternionEx.FromToRotation2D(Axis, axis));
 }
        public void AlignAxis3D(int axisIndex, AxisSign axisSign, Vector3 axis)
        {
            if (CanChange3D)
            {
                Vector3 axisToAlign = GetAxis3D(axisIndex, axisSign);
                Vector3 perpAxis    = GetAxis3D((axisIndex + 1) % 3, axisSign);

                Quaternion alignRotation = QuaternionEx.FromToRotation3D(axisToAlign, axis, perpAxis);
                Rotation3D = alignRotation * _rotation3D;
            }
        }
        public void AlignAxis2D(int axisIndex, AxisSign axisSign, Vector2 axis)
        {
            if (CanChange3D)
            {
                Vector2    axisToAlign   = GetAxis2D(axisIndex, axisSign);
                Quaternion alignRotation = QuaternionEx.FromToRotation2D(axisToAlign, axis);
                float      angle         = alignRotation.ConvertTo2DRotation();

                ChangeRotation2D(_rotation2DDegrees + angle);
            }
        }
        private void UpdateChildTransforms3D()
        {
            foreach (var child in _children)
            {
                child._position3D = _rotation3D * child._localPosition3D + _position3D;
                child._rotation3D = QuaternionEx.Normalize(_rotation3D * child._localRotation3D);
                child.Update3DAxes();

                child.UpdateChildTransforms3D();
                child.OnChanged(new GizmoTransform.ChangeData(ChangeReason.TRSChange, GizmoDimension.Dim3D));
            }
        }
        private void UpdateChildTransforms2D()
        {
            foreach (var child in _children)
            {
                Vector2 rotatedPos = _rotation2D * child._localPosition2D;
                child._position2D        = rotatedPos + _position2D;
                child._rotation2D        = (QuaternionEx.Normalize(_rotation2D * child._localRotation2D));
                child._rotation2DDegrees = child._rotation2D.ConvertTo2DRotation();
                child.Update2DAxes();

                child.UpdateChildTransforms2D();
                child.OnChanged(new GizmoTransform.ChangeData(ChangeReason.TRSChange, GizmoDimension.Dim2D));
            }
        }
        private void OnLocalRotation3DChanged()
        {
            if (_parent == null)
            {
                _rotation3D = _localRotation3D;
            }
            else
            {
                _rotation3D = QuaternionEx.Normalize(_parent._rotation3D * _localRotation3D);
            }

            Update3DAxes();
            UpdateChildTransforms3D();
            OnChanged(new GizmoTransform.ChangeData(ChangeReason.TRSChange, GizmoDimension.Dim3D));
        }
        public void SetMappedAxis(Vector3 axis)
        {
            if (!IsMapped)
            {
                return;
            }

            Vector3 perp180 = _transform.GetAxis3D(0, AxisSign.Positive);

            if (_mappedAxisDesc.Index == 0)
            {
                perp180 = _transform.GetAxis3D(1, AxisSign.Positive);
            }

            _transform.Rotate3D(QuaternionEx.FromToRotation3D(Axis, axis, perp180));
        }
        private void OnLocalRotation2DChanged()
        {
            if (_parent == null)
            {
                _rotation2D = _localRotation2D;
            }
            else
            {
                _rotation2D = QuaternionEx.Normalize(_parent._rotation2D * _localRotation2D);
            }

            _rotation2DDegrees = _rotation2D.ConvertTo2DRotation();

            Update2DAxes();
            UpdateChildTransforms2D();
            OnChanged(new GizmoTransform.ChangeData(ChangeReason.TRSChange, GizmoDimension.Dim2D));
        }
Exemplo n.º 10
0
 public void AlignDepth(Vector3 axis)
 {
     Rotation = QuaternionEx.FromToRotation3D(Look, axis, Right) * _rotation;
 }
 private void ChangeLocalRotation2D(Quaternion localRotation)
 {
     _localRotation2D = QuaternionEx.Normalize(localRotation);
     OnLocalRotation2DChanged();
 }
 private void ChangeLocalRotation2D(float localRotation)
 {
     _localRotation2DDegrees = localRotation;
     _localRotation2D        = QuaternionEx.Normalize(Quaternion.AngleAxis(_localRotation2DDegrees, Vector3.forward));
     OnLocalRotation2DChanged();
 }
 private void ChangeRotation2D(Quaternion rotation)
 {
     _rotation2D = QuaternionEx.Normalize(rotation);
     OnRotation2DChanged();
 }
 private void ChangeRotation2D(float rotation)
 {
     _rotation2DDegrees = rotation % 360.0f;
     _rotation2D        = QuaternionEx.Normalize(Quaternion.AngleAxis(_rotation2DDegrees, Vector3.forward));
     OnRotation2DChanged();
 }
Exemplo n.º 15
0
 public void AlignHeight(Vector3 axis)
 {
     Rotation = QuaternionEx.FromToRotation3D(Up, axis, Right) * _rotation;
 }
Exemplo n.º 16
0
 public void AlignUp(Vector3 axis)
 {
     Rotation = QuaternionEx.FromToRotation3D(Up, axis, Normal) * _rotation;
 }
Exemplo n.º 17
0
 public void AlignRight(Vector3 axis)
 {
     Rotation = QuaternionEx.FromToRotation3D(Right, axis, Up) * _rotation;
 }
Exemplo n.º 18
0
 public void AlignNormal(Vector3 axis)
 {
     Rotation = QuaternionEx.FromToRotation3D(Normal, axis, Right) * _rotation;
 }
 public void AlignTip(Vector3 axis)
 {
     Rotation = QuaternionEx.FromToRotation3D(CentralAxis, axis, Look) * _rotation;
 }
Exemplo n.º 20
0
        public void AlignWidth(Vector2 axis)
        {
            Quaternion newRotation = QuaternionEx.FromToRotation2D(Right, axis) * Rotation;

            RotationDegrees = QuaternionEx.ConvertTo2DRotation(newRotation);
        }
Exemplo n.º 21
0
 public void PointTipAlongAxis(Vector3 axis)
 {
     Rotation = QuaternionEx.FromToRotation3D(CentralAxis, axis, Right) * _rotation;
 }