public CameraState GetCurrentState(FScene scene) { CameraState s = new CameraState(); s.camPosition = Camera.GetPosition(); s.camRotation = Camera.GetRotation(); s.scenePosition = scene.RootGameObject.GetPosition(); s.sceneRotation = scene.RootGameObject.GetRotation(); s.target = Camera.GetTarget(); s.turntableAzimuth = turntableAzimuthD; s.turntableAltitude = turntableAltitudeD; return(s); }
// 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 = new fCamera(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); child.Destroy(); } } List <Camera> newCameras = new List <Camera>(); Vector3f mainPos = mainCamera.GetPosition(); Quaternionf mainRot = mainCamera.GetRotation(); // create camera for 3D widgets layer widgetCamera = new fCamera(Camera.Instantiate((Camera)mainCamera, mainPos, mainRot)); widgetCamera.SetName("WidgetCamera"); newCameras.Add(widgetCamera); // create camera for HUD layer hudCamera = new fCamera(Camera.Instantiate((Camera)mainCamera, mainPos, mainRot)); hudCamera.SetName("HUDCamera"); newCameras.Add(hudCamera); // create camera for UI uiCamera = new fCamera(Camera.Instantiate((Camera)mainCamera, mainPos, mainRot)); uiCamera.SetName("UICamera"); ((Camera)uiCamera).orthographic = true; ((Camera)uiCamera).orthographicSize = 0.5f; newCameras.Add(uiCamera); // create camera for cursor cursorCamera = new fCamera(Camera.Instantiate((Camera)mainCamera, mainPos, mainRot)); cursorCamera.SetName("CursorCamera"); 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; cam.tag = "Untagged"; } // 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; ((Camera)widgetCamera).cullingMask = (1 << nWidgetLayer); ((Camera)hudCamera).cullingMask = (1 << nHUDLayer); ((Camera)uiCamera).cullingMask = (1 << nUILayer); ((Camera)cursorCamera).cullingMask = (1 << nCursorLayer); ((Camera)mainCamera).cullingMask &= ~(1 << nWidgetLayer); ((Camera)mainCamera).cullingMask &= ~(1 << nHUDLayer); ((Camera)mainCamera).cullingMask &= ~(1 << nUILayer); ((Camera)mainCamera).cullingMask &= ~(1 << nCursorLayer); // attach camera animation object to main camera CameraAnimator anim = mainCamera.AddComponent <CameraAnimator>(); anim.UseCamera = mainCamera; anim.UseScene = this.controller.Scene; // add target point to camera CameraTarget target = mainCamera.AddComponent <CameraTarget>(); target.TargetPoint = new Vector3f(0.0f, mainCamera.GetPosition().y, 0.0f); target.context = this.controller; // add camera manipulator to camera // TODO: this does not need to be a monobehavior... var manipulator = mainCamera.AddComponent <CameraManipulator>(); manipulator.Camera = mainCamera; // initialize FPlatform FPlatform.MainCamera = mainCamera; FPlatform.WidgetCamera = widgetCamera; FPlatform.HUDCamera = hudCamera; FPlatform.OrthoUICamera = uiCamera; FPlatform.CursorCamera = cursorCamera; }