Esempio n. 1
0
    // InitCameraControllerVariables
    // Made public so that it can be called by classes that require information about the
    // camera to be present when initing variables in 'Start'
    public void InitCameraControllerVariables()
    {
        // Get the IPD value (distance between eyes in meters)
        OVRDeviceImposter.GetIPD(ref IPD);

        // Get the values for both IPD and lens distortion correction shift. We don't normally
        // need to set the PhysicalLensOffset once it's been set here.
        OVRDeviceImposter.CalculatePhysicalLensOffsets(ref LensOffsetLeft, ref LensOffsetRight);

        // Using the calculated FOV, based on distortion parameters, yeilds the best results.
        // However, public functions will allow to override the FOV if desired
        VerticalFOV = OVRDeviceImposter.VerticalFOV();

        // Store aspect ratio as well
        AspectRatio = OVRDeviceImposter.CalculateAspectRatio();

        OVRDeviceImposter.GetDistortionCorrectionCoefficients(ref DistK0, ref DistK1, ref DistK2, ref DistK3);

        // Get our initial world orientation of the cameras from the scene (we can grab it from
        // the set FollowOrientation object or this OVRCameraController gameObject)
        if (FollowOrientation != null)
        {
            OrientationOffset = FollowOrientation.rotation;
        }
        else
        {
            OrientationOffset = transform.rotation;
        }
    }
Esempio n. 2
0
    // SetCameraLensCorrection
    void ConfigureCameraLensCorrection(ref Camera camera)
    {
        // Get the distortion scale and aspect ratio to use when calculating distortion shader
        float distortionScale = 1.0f / OVRDeviceImposter.DistortionScale();
        float aspectRatio     = OVRDeviceImposter.CalculateAspectRatio();

        // These values are different in the SDK World Demo; Unity renders each camera to a buffer
        // that is normalized, so we will respect this rule when calculating the distortion inputs
        float NormalizedWidth  = 1.0f;
        float NormalizedHeight = 1.0f;

        OVRLensCorrection lc = camera.GetComponent <OVRLensCorrection>();

        lc._Scale.x        = (NormalizedWidth / 2.0f) * distortionScale;
        lc._Scale.y        = (NormalizedHeight / 2.0f) * distortionScale * aspectRatio;
        lc._ScaleIn.x      = (2.0f / NormalizedWidth);
        lc._ScaleIn.y      = (2.0f / NormalizedHeight) / aspectRatio;
        lc._HmdWarpParam.x = DistK0;
        lc._HmdWarpParam.y = DistK1;
        lc._HmdWarpParam.z = DistK2;
    }