Example #1
0
    /// <summary>
    /// Update the glove data once per frame.
    /// </summary>
    void Update()
    {
        // update glove data
        uint numGlovesEnabled = 0;

        CyberGloveUnityPlugin.CyberGloveData cd = new CyberGloveUnityPlugin.CyberGloveData();
        cd.palmPos      = new Vector3(0.0f, 0.0f, 0.0f);
        cd.palmRot_quat = new Quaternion(0.0f, 0.0f, 0.0f, 1.0f);

        for (int i = 0; i < MAX_GLOVES; i++)
        {
            if (m_Gloves[i] != null)
            {
                if (i == 0)              // GLOVE 0 IS TAKEN AS RIGHT GLOVE
                {
                    if (RGConn == true)

                    {
                        CyberGloveUnityPlugin.UpdateRightGrasp();
                        float[] palmPos_arr = { 0.0f, 0.0f, 0.0f };
                        float[] palmRot_arr = { 0.0f, 0.0f, 0.0f, 1.0f };

                        CyberGloveUnityPlugin.GetPalmsPositionRT(palmPos_arr);
                        cd.palmPos.Set(palmPos_arr[0], palmPos_arr[1], palmPos_arr[2]);

                        cd.which_hand = (int)CyberGloveHandedness.RIGHT;

                        CyberGloveUnityPlugin.GetPalmsRotationRT(palmRot_arr);
                        cd.palmRot_quat.Set(palmRot_arr[0], palmRot_arr[1], palmRot_arr[2], palmRot_arr[3]);


                        for (int finger = 0; finger < 5; finger++)
                        {
                            for (int joint = 0; joint < 4; joint++)
                            {
                                float[] fingerJointPos_arr = { 0.0f, 0.0f, 0.0f };
                                float[] fingerJointRot_arr = { 0.0f, 0.0f, 0.0f, 1.0f };

                                CyberGloveUnityPlugin.GetFingersPositionRT(finger, joint, fingerJointPos_arr);
                                cd.fingerJointPos[finger, joint].Set(fingerJointPos_arr[0], fingerJointPos_arr[1], fingerJointPos_arr[2]);

                                CyberGloveUnityPlugin.GetFingersRotationRT(finger, joint, fingerJointRot_arr);
                                cd.fingerJointRot_quat[finger, joint].Set(fingerJointRot_arr[0], fingerJointRot_arr[1], fingerJointRot_arr[2], fingerJointRot_arr[3]);
                            }
                        }
                        m_Gloves[i].Update(ref cd);
                        m_Gloves[i].SetEnabled(true);
                        numGlovesEnabled++;
                    }
                    else
                    {
                        m_Gloves[i].SetEnabled(false);
                    }
                }
                else if (i == 1)              // GLOVE 1 IS TAKEN AS LEFT GLOVE
                {
                    if (LGConn == true)

                    {
                        CyberGloveUnityPlugin.UpdateLeftGrasp();
                        float[] palmPos_arr = { 0.0f, 0.0f, 0.0f };
                        float[] palmRot_arr = { 0.0f, 0.0f, 0.0f, 1.0f };

                        CyberGloveUnityPlugin.GetPalmsPositionLT(palmPos_arr);
                        cd.palmPos.Set(palmPos_arr[0], palmPos_arr[1], palmPos_arr[2]);

                        cd.which_hand = (int)CyberGloveHandedness.LEFT;

                        CyberGloveUnityPlugin.GetPalmsRotationLT(palmRot_arr);
                        cd.palmRot_quat.Set(palmRot_arr[0], palmRot_arr[1], palmRot_arr[2], palmRot_arr[3]);


                        for (int finger = 0; finger < 5; finger++)
                        {
                            for (int joint = 0; joint < 4; joint++)
                            {
                                float[] fingerJointPos_arr = { 0.0f, 0.0f, 0.0f };
                                float[] fingerJointRot_arr = { 0.0f, 0.0f, 0.0f, 1.0f };

                                CyberGloveUnityPlugin.GetFingersPositionLT(finger, joint, fingerJointPos_arr);
                                cd.fingerJointPos[finger, joint].Set(fingerJointPos_arr[0], fingerJointPos_arr[1], fingerJointPos_arr[2]);

                                CyberGloveUnityPlugin.GetFingersRotationLT(finger, joint, fingerJointRot_arr);
                                cd.fingerJointRot_quat[finger, joint].Set(fingerJointRot_arr[0], fingerJointRot_arr[1], fingerJointRot_arr[2], fingerJointRot_arr[3]);
                            }
                        }
                        m_Gloves[i].Update(ref cd);
                        m_Gloves[i].SetEnabled(true);
                        numGlovesEnabled++;
                    }
                    else
                    {
                        m_Gloves[i].SetEnabled(false);
                    }
                }
            }
        }
    }