public void UpdateViewingCameraClipPlane(ClipPlaneManager clipPlane, GameObject viewingCam) { Camera cam = viewingCam.GetComponent <Camera>(); if (cam != null) { clipPlane.UpdateInfo(cam); } }
public void Awake() { LowerLeft = Vector2.zero; LowerRight = Vector2.zero; UpperLeft = Vector2.zero; UpperRight = Vector2.zero; representativePlane = new ClipPlaneManager(); }
public PlaneRect GenerateAggregatePlaneRect() { ClipPlaneManager clipPlane = new ClipPlaneManager(MainCamera.GetComponent <Camera>()); // Ensure that plane calculations won't get messed up by overlaying // a clipping plane in the same position as the camera, which // causes NaN errors in UV calculations //clipPlane.clipPlane.Translate(new Vector3(0, 0, WebCamSpecsManager.DefaultFarClippingPlane)); return(clipPlane.clipPlane); }
/// <summary> /// Check for UV value for something that would hit on the plane if it was extended out. /// </summary> /// <param name="canvas"></param> /// <param name="origin"></param> /// <param name="point"></param> /// <returns></returns> public Vector2 UVOffCanvas(Vector3 origin, Vector3 point) { Vector3 dir = point - origin; Ray ray = new Ray(origin, dir); RaycastHit rh = representativePlane.Intersect(ray, origin); ClipPlaneManager clipPlane = gameObject.GetComponent <ClipPlaneManager>(); //Debug.Log("rh.point = " + rh.point); //Debug.Log("UV00 = " + UV(clipPlane.ClipRect, rh.point)); return(UV(clipPlane.ClipRect, rh.point)); }
public void InitViewingCameras() { //ViewingCameras = new GameObject[webCamManager.NumWebCams]; //ClipPlanes = new ClipPlaneManager[ViewingCameras.Length]; List <GameObject> viewingCameraList = new List <GameObject>(); List <ClipPlaneManager> clipPlaneList = new List <ClipPlaneManager>(); List <int> ignorableWebCamIndices = new List <int>(); foreach (WebcamDeviceNames name in IgnorableWebCams) { ignorableWebCamIndices.AddRange(webCamManager.GetIndicesFor(name)); } for (int i = 0; i < webCamManager.NumWebCams; i++) { if (ignorableWebCamIndices.Contains(i)) { Debug.Log("Ignoring camera[" + i + "]..."); continue; } //ViewingCameras[i] = GenerateViewingCamera(i); GameObject viewingCam = GenerateViewingCamera(i); ClipPlaneManager clipPlane = associateClipPlane(viewingCam); // ERROR TESTING - OFFSETTING THE CAMERA STARTING POSITION MESSES UP THE PLANERECT HORRENDOUSLY - WHY? viewingCam.transform.position = CamStartingPositions[i]; clipPlane.ClipRect.Translate(CamStartingPositions[i]); viewingCameraList.Add(viewingCam); clipPlaneList.Add(clipPlane); //// ERROR TESTING - OFFSETTING THE CAMERA STARTING POSITION MESSES UP THE PLANERECT HORRENDOUSLY - WHY? //ViewingCameras[i].transform.position = CamStartingPositions[i]; //ClipPlanes[i].ClipRect.Translate(CamStartingPositions[i]); ////ClipPlanes[i].transform.position = CamStartingPositions[i]; //Debug.Log("Generated clip plane Corner00 = " + ClipPlanes[i].clipPlane.Corner00); //Debug.Log("Generated clip plane Corner01 = " + ClipPlanes[i].clipPlane.Corner01); //Debug.Log("Generated clip plane Corner11 = " + ClipPlanes[i].clipPlane.Corner11); //Debug.Log("Generated clip plane Corner10 = " + ClipPlanes[i].clipPlane.Corner10); } ViewingCameras = viewingCameraList.ToArray(); ClipPlanes = clipPlaneList.ToArray(); //ViewingCameras = new GameObject[1]; //ViewingCameras[0] = viewingCameraList[0]; //ClipPlanes = clipPlaneList.ToArray(); }
/// <summary> /// Must be called after initializing the viewing cameras. /// </summary> /// <param name="camIndex"></param> private ClipPlaneManager associateClipPlane(GameObject viewingCam) { //ClipPlaneManager clipPlane = ViewingCameras[camIndex].AddComponent<ClipPlaneManager>(); //ClipPlanes[camIndex] = clipPlane; ClipPlaneManager clipPlane = viewingCam.AddComponent <ClipPlaneManager>(); //UpdateViewingCameraClipPlane(camIndex); UpdateViewingCameraClipPlane(clipPlane, viewingCam); // Add miscellaneous scripts UVCalc uvCalc = viewingCam.AddComponent <UVCalc>(); uvCalc.SetRepresentativePlane(viewingCam.GetComponent <Camera>()); return(clipPlane); }
public void UpdateViewingCameraClipPlane(int camIndex) { if (ClipPlanes != null && ClipPlanes.Length > camIndex) { ClipPlaneManager clipPlane = ClipPlanes[camIndex]; if (ViewingCameras != null && ViewingCameras.Length > camIndex) { Camera cam = ViewingCameras[camIndex].GetComponent <Camera>(); if (cam != null) { clipPlane.UpdateInfo(cam); } } } }
public void SetRepresentativePlane(Camera cam) { GameObject tempCam = new GameObject(); tempCam.SetActive(false); Camera representativeCam = tempCam.AddComponent <Camera>(); representativeCam.fieldOfView = 175.0f; representativeCam.farClipPlane = cam.farClipPlane; representativeCam.nearClipPlane = cam.nearClipPlane; representativeCam.transform.position = cam.transform.position; representativeCam.transform.forward = cam.transform.forward; representativeCam.transform.up = cam.transform.up; representativeCam.transform.right = cam.transform.right; //representativePlane = new ClipPlaneManager(cam); representativePlane = new ClipPlaneManager(representativeCam); GameObject.Destroy(tempCam); }
// NOTE: If generating dynamic aggregate clip plane as originally intended, InterpolationManager's GenerateUV needs to call this instead of GenerateAggregatePlaneRect public PlaneRect GenerateAggregatePlaneRect(ClipPlaneManager[] clipPlanes)//, out Vector3 pos, out Vector3 forward) { // NOTE: If generating dynamic aggregate clip plane as originally intended, InterpolationManager's GenerateUV needs to call this instead of GenerateAggregatePlaneRect // Adjust all clipPlanes and viewing cameras to be in their starting position // ERROR TESTING // This is a bit of a hack to circumvent an issue encountered in ViewingCamManager in InitViewingCameras for (int i = 0; i < viewingCamManager.ViewingCameras.Length; i++) { GameObject viewingCam = viewingCamManager.ViewingCameras[i]; ClipPlaneManager clipPlane = viewingCam.GetComponent <ClipPlaneManager>(); // ERROR TESTING - this fix doesn't work either... //viewingCam.transform.Translate(viewingCamManager.CamStartingPositions[i]); //clipPlane.transform.Translate(viewingCamManager.CamStartingPositions[i]); } if (clipPlanes != null && clipPlanes.Length > 0) { List <ClipPlaneManager> clipPlaneList = ClipPlaneManager.SortClipPlanes(clipPlanes); ClipPlaneManager[] sortedClipPlanes = clipPlaneList.ToArray(); // Assumes all planes exist in the same plane and that they // are all horizontally aligned float leftX = sortedClipPlanes[0].clipPlane.Corner00.x; float rightX = sortedClipPlanes[0].clipPlane.Corner01.x; float bottomY = sortedClipPlanes[0].clipPlane.Corner00.y; float topY = sortedClipPlanes[0].clipPlane.Corner10.y; float z = sortedClipPlanes[0].clipPlane.Corner00.z; //Debug.Log("Sorted clip planes length = " + sortedClipPlanes.Length); //Debug.Log("Sorted clip planes:"); //Debug.Log("Sorted clip planes[0] corner00 = " + sortedClipPlanes[0].clipPlane.Corner00); //Debug.Log("Sorted clip planes[0] corner01 = " + sortedClipPlanes[0].clipPlane.Corner01); //Debug.Log("Sorted clip planes[0] corner11 = " + sortedClipPlanes[0].clipPlane.Corner11); //Debug.Log("Sorted clip planes[0] corner10 = " + sortedClipPlanes[0].clipPlane.Corner10); //Debug.Log("Unsorted clip planes[0] corner00 = " + clipPlanes[0].clipPlane.Corner00); //Debug.Log("Unsorted clip planes[0] corner01 = " + clipPlanes[0].clipPlane.Corner01); //Debug.Log("Unsorted clip planes[0] corner11 = " + clipPlanes[0].clipPlane.Corner11); //Debug.Log("Unsorted clip planes[0] corner10 = " + clipPlanes[0].clipPlane.Corner10); for (int i = 0; i < sortedClipPlanes.Length; i++) { Vector3[] corners = new Vector3[4] { sortedClipPlanes[i].clipPlane.Corner00, sortedClipPlanes[i].clipPlane.Corner01, sortedClipPlanes[i].clipPlane.Corner11, sortedClipPlanes[i].clipPlane.Corner10 }; foreach (Vector3 corner in corners) { if (corner.x < leftX) { leftX = corner.x; //Debug.Log(sortedClipPlanes[i].gameObject.name + "replaced leftX with: " + corner.x + " (" + corner + ")"); } if (corner.x > rightX) { rightX = corner.x; //Debug.Log(sortedClipPlanes[i].gameObject.name + "replaced rightX with: " + corner.x + " (" + corner + ")"); } if (corner.y < bottomY) { bottomY = corner.y; //Debug.Log(sortedClipPlanes[i].gameObject.name + "replaced bottomY with: " + corner.y + " (" + corner + ")"); } if (corner.y > topY) { topY = corner.y; //Debug.Log(sortedClipPlanes[i].gameObject.name + "replaced topY with: " + corner.y + " (" + corner + ")"); } } } PlaneRect newPlane = new PlaneRect( new Vector3(leftX, bottomY, z), // lower left new Vector3(leftX, topY, z), // upper left new Vector3(rightX, topY, z), // upper right new Vector3(rightX, bottomY, z) // lower right ); //int farRightIndex = sortedClipPlanes.Length - 1; //int farLeftIndex = 0; //ClipPlaneManager farLeft = sortedClipPlanes[farLeftIndex]; //ClipPlaneManager farRight = sortedClipPlanes[farRightIndex]; //PlaneRect newPlane = new PlaneRect( // farLeft.ClipRect.Corner00, // lower left // farLeft.ClipRect.Corner01, // upper left // farRight.ClipRect.Corner11, // upper right // farRight.ClipRect.Corner10 // lower right // ); //Debug.Log("Far Left C00 = " + farLeft.ClipRect.Corner00); //Debug.Log("Far Left C01 = " + farLeft.ClipRect.Corner01); //Debug.Log("Far Right C11 = " + farRight.ClipRect.Corner11); //Debug.Log("Far Right C10 = " + farRight.ClipRect.Corner10); //Debug.Log("New Plane Corner00 = " + newPlane.Corner00); //Debug.Log("New Plane Corner01 = " + newPlane.Corner01); //Debug.Log("New Plane Corner11 = " + newPlane.Corner11); //Debug.Log("New Plane Corner10 = " + newPlane.Corner10); // Generate a slightly shrunken plane for our purposes PlaneRect shrunkenPlane = ShrinkPlaneRect(newPlane, PlaneShrinkFactor); //// Form anchor for new plane (as if the image was projected from //// a camera at this point) //pos = farLeft.pos + ((farRight.pos - farLeft.pos) / 2.0f); //// ERROR TESTING - THIS NEEDS TO BE ADJUSTED TO ACCOUNT FOR STATES WHERE THE FORWARD DIRECTIONS ARE NOT THE SAME. //forward = farLeft.forward; return(shrunkenPlane); } else { //pos = Vector3.zero; //forward = new Vector3(0, 0, 1); return(null); } }