// Helper routine for creation of a stereo eye. private void CreateEye(GvrViewer.Eye eye) { string nm = name + (eye == GvrViewer.Eye.Left ? " Left" : " Right"); GameObject go = new GameObject(nm); go.transform.SetParent(transform, false); go.AddComponent <Camera>().enabled = false; var GvrEye = go.AddComponent <GvrEye>(); GvrEye.eye = eye; GvrEye.CopyCameraAndMakeSideBySide(this); }
public Pose3D GetEyePose(GvrViewer.Eye eye) { switch (eye) { case GvrViewer.Eye.Left: return(leftEyePose); case GvrViewer.Eye.Right: return(rightEyePose); default: return(null); } }
// Helper routine for creation of a stereo eye. private void CreateEye(GvrViewer.Eye eye, string camName) { string nm = name + (eye == GvrViewer.Eye.Left ? " Left" : " Right"); GameObject go = new GameObject(nm); //GameObject go = GameObject.FindWithTag(camName); go.transform.SetParent(transform, false); go.AddComponent <Camera>().enabled = false; go.AddComponent <UnityStandardAssets.CinematicEffects.Bloom> (); var GvrEye = go.AddComponent <GvrEye>(); GvrEye.eye = eye; GvrEye.CopyCameraAndMakeSideBySide(this); }
public Rect GetViewport(GvrViewer.Eye eye, GvrViewer.Distortion distortion = GvrViewer.Distortion.Distorted) { switch (eye) { case GvrViewer.Eye.Left: return(distortion == GvrViewer.Distortion.Distorted ? leftEyeDistortedViewport : leftEyeUndistortedViewport); case GvrViewer.Eye.Right: return(distortion == GvrViewer.Distortion.Distorted ? rightEyeDistortedViewport : rightEyeUndistortedViewport); default: return(new Rect()); } }
public Matrix4x4 GetProjection(GvrViewer.Eye eye, GvrViewer.Distortion distortion = GvrViewer.Distortion.Distorted) { switch (eye) { case GvrViewer.Eye.Left: return(distortion == GvrViewer.Distortion.Distorted ? leftEyeDistortedProjection : leftEyeUndistortedProjection); case GvrViewer.Eye.Right: return(distortion == GvrViewer.Distortion.Distorted ? rightEyeDistortedProjection : rightEyeUndistortedProjection); default: return(Matrix4x4.identity); } }
/// Compute the position of one of the stereo eye cameras. Accounts for both /// FOV matching and stereo comfort, if those features are enabled. The input is /// the [1,1] entry of the eye camera's projection matrix, representing the vertical /// field of view, and the overall scale being applied to the Z axis. Returns the /// position of the stereo eye camera in local coordinates. public Vector3 ComputeStereoEyePosition(GvrViewer.Eye eye, float proj11, float zScale) { if (centerOfInterest == null || !centerOfInterest.gameObject.activeInHierarchy) { return(GvrViewer.Instance.EyePose(eye).Position *stereoMultiplier); } // Distance of COI relative to head. float distance = centerOfInterest != null ? (centerOfInterest.position - transform.position).magnitude : 0; // Size of the COI, clamped to [0..distance] for mathematical sanity in following equations. float radius = Mathf.Clamp(radiusOfInterest, 0, distance); // Move the eye so that COI has about the same size onscreen as in the mono camera FOV. // The radius affects the horizon location, which is where the screen-size matching has to // occur. float scale = proj11 / cam.projectionMatrix[1, 1]; // vertical FOV float offset = Mathf.Sqrt(radius * radius + (distance * distance - radius * radius) * scale * scale); float eyeOffset = (distance - offset) * Mathf.Clamp01(matchMonoFOV) / zScale; float ipdScale = stereoMultiplier; if (checkStereoComfort) { // Manage IPD scale based on the distance to the COI. float minComfort = GvrViewer.Instance.ComfortableViewingRange.x; float maxComfort = GvrViewer.Instance.ComfortableViewingRange.y; if (minComfort < maxComfort) // Sanity check. // If closer than the minimum comfort distance, IPD is scaled down. // If farther than the maximum comfort distance, IPD is scaled up. // The result is that parallax is clamped within a reasonable range. { float minDistance = (distance - radius) / zScale - eyeOffset; ipdScale *= minDistance / Mathf.Clamp(minDistance, minComfort, maxComfort); } } return(ipdScale * GvrViewer.Instance.EyePose(eye).Position + eyeOffset * Vector3.forward); }