Esempio n. 1
0
        /// <summary>
        /// Turntable-rotate to set azimuth/altitude, while also re-centering camera on target at given distance.
        /// </summary>
        public void AnimateOrbitZoomFocusTo(float toAzimuth, float toAltitude, float toDistance, 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;

            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 curDist = UseCamera.GetPosition().Distance(UseCamera.GetTarget());
                float toDist  = MathUtil.SmoothInterp(curDist, toDistance, 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);
            }
        }
Esempio n. 2
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);
            }
        }