Beispiel #1
0
    IEnumerator toUpdate()
    {
        bool handInRange = true;

        if (sm.AcquireFrame(true).IsSuccessful())
        {
            // Hand and cursor tracking
            cursorData     = cursorModule.CreateOutput();
            adaptivePoints = new PXCMPoint3DF32();
            coordinates2d  = new PXCMPoint3DF32();
            PXCMCursorData.BodySideType bodySide;

            cursorData.Update();

            // Probando el código de la documentación
            PXCMCapture.Sample sample;
            sample = sm.QueryHandCursorSample();
            image  = sample.depth;


            // Check if alert data has fired
            for (int i = 0; i < cursorData.QueryFiredAlertsNumber(); i++)
            {
                PXCMCursorData.AlertData alertData;
                cursorData.QueryFiredAlertData(i, out alertData);

                if ((alertData.label == PXCMCursorData.AlertType.CURSOR_NOT_DETECTED) ||
                    (alertData.label == PXCMCursorData.AlertType.CURSOR_DISENGAGED) ||
                    (alertData.label == PXCMCursorData.AlertType.CURSOR_OUT_OF_BORDERS))
                {
                    handInRange = false;
                    Debug.Log("¡Tu mano no está en rango!");
                }
                else
                {
                    handInRange = true;
                    Debug.Log("¡Tu mano está en rango!");
                }
            }


            if (cursorData.IsGestureFired(PXCMCursorData.GestureType.CURSOR_CLICK, out gestureData))
            {
                click = true;
                Debug.Log("Click cambiando a true");
            }

            // Track hand cursor if it's within range
            int detectedHands = cursorData.QueryNumberOfCursors();

            if (detectedHands > 0)
            {
                // Retrieve the cursor data by order-based index
                PXCMCursorData.ICursor iCursor;
                cursorData.QueryCursorData(PXCMCursorData.AccessOrderType.ACCESS_ORDER_NEAR_TO_FAR,
                                           0,
                                           out iCursor);

                // Retrieve controlling body side (i.e., left or right hand)
                bodySide = iCursor.QueryBodySide();

                //Debug.Log("Resolución actual: " + Screen.currentResolution.height + ", " + Screen.currentResolution.width);



                adaptivePoints = iCursor.QueryAdaptivePoint();
                imagePoint     = Camera.main.WorldToScreenPoint(iCursor.QueryCursorPointImage());

                //coordinates2d.x = (adaptivePoints.x * resWidth);
                //coordinates2d.y = (adaptivePoints.y * resHeight);
                //Debug.Log("Image point: " + imagePoint.x + ", " + imagePoint.y);
                coordinates2d.x = imagePoint.x;
                coordinates2d.y = resHeight - imagePoint.y;

                //Debug.Log("Current resolution: " + resWidth + "x" + resHeight);
                //Debug.Log("Coordinates2d: " + coordinates2d.x + ", " + coordinates2d.y);

                mousePos = coordinates2d;
                //imagePoint = Camera.main.WorldToScreenPoint(coordinates2d);
                mousePos = Camera.main.WorldToScreenPoint(imagePoint);
                //v3 = Camera.main.WorldToScreenPoint(mousePos);
                //Debug.Log("MousePos: " + mousePos);
            }
            else
            {
                bodySide = PXCMCursorData.BodySideType.BODY_SIDE_UNKNOWN;
            }

            // Resume next frame processing
            cursorData.Dispose();
            sm.ReleaseFrame();
        }
        yield return(null);
    }
Beispiel #2
0
    IEnumerator toUpdate()
    {
        bool handInRange = true;

        if (sm.AcquireFrame(true).IsSuccessful())
        {
            // Hand and cursor tracking
            cursorData = cursorModule.CreateOutput();
            PXCMPoint3DF32 adaptivePoints = new PXCMPoint3DF32();
            PXCMPoint3DF32 coordinates2d  = new PXCMPoint3DF32();
            PXCMCursorData.BodySideType bodySide;

            cursorData.Update();

            // Check if alert data has fired
            for (int i = 0; i < cursorData.QueryFiredAlertsNumber(); i++)
            {
                PXCMCursorData.AlertData alertData;
                cursorData.QueryFiredAlertData(i, out alertData);

                if ((alertData.label == PXCMCursorData.AlertType.CURSOR_NOT_DETECTED) ||
                    (alertData.label == PXCMCursorData.AlertType.CURSOR_DISENGAGED) ||
                    (alertData.label == PXCMCursorData.AlertType.CURSOR_OUT_OF_BORDERS))
                {
                    handInRange = false;
                }
                else
                {
                    handInRange = true;
                }
            }


            if (cursorData.IsGestureFired(PXCMCursorData.GestureType.CURSOR_CLICK, out gestureData))
            {
                click = true;
            }

            // Track hand cursor if it's within range
            int detectedHands = cursorData.QueryNumberOfCursors();

            if (detectedHands > 0)
            {
                // Retrieve the cursor data by order-based index
                PXCMCursorData.ICursor iCursor;
                cursorData.QueryCursorData(PXCMCursorData.AccessOrderType.ACCESS_ORDER_NEAR_TO_FAR,
                                           0,
                                           out iCursor);

                adaptivePoints = iCursor.QueryAdaptivePoint();
                coordinates2d  = iCursor.QueryCursorPointImage();

                // Retrieve controlling body side (i.e., left or right hand)
                bodySide = iCursor.QueryBodySide();

                mousePos = new Vector3(coordinates2d.x, coordinates2d.y, 20);

                v3 = Camera.main.WorldToScreenPoint(mousePos);
            }
            else
            {
                bodySide = PXCMCursorData.BodySideType.BODY_SIDE_UNKNOWN;
            }

            // Resume next frame processing
            cursorData.Dispose();
            sm.ReleaseFrame();
        }
        yield return(null);
    }