Ejemplo n.º 1
0
        /// <summary>
        /// Shift scene towards (+) / away-from (-) camera.
        /// If bKeepTargetPos == false, then target shifts with scene
        /// </summary>
        public void SceneZoom(FScene scene, fCamera cam, float dz, bool bKeepTargetPos = true)
        {
            if (dz == 0.0f)
            {
                return;
            }

            float fScale = scene.GetSceneScale();

            //Vector3f fw = cam.gameObject.transform.forward;
            Vector3f fw          = cam.GetTarget() - cam.GetPosition();
            float    fTargetDist = fw.Length;

            fw.Normalize();

            float fMinTargetDist = 0.1f * fScale;

            if (dz > 0 && fTargetDist - dz < fMinTargetDist)
            {
                dz = fTargetDist - fMinTargetDist;
            }

            Vector3f delta = dz * fw;

            scene.RootGameObject.Translate(-delta, false);
            if (bKeepTargetPos)
            {
                cam.SetTarget(cam.GetTarget() - delta);
            }
        }
Ejemplo n.º 2
0
        public void SceneTumbleAround(FScene scene, Vector3f position, float dx, float dy)
        {
            Vector3 targetPos = Camera.GetTarget();

            Camera.SetTarget(position);
            SceneTumble(scene, Camera, dx, dy);
            Camera.SetTarget(targetPos);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// translates scene so that focusPointS lies on camera forward axis. Also updates
        /// camera.Target to be at this point.
        /// </summary>
        public void PanFocusOnScenePoint(FScene scene, fCamera camera, Vector3f focusPointS)
        {
            Vector3f focusPointW = scene.ToWorldP(focusPointS);

            // figure out the pan that we would apply to camera, then apply the delta to the scene
            Vector3f camPosW    = camera.GetPosition();
            Vector3f camForward = camera.Forward();
            float    fDist      = Vector3.Dot((focusPointW - camPosW), camForward);

            if (fDist == 0)
            {
                fDist = 2.0f * ((Camera)camera).nearClipPlane;
            }
            Vector3f newCamPosW = focusPointW - fDist * camForward;
            Vector3f delta      = camPosW - newCamPosW;

            scene.RootGameObject.Translate(delta, false);
            camera.SetTarget(focusPointW + delta);
        }
Ejemplo n.º 4
0
        public void ScenePanFocus(FScene scene, fCamera camera, Vector3f focusPointW, bool bAnimated)
        {
            CameraAnimator animator = camera.Animator();

            if (bAnimated == false || animator == null)
            {
                // figure out the pan that we would apply to camera, then apply the delta to the scene
                Vector3f camPosW    = camera.GetPosition();
                Vector3f camForward = camera.Forward();
                float    fDist      = Vector3.Dot((focusPointW - camPosW), camForward);
                Vector3f newCamPosW = focusPointW - fDist * camForward;
                Vector3f delta      = camPosW - newCamPosW;

                scene.RootGameObject.Translate(delta, false);
                camera.SetTarget(focusPointW + delta);
            }
            else
            {
                animator.PanFocus(focusPointW);
            }
        }
Ejemplo n.º 5
0
        public void ScenePanFocus(FScene scene, fCamera camera, Vector3f focusPoint, bool bAnimated)
        {
            CameraAnimator animator = camera.Animator();

            if (bAnimated == false || animator == null)
            {
                // figure out the pan that we would apply to camera, then apply the delta to the scene
                Vector3f curPos = camera.GetPosition();
                Vector3f curDir = camera.GetWorldFrame().Z;
                float    fDist  = Vector3.Dot((focusPoint - curPos), curDir);
                Vector3f newPos = focusPoint - fDist * curDir;
                Vector3f delta  = curPos - newPos;

                scene.RootGameObject.Translate(delta, false);
                camera.SetTarget(focusPoint);
            }
            else
            {
                animator.PanFocus(focusPoint);
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Shift scene towards (+) / away-from (-) camera.
        /// If bKeepTargetPos == false, then target shifts with scene
        /// </summary>
        public void SceneZoom(FScene scene, fCamera cam, float dz, bool bKeepTargetPos = true)
        {
            if (dz == 0.0f)
            {
                return;
            }

            if (cam.IsOrthographic)
            {
                float f = cam.OrthoHeight;
                f = f - dz;
                if (f < 0)
                {
                    f = 0.01f;
                }
                cam.OrthoHeight = f;
                scene.Context.CameraManager.UpdateMainCamOrthoSize();
            }
            else
            {
                float fScale = scene.GetSceneScale();

                Vector3f fw          = cam.GetTarget() - cam.GetPosition();
                float    fTargetDist = fw.Length;
                fw.Normalize();

                float fMinTargetDist = 0.1f * fScale;
                if (dz > 0 && fTargetDist - dz < fMinTargetDist)
                {
                    dz = fTargetDist - fMinTargetDist;
                }

                Vector3f delta = dz * fw;
                scene.RootGameObject.Translate(-delta, false);
                if (bKeepTargetPos)
                {
                    cam.SetTarget(cam.GetTarget() - delta);
                }
            }
        }