Пример #1
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);
            }
        }
Пример #2
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);
            }
        }
Пример #3
0
        public void ScenePanFocus(FScene scene, Camera camera, Vector3 focusPoint, bool bAnimated)
        {
            CameraAnimator animator = camera.gameObject.GetComponent <CameraAnimator>();

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

                scene.RootGameObject.transform.position += delta;
                camera.SetTarget(focusPoint);
            }
            else
            {
                animator.PanFocus(focusPoint);
            }
        }
Пример #4
0
        // Use this for initialization
        public void Initialize(FContext controller)
        {
            this.controller = controller;

            // find main camera
            GameObject[] mainCameras = GameObject.FindGameObjectsWithTag("MainCamera");
            if (mainCameras.Length == 0)
            {
                throw new MissingComponentException("CameraTracking.Initialize: could not find camera with tag MainCamera");
            }
            var mainCameraObj = mainCameras[0];

            if (mainCameras.Length > 1)
            {
                DebugUtil.Log(2, "CameraTracking.Initialize: there are multiple objects with tag MainCamera. Using the one named " + mainCameraObj.GetName());
            }
            mainCamera = mainCameraObj.GetComponent <Camera> () as Camera;

            // on Vive the MainCamera will have some child cameras that are a problem,
            // so get rid of them
            if (gs.VRPlatform.CurrentVRDevice == gs.VRPlatform.Device.HTCVive)
            {
                List <GameObject> children = new List <GameObject>(mainCameraObj.Children());
                foreach (var child in children)
                {
                    mainCameraObj.RemoveChild(child);
                    GameObject.Destroy(child);
                }
            }

            List <Camera> newCameras = new List <Camera>();

            // create camera for 3D widgets layer
            widgetCamera = Camera.Instantiate(mainCamera);
            widgetCamera.SetName("WidgetCamera");
            widgetCamera.transform.position = mainCamera.transform.position;
            widgetCamera.transform.rotation = mainCamera.transform.rotation;
            newCameras.Add(widgetCamera);

            // create camera for HUD layer
            hudCamera = Camera.Instantiate(mainCamera);
            hudCamera.SetName("HUDCamera");
            hudCamera.transform.position = mainCamera.transform.position;
            hudCamera.transform.rotation = mainCamera.transform.rotation;
            newCameras.Add(hudCamera);

            // create camera for UI
            uiCamera = Camera.Instantiate(mainCamera);
            uiCamera.SetName("UICamera");
            uiCamera.transform.position = mainCamera.transform.position;
            uiCamera.transform.rotation = mainCamera.transform.rotation;
            uiCamera.orthographic       = true;
            uiCamera.orthographicSize   = 0.5f;
            newCameras.Add(uiCamera);

            // create camera for cursor
            cursorCamera = Camera.Instantiate(mainCamera);
            cursorCamera.SetName("CursorCamera");
            cursorCamera.transform.position = mainCamera.transform.position;
            cursorCamera.transform.rotation = mainCamera.transform.rotation;
            newCameras.Add(cursorCamera);

            // configure these cameras
            //   - must disable audio listener if it exists
            //   - do depth clear so we can draw on top of other layers
            foreach (Camera cam in newCameras)
            {
                AudioListener listener = cam.GetComponent <AudioListener>();
                if (listener != null)
                {
                    listener.enabled = false;
                }

                cam.clearFlags = CameraClearFlags.Depth;
            }


            // set up camera masks

            // this camera only renders 3DWidgetOverlay layer, and mainCam does not!
            int nWidgetLayer = FPlatform.WidgetOverlayLayer;
            int nHUDLayer    = FPlatform.HUDLayer;
            int nUILayer     = FPlatform.UILayer;
            int nCursorLayer = FPlatform.CursorLayer;

            widgetCamera.cullingMask = (1 << nWidgetLayer);
            hudCamera.cullingMask    = (1 << nHUDLayer);
            uiCamera.cullingMask     = (1 << nUILayer);
            cursorCamera.cullingMask = (1 << nCursorLayer);

            mainCamera.cullingMask &= ~(1 << nWidgetLayer);
            mainCamera.cullingMask &= ~(1 << nHUDLayer);
            mainCamera.cullingMask &= ~(1 << nUILayer);
            mainCamera.cullingMask &= ~(1 << nCursorLayer);

            // attach camera animation object to main camera
            CameraAnimator anim = mainCamera.gameObject.AddComponent <CameraAnimator>();

            anim.UseCamera = mainCamera;
            anim.UseScene  = this.controller.Scene;

            // add target point to camera
            CameraTarget target = mainCamera.gameObject.AddComponent <CameraTarget>();

            target.TargetPoint = new Vector3(
                0.0f, mainCamera.transform.position[1], 0.0f);
            target.context = this.controller;

            // add camera manipulator to camera
            mainCamera.gameObject.AddComponent <CameraManipulator>();
        }