private void UpdateFieldOfView(FieldOfView leftEyeFov, FieldOfView rightEyeFov)
            {
                CardboardDeviceParams cdp        = mHmd.getCardboard();
                ScreenParams          screen     = mHmd.getScreen();
                Distortion            distortion = cdp.getDistortion();

                float idealFovAngle = (float)Math.ToDegrees(Math.Atan2(cdp.getLensDiameter() / 2.0F, cdp.getEyeToLensDistance()));

                float eyeToScreenDist = cdp.getEyeToLensDistance() + cdp.getScreenToLensDistance();

                float outerDist = (screen.getWidthMeters() - cdp.getInterpupillaryDistance()) / 2.0F;

                float innerDist  = cdp.getInterpupillaryDistance() / 2.0F;
                float bottomDist = cdp.getVerticalDistanceToLensCenter() - screen.getBorderSizeMeters();

                float topDist = screen.getHeightMeters() + screen.getBorderSizeMeters() - cdp.getVerticalDistanceToLensCenter();

                float outerAngle = (float)Math.ToDegrees(Math.Atan2(distortion.distort(outerDist), eyeToScreenDist));

                float innerAngle = (float)Math.ToDegrees(Math.Atan2(distortion.distort(innerDist), eyeToScreenDist));

                float bottomAngle = (float)Math.ToDegrees(Math.Atan2(distortion.distort(bottomDist), eyeToScreenDist));

                float topAngle = (float)Math.ToDegrees(Math.Atan2(distortion.distort(topDist), eyeToScreenDist));

                leftEyeFov.setLeft(Math.Min(outerAngle, idealFovAngle));
                leftEyeFov.setRight(Math.Min(innerAngle, idealFovAngle));
                leftEyeFov.setBottom(Math.Min(bottomAngle, idealFovAngle));
                leftEyeFov.setTop(Math.Min(topAngle, idealFovAngle));

                rightEyeFov.setLeft(Math.Min(innerAngle, idealFovAngle));
                rightEyeFov.setRight(Math.Min(outerAngle, idealFovAngle));
                rightEyeFov.setBottom(Math.Min(bottomAngle, idealFovAngle));
                rightEyeFov.setTop(Math.Min(topAngle, idealFovAngle));
            }
        private EyeViewport initViewportForEye(EyeParams eye, float xOffsetM)
        {
            ScreenParams          screen = mHmd.getScreen();
            CardboardDeviceParams cdp    = mHmd.getCardboard();

            float eyeToScreenDistanceM = cdp.getEyeToLensDistance() + cdp.getScreenToLensDistance();
            float leftM = (float)Math.Tan(Math.ToRadians(eye.getFov().getLeft())) * eyeToScreenDistanceM;

            float rightM = (float)Math.Tan(Math.ToRadians(eye.getFov().getRight())) * eyeToScreenDistanceM;

            float bottomM = (float)Math.Tan(Math.ToRadians(eye.getFov().getBottom())) * eyeToScreenDistanceM;

            float topM = (float)Math.Tan(Math.ToRadians(eye.getFov().getTop())) * eyeToScreenDistanceM;

            EyeViewport vp = new EyeViewport();

            vp.x      = xOffsetM;
            vp.y      = 0.0F;
            vp.width  = (leftM + rightM);
            vp.height = (bottomM + topM);
            vp.eyeX   = (leftM + xOffsetM);
            vp.eyeY   = bottomM;

            float xPxPerM = screen.getWidth() / screen.getWidthMeters();
            float yPxPerM = screen.getHeight() / screen.getHeightMeters();

            eye.getViewport().x      = Math.Round(vp.x * xPxPerM);
            eye.getViewport().y      = Math.Round(vp.y * xPxPerM);
            eye.getViewport().width  = Math.Round(vp.width * xPxPerM);
            eye.getViewport().height = Math.Round(vp.height * xPxPerM);

            return(vp);
        }