/// <summary> /// Initialization. Create eye objects and save wall definition. /// </summary> void Start() { // Create a debug string for wall information WallInfo = new StringWriter(); // Debug WallInfo.WriteLine("Wall: " + WallObject.name); WallInfo.WriteLine("Position: " + WallObject.transform.localPosition); WallInfo.WriteLine("Orientation: " + WallObject.transform.localRotation.eulerAngles); // Get the wall definition object for the wall object. // There should probably be some error checking if it doesn't exist. wallDef = WallObject.GetComponent(typeof(WallDefinition)) as WallDefinition; WallInfo.WriteLine("Size: " + wallDef.Width + ", " + wallDef.Height); // calculate eye offset based on camera eye separation value. //float eyeOffset = camera.stereoSeparation / 2.0f; // create objects to represent left and right eye positions. //leftEyeObj = CreateEyeObject(-eyeOffset, camera.name + ":Left Eye"); //rightEyeObj = CreateEyeObject(eyeOffset, camera.name + ":Right Eye"); eyeObj = CreateEyeObject(0, GetComponent <Camera>().name + ":Eye"); }
/// <summary> /// Initialize the display setup base on the contents of DisplaySettings. /// </summary> /// <param name="settings">Display settings defining each wall.</param> public void InitializeDisplay(DisplaySettings settings) { /// Abort if null settings were passed in. Just use the cameras defined in the project. if (settings == null || settings.screens.Count <= 0) { Debug.LogWarning("No screens defined, reverting to default display mode"); return; } /// Get a list of cameras that are in the scene by default. These will be destroyed and /// replaced by cameras defined in the display file. Camera[] camsToDestroy = GameObject.FindObjectsOfType(typeof(Camera)) as Camera[]; /// Find the GameObject that will act as the local origin for Walls /// This assumes a fixed position display (projection screen, monitor, etc.) in which the /// users head position will change with regard to the walls. For something like a HMD, /// the head itself would be the display origin. GameObject wallsParent = DIRE.Instance.DisplayOrigin; Debug.Log("Wall parent: " + wallsParent); /// Create and initialize game objects to represent each eye. GameObject leftEyeObj = null; GameObject rightEyeObj = null; leftEyeObj = DIRE.Instance.Head; rightEyeObj = DIRE.Instance.Head; if (IsStereoMode) { Transform eyeParent = DIRE.Instance.Head.transform; float eyeOffset = baseCam.stereoSeparation / 2.0f; leftEyeObj = CreateEyeObject(eyeParent, new Vector3(-eyeOffset, 0, 0), "Left Eye"); rightEyeObj = CreateEyeObject(eyeParent, new Vector3(eyeOffset, 0, 0), "Right Eye"); } else { leftEyeObj = DIRE.Instance.Head; rightEyeObj = DIRE.Instance.Head; } // Instantiate a camera for every screen from the display settings file. for (int i = 0; i < settings.screens.Count; i++) { ScreenInfo sInfo = settings.screens[i]; /// Create a wall object with wall component for each screen. Place wall on wall parent. GameObject wallObject = new GameObject(); wallObject.name = sInfo.Name + " Wall"; wallObject.transform.parent = wallsParent.transform; wallObject.transform.localPosition = sInfo.Location.Position; wallObject.transform.localEulerAngles = sInfo.Location.Orientation; wallObject.AddComponent(typeof(WallDefinition)); WallDefinition wallDef = wallObject.GetComponent(typeof(WallDefinition)) as WallDefinition; wallDef.Width = sInfo.Location.Width; wallDef.Height = sInfo.Location.Height; /// Create a camera for each wall. Place the camera on the users head. Camera camera = Instantiate(baseCam) as Camera; camera.name = sInfo.Name + " Camera"; camera.transform.parent = DIRE.Instance.Head.transform; camera.transform.localPosition = Vector3.zero; camera.transform.localRotation = Quaternion.identity; camera.transform.localScale = Vector3.one; /// set camera display area in window camera.rect = new Rect((float)(sInfo.Viewport.X - settings.X) / settings.Width, (float)(settings.Y + settings.Height - sInfo.Viewport.Y - sInfo.Viewport.Height) / settings.Height, (float)(sInfo.Viewport.Width) / settings.Width, (float)(sInfo.Viewport.Height) / settings.Height); /// Create a FixedDisplay component if none exists if (camera.GetComponent(typeof(FixedDisplay)) == null) { camera.gameObject.AddComponent(typeof(FixedDisplay)); } /// Associate the wall object the FixedDisplay component on the camera FixedDisplay fdScript = camera.GetComponent(typeof(FixedDisplay)) as FixedDisplay; //fdScript.leftEyeObj = (sInfo.SwapEyes ? rightEyeObj : leftEyeObj ); //fdScript.rightEyeObj = (sInfo.SwapEyes ? leftEyeObj : rightEyeObj ); fdScript.WallObject = wallObject; } // This foreach destroys all of the non-DIRE cameras in the scene. // This is performed after the new cameras are set up to prevent a blank screen while the new cameras are set up. /*foreach(Camera obj in camsToDestroy) * { * if (obj.gameObject.tag != "DIRE") * Destroy(obj.gameObject); * }*/ }