Exemple #1
0
    // IMPORTANT: This method MUST be called after
    // OVRManager.LateUpdate
    // NOTE: Call order is determined by enabling...
    // Use ExecutionOrdering script to ensure correct call order
    void LateUpdate()
    {
        if (handController == null ||
            leftEye == null ||
            rightEye == null)
        {
            Debug.Log("Hand Controller & Eye references cannot be null");
            return;
        }

        if (HasNaN(leftEye.position) ||
            HasNaN(centerEye.position) ||
            HasNaN(rightEye.position))
        {
            // Uninitialized transforms
            return;
        }

        // ASSUME: Oculus resets camera positions in each frame
        Vector3 oculusIPD = rightEye.position - leftEye.position;

        if (oculusIPD.magnitude < float.Epsilon)
        {
            // Unmodified camera positions
            return;
        }

        LeapDeviceInfo device = handController.GetDeviceInfo();

        if (device.type == LeapDeviceType.Invalid)
        {
            return;
        }

        Vector3 addIPD   = 0.5f * oculusIPD.normalized * (device.baseline - oculusIPD.magnitude) * tween;
        Vector3 toDevice = centerEye.forward * device.focalPlaneOffset * tween;

        if (HasNaN(leftEye.position) ||
            HasNaN(centerEye.position) ||
            HasNaN(rightEye.position))
        {
            // Uninitialized transforms
            return;
        }
        leftEye.position   = leftEye.position - addIPD + toDevice;
        rightEye.position  = rightEye.position + addIPD + toDevice;
        centerEye.position = 0.5f * (leftEye.position + rightEye.position);
    }
Exemple #2
0
    void Start()
    {
        HandController[] allControllers = FindObjectsOfType <HandController> ();
        foreach (HandController controller in allControllers)
        {
            if (controller.isActiveAndEnabled)
            {
                handController = controller;
            }
        }
        if (handController == null)
        {
            //Debug.LogWarning ("Camera alignment requires an active HandController in the scene -> enabled = false");
            enabled = false;
            return;
        }

        LeapImageRetriever[] allRetrievers = FindObjectsOfType <LeapImageRetriever> ();
        foreach (LeapImageRetriever retriever in allRetrievers)
        {
            if (retriever.isActiveAndEnabled)
            {
                imageRetriever = retriever;
            }
        }

        /*if (imageRetriever == null) {
         * //Debug.LogWarning ("Camera alignment requires an active LeapImageRetriever in the scene -> enabled = false");
         * enabled = false;
         * return;
         * }*/

        hasCameras = VRCameras.NONE;
        if (centerCamera != null)
        {
            Camera center = centerCamera.GetComponent <Camera>();
            if (center != null && center.isActiveAndEnabled)
            {
                hasCameras = VRCameras.CENTER;
            }
        }
        if (hasCameras == VRCameras.NONE)
        {
            Camera left  = leftCamera.GetComponent <Camera>();
            Camera right = rightCamera.GetComponent <Camera>();
            if (left != null && left.isActiveAndEnabled &&
                right != null && right.isActiveAndEnabled)
            {
                hasCameras = VRCameras.LEFT_RIGHT;
            }
        }
        if (hasCameras == VRCameras.NONE)
        {
            //Debug.LogWarning ("Either a central Camera for both eyes, or a Left and Right cameras must be referenced -> enabled = false");
            enabled = false;
            return;
        }

        if (transform.parent == null)
        {
            //Debug.LogWarning ("Alignment requires a parent object to define the location of the player in the world. enabled -> false");
            enabled = false;
            return;
        }

        if (transform != leftCamera.parent ||
            transform != centerCamera.parent ||
            transform != rightCamera.parent)
        {
            //Debug.LogWarning ("LeapCameraAlignment must be a component of the parent of the camera tranasforms -> enabled = false");
            enabled = false;
            return;
        }

        deviceInfo = (overrideDeviceType) ? new LeapDeviceInfo(overrideDeviceTypeWith) : handController.GetDeviceInfo();
        if (deviceInfo.type == LeapDeviceType.Invalid)
        {
            //Debug.LogWarning ("Invalid Leap Device -> enabled = false");
            enabled = false;
            return;
        }

        if (VRDevice.isPresent &&
            VRSettings.loadedDevice == VRDeviceType.Oculus)
        {
            eyeAlignment = new UserEyeAlignment()
            {
                use       = true,
                ipd       = OVRPlugin.ipd,
                eyeDepth  = OVRPlugin.eyeDepth,
                eyeHeight = OVRPlugin.eyeHeight
            };
            //Debug.Log ("Unity VR Support with Oculus");
        }
        else
        {
            eyeAlignment = new UserEyeAlignment()
            {
                use       = false,
                ipd       = 0f,
                eyeDepth  = 0f,
                eyeHeight = 0f
            };
            //Debug.Log ("Two-camera stereoscopic alignment");
        }
    }