示例#1
0
        //-----------------------------------------------------------------------------------------------------------------------------------------
        // Monobeviour

        // Use this for initialization
        void Start()
        {
            GenerateFingers();
            ResizeFingers();
            SG_HandPose startPose = SG_HandPose.Idle(this.IsRight);

            this.UpdateHand(startPose);
        }
示例#2
0
        // Update is called once per frame
        void Update()
        {
            //Keybinds
            if (Input.GetKeyDown(this.toggleGloveKey))
            {
                this.GloveVisible = !GloveVisible;
            }
            if (Input.GetKeyDown(this.toggleHandKey))
            {
                this.HandVisible = !HandVisible;
            }

            //Automated Updates
            if (this.glove != null && glove.IsConnected)
            {
                if (!setupComplete)
                {
                    setupComplete     = true;
                    this.HandGeometry = SGCore.Kinematics.BasicHandModel.Default(this.glove.IsRight);
                    //Debug.Log("WireFrame; " + this.HandGeometry.ToString());

                    this.CalibrateWrist();

                    SG_HandPose idleHand = SG_HandPose.Idle(glove.IsRight);
                    this.UpdateHand(idleHand);

                    if (this.glove.InternalGlove is SGCore.SG.SenseGlove)
                    {
                        //  Debug.Log("Generated glove model for " + this.glove.GetInternalObject().GetDeviceID());
                        SGCore.SG.SG_GloveInfo gloveModel = ((SGCore.SG.SenseGlove) this.glove.InternalGlove).GetGloveModel();
                        GenerateGlove(gloveModel);
                        SGCore.SG.SG_GlovePose idlePose = SGCore.SG.SG_GlovePose.IdlePose(gloveModel);
                        this.UpdateGlove(idlePose);
                    }
                }
                if (this.wristTransform != null && this.foreArmTransform != null)
                {
                    if (Input.GetKeyDown(this.resetWristKey))
                    {
                        this.CalibrateWrist();
                    }
                    Quaternion imu;
                    if (this.glove.GetIMURotation(out imu))
                    {
                        this.UpdateWrist(imu);
                    }
                }
                if (this.gloveBase.activeInHierarchy)
                {
                    this.UpdateGlove();
                }
                if (this.handBase.activeInHierarchy)
                {
                    this.UpdateHand();
                }
            }
        }
示例#3
0
        // Update is called once per frame
        void Update()
        {
            if (activeHand == null)
            {
                if (leftHand.gloveHardware.IsConnected || rightHand.gloveHardware.IsConnected)
                {
                    activeHand = rightHand.gloveHardware.IsConnected ? rightHand : leftHand;

                    activeHand.handModel.gameObject.SetActive(true);
                    activeHand.handAnimation.updateWrist = true;
                    activeHand.handAnimation.CalibrateWrist();
                    activeHand.handAnimation.UpdateWrist(activeHand.GetIMURotation());

                    activeHand.handAnimation.UpdateHand(SG_HandPose.Idle(activeHand.TracksRightHand));
                    activeHand.feedbackScript.DebugEnabled       = true;
                    activeHand.grabScript.DebugEnabled           = true;
                    activeHand.rigidBodyLayer.DebugEnabled       = true;
                    activeHand.physicsTrackingLayer.DebugEnabled = true;
                    calibrateWristBtn.gameObject.SetActive(true);
                    if (this.showing != ShowingLayer.PhysicsLayer)
                    {
                        activeHand.physicsTrackingLayer.gameObject.SetActive(false);
                    }
                    gestureUI.gestureLayer = activeHand.gestureLayer;
                    if (gestureUI.gestureLayer != null)
                    {
                        gestureUI.gestureToCheck = activeHand.gestureLayer.gestures.Length > 0 ? activeHand.gestureLayer.gestures[0] : null;
                    }
                }
            }
            else
            {
                if (Input.GetKeyDown(nextKey))
                {
                    NextStep();
                }
                else if (Input.GetKeyDown(prevKey))
                {
                    PreviousStep();
                }
                if (Input.GetKeyDown(wristKey))
                {
                    CalibrateWrist();
                }
            }
        }
示例#4
0
        /// <summary> Update the hand wireframe based off a HandPose. </summary>
        /// <param name="pose"></param>
        public void UpdateHand(SG_HandPose pose)
        {
            if (pose != null)
            {
                //Debug.Log("WireFrame; " + this.HandGeometry.ToString());
                if (this.iFingerCorrections == null)
                {
                    this.CollectCorrections();
                }
                Quaternion[][] angles    = pose.jointRotations;
                Vector3[][]    positions = pose.jointPositions;
                if (fingerJoints != null && this.iFingerCorrections != null)
                {
                    for (int f = 0; f < fingerJoints.Length; f++)
                    {
                        if (pose.jointRotations.Length > f)
                        {
                            for (int j = 0; j < fingerJoints[f].Length; j++)
                            {
                                if (pose.jointRotations[f].Length > j)
                                {
                                    fingerJoints[f][j].rotation = this.wristTransform.rotation
                                                                  * (angles[f][j] * this.iFingerCorrections[f][j]);

                                    fingerJoints[f][j].localPosition = positions[f][j];
                                }
                                if (j > 0)
                                {
                                    Debug.DrawLine(fingerJoints[f][j - 1].position, fingerJoints[f][j].position);
                                }
                            }
                        }
                    }
                }
            }
        }