示例#1
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();
                }
            }
        }
示例#2
0
        //-----------------------------------------------------------------------------------------------------------------------------------------
        // Glove Model WireFrame Functions

        /// <summary> Generate a wireframe for a glove, based on its GloveModel </summary>
        /// <param name="gloveModel"></param>
        public void GenerateGlove(SGCore.SG.SG_GloveInfo gloveModel)
        {
            if (gloveModel != null)
            {
                gloveBase.SetActive(true);
                gloveSectionModel.SetActive(true);

                Vector3[][] gloveLengths = SG.Util.SG_Conversions.ToUnityPositions(gloveModel.GloveLengths, true);
                int         x = 0, y = 1, z = 2;
                this.gloveJoints = new Transform[gloveModel.GloveLengths.Length][];
                for (int f = 0; f < gloveJoints.Length; f++)
                {
                    gloveJoints[f] = new Transform[gloveModel.GloveLengths[f].Length + 1];

                    for (int i = 0; i < gloveJoints[f].Length; i++)
                    {
                        GameObject gloveJoint = GameObject.Instantiate(gloveSectionModel, this.gloveBase.gameObject.transform);
                        gloveJoint.name = "GlovePostion" + f + "" + i;
                        gloveJoint.transform.localRotation = Quaternion.identity;
                        gloveJoints[f][i] = gloveJoint.transform;
                        //gloveJoint.SetActive(true);
                        if (i < gloveJoints[f].Length - 1)
                        {
                            if (gloveJoint.transform.childCount > 2)
                            {
                                Transform dX = gloveJoint.transform.GetChild(2);
                                Transform dY = gloveJoint.transform.GetChild(1);
                                Transform dZ = gloveJoint.transform.GetChild(0);

                                //Setup correct sizes.
                                if (gloveLengths[f][i][x] != 0)
                                {
                                    dX.localScale = new Vector3(dX.localScale.x, gloveLengths[f][i][x] / 2.0f, dX.localScale.z);
                                }
                                else
                                {
                                    dX.gameObject.SetActive(false);
                                }
                                if (gloveLengths[f][i][y] != 0)
                                {
                                    dY.localScale = new Vector3(dX.localScale.x, gloveLengths[f][i][y] / 2.0f, dX.localScale.z);
                                }
                                else
                                {
                                    dY.gameObject.SetActive(false);
                                }
                                if (gloveLengths[f][i][z] != 0)
                                {
                                    dZ.localScale = new Vector3(dX.localScale.x, gloveLengths[f][i][z] / 2.0f, dX.localScale.z);
                                }
                                else
                                {
                                    dZ.gameObject.SetActive(false);
                                }

                                //set correct positions based on ZYX?
                                dY.localPosition = new Vector3(0, gloveLengths[f][i][y] / 2.0f, 0);
                                dX.localPosition = new Vector3(gloveLengths[f][i][x] / 2.0f, gloveLengths[f][i][y] / 1.0f, 0);
                                //dY ?
                            }
                        }
                        else
                        {
                            for (int j = 0; j < gloveJoint.transform.childCount - 1; j++) //the last one is just the dot
                            {
                                GameObject.Destroy(gloveJoint.transform.GetChild(j).gameObject);
                            }
                        }
                    }
                }
                gloveSectionModel.SetActive(false);
            }
            else
            {
                SG_Debugger.Log("WARNING : No base model for Glove Wireframe");
            }
        }