Esempio n. 1
0
    //--------------------------------------------------------------------------------------------------------------------------
    // Connection Methods

    /// <summary> Link this Sense Glove to one of the SenseGlove_Manager's detected gloves. </summary>
    /// <param name="gloveIndex"></param>
    public bool LinkToGlove(int gloveIndex)
    {
        if (!this.IsLinked)
        {
            this.trackedGloveIndex  = gloveIndex;
            this.actualTrackedIndex = gloveIndex;
            this.linkedGlove        = SenseGlove_DeviceManager.GetSenseGlove(gloveIndex);

            this.linkedGlove.OnFingerCalibrationFinished += LinkedGlove_OnCalibrationFinished;
            //TODO: Subscribe to more events if needed

            //uodating once so glovedata is available, but not through the UpdateHand command, as that one needs the glove to already be connected.
            SenseGloveCs.GloveData rawData = this.linkedGlove.Update(UpdateLevel.HandPositions, this.solver, this.limitFingers, this.updateWrist, new Quat(0, 0, 0, 1), false);
            this.linkedGloveData = new SenseGlove_Data(rawData);

            this.OnGloveLink(); //Fire glove linked event.

            return(true);
        }
        else
        {
            Debug.LogWarning("Could not Link the Sense Glove because it has already been assigned. Unlink it first bu calling the UnlinkGlove() Method.");
        }
        return(false);
    }
        void UpdateAngles()
        {
            if (this.glove != null && glove.GloveReady)
            {
                float[][] angles            = this.glove.GloveData.gloveValues;
                SenseGloveCs.GloveData data = SenseGlove_DeviceManager.GetSenseGlove(this.glove.GloveIndex).gloveData;

                string msg = "";
                for (int f = 0; f < angles.Length; f++)
                {
                    for (int j = 0; j < angles[f].Length; j++)
                    {
                        msg += (int)Mathf.Round(SenseGloveCs.Values.Degrees(angles[f][j]));


                        msg += "/";
                        if (j == 0)
                        {
                            msg += (int)Mathf.Round(SenseGloveCs.Values.Degrees(data.kinematics.gloveLinks[f].joints[j].relativeAngle.z));
                        }
                        else
                        {
                            msg += (int)Mathf.Round(SenseGloveCs.Values.Degrees(data.kinematics.gloveLinks[f].joints[j + 1].relativeAngle.y));
                        }

                        if (j < angles[f].Length - 1)
                        {
                            msg += " \t";
                        }
                    }
                    msg += "\r\n";
                }
                this.text.text = msg;
            }
        }