Leap device info struct.
Default values are for Leap peripheral.
  void Start() {
#if UNITY_EDITOR
    if (!Application.isPlaying) {
      return;
    }
#endif

    _deviceInfo = new LeapDeviceInfo(LeapDeviceType.Peripheral);
  }
    void Start()
    {
#if UNITY_EDITOR
        if (!Application.isPlaying)
        {
            return;
        }
#endif

        _deviceInfo = new LeapDeviceInfo(LeapDeviceType.Peripheral);
    }
Exemplo n.º 3
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);
    }
Exemplo n.º 4
0
        /** Returns information describing the device hardware. */
        public LeapDeviceInfo GetDeviceInfo()
        {
            if (overrideDeviceType)
            {
                return(new LeapDeviceInfo(overrideDeviceTypeWith));
            }

            DeviceList devices = GetLeapController().Devices;

            if (devices.Count == 1)
            {
                LeapDeviceInfo info = new LeapDeviceInfo(LeapDeviceType.Peripheral);
                // TODO: DeviceList does not tell us the device type. Dragonfly serial starts with "LE" and peripheral starts with "LP"
                if (devices[0].SerialNumber.Length >= 2)
                {
                    switch (devices[0].SerialNumber.Substring(0, 2))
                    {
                    case ("LP"):
                        info = new LeapDeviceInfo(LeapDeviceType.Peripheral);
                        break;

                    case ("LE"):
                        info = new LeapDeviceInfo(LeapDeviceType.Dragonfly);
                        break;

                    default:
                        break;
                    }
                }

                // TODO: Add baseline & offset when included in API
                // NOTE: Alternative is to use device type since all parameters are invariant
                info.isEmbedded          = devices[0].IsEmbedded;
                info.horizontalViewAngle = devices[0].HorizontalViewAngle * Mathf.Rad2Deg;
                info.verticalViewAngle   = devices[0].VerticalViewAngle * Mathf.Rad2Deg;
                info.trackingRange       = devices[0].Range / 1000f;
                info.serialID            = devices[0].SerialNumber;
                return(info);
            }
            else if (devices.Count > 1)
            {
                return(new LeapDeviceInfo(LeapDeviceType.Peripheral));
            }
            return(new LeapDeviceInfo(LeapDeviceType.Invalid));
        }
Exemplo n.º 5
0
    /** Returns information describing the device hardware. */
    public LeapDeviceInfo GetDeviceInfo()
    {
        LeapDeviceInfo info    = new LeapDeviceInfo(LeapDeviceType.Peripheral);
        DeviceList     devices = leap_controller_.Devices;

        if (devices.Count != 1)
        {
            return(info);
        }
        // TODO: Add baseline & offset when included in API
        // NOTE: Alternative is to use device type since all parameters are invariant
        info.isEmbedded          = devices [0].IsEmbedded;
        info.horizontalViewAngle = devices[0].HorizontalViewAngle * Mathf.Rad2Deg;
        info.verticalViewAngle   = devices[0].VerticalViewAngle * Mathf.Rad2Deg;
        info.trackingRange       = devices[0].Range / 1000f;
        info.serialID            = devices[0].SerialNumber;
        return(info);
    }
Exemplo n.º 6
0
    protected void Start()
    {
        if (HandController.Main == null)
        {
            Debug.LogWarning("Camera alignment requires an active main HandController in the scene -> enabled = false");
            enabled = false;
            return;
        }

        //Get a callback right as rendering begins for this frame so we can update the history and warping.
        LeapVRCameraControl.OnValidCameraParams += onValidCameraParams;

        deviceInfo = HandController.Main.GetDeviceInfo();
        if (deviceInfo.type == LeapDeviceType.Invalid)
        {
            Debug.LogWarning("Invalid Leap Device -> enabled = false");
            enabled = false;
            return;
        }
    }
Exemplo n.º 7
0
        /** Returns information describing the device hardware. */
        public LeapDeviceInfo GetDeviceInfo()
        {
            if (overrideDeviceType) {
            return new LeapDeviceInfo(overrideDeviceTypeWith);
              }

              DeviceList devices = GetLeapController().Devices;
              if (devices.Count == 1) {
            LeapDeviceInfo info = new LeapDeviceInfo(LeapDeviceType.Peripheral);
            // TODO: DeviceList does not tell us the device type. Dragonfly serial starts with "LE" and peripheral starts with "LP"
            if (devices[0].SerialNumber.Length >= 2) {
              switch (devices[0].SerialNumber.Substring(0, 2)) {
            case ("LP"):
              info = new LeapDeviceInfo(LeapDeviceType.Peripheral);
              break;
            case ("LE"):
              info = new LeapDeviceInfo(LeapDeviceType.Dragonfly);
              break;
            default:
              break;
              }
            }

            // TODO: Add baseline & offset when included in API
            // NOTE: Alternative is to use device type since all parameters are invariant
            info.isEmbedded = devices[0].IsEmbedded;
            info.horizontalViewAngle = devices[0].HorizontalViewAngle * Mathf.Rad2Deg;
            info.verticalViewAngle = devices[0].VerticalViewAngle * Mathf.Rad2Deg;
            info.trackingRange = devices[0].Range / 1000f;
            info.serialID = devices[0].SerialNumber;
            return info;
              } else if (devices.Count > 1) {
            return new LeapDeviceInfo(LeapDeviceType.Peripheral);
              }
              return new LeapDeviceInfo(LeapDeviceType.Invalid);
        }
    void Start()
    {
        if (handController == null ||
        imageRetriever == null ||
        leftCamera == null ||
        rightCamera == null ||
        centerCamera == null) {
          Debug.LogWarning ("HandController, ImageRetriever and Alignment Target references cannot be null -> enabled = false");
          enabled = false;
          return;
        }

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

        history = new List<TransformData> ();
        imageLatency = new SmoothedFloat () {
          delay = latencySmoothing
        };
        frameLatency = new SmoothedFloat () {
          delay = latencySmoothing
        };
    }
Exemplo n.º 9
0
 /** Returns information describing the device hardware. */
 public LeapDeviceInfo GetDeviceInfo() {
   LeapDeviceInfo info = new LeapDeviceInfo(LeapDeviceType.Peripheral);
   DeviceList devices = leap_controller_.Devices;
   if (devices.Count != 1) {
     return info;
   }
   // TODO: Add baseline & offset when included in API
   // NOTE: Alternative is to use device type since all parameters are invariant
   info.isEmbedded = devices [0].IsEmbedded;
   info.horizontalViewAngle = devices[0].HorizontalViewAngle * Mathf.Rad2Deg;
   info.verticalViewAngle = devices[0].VerticalViewAngle * Mathf.Rad2Deg;
   info.trackingRange = devices[0].Range / 1000f;
   info.serialID = devices[0].SerialNumber;
   return info;
 }
Exemplo n.º 10
0
    /** Returns information describing the device hardware. */
    public LeapDeviceInfo GetDeviceInfo()
    {
        DeviceList devices = leap_controller_.Devices;
        if (devices.Count == 1) {
          LeapDeviceInfo info = new LeapDeviceInfo(LeapDeviceType.Invalid);
          // TODO: DeviceList does not tell us the device type. Dragonfly serial starts with "LE" and peripheral starts with "LP"
          if (devices[0].SerialNumber.Length >= 2) {
        switch (devices[0].SerialNumber.Substring(0, 2)) {
          case ("LP"):
            info = new LeapDeviceInfo(LeapDeviceType.Peripheral);
            break;
          case ("LE"):
            info = new LeapDeviceInfo(LeapDeviceType.Dragonfly);
            break;
          default:
            // fix: https://community.leapmotion.com/t/quick-fix-for-unity-vr-developers/4322
            info = new LeapDeviceInfo(LeapDeviceType.Peripheral);
            break;
        }
          }

          // TODO: Add baseline & offset when included in API
          // NOTE: Alternative is to use device type since all parameters are invariant
          info.isEmbedded = devices[0].IsEmbedded;
          info.horizontalViewAngle = devices[0].HorizontalViewAngle * Mathf.Rad2Deg;
          info.verticalViewAngle = devices[0].VerticalViewAngle * Mathf.Rad2Deg;
          info.trackingRange = devices[0].Range / 1000f;
          info.serialID = devices[0].SerialNumber;
          return info;
        }
        else if (devices.Count > 1) {
          return new LeapDeviceInfo(LeapDeviceType.Peripheral);
        }
        return new LeapDeviceInfo(LeapDeviceType.Invalid);
    }
Exemplo n.º 11
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");
        }
    }
Exemplo n.º 12
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");
        }
    }
Exemplo n.º 13
0
 /** Returns information describing the device hardware. */
 public LeapDeviceInfo GetDeviceInfo()
 {
     return(LeapDeviceInfo.GetLeapDeviceInfo());
 }
  protected void Start() {
    if (leapHandController == null) {
      Debug.LogWarning("Camera alignment requires an active LeapHandController -> enabled = false");
      enabled = false;
      return;
    }

    //Get a callback right as rendering begins for this frame so we can update the history and warping.
    LeapVRCameraControl.OnValidCameraParams += onValidCameraParams;

    deviceInfo = provider.GetDeviceInfo();
    if (deviceInfo.type == LeapDeviceType.Invalid) {
      Debug.LogWarning("Invalid Leap Device -> enabled = false");
      enabled = false;
      return;
    }
  }