示例#1
0
 private void MoveBody(nuitrack.Skeleton skeleton)
 {
     foreach (ModelJoint modelJoint in modelJoints)
     {
         modelJoint.bone.position = (0.001f * skeleton.GetJoint(modelJoint.jointType).ToVector3());
     }
 }
示例#2
0
    void NuitrackManager_onSkeletonTrackerUpdate(nuitrack.SkeletonData skeletonData)
    {
        if ((skeletonData == null) || (skeletonData.NumUsers == 0))
        {
            currentUser     = 0;
            currentSkeleton = null;
            return;
        }

        if (currentUser != 0)
        {
            currentSkeleton = skeletonData.GetSkeletonByID(currentUser);
            currentUser     = (currentSkeleton == null) ? 0 : currentUser;
        }

        if (currentUser == 0)
        {
            currentUser     = skeletonData.Skeletons[0].ID;
            currentSkeleton = skeletonData.Skeletons[0];
        }

        /*Vector3 Position = scalK * currentSkeleton.GetJoint(nuitrack.JointType.RightShoulder).ToVector3();
         *
         * float distSizeofLeg = Vector3.Distance(Position, Floor.gameObject.transform.position);
         *
         * print(distSizeofLeg);*/
    }
示例#3
0
    void Update()
    {
        frameNum++;
        if (CurrentUserTracker.CurrentUser != 0)
        {
            string newData = "";
            newData += frameNum + "," + System.DateTime.Now.Hour + "" + System.DateTime.Now.Minute + System.DateTime.Now.Second + System.DateTime.Now.Millisecond;


            nuitrack.Skeleton skeleton = CurrentUserTracker.CurrentSkeleton;

            for (int q = 0; q < typeJoint.Length; q++)
            {
                nuitrack.Joint joint       = skeleton.GetJoint(typeJoint[q]);
                Vector3        newPosition = 0.001f * joint.ToVector3();
                CreatedJoint[q].transform.localPosition = newPosition;

                newData += "," + joint.Confidence;
                newData += "," + joint.ToVector3().x;
                newData += "," + joint.ToVector3().y;
                newData += "," + joint.ToVector3().z;
            }
            file.WriteLine(newData);
        }
        else
        {
        }
    }
示例#4
0
    /// <summary>
    /// Getting skeleton data from thr sensor and updating transforms of the model bones
    /// </summary>
    void ProcessSkeleton(nuitrack.Skeleton skeleton)
    {
        foreach (var riggedJoint in jointsRigged)
        {
            //Get joint from the Nuitrack
            nuitrack.Joint joint = skeleton.GetJoint(riggedJoint.Key);

            //Get modelJoint
            ModelJoint modelJoint = riggedJoint.Value;

            //Bone position
            Vector3 newPos = Quaternion.Euler(0f, 180f, 0f) * (0.001f * joint.ToVector3());
            modelJoint.bone.position = newPos;

            //Bone rotation
            Quaternion jointOrient = Quaternion.Inverse(CalibrationInfo.SensorOrientation) * (joint.ToQuaternionMirrored()) * modelJoint.baseRotOffset;
            modelJoint.bone.rotation = jointOrient;

            //Bone scale
            if (modelJoint.parentBone != null)
            {
                //Take the Transform of a parent bone
                Transform parentBone = modelJoint.parentBone;
                //calculate how many times the distance between the child bone and its parent bone has changed compared to the base distance (which was recorded at the start)
                float scaleDif = modelJoint.baseDistanceToParent / Vector3.Distance(newPos, parentBone.position);
                //change the size of the bone to the resulting value (On default bone size (1,1,1))
                parentBone.localScale = Vector3.one / scaleDif;
            }
        }
    }
    // Update is called once per frame
    void Update()
    {
        if (CurrentUserTracker.CurrentUser != 0)
        {
            nuitrack.Skeleton skeleton = CurrentUserTracker.CurrentSkeleton;
            joint = skeleton.GetJoint(typeJoint);
            Vector3 position = 0.001f * joint.ToVector3();

            if (joint.ToVector3().z < 800)
            {
                message = "Please step away from camera";
            }
            else if (joint.ToVector3().z > 1500)
            {
                message = "Please step towards the camera";
            }
            else
            {
                message = "";
            }
        }
        else
        {
            message = "User not found";
        }
    }
    void Update()
    {
        if (CurrentUserTracker.CurrentUser != 0)
        {
            nuitrack.Skeleton skeleton = CurrentUserTracker.CurrentSkeleton;
            message = "Skeleton found";

            for (int q = 0; q < typeJoint.Length; q++)
            {
                nuitrack.Joint joint       = skeleton.GetJoint(typeJoint[q]);
                Vector3        newPosition = 0.001f * joint.ToVector3();
                CreatedJoint[q].transform.localPosition = newPosition;
            }
            for (int i = 0; i < typeConnection.GetLength(0); i++)
            {
                nuitrack.Joint startJoint = skeleton.GetJoint(typeConnection[i, 0]);
                nuitrack.Joint endJoint   = skeleton.GetJoint(typeConnection[i, 1]);

                CreatedConnection[i].transform.position = startJoint.ToVector3();
                CreatedConnection[i].transform.right    = endJoint.ToVector3() - startJoint.ToVector3();
                float distance = Vector3.Distance(endJoint.ToVector3(), startJoint.ToVector3());
                CreatedConnection[i].transform.localScale = new Vector3(distance, 1f, 1f);
                Debug.Log(CreatedConnection [i].transform.position.ToString());
                connectionParticleSystem[i].transform.position = CreatedConnection[i].transform.position;
            }
        }
        else
        {
            message = "Skeleton not found";
        }
    }
    private void RefreshBodyLocation(nuitrack.Skeleton skeleton, GameObject body)
    {
        nuitrack.JointType Anchor = nuitrack.JointType.Torso;

        Vector3 pos = Quaternion.Euler(0f, 180f, 0f) * (0.001f * skeleton.GetJoint(Anchor).ToVector3());

        body.transform.position = pos;
    }
示例#8
0
    public void ProcessSkeleton(nuitrack.Skeleton skeleton)
    {
        if (skeleton == null)
        {
            return;
        }

        if (!gameObject.activeSelf)
        {
            gameObject.SetActive(true);
        }

        for (int i = 0; i < jointsInfo.Length; i++)
        {
            nuitrack.Joint j = skeleton.GetJoint(jointsInfo[i]);
            if (j.Confidence > 0.5f)
            {
                if (!joints[jointsInfo[i]].activeSelf)
                {
                    joints[jointsInfo[i]].SetActive(true);
                }

                joints[jointsInfo[i]].transform.position = 0.001f * j.ToVector3();
                joints[jointsInfo[i]].transform.rotation = j.ToQuaternionMirrored();
            }
            else
            {
                if (joints[jointsInfo[i]].activeSelf)
                {
                    joints[jointsInfo[i]].SetActive(false);
                }
            }
        }

        for (int i = 0; i < connectionsInfo.GetLength(0); i++)
        {
            if (joints[connectionsInfo[i, 0]].activeSelf && joints[connectionsInfo[i, 1]].activeSelf)
            {
                if (!connections[i].activeSelf)
                {
                    connections[i].SetActive(true);
                }

                Vector3 diff = joints[connectionsInfo[i, 1]].transform.position - joints[connectionsInfo[i, 0]].transform.position;

                connections[i].transform.position   = joints[connectionsInfo[i, 0]].transform.position;
                connections[i].transform.rotation   = Quaternion.LookRotation(diff);
                connections[i].transform.localScale = new Vector3(1f, 1f, diff.magnitude);
            }
            else
            {
                if (connections[i].activeSelf)
                {
                    connections[i].SetActive(false);
                }
            }
        }
    }
示例#9
0
    public void ProcessSkeleton(nuitrack.Skeleton skeleton)
    {
        if (skeleton == null)
        {
            return;
        }

        if (!gameObject.activeSelf)
        {
            gameObject.SetActive(true);
        }

        for (int i = 0; i < jointsInfo.Length; i++)
        {
            nuitrack.Joint j = skeleton.GetJoint(jointsInfo[i]);
            if (j.Confidence > 0.5f)
            {
                if (!joints[jointsInfo[i]].activeSelf)
                {
                    joints[jointsInfo[i]].SetActive(true);
                }

                joints[jointsInfo[i]].transform.position = new Vector2(j.Proj.X * Screen.width, Screen.height - j.Proj.Y * Screen.height);
            }
            else
            {
                if (joints[jointsInfo[i]].activeSelf)
                {
                    joints[jointsInfo[i]].SetActive(false);
                }
            }
        }

        for (int i = 0; i < connectionsInfo.GetLength(0); i++)
        {
            if (joints[connectionsInfo[i, 0]].activeSelf && joints[connectionsInfo[i, 1]].activeSelf)
            {
                if (!connections[i].activeSelf)
                {
                    connections[i].SetActive(true);
                }

                Vector3 diff = joints[connectionsInfo[i, 1]].transform.position - joints[connectionsInfo[i, 0]].transform.position;
                connections[i].transform.position   = joints[connectionsInfo[i, 0]].transform.position;
                connections[i].transform.right      = joints[connectionsInfo[i, 1]].transform.position - connections[i].transform.position;
                connections[i].transform.localScale = new Vector3(diff.magnitude, 1f, 1f);
            }
            else
            {
                if (connections[i].activeSelf)
                {
                    connections[i].SetActive(false);
                }
            }
        }
    }
示例#10
0
 private void MoveJoints(nuitrack.Skeleton skeleton)
 {
     foreach (var modelJoint in modelJoints)
     {
         modelJoint.bone.rotation =
             Quaternion.Inverse(CalibrationInfo.SensorOrientation)
             * (skeleton.GetJoint(modelJoint.jointType).ToQuaternionMirrored())
             * modelJoint.baseRotOffset;
     }
 }
 private void RefreshJointRotation(nuitrack.Skeleton skeleton)
 {
     foreach (var riggedJoint in jointsRigged)
     {
         nuitrack.Joint joint       = skeleton.GetJoint(riggedJoint.Key);
         ModelJoint     modelJoint  = riggedJoint.Value;
         Quaternion     jointOrient = Quaternion.Inverse(CalibrationInfo.SensorOrientation) * (joint.ToQuaternion()) * modelJoint.baseRotOffset;
         modelJoint.bone.rotation = jointOrient;
     }
 }
示例#12
0
    void Update()
    {
        if (CurrentUserTracker.CurrentUser != 0)
        {
            nuitrack.Skeleton skeleton = CurrentUserTracker.CurrentSkeleton;
            message = "";

            for (int q = 0; q < typeJoint.Length; q++)
            {
                nuitrack.Joint joint       = skeleton.GetJoint(typeJoint[q]);
                Vector3        newPosition = 0.001f * joint.ToVector3();
                CreatedJoint[q].transform.localPosition = newPosition;
            }

            contadorAgachamentos.text = agachamentos.ToString(); //atualiza mensagem dos agachamentos

            coordenadasJoints[0] = scalK * skeleton.GetJoint(nuitrack.JointType.Head).ToVector3();
            coordenadasJoints[1] = scalK * skeleton.GetJoint(nuitrack.JointType.Neck).ToVector3();
            coordenadasJoints[2] = scalK * skeleton.GetJoint(nuitrack.JointType.RightShoulder).ToVector3();
            coordenadasJoints[3] = scalK * skeleton.GetJoint(nuitrack.JointType.LeftShoulder).ToVector3();

            if (!isPosicaoInicialGuardada) //inicia a contagem decrescente para guardar a posição inicial e iniciar o exercício
            {
                timerComecar      -= Time.deltaTime;;
                timerMensagem.text = timerComecar.ToString();

                if (timerComecar < 0)
                {
                    GuardaPosicaoInicial(coordenadasJoints);
                }

                return;
            }

            if (agachamentos > 0)
            {
                VerificaAgachamento(coordenadasJoints);

                if (isAgachado)
                {
                    ContaAgachamento(coordenadasJoints);
                }
            }
            else
            {
                DescansaProximaSerie();
            }
        }
        else
        {
            message = "Skeleton not found!";
        }
    }
示例#13
0
    void LateUpdate()
    {
        if (CurrentUserTracker.CurrentSkeleton != null)
        {
            nuitrack.Skeleton skeleton = CurrentUserTracker.CurrentSkeleton;
            transform.position = Quaternion.Euler(0f, 180f, 0f) * (0.001f * skeleton.GetJoint(rootJoint).ToVector3());

            foreach (SimpleJoint item in joints)
            {
                nuitrack.Joint joint = skeleton.GetJoint(item.nuitrackJoint);

                Quaternion rotation = Quaternion.Inverse(CalibrationInfo.SensorOrientation) * joint.ToQuaternionMirrored() * item.Offset;
                item.Bone.rotation = rotation;
            }
        }
    }
示例#14
0
    void ProcessSkeleton(nuitrack.Skeleton skeleton)
    {
        //Vector3 torsoPos = Quaternion.Euler(0f, 0f, 0f) * (0.001f * skeleton.GetJoint(nuitrack.JointType.Torso).ToVector3());
        //transform.position = torsoPos;

        foreach (var riggedJoint in jointsRigged)
        {
            nuitrack.Joint joint      = skeleton.GetJoint(riggedJoint.Key);
            ModelJoint     modelJoint = riggedJoint.Value;

            Quaternion jointOrient =
                Quaternion.Inverse(CalibrationInfo.SensorOrientation)
                * (joint.ToQuaternionMirrored())
                * modelJoint.baseRotOffset;
            modelJoint.bone.rotation = jointOrient;
        }
    }
    /// <summary>
    /// Getting skeleton data from sensor and update model bones transforms
    /// </summary>
    void ProcessSkeleton(nuitrack.Skeleton skeleton)
    {
        if (skeleton == null)
        {
            return;
        }

        if (!firstOffset)
        {
            firstOffset = true;
            StartCoroutine(CalculateOffset());
        }

        foreach (var riggedJoint in jointsRigged)
        {
            nuitrack.Joint j = skeleton.GetJoint(riggedJoint.Key);
            if (j.Confidence > 0.5f)
            {
                //Bone position
                Vector3 newPos = (q180) * (Vector3.up * CalibrationInfo.FloorHeight + CalibrationInfo.SensorOrientation * (0.001f * j.ToVector3())) * scale + basePivotOffset;

                ModelJoint rj = riggedJoint.Value;

                //Bone scale
                if (rj.parentBone != null)
                {
                    Transform bone = rj.parentBone;
                    bone.parent = bone.root;
                    float scaleDif = rj.baseDistanceToParent / Vector3.Distance(newPos, bone.position);
                    bone.localScale = Vector3.one / scaleDif;
                }

                rj.bone.position = newPos;

                if (j.Type != nuitrack.JointType.None)
                {
                    Quaternion jointOrient = CalibrationInfo.SensorOrientation * (j.ToQuaternionMirrored());
                    rj.bone.rotation = q0 * Quaternion.Inverse(CalibrationInfo.SensorOrientation) * jointOrient * rj.baseRotOffset;
                }
            }
        }

        leftHandPos  = jointsRigged[nuitrack.JointType.LeftWrist].bone.position;
        rightHandPos = jointsRigged[nuitrack.JointType.RightWrist].bone.position;
    }
示例#16
0
 // Update is called once per frame
 void Update()
 {
     if (CurrentUserTracker.CurrentUser != 0)
     {
         msg = "Skeleton Found";
         nuitrack.Skeleton skeleton = CurrentUserTracker.CurrentSkeleton;
         for (int q = 0; q < typeJoint.Length; q++)
         {
             nuitrack.Joint joint  = skeleton.GetJoint(typeJoint[q]);
             Vector3        newPos = 0.001f * joint.ToVector3();
             CreatedJoint[q].transform.localPosition = newPos;
         }
     }
     else
     {
         msg = "Skeleton not found";
     }
 }
示例#17
0
    void Update()
    {
        string json = nuitrack.Nuitrack.GetInstancesJson();

        faceInfo = JsonUtility.FromJson <JsonInfo>(json.Replace("\"\"", "[]"));

        faces = faceInfo.Instances;
        for (int i = 0; i < faceControllers.Count; i++)
        {
            if (faces != null && i < faces.Length)
            {
                int  id          = 0;
                Face currentFace = faces[i].face;
                // Pass the face to FaceController
                faceControllers[i].SetFace(currentFace);
                faceControllers[i].gameObject.SetActive(true);

                // IDs of faces and skeletons are the same
                id = faces[i].id;

                nuitrack.Skeleton skeleton = null;
                if (NuitrackManager.SkeletonData != null)
                {
                    skeleton = NuitrackManager.SkeletonData.GetSkeletonByID(id);
                }

                if (skeleton != null)
                {
                    nuitrack.Joint head = skeleton.GetJoint(nuitrack.JointType.Head);

                    faceControllers[i].transform.position = new Vector2(head.Proj.X * Screen.width, Screen.height - head.Proj.Y * Screen.height);
                    //stretch the face to fit the rectangle
                    if (currentFace.rectangle != null)
                    {
                        faceControllers[i].transform.localScale = new Vector2(currentFace.rectangle.width * Screen.width, currentFace.rectangle.height * Screen.height);
                    }
                }
            }
            else
            {
                faceControllers[i].gameObject.SetActive(false);
            }
        }
    }
示例#18
0
    public void ProcessSkeleton(nuitrack.Skeleton skeleton)
    {
        if (skeleton == null)
        {
            return;
        }

        for (int i = 0; i < jointsInfo.Length; i++)
        {
            nuitrack.Joint j = skeleton.GetJoint(jointsInfo[i]);
            if (j.Confidence > 0.5f)
            {
                joints[jointsInfo[i]].SetActive(true);
                joints[jointsInfo[i]].transform.position = new Vector2(j.Proj.X * Screen.width, Screen.height - j.Proj.Y * Screen.height);
                exportJoints[jointsInfo[i]] = joints[jointsInfo[i]].transform.position;
                //exportJoints[jointsInfoStr[i]] = joints[jointsInfo[i]].transform.position;
                //exportOrientations[jointsInfoStr[i]] = joints[jointsInfo[i]].Orient;
            }
            else
            {
                joints[jointsInfo[i]].SetActive(false);
            }
        }

        for (int i = 0; i < connectionsInfo.GetLength(0); i++)
        {
            GameObject startJoint = joints[connectionsInfo[i, 0]];
            GameObject endJoint   = joints[connectionsInfo[i, 1]];

            if (startJoint.activeSelf && endJoint.activeSelf)
            {
                connections[i].SetActive(true);

                connections[i].transform.position = startJoint.transform.position;
                connections[i].transform.right    = endJoint.transform.position - startJoint.transform.position;
                float distance = Vector3.Distance(endJoint.transform.position, startJoint.transform.position);
                connections[i].transform.localScale = new Vector3(distance, 1f, 1f);
            }
            else
            {
                connections[i].SetActive(false);
            }
        }
    }
示例#19
0
    void ProcessSkeleton(nuitrack.Skeleton skeleton)
    {
        //Calculate the model position: take the Torso position and invert movement along the Z axis
        Vector3 torsoPos = Quaternion.Euler(0f, 180f, 0f) * (0.001f * skeleton.GetJoint(nuitrack.JointType.Torso).ToVector3());

        transform.position = torsoPos + basePivotOffset;

        foreach (var riggedJoint in jointsRigged)
        {
            //Get joint from the Nuitrack
            nuitrack.Joint joint = skeleton.GetJoint(riggedJoint.Key);

            ModelJoint modelJoint = riggedJoint.Value;

            //Calculate the model bone rotation: take the mirrored joint orientation, add a basic rotation of the model bone, invert movement along the Z axis
            Quaternion jointOrient = Quaternion.Inverse(CalibrationInfo.SensorOrientation) * (joint.ToQuaternionMirrored()) * modelJoint.baseRotOffset;
            modelJoint.bone.rotation = jointOrient;
        }
    }
示例#20
0
 // Update is called once per frame
 void Update()
 {
     // Check user presence in frame
     if (CurrentUserTracker.CurrentUser != 0)
     {
         message = "Skeleton found!";
         nuitrack.Skeleton skeleton = CurrentUserTracker.CurrentSkeleton; // Get current user skeleton info
         for (int i = 0; i < typeJoint.Length; i++)
         {
             // Get current joint data
             nuitrack.Joint joint       = skeleton.GetJoint(typeJoint[i]);
             Vector3        newPosition = 0.001f * joint.ToVector3(); // Convert to milimeters
             CreatedJoint[i].transform.localPosition = newPosition;
         }
     }
     else
     {
         message = "Skeleton not found!";
     }
 }
示例#21
0
    void Update()
    {
        if (CurrentUserTracker.CurrentUser != 0)
        {
            nuitrack.Skeleton skeleton = CurrentUserTracker.CurrentSkeleton;
            message = "Skeleton found";//通过CurrentUserTracker.CurrentSkeleton动态获取USER的信息

            //遍历信息到各个虚拟关节点信息上
            for (int q = 0; q < typeJoint.Length; q++)
            {
                nuitrack.Joint joint       = skeleton.GetJoint(typeJoint[q]);
                Vector3        newPosition = 0.001f * joint.ToVector3();
                CreatedJoint[q].transform.localPosition = newPosition;
            }
        }
        else
        {
            message = "Skeleton not found";
        }
    }
    void NuitrackManager_onSkeletonTrackerUpdate(nuitrack.SkeletonData skeletonData)
    {
        if ((skeletonData == null) || (skeletonData.NumUsers == 0))
        {
            currentUser     = 0;
            currentSkeleton = null;
            return;
        }

        if (currentUser != 0)
        {
            currentSkeleton = skeletonData.GetSkeletonByID(currentUser);
            currentUser     = (currentSkeleton == null) ? 0 : currentUser;
        }

        if (currentUser == 0)
        {
            currentUser     = skeletonData.Skeletons[0].ID;
            currentSkeleton = skeletonData.Skeletons[0];
        }
    }
    }// end OnDestroy

    // Update is called once per frame
    void Update()
    {
        float initMousePos = Input.GetAxis("Mouse X");

        if (CurrentUserTracker.CurrentUser != 0) // If there is a user in frame...
        {
            // Get the user's skeleton from nuitrack's scripts.
            nuitrack.Skeleton skeleton = CurrentUserTracker.CurrentSkeleton;

            // Get the right and left joint positions.
            nuitrack.Joint rightJoint = skeleton.GetJoint(typeJoint[0]);
            Vector3        rightPos   = rightJoint.ToVector3();

            nuitrack.Joint leftJoint = skeleton.GetJoint(typeJoint[1]);
            Vector3        leftPos   = leftJoint.ToVector3();

            ///// Tracking user with camera. //////

            // Get right hand positions
            Vector3 rightNewPos = new Vector3(rightPos.x + camera.transform.position.x, rightPos.y + camera.transform.position.y, ZPosition);
            if (orthographic)
            {
                rightNewPos.x = rightNewPos.x / 100;
                rightNewPos.y = rightNewPos.y / 100;
            }

            rightHand.transform.position = rightNewPos;
            //Debug.Log("Right: " + rightNewPos);

            // Get left hand positions
            Vector3 leftNewPos = new Vector3(leftPos.x + camera.transform.position.x, leftPos.y + camera.transform.position.y, ZPosition);
            if (orthographic)
            {
                leftNewPos.x = leftNewPos.x / 100;
                leftNewPos.y = leftNewPos.y / 100;
            }
            leftHand.transform.position = leftNewPos;
            //Debug.Log("Left: " + leftNewPos);
        } // end if user is in frame
    }     // end Update
    void ProcessSkeleton(nuitrack.Skeleton skeleton)
    {
        if (skeleton == null)
        {
            return;
        }

        if (headTransform != null)
        {
#if UNITY_IOS
            headTransform.position = headDirectionTransform.rotation * neckHMDOffset + (rotate180 ? q180 : q0) * (Vector3.up * CalibrationInfo.FloorHeight + CalibrationInfo.SensorOrientation * (0.001f * skeleton.GetJoint(nuitrack.JointType.Neck).ToVector3())) + basePivotOffset;
#else
            headTransform.position = (rotate180 ? q180 : q0) * (Vector3.up * CalibrationInfo.FloorHeight + CalibrationInfo.SensorOrientation * (0.001f * skeleton.GetJoint(nuitrack.JointType.Head).ToVector3())) + basePivotOffset;
#endif

            basePivot = (rotate180 ? q180 : q0) * (Vector3.up * CalibrationInfo.FloorHeight + CalibrationInfo.SensorOrientation * (0.001f * skeleton.GetJoint(nuitrack.JointType.Waist).ToVector3())) + basePivotOffset;
        }

        if (!skeletonRoot.activeSelf)
        {
            skeletonRoot.SetActive(true);
        }

        for (int i = 0; i < jointsInfo.Length; i++)
        {
            nuitrack.Joint j = skeleton.GetJoint(jointsInfo[i]);
            if (j.Confidence > 0.5f)
            {
                if (!joints[jointsInfo[i]].activeSelf)
                {
                    joints[jointsInfo[i]].SetActive(true);
                }

                joints[jointsInfo[i]].transform.position = (rotate180 ? q180 : q0) * (Vector3.up * CalibrationInfo.FloorHeight + CalibrationInfo.SensorOrientation * (0.001f * j.ToVector3())) + basePivotOffset;
                joints[jointsInfo[i]].transform.rotation = (rotate180 ? q180 : q0) * CalibrationInfo.SensorOrientation * j.ToQuaternionMirrored();

                leftHandPos  = (rotate180 ? q180 : q0) * (Vector3.up * CalibrationInfo.FloorHeight + CalibrationInfo.SensorOrientation * (0.001f * skeleton.GetJoint(nuitrack.JointType.LeftHand).ToVector3())) + basePivotOffset;
                rightHandPos = (rotate180 ? q180 : q0) * (Vector3.up * CalibrationInfo.FloorHeight + CalibrationInfo.SensorOrientation * (0.001f * skeleton.GetJoint(nuitrack.JointType.RightHand).ToVector3())) + basePivotOffset;
            }
            else
            {
                if (joints[jointsInfo[i]].activeSelf)
                {
                    joints[jointsInfo[i]].SetActive(false);
                }
            }
        }

        for (int i = 0; i < connectionsInfo.GetLength(0); i++)
        {
            if (joints[connectionsInfo[i, 0]].activeSelf && joints[connectionsInfo[i, 1]].activeSelf)
            {
                if (!connections[i].activeSelf)
                {
                    connections[i].SetActive(true);
                }

                Vector3 diff = joints[connectionsInfo[i, 1]].transform.position - joints[connectionsInfo[i, 0]].transform.position;

                connections[i].transform.position   = joints[connectionsInfo[i, 0]].transform.position;
                connections[i].transform.rotation   = Quaternion.LookRotation(diff);
                connections[i].transform.localScale = new Vector3(1f, 1f, diff.magnitude);
            }
            else
            {
                if (connections[i].activeSelf)
                {
                    connections[i].SetActive(false);
                }
            }
        }
    }
示例#25
0
    void Update()
    {
        if (CurrentUserTracker.CurrentUser != 0)
        {
            nuitrack.Skeleton skeleton = CurrentUserTracker.CurrentSkeleton;
            message = "Skeleton found";

            for (int q = 0; q < typeJoint.Length; q++)
            {
                nuitrack.Joint joint       = skeleton.GetJoint(typeJoint[q]);
                Vector3        newPosition = 0.001f * joint.ToVector3();
                CreatedJoint[q].transform.localPosition = newPosition;

                if (q == 0)
                {
                    UpwardParticleSystem[0].transform.localPosition = newPosition;
                }
                else if (q == 3)
                {
                    UpwardParticleSystem[1].transform.localPosition = newPosition;
                }
                else if (q == 4)
                {
                    UpwardParticleSystem[2].transform.localPosition = newPosition;
                }
                else if (q == 5)
                {
                    UpwardParticleSystem[3].transform.localPosition = newPosition;
                }
                else if (q == 13)
                {
                    UpwardParticleSystem[4].transform.localPosition = newPosition;
                }
                else if (q == 14)
                {
                    UpwardParticleSystem[5].transform.localPosition = newPosition;
                }
                else if (q == 15)
                {
                    UpwardParticleSystem[6].transform.localPosition = newPosition;
                }
            }
            ConnectJoints(0, 1, 0);
            ConnectJoints(1, 2, 1);
            ConnectJoints(3, 4, 3);
            ConnectJoints(4, 5, 4);
            ConnectJoints(6, 7, 6);
            ConnectJoints(7, 8, 7);
            ConnectJoints(9, 10, 9);
            ConnectJoints(10, 12, 10);
            ConnectJoints(13, 14, 13);
            ConnectJoints(14, 15, 14);

            foreach (GameObject ps_clone in psSlider)
            {
                ParticleSystem psssss = ps_clone.GetComponentInChildren <ParticleSystem>();
                var            em     = psssss.emission;
                em.enabled = true;
                em.rate    = Emission.value;
            }
            foreach (GameObject ps_clone in psuSlider)
            {
                ParticleSystem psssss = ps_clone.GetComponentInChildren <ParticleSystem>();
                var            em     = psssss.emission;
                em.enabled = true;
                em.rate    = EmissionUpwards.value;
            }
            //Emission.text = Emission.value.ToString("0.0");
            //EmissionUpwards.text = EmissionUpwards.value.ToString("0.0");
            textComponent.text = Mathf.Round(Emission.value * 100).ToString();
        }
        else
        {
            message = "Skeleton not found";
        }
    }
示例#26
0
    private void MoveTorso(nuitrack.Skeleton skeleton)
    {
        Vector3 torsoPos = (0.001f * skeleton.GetJoint(nuitrack.JointType.Torso).ToVector3());

        transform.position = torsoPos;
    }
示例#27
0
 public SkeletonData(nuitrack.Skeleton skeleton)
 {
     RawSkeleton = skeleton;
 }
示例#28
0
    void Update()
    {
        if (CurrentUserTracker.CurrentUser != 0)
        {
            nuitrack.Skeleton skeleton = CurrentUserTracker.CurrentSkeleton;
            message = "";

            for (int q = 0; q < typeJoint.Length; q++)
            {
                nuitrack.Joint joint       = skeleton.GetJoint(typeJoint[q]);
                Vector3        newPosition = 0.001f * joint.ToVector3();
                CreatedJoint[q].transform.localPosition = newPosition;
            }

            contadorRepeticoes.text = repeticoes.ToString();                                                //atualiza mensagem dos agachamentos

            coordenadasJoints[0] = scalK * skeleton.GetJoint(nuitrack.JointType.Head).ToVector3();          //Cabeça
            coordenadasJoints[1] = scalK * skeleton.GetJoint(nuitrack.JointType.Neck).ToVector3();          //Pescoço
            coordenadasJoints[2] = scalK * skeleton.GetJoint(nuitrack.JointType.RightShoulder).ToVector3(); //ombro direito
            coordenadasJoints[3] = scalK * skeleton.GetJoint(nuitrack.JointType.LeftShoulder).ToVector3();  //ombro esquerdo
            coordenadasJoints[4] = scalK * skeleton.GetJoint(nuitrack.JointType.Torso).ToVector3();         //torso

            coordenadasJoints[5] = scalK * skeleton.GetJoint(nuitrack.JointType.RightElbow).ToVector3();    //braco direito
            coordenadasJoints[6] = scalK * skeleton.GetJoint(nuitrack.JointType.LeftElbow).ToVector3();     //braco esquerdo
            coordenadasJoints[7] = scalK * skeleton.GetJoint(nuitrack.JointType.RightKnee).ToVector3();     //joelho direito
            coordenadasJoints[8] = scalK * skeleton.GetJoint(nuitrack.JointType.LeftKnee).ToVector3();      //joelho esquerdo


            print("CABECA: " + coordenadasJoints[0]);
            print("PESCOCO: " + coordenadasJoints[1]);
            print("OMBRO DIREITO: " + coordenadasJoints[2]);
            print("OMBRO ESQUERDO: " + coordenadasJoints[3]);
            print("TORSO: " + coordenadasJoints[4]);
            print("BRACO DIREITO: " + coordenadasJoints[5]);

            print("BRACO ESQUERDO: " + coordenadasJoints[6]);
            print("JOELHO DIREITO: " + coordenadasJoints[7]);
            print("JOELHO ESQUERDO: " + coordenadasJoints[8]);


            if (!isPosicaoInicialGuardada) //inicia a contagem decrescente para guardar a posição inicial e iniciar o exercício
            {
                timerComecar      -= Time.deltaTime;;
                timerMensagem.text = timerComecar.ToString();

                if (timerComecar < 0)
                {
                    GuardaPosicaoInicial(coordenadasJoints);
                }

                return;
            }


            if (repeticoes > 0)
            {
                VerificaRepeticao(coordenadasJoints);

                if (isAgachado)
                {
                    ContaAgachamento(coordenadasJoints);
                }
            }
            else
            {
                if (trocouPerna)
                {
                    DescansaProximaSerie();
                }
                else  //troca de perna
                {
                    repeticoes         = nRepeticoes;
                    trocouPerna        = true;
                    timerMensagem.text = "Vamos lá! Lentanta a perna direita";
                }
            }
        }
        else
        {
            message = "Skeleton not found!";
        }
    }
示例#29
0
 internal void AddData(nuitrack.Skeleton skeleton)
 {
     Skeleton = new SkeletonData(skeleton);
 }
示例#30
0
    void CheckSkeletonPositions(nuitrack.SkeletonData skeletonData)
    {
        nuitrack.Skeleton skelet = CurrentUserTracker.CurrentSkeleton;
        if (skelet == null)
        {
            return;
        }
        List <nuitrack.Joint> joints = new List <nuitrack.Joint>(10);

        joints.Add(skelet.GetJoint(nuitrack.JointType.Head));
        joints.Add(skelet.GetJoint(nuitrack.JointType.Torso));
        joints.Add(skelet.GetJoint(nuitrack.JointType.LeftElbow));
        joints.Add(skelet.GetJoint(nuitrack.JointType.LeftWrist));
        joints.Add(skelet.GetJoint(nuitrack.JointType.RightElbow));
        joints.Add(skelet.GetJoint(nuitrack.JointType.RightWrist));
        joints.Add(skelet.GetJoint(nuitrack.JointType.LeftKnee));
        joints.Add(skelet.GetJoint(nuitrack.JointType.RightKnee));
        joints.Add(skelet.GetJoint(nuitrack.JointType.LeftAnkle));
        joints.Add(skelet.GetJoint(nuitrack.JointType.RightAnkle));

        float min  = 1;
        float max  = 0;
        float minZ = 4000;

        foreach (nuitrack.Joint i in joints)
        {
            float xplus = 0;
            float zplus = 0;
            if (i.Type == nuitrack.JointType.Head || i.Type == nuitrack.JointType.Torso)
            {
                xplus = 0.15f;
                zplus = 250f;
            }

            if (i.Proj.X < min)
            {
                min = i.Proj.X - xplus;
            }
            if (i.Proj.X > max)
            {
                max = i.Proj.X + xplus;
            }
            if (i.Proj.Z < minZ)
            {
                minZ = i.Proj.Z - zplus;
            }
        }

        float distance = Mathf.Min(min, 1.0f - max);
        float alpha    = 0;

        if (distance < XYTrigger)
        {
            alpha = 1 - distance / XYTrigger;
        }
        if (minZ < 1500)
        {
            alpha = 1;
        }
        else if (1 - (minZ - 1500) / (ZTrigger - 1500) > alpha)
        {
            alpha = 1 - (minZ - 1500) / (ZTrigger - 1500);
        }
        gridColor.a        = alpha;
        gridMaterial.color = gridColor;
    }