//Populate bones and joints gameobjects
    void InitializeGameobjects()
    {
        myJoints  = new GameObject[MaxHands][];
        myBones   = new GameObject[MaxHands][];
        jointData = new PXCMHandData.JointData[MaxHands][];
        for (int i = 0; i < MaxHands; i++)
        {
            myJoints[i]   = new GameObject[MaxJoints];
            myBones[i]    = new GameObject[MaxJoints];
            smoother3D[i] = new PXCMSmoother.Smoother3D[MaxJoints];
            jointData[i]  = new PXCMHandData.JointData[MaxJoints];
        }

        for (int i = 0; i < MaxHands; i++)
        {
            for (int j = 0; j < MaxJoints; j++)
            {
                smoother3D[i][j] = smoother.Create3DWeighted(weightsNum);
                jointData[i][j]  = new PXCMHandData.JointData();

                if (j == 1)
                {
                    myJoints[i][j] = (GameObject)Instantiate(PalmCenterPrefab, Vector3.zero, Quaternion.identity);
                }
                else if (j == 21 || j == 17 || j == 13 || j == 9 || j == 5)
                {
                    myJoints[i][j] = (GameObject)Instantiate(TipPrefab, Vector3.zero, Quaternion.identity);
                }
                else
                {
                    myJoints[i][j] = (GameObject)Instantiate(JointPrefab, Vector3.zero, Quaternion.identity);
                }

                if (j != 1)
                {
                    myBones[i][j] = (GameObject)Instantiate(BonePrefab, Vector3.zero, Quaternion.identity);
                }
            }
        }
    }
Esempio n. 2
0
    private void CreateSmootherType(SmoothingTypes type, float factor, out PXCMSmoother.Smoother3D smoother)
    {
        switch (type)
        {
        case SmoothingTypes.Quadratic:
            smoother = _smoother.Create3DQuadratic(factor);
            break;

        case SmoothingTypes.Stabilizer:
            smoother = _smoother.Create3DStabilizer(7, factor);
            break;

        case SmoothingTypes.Weighted:
            smoother = _smoother.Create3DWeighted((int)factor);
            break;

        case SmoothingTypes.Spring:
        default:
            smoother = _smoother.Create3DSpring(factor);
            break;
        }
    }
Esempio n. 3
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);
                }
            }
        }
    }