コード例 #1
0
    private void SetupWrist()
    {
        if (this.glove != null && this.glove.gloveData.dataLoaded)
        {
            string ID = this.gloveData.deviceID;


            if (this.gloveData.firmwareVersion <= 2.19f)
            {
                if (ID.Contains("120206"))
                {
                    this.glove.gloveData.wrist.SetHardwareOrientation(Quat.FromEuler(Mathf.PI / 2.0f, 0, Mathf.PI)); //correction for glove 1
                    SenseGlove_Debugger.Log("Firmware Version v2.19 or earlier. Adding Hardware Compensation");
                }
                else if (ID.Contains("120101"))
                {
                    this.glove.gloveData.wrist.SetHardwareOrientation(Quat.FromEuler(Mathf.PI, 0, 0)); //correction for glove 1
                    SenseGlove_Debugger.Log("Firmware Version v2.19 or earlier. Adding Hardware Compensation");
                }
                else if (ID.Contains("120203"))
                {
                    this.glove.gloveData.wrist.SetHardwareOrientation(Quat.FromEuler(0, 0, Mathf.PI / 2.0f)); //correction?
                    SenseGlove_Debugger.Log("Firmware Version v2.19 or earlier. Adding Hardware Compensation");
                }
                else if (ID.Contains("120307") || ID.Contains("120304") || ID.Contains("120310") || ID.Contains("120309") || ID.Contains("120311") || ID.Contains("120312"))
                {
                    this.glove.gloveData.wrist.SetHardwareOrientation(Quat.FromEuler(0, 0, Mathf.PI)); //correction for glove 7 & 4?
                    SenseGlove_Debugger.Log("Firmware Version v2.19 or earlier. Adding Hardware Compensation");
                }
            }
        }
    }
コード例 #2
0
    /// <summary> Remove an object from this dropzone and restore its original settings. </summary>
    /// <param name="objectIndex"></param>
    public void RemoveObject(int objectIndex)
    {
        //SenseGlove_Debugger.Log("The script wishes to remove " + objectIndex);
        if (objectIndex >= 0 && objectIndex < this.objectsInside.Count)
        {
            SenseGlove_Debugger.Log("removing " + this.objectsInside[objectIndex].name + " from the DropZone!");
            SenseGlove_Grabable obj = this.objectsInside[objectIndex];

            SenseGlove_Debugger.Log("RBProps.lengh = " + RBprops.Count);

            if (obj.GetComponent <Rigidbody>() != null && RBprops[objectIndex] != null)
            {   //if it is currently picked up, we assign the previous properties to its grabscript, which will then apply them once it lets go.
                SenseGlove_Debugger.Log("It has a physicsBody");
                if (obj.IsGrabbed())
                {
                    obj.SetOriginalParent(this.originalParent[objectIndex]);
                    obj.SetRBProps(this.RBprops[objectIndex][0], this.RBprops[objectIndex][1]);
                }
                else
                {
                    obj.transform.parent        = this.originalParent[objectIndex];
                    obj.physicsBody.useGravity  = this.RBprops[objectIndex][0];
                    obj.physicsBody.isKinematic = this.RBprops[objectIndex][1];
                }
            }

            this.objectsInside.RemoveAt(objectIndex);
            SenseGlove_Debugger.Log("Removed it from ObjectsInside!");
            this.RBprops.RemoveAt(objectIndex);
            this.originalParent.RemoveAt(objectIndex);

            obj.SetInteractable(true); //now the function can also be used to force removal of the object.
            this.OnObjectRemoved(obj);
        }
    }
コード例 #3
0
 // Update is called once per frame
 void Update()
 {
     if (Input.GetKeyDown(resetKey))
     {
         SenseGlove_Debugger.Log("Reset!");
         this.Reset();
     }
 }
コード例 #4
0
    //--------------------------------------------------------------------------------------------------------------------------
    // Internal Calibration Algorithms

    #region InternalCalibration

    /// <summary> Reset the Calibration of the glove if, for instance, something went wrong, or if we are shutting down. </summary>
    public void CancelCalibration()
    {
        if (linkedGlove != null)
        {
            linkedGlove.StopCalibration();
            SenseGlove_Debugger.Log("Canceled Calibration");
        }
    }
コード例 #5
0
 // Runs every frame
 private void Update()
 {
     if (Input.GetKeyDown(this.resetCalibrationKey))
     {
         SenseGlove_Debugger.Log("Resetting Hand Parameters");
         this.senseGlove.ResetKinematics();
     }
 }
コード例 #6
0
    //------------------------------------------------------------------------------------------------------------------------------------
    // (Semi)Automatic Calibration Steps


    /// <summary> Start a semi-automatic calibration of the thumb, using thumb abduction. </summary>
    public void CalibrateThumb()
    {
        if (this.GloveReady())
        {
            SenseGlove_Debugger.Log("Calibrating Thumb");
            CalibrationAlgorithm algorithm = new Circle2D(new bool[] { true, false, false, false, false });
            this.glove.StartSemiAutoCalibration(algorithm, true, 10, 1f, 5);
        }
    }
コード例 #7
0
 /// <summary> Fires when the Sense Glove has calculated new finger Lengths. </summary>
 /// <param name="source"></param>
 /// <param name="args"></param>
 private void SenseGlove_OnCalibrationFinished(object source, CalibrationArgs args)
 {
     if (this.canUpdate)
     {
         //the new gloveLengths have already been applied to the SenseGlove-Object, but should be updated in the database.
         HandProfile updatedProfile = new HandProfile(args.newFingerLengths);
         UserProfiles.AddEntry(this.userName, updatedProfile); //update / add entry
         SenseGlove_Debugger.Log("Updated " + this.userName);
     }
 }
コード例 #8
0
 /// <summary>
 /// Calibrate the Wrist, based on the orientation of the foreArm.
 /// </summary>
 /// <returns></returns>
 public bool CalibrateWrist()
 {
     if (glove != null && glove.IsConnected() && foreArm != null)
     {
         glove.CalibrateWrist(null, SenseGlove_Util.ToQuaternion(this.foreArm.transform.rotation));
         SenseGlove_Debugger.Log("Calibrated Wrist");
         return(true);
     }
     return(false);
 }
コード例 #9
0
 /// <summary>
 /// Set the current lowerArm quaternion as the 'zero'
 /// </summary>
 /// <param name="lowerArm"></param>
 /// <returns></returns>
 public bool CalibrateWrist(Quaternion lowerArm)
 {
     if (glove != null && glove.IsConnected())
     {
         glove.CalibrateWrist(null, SenseGlove_Util.ToQuaternion(lowerArm));
         SenseGlove_Debugger.Log("Calibrated Wrist");
         return(true);
     }
     return(false);
 }
コード例 #10
0
 /// <summary> Reset the Calibration of the glove if, for instance, something went wrong. </summary>
 public void CancelCalibration()
 {
     if (glove != null)
     {
         glove.StopCalibration();
         this.calSteps    = 0;
         this.calibrating = false;
         SenseGlove_Debugger.Log("Canceled Calibration");
     }
 }
コード例 #11
0
    private void TrackedGlove_OnCalibrationFinished(object source, CalibrationArgs args)
    {
        SenseGlove_Debugger.Log("Resizing Model.");
        //Debug.Log( "Old: " + SenseGlove_Util.ToString(args.oldJointPositions[1]) + ", New: " + SenseGlove_Util.ToString(args.newJointPositions[1]));
        Vector3 dJoints = args.newJointPositions[1] - args.oldJointPositions[1];

        this.RescaleHand(args.newFingerLengths);
        this.handGroup.transform.localPosition  = this.handGroup.transform.localPosition - dJoints;
        this.gloveGroup.transform.localPosition = this.gloveGroup.transform.localPosition - dJoints;
    }
コード例 #12
0
    // Update is called once per frame
    void Update()
    {
        if (this.senseGlove != null)
        {
            if (Input.GetKeyDown(this.calibrateWristKey))
            {
                this.senseGlove.CalibrateWrist();
            }

            ///////

            if (Input.GetKeyDown(this.calibrateFingersKey))
            {
                this.senseGlove.StartCalibration();
            }

            ///////

            if (Input.GetKeyDown(this.manualCalibrationKey))
            {
                this.senseGlove.NextCalibrationStep(this.calibrateFingersKey);
            }

            ////////

            if (Input.GetKeyDown(this.cancelCalibrationKey))
            {
                this.senseGlove.CancelCalibration();
            }

            /////////

            if (Input.GetKeyDown(this.calibrateThumb))
            {
                this.senseGlove.CalibrateThumb();
            }

            /////////

            if (Input.GetKeyDown(this.resetFingerLengthsKey))
            {
                SenseGlove_Debugger.Log("Reset Fingers");
                this.senseGlove.ResetFingers();
            }
        }

        if (grabScript != null)
        {
            if (Input.GetKeyDown(this.releaseObjectKey))
            {
                this.grabScript.ManualRelease(this.releaseTimeOut);
            }
        }
    }
コード例 #13
0
 // OnApplicationQuit is called when the game shuts down.
 void OnApplicationQuit()
 {
     this.CancelCalibration();
     if (glove != null && glove.IsConnected())
     {
         glove.SimpleBrakeCmd(0, 0, 0, 0, 0);
         glove.Disconnect();
         SenseGlove_Debugger.Log("Disconnected the SenseGlove on " + glove.communicator.Address());
     }
     SenseGloveCs.DeviceScanner.CleanUp();
 }
コード例 #14
0
    void Start()
    {
        if (!this.CanInteract())
        {
            SenseGlove_Debugger.Log("Warning: " + this.name + " is unable to pick up anything.");
        }

        if (this.senseGlove == null)
        {
            this.senseGlove = this.GetComponent <SenseGlove_Object>();
        }
    }
コード例 #15
0
 /// <summary> Dispose of resources. </summary>
 private void Dispose()
 {
     this.CancelCalibration();
     if (glove != null && glove.IsConnected())
     {
         glove.StopBrakes();
         glove.StopBuzzMotors();
         glove.Disconnect();
         SenseGlove_Debugger.Log("Disconnected the SenseGlove on " + glove.communicator.Address());
     }
     this.Disconnect();
 }
コード例 #16
0
    /// <summary> Add an object to this DropZone, and apply the desired settings. </summary>
    /// <param name="obj"></param>
    public void AddObject(SenseGlove_Grabable obj)
    {
        SenseGlove_Debugger.Log("Adding " + obj.name + " to the DropZone!");

        // remember original parent
        if (obj.IsGrabbed())
        {
            this.originalParent.Add(obj.GetOriginalParent());
        }
        else
        {
            this.originalParent.Add(obj.transform.parent);
        }

        bool[] props = null;

        if (this.snapToMe && (this.takeFromHand || !obj.IsGrabbed()))
        {
            obj.EndInteraction();
            Transform zoneParent = this.snapTarget;
            if (zoneParent == null)
            {
                zoneParent = this.gameObject.transform;
            }

            obj.gameObject.transform.parent        = zoneParent;
            obj.gameObject.transform.localPosition = Vector3.zero;
            obj.gameObject.transform.localRotation = Quaternion.identity;

            Rigidbody RB = obj.physicsBody;
            if (RB != null)
            {
                if (obj.IsGrabbed())
                {
                    props = obj.GetRBProps();
                }
                else
                {
                    props = new bool[2] {
                        RB.useGravity, RB.isKinematic
                    };
                }
                RB.useGravity  = false;
                RB.isKinematic = true;
            }
        }

        this.RBprops.Add(props);
        this.objectsInside.Add(obj);
        obj.SetInteractable(!this.disableInteration); //enable / disable interactions.
        this.OnObjectDetected(obj);
    }
コード例 #17
0
    /// <summary>
    /// Disconnect and retry the connecting to the SenseGlove,
    /// such as when a different glove is connected or when the (manual) connection is lost.
    /// </summary>
    public void RetryConnection()
    {
        this.Disconnect();
        if (this.connectionMethod != ConnectionMethod.HardCoded)
        {
            if (!SenseGloveCs.DeviceScanner.IsScanning())
            {
                SenseGloveCs.DeviceScanner.pingTime  = 200;
                SenseGloveCs.DeviceScanner.scanDelay = 500;
                SenseGloveCs.DeviceScanner.StartScanning(true);
            }
        }
        else //we're dealing with a custom connection!
        {
            if (canReport)
            {
                SenseGlove_Debugger.Log("Attempting to connect to " + this.address);
            }
            Communicator PCB = null;
            if (this.address.Contains("COM")) //Serial connections
            {
                if (this.address.Length > 4 && this.address.Length < 6)
                {
                    this.address = "\\\\.\\" + this.address;
                }
                PCB = new SerialCommunicator(this.address);
            }
            if (PCB != null)
            {
                PCB.Connect();
                if (PCB.IsConnected())
                {
                    this.glove = new SenseGlove(PCB);
                    this.glove.OnFingerCalibrationFinished += Glove_OnFingerCalibrationFinished;
                }
                else if (canReport)
                {
                    SenseGlove_Debugger.Log("ERROR: Could not connect to " + this.address);
                    canReport = false;
                }
            }
            else if (canReport)
            {
                SenseGlove_Debugger.Log("ERROR: " + this.address + " is not a valid address.");
                canReport = false;
            }
        }


        this.elapsedTime = 0;
        this.standBy     = false;
    }
コード例 #18
0
 /// <summary> Check if two SenseGlove_Touch scripts are touching the same object </summary>
 /// <param name="other"></param>
 /// <returns></returns>
 public bool IsTouching(SenseGlove_Touch other)
 {
     if (other == null)
     {
         SenseGlove_Debugger.Log("Other is Null");
     }
     else
     if (this.touchedObject != null && other.touchedObject != null)
     {
         return(GameObject.ReferenceEquals(this.touchedObject, other.touchedObject));
     }
     return(false);
 }
コード例 #19
0
        /// <summary> Retrieve the Material properties from the chosen Library. </summary>
        /// <param name="libName"></param>
        /// <param name="matName"></param>
        /// <returns></returns>
        public static MaterialProps GetMaterial(string matName)
        {
            matName = matName.ToLowerInvariant(); //always convert to lower case to prevent typos on Dev/User side;
            MaterialProps res;

            if (materials.TryGetValue(matName, out res))
            {
                return(res);
            }
            else
            {
                SenseGlove_Debugger.Log("Error loading " + matName + ": No such material loaded.");
            }
            return(MaterialProps.Default());
        }
コード例 #20
0
    private void TrackedGlove_OnGloveLoaded(object source, System.EventArgs args)
    {
        SenseGlove_Debugger.Log("Setting up WireFrame...");
        SetupGlove(trackedGlove.GloveData());
        SetupHand(trackedGlove.GloveData());
        SetGlove(false);    //hide the glove by default.
        SetHand(true);      //show the hand by default.
        SetupGrabColliders();
        this.setupComplete = true;

        //remove the preview models, if any are available
        if (this.preview != null)
        {
            Destroy(this.preview);
        }
    }
コード例 #21
0
    //--------------------------------------------------------------------------------------
    //  Profile / Class Methods

    /// <summary> If this user exists within the database, apply their hand profile to this SenseGlove_Object. </summary>
    /// <param name="userName"></param>
    public void SetProfile(string name)
    {
        if (userName != null && userName.Length > 0)
        {
            this.canUpdate = false;
            this.userName  = name;
            UserProfiles.SetLastUser(this.userName, this.senseGlove.GloveData().deviceID);
            HandProfile newProfile = UserProfiles.GetProfile(name);
            this.SetProfile(newProfile);
            SenseGlove_Debugger.Log("Set Profile for " + this.userName);
            this.canUpdate = true; //prevent additional calls to fingerCalibrationFinished while we update the profile.
        }
        else
        {
            SenseGlove_Debugger.LogWarning("Invalid Username");
        }
    }
コード例 #22
0
    /// <summary> Apply the profile when the Sense Glove has loaded </summary>
    /// <param name="source"></param>
    /// <param name="args"></param>
    private void SenseGlove_OnGloveLoaded(object source, System.EventArgs args)
    {
        //check if a profile is already established for this glove. If not assign the name of this glove.
        string ID           = this.senseGlove.GloveData().deviceID;
        string lastUsedName = UserProfiles.GetLastUser(ID);

        if (lastUsedName.Length > 0)
        {   //a lastUsedName exits
            this.userName = lastUsedName;
        }
        else
        {   //not been assigned yet, tell the database this is the new lastUser
            UserProfiles.SetLastUser(this.userName, ID);
        }
        this.SetProfile(UserProfiles.GetProfile(this.userName));
        SenseGlove_Debugger.Log("Applied profile for " + userName);
        this.canUpdate = true;
    }
コード例 #23
0
    //------------------------------------------------------------------------------------------------------------------------------------
    // Backwards Compatibility Methods

    #region BackwardsComp

    /// <summary> Manually assign IMU Correction for old firmware versions. </summary>
    private void SetupWrist()
    {
        if (this.glove != null && this.glove.gloveData.dataLoaded)
        {
            string ID = this.gloveData.deviceID;

            if (ID.Contains("220102"))
            {
                this.glove.gloveData.wrist.SetHardwareOrientation(Quaternions.FromEuler(Mathf.PI, 0, Mathf.PI / 2.0f)); //correction for glove 1
                SenseGlove_Debugger.Log("Red Glove Compensation");
            }

            string[] gloveVersion = this.gloveData.firmwareVersion.Split('.');
            if (gloveVersion[0][0] == 'v')
            {
                gloveVersion[0] = gloveVersion[0].Substring(1);
            }                                                                                  //if there is a v in front of it, remove this.
            int mainVersion = int.Parse(gloveVersion[0]);
            int subVersion  = int.Parse(gloveVersion[1]);
            if (mainVersion <= 2 && subVersion <= 19)
            {
                if (ID.Contains("120206"))
                {
                    this.glove.gloveData.wrist.SetHardwareOrientation(Quaternions.FromEuler(Mathf.PI / 2.0f, 0, Mathf.PI)); //correction for glove 1
                    SenseGlove_Debugger.Log("Firmware Version v2.19 or earlier. Adding Hardware Compensation");
                }
                else if (ID.Contains("120101"))
                {
                    this.glove.gloveData.wrist.SetHardwareOrientation(Quaternions.FromEuler(Mathf.PI, 0, 0)); //correction for glove 1
                    SenseGlove_Debugger.Log("Firmware Version v2.19 or earlier. Adding Hardware Compensation");
                }
                else if (ID.Contains("120203"))
                {
                    this.glove.gloveData.wrist.SetHardwareOrientation(Quaternions.FromEuler(0, 0, Mathf.PI / 2.0f)); //correction?
                    SenseGlove_Debugger.Log("Firmware Version v2.19 or earlier. Adding Hardware Compensation");
                }
                else if (ID.Contains("120307") || ID.Contains("120304") || ID.Contains("120310") || ID.Contains("120309") || ID.Contains("120311") || ID.Contains("120312"))
                {
                    this.glove.gloveData.wrist.SetHardwareOrientation(Quaternions.FromEuler(0, 0, Mathf.PI)); //correction for glove 7 & 4?
                    SenseGlove_Debugger.Log("Firmware Version v2.19 or earlier. Adding Hardware Compensation");
                }
            }
        }
    }
コード例 #24
0
    /// <summary>
    /// Perform the next calibration step of the fingers. If we are not already calibrating, start the calibration!
    /// </summary>
    /// <param name="calibrationKey">The key used to call this method, used for the debug messages.</param>
    public void NextCalibrationStep(KeyCode calibrationKey)
    {
        if (glove != null && gloveReady)
        {
            if (!calibrating)
            {
                this.CancelCalibration();
                this.StartCalibration(new bool[] { false, true, true, true, true }, true);
                calSteps = 0;
                // SenseGlove_Debugger.Log("Calibrate is called : " + calSteps);
            }
            else if (calSteps <= 3)
            {
                this.NextCalibrationStep();
                // SenseGlove_Debugger.Log("NextStep is called : " + calSteps);
            }

            if (calSteps == 0)
            {
                calibrating = true;
                SenseGlove_Debugger.Log("Started Calibration. Please stretch your fingers in front of you and press " + calibrationKey.ToString());
                calSteps++;
            }
            else if (calSteps == 1)
            {
                SenseGlove_Debugger.Log("Step 1 completed. Please bend you MCP joint to 45* and press " + calibrationKey.ToString());
                calSteps++;
            }
            else if (calSteps == 2)
            {
                SenseGlove_Debugger.Log("Step 2 completed. Please bend you MCP joint to 90* and press " + calibrationKey.ToString());
                calSteps++;
            }
            else
            {
                SenseGlove_Debugger.Log("Step 3 completed. Calibration has finished.");
                calibrating = false;
                calSteps    = 0;
            }
        }
    }
コード例 #25
0
    /// <summary> Collect the absolute angles of the fingers in their 'calibration' pose, correct these with the current wrist orientation. </summary>
    protected virtual void CollectCorrections() //virtual
    {
        if (this.fingerJoints != null && this.fingerJoints.Count > 0)
        {
            this.fingerCorrection.Clear();
            for (int f = 0; f < this.fingerJoints.Count; f++)
            {
                List <Quaternion> fingerAngles = new List <Quaternion>();
                for (int j = 0; j < this.fingerJoints[f].Count; j++)
                {
                    fingerAngles.Add(Quaternion.Inverse(this.wristTransfrom.rotation) * this.fingerJoints[f][j].rotation);
                }
                this.fingerCorrection.Add(fingerAngles);
            }
        }
        else
        {
            SenseGlove_Debugger.Log("Warning: No finger joints were collected...");
        }

        this.wristCorrection = Quaternion.Inverse(this.foreArmTransfrom.rotation) * this.wristTransfrom.rotation;
    }
コード例 #26
0
    /// <summary> Activate the next step of the Sense Glove's manual calibration sequence; reporting the next step. </summary>
    /// <param name="calibrationKey"></param>
    /// <returns></returns>
    public bool NextCalibrationStep(KeyCode calibrationKey)
    {
        if (!this.IsCalibrating())
        {
            // Start a new Calibration
            CalibrateVariable whatTo = CalibrateVariable.FingerVariables;

            //TODO : Make this dependant on solvers

            bool strt = this.StartCalibration(whatTo, CollectionMethod.Manual);
            if (strt)
            {
                SenseGlove_Debugger.Log("Started Calibration. Please stretch your fingers in front of you and press " + calibrationKey.ToString());
                return(true);
            }
        }
        else
        {
            bool added = this.glove.NextCalibrationStep();
            if (added)
            {
                this.convertedGloveData.calibrationStep = this.convertedGloveData.calibrationStep + 1;
                if (this.convertedGloveData.calibrationStep == 1)
                {
                    SenseGlove_Debugger.Log("Step 1 completed. Please bend you MCP joint to 45* and press " + calibrationKey.ToString());
                }
                else if (this.convertedGloveData.calibrationStep == 2)
                {
                    SenseGlove_Debugger.Log("Step 2 completed. Please bend you MCP joint to 90* and press " + calibrationKey.ToString());
                }
                else if (this.convertedGloveData.calibrationStep == 3)
                {
                    SenseGlove_Debugger.Log("Step 3 completed. Calculating...");
                }
            }
        }
        return(false);
    }
コード例 #27
0
 /// <summary> Connect this Grabable's rigidBody to another using a FixedJoint </summary>
 /// <param name="other"></param>
 /// <returns>True, if the connection was sucesfully made.</returns>
 public bool ConnectJoint(Rigidbody other, float breakForce = 4000)
 {
     if (other != null)
     {
         if (this.physicsBody)
         {
             this.connection = this.physicsBody.gameObject.AddComponent <FixedJoint>();
             this.connection.connectedBody   = other;
             this.connection.enableCollision = false;
             this.connection.breakForce      = breakForce;
             return(true);
         }
         else
         {
             SenseGlove_Debugger.Log("Using a FixedJoint connection requires a Rigidbody.");
         }
     }
     else
     {
         SenseGlove_Debugger.Log("No rigidbody to connect to " + other.name);
     }
     return(false);
 }
コード例 #28
0
 /// <summary>  If this WireFrame model has a grabscript, attach the appropriate colliders. </summary>
 private void SetupGrabColliders()
 {
     if (!this.setupComplete)
     {
         SenseGlove_PhysGrab grabscript = this.GetComponent <SenseGlove_PhysGrab>();
         if (grabscript != null)
         {
             //attack capsule colliders to the fingers
             SenseGlove_Debugger.Log("Grabscript detected! Attaching colliders.");
             List <List <Collider> > pickups = new List <List <Collider> >();
             for (int f = 0; f < handPositions.Length; f++) //DEBUG : Only thumb & index
             {
                 List <Collider> fingerColliders = new List <Collider>();
                 GameObject      fingerTip       = this.handPositions[f][handPositions[f].Length - 1];
                 SphereCollider  C = fingerTip.AddComponent <SphereCollider>();
                 //        C.radius = grabscript.pickupColliderSize; //determine collider size
                 fingerColliders.Add(C);
                 pickups.Add(fingerColliders);
             }
             grabscript.Setup(pickups, this.palmCollider);
         }
         //else try other forms of grabscripts
     }
 }
コード例 #29
0
    // Update is called once per frame
    void Update()
    {
        if (!standBy)
        {
            if (this.elapsedTime < SenseGlove_Object.setupTime)
            {
                this.elapsedTime += Time.deltaTime;
            }
            else if (this.glove == null) //No connection yet...
            {
                if (this.connectionMethod == ConnectionMethod.HardCoded)
                {
                    //no glove was ever assigned...
                    this.RetryConnection(); //keep trying!
                }
                else
                {
                    SenseGlove myGlove = ExtractSenseGlove(SenseGloveCs.DeviceScanner.GetDevices());
                    if (myGlove != null) //The glove matches our parameters!
                    {
                        this.glove = myGlove;
                        SenseGlove_Manager.SetUsed(this.glove.GetData(false).deviceID, true);
                        this.glove.OnFingerCalibrationFinished += Glove_OnFingerCalibrationFinished;
                    }
                    else
                    {
                        if (this.canReport)
                        {
                            string message = this.gameObject.name + " looking for SenseGlove...";
                            if (this.connectionMethod == ConnectionMethod.FindNextLeftHand)
                            {
                                message = this.gameObject.name + " looking for left-handed SenseGlove...";
                            }
                            else if (this.connectionMethod == ConnectionMethod.FindNextRightHand)
                            {
                                message = this.gameObject.name + " looking for right-handed SenseGlove...";
                            }
                            SenseGlove_Debugger.Log(message);
                            this.canReport = false;
                        }
                        this.elapsedTime = 0;
                    }
                }
            }
            else if (this.connectionMethod == ConnectionMethod.HardCoded && !this.glove.IsConnected())
            {                           //lost connection :(
                this.canReport = true;
                this.RetryConnection(); //keep trying!
            }
            else if (!gloveReady)
            {
                if (this.glove.GetData(false).dataLoaded)
                {
                    bool runSetup = this.gloveData == null; //used to raise event only once!

                    float[][] oldFingerLengths  = null;
                    float[][] oldStartPositions = null;
                    if (this.gloveData != null)
                    {
                        oldFingerLengths  = this.GetFingerLengths();
                        oldStartPositions = SenseGlove_Util.ToPosition(this.GetStartJointPositions());
                    }

                    this.gloveData = this.glove.GetData(false); //get the latest data without calculating anything.
                    this.rightHand = this.gloveData.isRight;    //so that users can use this variable during setup.

                    if (oldFingerLengths != null)
                    {
                        this.SetFingerLengths(oldFingerLengths);
                    }                                                                          //re-apply old fingerlengths, if possible.
                    if (oldStartPositions != null)
                    {
                        this.SetStartJointPositions(oldStartPositions);
                    }                                                                                  //re=apply joint positions, if possible.

                    this.convertedGloveData = new SenseGlove_Data(this.gloveData, this.glove.communicator.samplesPerSecond,
                                                                  this.glove.TotalCalibrationSteps(), this.glove.TotalCalibrationSteps());
                    this.SetupWrist();
                    this.calibratedWrist = false;
                    this.gloveReady      = true;
                    if (runSetup)
                    {
                        this.originalLengths = this.gloveData.handModel.GetFingerLengths();
                        this.originalJoints  = this.gloveData.handModel.GetJointPositions();
                        SenseGlove_Debugger.Log("Sense Glove " + this.convertedGloveData.deviceID + " is ready!");
                        this.GloveLoaded();  //raise the event!
                    }
                }
            }
            else //glove != null && gloveReady!
            {
                this.CheckCalibration();

                //Update to the latest GloveData.
                this.UpdateGloveData();

                //Calibrate once more after reconnecting to the glove.
                if (!calibratedWrist)
                {
                    this.CalibrateWrist();
                    this.calibratedWrist = true;
                }

                //Update the public values automatically.
                if (connectionMethod != ConnectionMethod.HardCoded)
                {
                    this.address = glove.communicator.Address();
                }
                this.rightHand = glove.IsRight();
            }
        }
    }
コード例 #30
0
    // Update is called once per frame
    void Update()
    {
        if (this.senseGlove != null && this.senseGlove.GloveReady())
        {
            if (Input.GetKeyDown(this.smallPresetKey))
            {
                SenseGlove_Debugger.Log("Set Small Hand Preset");
                float[][] newLengths = new float[5][]
                {
                    new float[3] {
                        25, 25, 20
                    },
                    new float[3] {
                        25, 20, 20
                    },
                    new float[3] {
                        30, 25, 20
                    },
                    new float[3] {
                        30, 20, 20
                    },
                    new float[3] {
                        20, 20, 20
                    }
                };

                this.senseGlove.SetFingerLengths(newLengths);
            }
            else if (Input.GetKeyDown(this.mediumPresetKey))
            {
                SenseGlove_Debugger.Log("Set Medium Hand Preset");
                float[][] newLengths = new float[5][]
                {
                    new float[3] {
                        30, 25, 20
                    },
                    new float[3] {
                        30, 25, 20
                    },
                    new float[3] {
                        35, 25, 20
                    },
                    new float[3] {
                        30, 25, 20
                    },
                    new float[3] {
                        25, 20, 20
                    }
                };

                this.senseGlove.SetFingerLengths(newLengths);
            }
            else if (Input.GetKeyDown(this.largePresetKey))
            {
                SenseGlove_Debugger.Log("Set Large Hand Preset");
                float[][] newLengths = new float[5][]
                {
                    new float[3] {
                        30, 25, 25
                    },
                    new float[3] {
                        35, 25, 25
                    },
                    new float[3] {
                        40, 35, 25
                    },
                    new float[3] {
                        35, 25, 20
                    },
                    new float[3] {
                        30, 20, 20
                    }
                };

                this.senseGlove.SetFingerLengths(newLengths);
            }

            if (Input.GetKeyDown(this.calibratePositionsKey))
            {
                SenseGlove_Debugger.Log("Calculating joint positions.");
                this.senseGlove.CalculateJointPositions();
            }
        }
    }