Ejemplo 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);
    }
Ejemplo n.º 2
0
    /// <summary> Check if a device manager is currently active within the Scene. If not, create an instance to manager our connection(s). </summary>
    protected void CheckForDeviceManager()
    {
        SenseGlove_DeviceManager manager = null;

        if (!SenseGlove_Object.deviceScannerPresent)
        {
            object deviceManagerObj = GameObject.FindObjectOfType(typeof(SenseGlove_DeviceManager));
            if (deviceManagerObj != null) //it exists
            {
                manager = (SenseGlove_DeviceManager)deviceManagerObj;
                if (!manager.isActiveAndEnabled || !manager.gameObject.activeInHierarchy)
                {
                    Debug.LogWarning("WARNING: The SenseGlove_DeviceManager is not active in the scene. Objects will not connect until it is active.");
                }
            }
            else
            {
                GameObject newdeviceManager = new GameObject("[SG DeviceManager]");
                manager = newdeviceManager.AddComponent <SenseGlove_DeviceManager>();
            }
            SenseGlove_Object.deviceScannerPresent = true; //we have either found it or created it.
        }
        else //it already exists
        {
            manager = (SenseGlove_DeviceManager)GameObject.FindObjectOfType(typeof(SenseGlove_DeviceManager));
        }

        if (manager != null && this.autoConnect) //redundant check.
        {
            manager.AddToWatchList(this);        //make sure this glove is added to its watchlist.
        }
    }
Ejemplo n.º 3
0
        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;
            }
        }