public override void Listen()
 {
     // attach the controller to the PXCM sensor
     _senseManager = Session.CreateSenseManager();      
     _senseManager.EnableStream(PXCMCapture.StreamType.STREAM_TYPE_COLOR, 640, 480, 30);
     _senseManager.EnableHand();
     _handModule = _senseManager.QueryHand();
     _handData = _handModule.CreateOutput();
     _handConfiguration = _handModule.CreateActiveConfiguration();
     _handConfiguration.SubscribeGesture(_handGestureHandler);
     _handConfiguration.SubscribeAlert(_handAlertHandler);
     _handConfiguration.EnableAlert(PXCMHandData.AlertType.ALERT_HAND_TRACKED);
     _handConfiguration.EnableAlert(PXCMHandData.AlertType.ALERT_HAND_CALIBRATED);
     _handConfiguration.EnableGesture("full_pinch");
     _handConfiguration.EnableGesture("thumb_up");
     _handConfiguration.ApplyChanges();
     _senseManager.Init(_handler);
     sensorActive = true;
     _senseManager.StreamFrames(true);
     _senseManager.Close();           
     }
    private Hashtable handList;                            //keep track of bodyside and hands for GUItext

    // Use this for initialization
    void Start()
    {
        handList = new Hashtable();

        /* Initialize a PXCMSenseManager instance */
        sm = PXCMSenseManager.CreateInstance();
        if (sm == null)
        {
            Debug.LogError("SenseManager Initialization Failed");
        }

        /* Enable hand tracking and retrieve an hand module instance to configure */
        sts          = sm.EnableHand();
        handAnalyzer = sm.QueryHand();
        if (sts != pxcmStatus.PXCM_STATUS_NO_ERROR)
        {
            Debug.LogError("PXCSenseManager.EnableHand: " + sts);
        }

        /* Initialize the execution pipeline */
        sts = sm.Init();
        if (sts != pxcmStatus.PXCM_STATUS_NO_ERROR)
        {
            Debug.LogError("PXCSenseManager.Init: " + sts);
        }

        /* Retrieve the the DataSmoothing instance */
        sm.QuerySession().CreateImpl <PXCMSmoother>(out smoother);

        /* Create a 3D Weighted algorithm */
        smoother3D = new PXCMSmoother.Smoother3D[MaxHands][];

        /* Configure a hand - Enable Gestures and Alerts */
        PXCMHandConfiguration hcfg = handAnalyzer.CreateActiveConfiguration();

        if (hcfg != null)
        {
            hcfg.EnableAllGestures();
            hcfg.EnableAlert(PXCMHandData.AlertType.ALERT_HAND_NOT_DETECTED);
            hcfg.ApplyChanges();
            hcfg.Dispose();
        }

        InitializeGameobjects();
    }
Example #3
0
    /* Constructor */
    public HandsData(int MaxHands, int MaxJoints)
    {
        NumOfHands  = MaxHands;
        NumOfJoints = MaxJoints;
        JointData   = new PXCMHandData.JointData[NumOfHands][]; // Joint coordinates
        Coordinates = new Main.HandCoord[NumOfHands];

        /* Declaration of the array for the hand data*/
        for (int i = 0; i < NumOfHands; i++)
        {
            JointData[i]   = new PXCMHandData.JointData[NumOfJoints];
            Coordinates[i] = new Main.HandCoord(6, NumOfJoints);
            for (int j = 0; j < NumOfJoints; j++)
            {
                JointData[i][j] = new PXCMHandData.JointData();
            }
        }

        /* Initialization of SenseManager */
        SenseManager = PXCMSenseManager.CreateInstance();
        if (SenseManager == null)
        {
            Debug.LogError("Initialization of the SenseManager has failed");
        }

        /* Enable hand tracking and get an instance of an hand module */
        Status     = SenseManager.EnableHand();
        HandModule = SenseManager.QueryHand();
        if (Status != pxcmStatus.PXCM_STATUS_NO_ERROR)
        {
            Debug.LogError("SenseManager --> EnableHand " + Status);
        }

        /* Create the connection to the Intel RealSense camera */
        Status = SenseManager.Init();
        if (Status != pxcmStatus.PXCM_STATUS_NO_ERROR)
        {
            Debug.LogError("Initialization of SenseManager: " + Status);
        }



        /* Settings for the hand module */
        PXCMHandConfiguration HandConfig = HandModule.CreateActiveConfiguration();

        if (HandConfig != null)
        {
            HandConfig.EnableAllGestures();
            HandConfig.EnableAlert(PXCMHandData.AlertType.ALERT_HAND_NOT_DETECTED);

            PXCMHandData.JointType st = PXCMHandData.JointType.JOINT_WRIST;
            for (int i = 0; i < NumOfJoints; i++)
            {
                HandConfig.EnableJointSpeed(st, PXCMHandData.JointSpeedType.JOINT_SPEED_AVERAGE, 1000 / 10);
                st++;
            }

            //HandConfig.EnableJointSpeed(PXCMHandData.JointType.JOINT_WRIST, PXCMHandData.JointSpeedType.JOINT_SPEED_ABSOLUTE,1000/20);
            HandConfig.ApplyChanges();
            HandConfig.Dispose();
        }
    }
Example #4
0
    private Hashtable handList;                            //keep track of bodyside and hands for GUItext

    // Use this for initialization
    void Start()
    {
        handList = new Hashtable();

        /* Initialize a PXCMSenseManager instance */
        sm = PXCMSenseManager.CreateInstance();
        if (sm == null)
        {
            Debug.LogError("SenseManager Initialization Failed");
        }

        /* Enable hand tracking and retrieve an hand module instance to configure */
        sts          = sm.EnableHand();
        handAnalyzer = sm.QueryHand();
        if (sts != pxcmStatus.PXCM_STATUS_NO_ERROR)
        {
            Debug.LogError("PXCSenseManager.EnableHand: " + sts);
        }

        /* Initialize the execution pipeline */
        sts = sm.Init();
        if (sts != pxcmStatus.PXCM_STATUS_NO_ERROR)
        {
            Debug.LogError("PXCSenseManager.Init: " + sts);
        }

        /* Retrieve the the DataSmoothing instance */
        sm.QuerySession().CreateImpl <PXCMSmoother>(out smoother);

        /* Create a 3D Weighted algorithm */
        smoother3D = new PXCMSmoother.Smoother3D[MaxHands, MaxJoints];

        /* Configure a hand - Enable Gestures and Alerts */
        PXCMHandConfiguration hcfg = handAnalyzer.CreateActiveConfiguration();

        if (hcfg != null)
        {
            hcfg.EnableAllGestures();
            hcfg.EnableAlert(PXCMHandData.AlertType.ALERT_HAND_NOT_DETECTED);
            hcfg.ApplyChanges();
            hcfg.Dispose();
        }

        myJoints = new Joint[MaxHands, MaxJoints];

        Joint[] joints;
        if (RightHand != null)
        {
            HandMapping RightMapping = RightHand.GetComponent <HandMapping>();
            joints = RightMapping.GetJoints();
            for (int j = 0; j < MaxJoints; j++)
            {
                myJoints[0, j] = joints[j];
            }
        }

        if (LeftHand != null)
        {
            HandMapping LeftMapping = LeftHand.GetComponent <HandMapping>();
            joints = LeftMapping.GetJoints();
            for (int j = 0; j < MaxJoints; j++)
            {
                myJoints[1, j] = joints[j];
            }
        }

        jointData = new PXCMHandData.JointData[MaxHands, MaxJoints];

        for (int i = 0; i < MaxHands; i++)
        {
            for (int j = 0; j < MaxJoints; j++)
            {
                Joint joint = myJoints[i, j];
                if (joint != null)
                {
                    joint.originalPosition = joint.transform.position;
                    joint.originalRotation = joint.transform.rotation;

                    //Calculate orientation
                    Vector3 v          = Vector3.zero;
                    Vector3 parent     = joint.transform.position;
                    int     childcount = 0;

                    foreach (Joint.Neighbour n in joint.neighbours)
                    {
                        if (n.index < j)
                        {
                            parent = n.joint.transform.position;
                        }
                        else
                        {
                            v += n.joint.transform.position;
                            childcount++;
                        }
                    }
                    Vector3 direction = v - parent * childcount;
                    joint.originalOrientation = direction + parent - joint.transform.position;

                    //Joint extensions
                    foreach (Joint e in joint.extensions)
                    {
                        e.originalPosition    = e.transform.position;
                        e.originalRotation    = e.transform.rotation;
                        e.originalOrientation = joint.transform.position - e.transform.position;
                    }
                }

                smoother3D[i, j] = smoother.Create3DWeighted(smoothing);
                jointData[i, j]  = new PXCMHandData.JointData();

                //Test output to check Hand Mapping
                if (myJoints[i, j] == null)
                {
                    Debug.Log("null");
                }
                else
                {
                    Debug.Log(myJoints[i, j].transform.name);
                }
            }
        }
    }