Example #1
0
        /// <summary>
        /// Animate camera so that focusPoint moves to center of camera
        /// Camera target is also set to focusPoint
        /// </summary>
        public void AnimatePanFocus(Vector3f focusPoint, CoordSpace eSpace, float duration)
        {
            if (duration > 0 && ShowTargetDuringAnimations)
            {
                UseCamera.SetTargetVisible(true);
            }

            Vector3f       focusPointS = (eSpace == CoordSpace.WorldCoords) ? UseScene.ToSceneP(focusPoint) : focusPoint;
            Vector3f       startFocusS = UseScene.ToSceneP(UseCamera.GetTarget());
            Action <float> tweenF      = (t) => {
                Vector3f newTargetS = Vector3f.Lerp(startFocusS, focusPointS, t);
                UseCamera.Manipulator().PanFocusOnScenePoint(UseScene, UseCamera, newTargetS);
            };

            if (duration > 0)
            {
                TweenAnimator anim = new TweenAnimator(tweenF, duration)
                {
                    OnCompletedF = () => { UseCamera.SetTargetVisible(false); }
                };
                UseScene.ObjectAnimator.Register(anim);
            }
            else
            {
                tweenF(1.0f);
            }
        }
Example #2
0
        /// <summary>
        /// Tumble scene to given orientation, around current target point
        /// [TODO] currently this does some weird stuff, because distance from target varies...
        /// </summary>
        public void AnimateTumbleTo(Quaternionf toOrientation, float duration = 0.25f)
        {
            if (duration > 0 && ShowTargetDuringAnimations)
            {
                UseCamera.SetTargetVisible(true);
            }

            Vector3f startTargetS = UseScene.ToSceneP(UseCamera.GetTarget());
            Frame3f  startF       = UseScene.SceneFrame;

            Action <float> tweenF = (t) => {
                // update rotation
                Quaternionf rot = Quaternion.Slerp(startF.Rotation, toOrientation, t);
                UseScene.SceneFrame = new Frame3f(startF.Origin, rot);

                // stay on target
                UseCamera.Manipulator().PanFocusOnScenePoint(UseScene, UseCamera, startTargetS);
            };

            if (duration > 0)
            {
                TweenAnimator anim = new TweenAnimator(tweenF, duration)
                {
                    OnCompletedF = () => { UseCamera.SetTargetVisible(false); }
                };
                UseScene.ObjectAnimator.Register(anim);
            }
            else
            {
                tweenF(1.0f);
            }
        }
Example #3
0
        /// <summary>
        /// Animate camera so that focusPoint moves to center of camera, at distance distanceW along cam.Forward
        /// Camera target is also set to focusPoint
        /// </summary>
        public void AnimatePanZoomFocus(Vector3f focusPoint, CoordSpace eSpace, float distanceW, float duration)
        {
            if (duration > 0 && ShowTargetDuringAnimations)
            {
                UseCamera.SetTargetVisible(true);
            }

            Vector3f focusPointS = (eSpace == CoordSpace.WorldCoords) ? UseScene.ToSceneP(focusPoint) : focusPoint;
            Vector3f startFocusS = UseScene.ToSceneP(UseCamera.GetTarget());
            float    startDistW  = UseCamera.GetPosition().Distance(UseCamera.GetTarget());

            Action <float> tweenF = (t) => {
                float    smooth_t   = MathUtil.WyvillRise01(t);
                Vector3f newTargetS = Vector3f.Lerp(startFocusS, focusPointS, smooth_t);
                UseCamera.Manipulator().PanFocusOnScenePoint(UseScene, UseCamera, newTargetS);

                float curDist = UseCamera.GetPosition().Distance(UseCamera.GetTarget());
                float toDist  = MathUtil.Lerp(startDistW, distanceW, smooth_t);
                float dolly   = toDist - curDist;
                UseCamera.Manipulator().SceneZoom(UseScene, UseCamera, -dolly);
            };

            if (duration > 0)
            {
                TweenAnimator anim = new TweenAnimator(tweenF, duration)
                {
                    OnCompletedF = () => { UseCamera.SetTargetVisible(false); }
                };
                UseScene.ObjectAnimator.Register(anim);
            }
            else
            {
                tweenF(1.0f);
            }
        }
Example #4
0
        IEnumerator SmoothOrbitTo(float azimuth, float altitude, float duration)
        {
            yield return(null);

            var      manip  = UseCamera.Manipulator();
            Vector2f target = new Vector2f(azimuth, altitude);

            DOTween.To(() => { return(new Vector2f(manip.TurntableAzimuthD, manip.TurntableAltitudeD)); },
                       (v) => { manip.SceneOrbit(UseScene, UseCamera, v.x, v.y, true); },
                       target, duration);
        }
Example #5
0
        /// <summary>
        /// Animate camera so that centerPt moves to center of camera, and height is visible.
        /// Camera target is also set to centerPt
        /// </summary>
        public void AnimateFitHeightToView(Vector3f centerPt, float height, CoordSpace eSpace, float duration)
        {
            if (eSpace != CoordSpace.WorldCoords)
            {
                height = UseScene.ToWorldDimension(height);
            }
            float    fFitDistW   = UseCamera.Manipulator().GetFitHeightCameraDistance(height);
            Vector3f focusPointW = (eSpace == CoordSpace.WorldCoords) ? centerPt : UseScene.ToWorldP(centerPt);

            AnimatePanZoomFocus(focusPointW, CoordSpace.WorldCoords, fFitDistW, duration);
        }
Example #6
0
        /// <summary>
        /// Animate camera so that centerPt moves to center of camera, and width is visible.
        /// Camera target is also set to centerPt
        /// </summary>
        public void AnimateFitWidthToView(Vector3f centerPt, float width, CoordSpace eSpace, float duration)
        {
            if (eSpace != CoordSpace.WorldCoords)
            {
                width = UseScene.ToWorldDimension(width);
            }
            Vector3f focusPointW = (eSpace == CoordSpace.WorldCoords) ? centerPt : UseScene.ToWorldP(centerPt);

            if (UseCamera.IsOrthographic)
            {
                float targetHeight = UseCamera.AspectRatio * width;
                AnimatePanZoomFocusOrtho(focusPointW, CoordSpace.WorldCoords, targetHeight, duration);
            }
            else
            {
                float fFitDistW = UseCamera.Manipulator().GetFitWidthCameraDistance(width);
                AnimatePanZoomFocus(focusPointW, CoordSpace.WorldCoords, fFitDistW, duration);
            }
        }
Example #7
0
        /// <summary>
        /// Ortho variant of Turntable-rotate to set azimuth/altitude, while also re-centering camera on target at given distance.
        /// </summary>
        public void AnimateOrbitZoomFocusToOrtho(float toAzimuth, float toAltitude, float targetHeight, Vector3f toTargetS, float duration = 0.25f)
        {
            if (duration > 0 && ShowTargetDuringAnimations)
            {
                UseCamera.SetTargetVisible(true);
            }

            Vector3f startTargetS     = UseScene.ToSceneP(UseCamera.GetTarget());
            float    startAltitude    = UseCamera.Manipulator().TurntableAltitudeD;
            float    startAzimuth     = UseCamera.Manipulator().TurntableAzimuthD;
            float    startOrthoHeight = UseCamera.OrthoHeight;

            Action <float> tweenF = (t) => {
                Vector3f newTargetS = Vector3f.Lerp(startTargetS, toTargetS, t);
                //Vector3f newTargetW = UseScene.ToWorldP(newTargetS);
                //UseCamera.Manipulator().ScenePanFocus(UseScene, UseCamera, newTargetW, false);
                UseCamera.Manipulator().PanFocusOnScenePoint(UseScene, UseCamera, newTargetS);

                float alt = MathUtil.Lerp(startAltitude, toAltitude, t);
                float az  = MathUtil.Lerp(startAzimuth, toAzimuth, t);
                UseCamera.Manipulator().SceneOrbit(UseScene, UseCamera, az, alt, true);

                float curHeight = UseCamera.OrthoHeight;
                float toHeight  = MathUtil.Lerp(startOrthoHeight, targetHeight, t);
                float dh        = toHeight - curHeight;
                UseCamera.Manipulator().SceneZoom(UseScene, UseCamera, -dh);
            };

            if (duration > 0)
            {
                TweenAnimator anim = new TweenAnimator(tweenF, duration)
                {
                    OnCompletedF = () => { UseCamera.SetTargetVisible(false); }
                };
                UseScene.ObjectAnimator.Register(anim);
            }
            else
            {
                tweenF(1.0f);
            }
        }
        IEnumerator Teleport_Level_Helper(Vector3 vMoveToLocation, Vector3 vNewTargetLocation, Vector3 vPivotAround, float fLevelRotateAngle, float duration)
        {
            yield return(null);

            Sequence mySequence = DOTween.Sequence();

            mySequence.Append(
                fadeObject.GetComponent <MeshRenderer>().material.DOFade(1.0f, duration / 3.0f).OnComplete(() => {
                GameObject sceneGO = UseScene.RootGameObject;

                // set target to new target location explicitly, then reset orbit altitude.
                // now we are level with ground but not at location
                CameraTarget = vPivotAround;
                UseCamera.Manipulator().ResetSceneOrbit(UseScene, false, true, true);

                // add planar rotation if we need it
                if (fLevelRotateAngle != 0)
                {
                    UseCamera.Manipulator().SceneOrbit(UseScene, UseCamera, fLevelRotateAngle, 0.0f);
                }

                // figure out the pan that we would apply to camera, opposite is pan to scene
                Vector3 delta = UseCamera.transform.position - vMoveToLocation;
                sceneGO.transform.position += delta;
                // also have to shift scene target pos
                CameraTarget = vNewTargetLocation + delta;

                UseCamera.gameObject.GetComponent <CameraTarget>().ShowTarget = true;
            }));
            mySequence.AppendInterval(duration / 3.0f);
            mySequence.Append(
                fadeObject.GetComponent <MeshRenderer>().material.DOFade(0.0f, duration / 3.0f));

            // add a delay before we hide target
            mySequence.AppendInterval(1.0f);
            mySequence.OnComplete(() => {
                UseCamera.gameObject.GetComponent <CameraTarget>().ShowTarget = false;
            });
        }
Example #9
0
        /// <summary>
        /// Ortho variant of Tumble scene to given orientation, while also re-centering camera on target at given distance.
        /// </summary>
        public void AnimateTumbleZoomFocusToOrtho(Quaternionf toOrientation, float targetHeight, Vector3f toTargetS, float duration = 0.25f)
        {
            if (duration > 0 && ShowTargetDuringAnimations)
            {
                UseCamera.SetTargetVisible(true);
            }

            Vector3f startTargetS     = UseScene.ToSceneP(UseCamera.GetTarget());
            Frame3f  startF           = UseScene.SceneFrame;
            float    startOrthoHeight = UseCamera.OrthoHeight;

            Action <float> tweenF = (t) => {
                Vector3f newTargetS = Vector3f.Lerp(startTargetS, toTargetS, t);
                UseCamera.Manipulator().PanFocusOnScenePoint(UseScene, UseCamera, newTargetS);

                Quaternionf rot = Quaternion.Slerp(startF.Rotation, toOrientation, t);
                UseScene.RootGameObject.SetLocalRotation(rot);

                float curHeight = UseCamera.OrthoHeight;
                float toHeight  = MathUtil.Lerp(startOrthoHeight, targetHeight, t);
                float dh        = toHeight - curHeight;
                UseCamera.Manipulator().SceneZoom(UseScene, UseCamera, -dh);
            };

            if (duration > 0)
            {
                TweenAnimator anim = new TweenAnimator(tweenF, duration)
                {
                    OnCompletedF = () => { UseCamera.SetTargetVisible(false); }
                };
                UseScene.ObjectAnimator.Register(anim);
            }
            else
            {
                tweenF(1.0f);
            }
        }