public ReflectorOptics(Vector3 pupilPosition, EllipsoidTransform ellipse, Transform Screen, Vector4 projectionParameters, Pose?headsetOrigin = null, Quaternion?optionalPupilRotation = null, bool updateEllipsoid = true) { eyePosition = pupilPosition; bool didEllipsoidActuallyUpdate = false; if (updateEllipsoid) { didEllipsoidActuallyUpdate = ellipse.UpdateEllipsoid(); } sphereToWorldSpace = ellipse.sphereToWorldSpace; ellipseMajorAxis = ellipse.MajorAxis; ellipseMinorAxis = ellipse.MinorAxis; screenForward = Screen.forward; screenPosition = Screen.position; worldToScreenSpace = Screen.worldToLocalMatrix; cameraProjection = projectionParameters; eyeRotation = Quaternion.identity; if (optionalPupilRotation.HasValue) { var pupilRotation = optionalPupilRotation.Value; if (optionalPupilRotation == default(Quaternion)) { optionalPupilRotation = Quaternion.identity; } eyeRotation = pupilRotation; } if (headsetOrigin.HasValue) { // If debugging this, helps to draw matrices with: // var drawer = HyperMegaStuff.HyperMegaLines.drawer; // (new Geometry.Sphere(radius)).DrawLines( // drawer.DrawLine, // overrideMatrix: aLocalToWorldMatrix); var headsetWorldToLocal = headsetOrigin.Value.inverse.matrix; eyePosition = headsetWorldToLocal.MultiplyPoint3x4(eyePosition); eyeRotation = OpticalCalibrationManager.LossyMatrixMultQuaternion( headsetWorldToLocal, eyeRotation ); screenForward = headsetWorldToLocal.MultiplyVector(Screen.forward) .normalized; screenPosition = headsetWorldToLocal.MultiplyPoint3x4(Screen.position); worldToScreenSpace = (headsetWorldToLocal * Screen.localToWorldMatrix) .inverse; if (didEllipsoidActuallyUpdate) { sphereToWorldSpace = headsetWorldToLocal * sphereToWorldSpace; } } }
public OpticalSystem(Camera eyePerspective, EllipsoidTransform ellipse, Transform Screen, Pose?headsetOrigin = null) { eyePosition = eyePerspective.transform.position; bool didEllipsoidActuallyUpdate = ellipse.UpdateEllipsoid(); // Sigh. sphereToWorldSpace = ellipse.sphereToWorldSpace; worldToSphereSpace = ellipse.worldToSphereSpace; ellipseMajorAxis = ellipse.MajorAxis; ellipseMinorAxis = ellipse.MinorAxis; screenForward = Screen.forward; screenPosition = Screen.position; worldToScreenSpace = Screen.worldToLocalMatrix; clipToWorld = eyePerspective.cameraToWorldMatrix * eyePerspective.projectionMatrix.inverse; Debug.Log(eyePerspective.projectionMatrix); if (headsetOrigin.HasValue) { // If debugging this, helps to draw matrices with: // var drawer = HyperMegaStuff.HyperMegaLines.drawer; // (new Geometry.Sphere(radius)).DrawLines( // drawer.DrawLine, // overrideMatrix: aLocalToWorldMatrix); var headsetWorldToLocal = headsetOrigin.Value.inverse.matrix; eyePosition = headsetWorldToLocal.MultiplyPoint3x4(eyePosition); screenForward = headsetWorldToLocal.MultiplyVector(Screen.forward) .normalized; screenPosition = headsetWorldToLocal.MultiplyPoint3x4(Screen.position); worldToScreenSpace = (headsetWorldToLocal * Screen.localToWorldMatrix) .inverse; clipToWorld = headsetWorldToLocal * clipToWorld; if (didEllipsoidActuallyUpdate) { sphereToWorldSpace = headsetWorldToLocal * sphereToWorldSpace; worldToSphereSpace = sphereToWorldSpace.inverse; } } }