Пример #1
0
 public RotationAnimator(SplitSide splitSide, Quaternion from, Quaternion to, RotateableBranch rotateable)
 {
     SplitSide = splitSide;
     Rotateable = rotateable;
     From = from;
     To = to;
     Delta = 0;
 }
Пример #2
0
        IEnumerator Rotate90Degrees(SplitSide splitRotation, IList<RotationAnimator> animators)
        {
            float startTime = Time.time;
            float deltaTime;
            do
            {
                deltaTime = Mathf.Clamp(Time.time - startTime, 0, 1);
                foreach (RotationAnimator animator in animators)
                {
                    Quaternion lerpRotation = Quaternion.Lerp(animator.From, animator.To, Mathf.SmoothStep(0, 1, deltaTime));
                    Transformation transformation = new RotateAroundPivotTransform(splitRotation.Pivot, lerpRotation);
                    Vector3 localPosition = transformation.Transform(new Vector3());

                    animator.UpdateTransform(lerpRotation, localPosition);
                }

                yield return null;
            } while (deltaTime < 1);

            _eventRegistry.Notify(new GameEvent(GameEvent.Type.RESUMED));
            _readyToRot = true;
        }
Пример #3
0
        public IList<RotationAnimator> Rotate(SplitSide splitSide, Direction direction)
        {
            float directionMult = direction == Direction.Clockwise ? 1 : -1;
            Quaternion rotationDelta = Quaternion.Euler(splitSide.Axis * 90 * directionMult);

            GroupBranch group = splitSide.Group;

            List<RotationAnimator> animators = new List<RotationAnimator>();
            foreach (SplitBoundsBranch splitBoundsBranch in group.SplitBoundsBranches)
            {
                float distance;
                Split.ConstraintResult constraintResult = splitSide.Constrains(splitBoundsBranch.RotatedBounds, out distance);
                switch (constraintResult)
                {
                    case Split.ConstraintResult.Blocked:
                        return new RotationAnimator[0];
                    case Split.ConstraintResult.Included:
                        Transformation transformation;
                        RotationAnimator animator = CreateRotationAnimation(splitSide, splitBoundsBranch, rotationDelta, out transformation);
                        _eventRegistry.Notify(new BlockRotationEvent(group.Group, transformation, splitBoundsBranch.SplittedRegion));
                        animators.Add(animator);
                        break;
                }
            }

            foreach(GroupBranch attachedGroup in splitSide.AttachedRotateables)
            {
                Transformation transformation;
                RotationAnimator animator = CreateRotationAnimation(splitSide, attachedGroup, rotationDelta, out transformation);
                _eventRegistry.Notify(new GroupRotationEvent(group.Group, transformation));
                animators.Add(animator);
            }

            return animators;
        }
Пример #4
0
        private RotationAnimator CreateRotationAnimation(SplitSide splitSide, RotateableBranch rotateable, Quaternion rotationDelta, out Transformation transformation)
        {
            BlockBounds rotatedBounds = rotateable.RotatedBounds;
            Quaternion startRot = rotatedBounds.Rotation;
            Quaternion endRot = startRot * rotationDelta;

            rotatedBounds.SetToRotationFrom(endRot, splitSide.Pivot, rotateable.OriginalBounds);
            transformation = new RotateAroundPivotTransform(splitSide.Pivot, endRot);
            return new RotationAnimator(splitSide, startRot, endRot, rotateable);
        }