void makeScreens() { cameras = new Camera[cameraCount]; planes = new GameObject[cameraCount]; // create cameras for (int i = 0; i < cameras.Length; i++) { // make plane GameObject plane = Object.Instantiate(basePlane, transform); plane.SetActive(true); plane.name = "Plane" + i.ToString("D3"); plane.transform.parent = transform; plane.transform.Rotate(0, 0, rotationOffset + (i * (360 / cameras.Length))); // figure out screen dimensions based on camera number and screen dimensions float screenWidth = 2f * Mathf.Sin(Mathf.PI * 1f / cameraCount) * screenRadius; float screenDist = Mathf.Cos(Mathf.PI * 1f / cameraCount) * screenRadius; // edges of camera frustum on screen plane.transform.Translate(-Vector3.up * screenDist); plane.transform.Translate(Vector3.forward * viewerHeight); // plane is 10x0x10, scale based on screenHeight plane.transform.localScale = new Vector3(.1f * screenWidth, 0f, 0.1f * screenHeight); planes[i] = plane; //camera pos and orientation GameObject go = new GameObject("Camera" + i.ToString("D3")); go.AddComponent(typeof(Camera)); go.transform.parent = transform; go.transform.localPosition = Vector3.zero; go.transform.localRotation = Quaternion.identity; go.transform.Rotate(0, rotationOffset + (i * (360 / cameras.Length)), 0); cameras[i] = go.GetComponent <Camera>(); // set pretty background colours cameras[i].backgroundColor = new Color( myCamera.backgroundColor.r + .1f * Mathf.Sin(2f * Mathf.PI * i / (float)cameraCount), myCamera.backgroundColor.g + .1f * Mathf.Sin(2f * Mathf.PI * (i + (cameraCount / 3f)) / (float)cameraCount), myCamera.backgroundColor.b + .1f * Mathf.Sin(2f * Mathf.PI * (i + (2 * cameraCount / 3f)) / (float)cameraCount) ); cameras[i].depth = -cameraCount + myCamera.depth + i; // set camera rect on screen cameras[i].rect = new Rect( (2f * (viewportOffsetH + (((float)i) / cameras.Length)) % 2) / 2f, viewportOffsetV, (float)(1f / cameras.Length), viewportHeight ); // off-axis projection settings cameras[i].gameObject.AddComponent(typeof(Kooima)); Kooima kooima = cameras [i].GetComponent <Kooima> (); if (kooima) { kooima.projectionScreen = planes[i]; kooima.estimateViewFrustum = false; kooima.setNearClipPlane = true; kooima.nearClipDistanceOffset = -0.01f; }// */ } }
void makeScreens() { cameras = new Camera[cameraCount]; planes = new GameObject[cameraCount]; // create cameras for (int i = 0; i < cameras.Length; i++) { // make plane representing camera view GameObject plane = Object.Instantiate(basePlane, transform); plane.SetActive(true); plane.name = "Plane" + i.ToString("D3"); plane.transform.parent = transform; plane.transform.Rotate(0, 0, rotationOffset + (i * (360 / cameras.Length))); // figure out screen dimensions based on camera number and screen dimensions float screenWidth = 2f * Mathf.Sin(Mathf.PI * 1f / cameraCount) * screenRadius; float screenDist = Mathf.Cos(Mathf.PI * 1f / cameraCount) * screenRadius; // edges of camera frustum on screen plane.transform.Translate(-Vector3.up * screenDist); plane.transform.Translate(Vector3.forward * screenHeight * 0.5f); // half plane height, to get cameras in centre // plane is 10x0x10, scale based on screenHeight plane.transform.localScale = new Vector3(.1f * screenWidth, 0f, 0.1f * screenHeight); planes[i] = plane; //camera pos and orientation GameObject go = new GameObject("Camera" + i.ToString("D3")); go.AddComponent(typeof(Camera)); go.transform.parent = transform; go.transform.localPosition = Vector3.zero; go.transform.localRotation = Quaternion.identity; go.transform.Rotate(0, rotationOffset + (i * (360 / cameras.Length)), 0); go.transform.Translate(Vector3.up * viewerHeight); //if (useStereo) go.transform.Translate (Vector3.left * eyeSeparation); cameras[i] = go.GetComponent <Camera>(); cameras[i].depth = -cameraCount + i; // set camera rect on screen cameras[i].rect = new Rect( (2f * (viewportOffsetH + (((float)i) / cameras.Length)) % 2) / 2f, viewportOffsetV, (float)(1f / cameras.Length), viewportHeight ); // off-axis projection settings cameras[i].gameObject.AddComponent(typeof(Kooima)); Kooima kooima = cameras [i].GetComponent <Kooima> (); if (kooima) { kooima.projectionScreen = planes[i]; kooima.estimateViewFrustum = estimateViewFrustumOnCameras; kooima.setNearClipPlane = clipToArena; if (!clipToArena) { cameras[i].nearClipPlane = nearClipPlane; } cameras[i].farClipPlane = farClipPlane; kooima.nearClipDistanceOffset = -0.01f; } } }