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";
        }
    }
Example #2
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!";
        }
    }
Example #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
        {
        }
    }
Example #4
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;
            }
        }
    }
Example #5
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";
        }
    }
Example #7
0
 private void MoveBody(nuitrack.Skeleton skeleton)
 {
     foreach (ModelJoint modelJoint in modelJoints)
     {
         modelJoint.bone.position = (0.001f * skeleton.GetJoint(modelJoint.jointType).ToVector3());
     }
 }
    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;
    }
Example #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 = 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);
                }
            }
        }
    }
Example #10
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);
                }
            }
        }
    }
Example #11
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;
        }
    }
 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;
     }
 }
Example #13
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;
     }
 }
    }// 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
Example #15
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;
    }
Example #17
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";
     }
 }
Example #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);
            }
        }
    }
Example #19
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);
            }
        }
    }
Example #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!";
     }
 }
Example #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 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);
                }
            }
        }
    }
Example #23
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;
    }
Example #24
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";
        }
    }
Example #25
0
    void NuitrackManager_onSkeletonTrackerUpdate(nuitrack.SkeletonData skeletonData)
    {
        if (Input.GetKeyUp(KeyCode.Space))
        {
            var pins = GameObject.FindGameObjectsWithTag("Pin");

            for (int i = 0; i < pins.Length; i++)
            {
                var pinPhysics = pins[i].GetComponent <Rigidbody>();
                pinPhysics.velocity        = Vector3.zero;
                pinPhysics.position        = pinPositions[i];
                pinPhysics.rotation        = pinRotations[i];
                pinPhysics.velocity        = Vector3.zero;
                pinPhysics.angularVelocity = Vector3.zero;
            }
        }

        if (CurrentUserTracker.CurrentUser != 0)
        {
            nuitrack.Skeleton skeleton = CurrentUserTracker.CurrentSkeleton;

            Vector3 leftKneePosition = scalK * skeleton.GetJoint(nuitrack.JointType.LeftKnee).ToVector3();

            Vector3 rightKneePosition = scalK * skeleton.GetJoint(nuitrack.JointType.RightKnee).ToVector3();

            float distSizeofLeg = Vector3.Distance(rightKneePosition, Floor.gameObject.transform.position);

            float distJoelhoEsqaoChao = Vector3.Distance(Floor.gameObject.transform.position, leftKneePosition);

            float distJoelhoDiraoChao = Vector3.Distance(Floor.gameObject.transform.position, rightKneePosition);



            //Timer para guardar tamanho das pernas
            if (validarapenas1vezPerna)
            {
                timerTamanhoPernas -= Time.deltaTime;
                EstadoAtual.text    = "Timer: " + timerTamanhoPernas;
                if (timerTamanhoPernas < -0)
                {
                    tamanhoPernas          = distSizeofLeg;
                    validarapenas1vezPerna = false;
                    EstadoAtual.text       = "Tamanho da perna: " + tamanhoPernas;
                }
            }

            if (tamanhoPernas > 0)
            {
                //Lado Direito
                Vector3 targetPostion = scalK * skeleton.GetJoint(targetJoint).ToVector3();
                Vector3 moveDirection = targetPostion - rightKneePosition;

                Vector3 velocityMove = Vector3.Project(rightKneePosition.normalized, moveDirection);


                float distSeparacaodePernas = Vector3.Distance(rightKneePosition, targetPostion);

                //Lado Esq
                Vector3 targetPostionEsq = scalK * skeleton.GetJoint(targetJointRightKnee).ToVector3();
                Vector3 moveDirectionEsq = targetPostionEsq - leftKneePosition;

                Vector3 velocityMoveEsq = Vector3.Project(leftKneePosition, moveDirectionEsq);

                float distSeparacaodePernasEsq = Vector3.Distance(leftKneePosition, targetPostionEsq);



                //Debug.Log("Tamanho da perna: " + tamanhoPernas);
                //Debug.Log("Separacao das pernas: " + distSeparacaodePernasEsq);
                //Debug.Log("Distancia Joelho Direito ao chao:" + distJoelhoDiraoChao);
                //Debug.Log("Distancia Joelho Esquerdo ao chao:" + distJoelhoEsqaoChao);



                //text.text = "" + distJoelhoDiraoChao;
            }
        }
    }
Example #26
0
    private void CheckIfUserDetected()
    {
        if (UseNuitrack)
        {
            if (CurrentUserTracker.CurrentUser != 0)
            {
                _skeleton = CurrentUserTracker.CurrentSkeleton;

                _leftAnkleJoint  = _skeleton.GetJoint(nuitrack.JointType.LeftAnkle);
                _rightAnkleJoint = _skeleton.GetJoint(nuitrack.JointType.RightAnkle);

                _leftHipJoint  = _skeleton.GetJoint(nuitrack.JointType.LeftHip);
                _rightHipJoint = _skeleton.GetJoint(nuitrack.JointType.RightHip);

                _leftShoulderJoint  = _skeleton.GetJoint(nuitrack.JointType.LeftShoulder);
                _rightShoulderJoint = _skeleton.GetJoint(nuitrack.JointType.RightShoulder);

                _headJoint = _skeleton.GetJoint(nuitrack.JointType.Head);

                if (_gameManager.GameState == GameManager.GameStateType.Playing)
                {
                    if (CheckForTPose())
                    {
                        if (_currentTimer > 0.0f)
                        {
                            _currentTimer -= Time.deltaTime;
                        }
                        else
                        {
                            if (!StartingPositionSet)
                            {
                                if (AreYouReadyText.activeSelf)
                                {
                                    AreYouReadyText.SetActive(false);
                                }

                                _leftHipStartingPosition  = _leftHipJoint.ToVector3();
                                _rightHipStartingPosition = _rightHipJoint.ToVector3();

                                MessureHeight();

                                StartingPositionSet = true;

                                _userDetected = true;

                                _currentTimer = 1.0f;
                            }
                        }
                    }
                }
            }
            else
            {
                AreYouReadyText.SetActive(true);

                _currentTimer       = _startTimer;
                _userDetected       = false;
                StartingPositionSet = false;

                _crouch = false;
                _jump   = false;
                _glide  = false;

                AddiAC.SetBool("Crouching", false);
                AddiAC.SetBool("Falling", false);
                AddiAC.SetBool("Glide", false);

                AddiAC.ResetTrigger("Jump");
            }
        }
    }
Example #27
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!";
        }
    }
Example #28
0
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.S) && PointCloudGPU.Instance.trainFile)
        {
            String str = coordinatesSave.Count + " 48  1" + Environment.NewLine;
            for (int i = 0; i < coordinatesSave.Count; i++)
            {
                str += coordinatesSave[i][0] + " " + coordinatesSave[i][1] + " " + coordinatesSave[i][2] + " " + coordinatesSave[i][3] + " " + coordinatesSave[i][4] + " " + coordinatesSave[i][5] + " " + coordinatesSave[i][6] + " " + coordinatesSave[i][7] + " " + coordinatesSave[i][8] + " " + coordinatesSave[i][9] + " " + coordinatesSave[i][10] + " " + coordinatesSave[i][11] + " " + coordinatesSave[i][12] + " " + coordinatesSave[i][13] + " " + coordinatesSave[i][14] + " " + coordinatesSave[i][15] + " " + coordinatesSave[i][16] + " " + coordinatesSave[i][17] + " " + coordinatesSave[i][18] + " " + coordinatesSave[i][19] + " " + coordinatesSave[i][20] + " " + coordinatesSave[i][21] + " " + coordinatesSave[i][22] + " " + coordinatesSave[i][23] + " " + coordinatesSave[i][24] + " " + coordinatesSave[i][25] + " " + coordinatesSave[i][26] + " " + coordinatesSave[i][27] + " " + coordinatesSave[i][28] + " " + coordinatesSave[i][29] + " " + coordinatesSave[i][30] + " " + coordinatesSave[i][31] + " " + coordinatesSave[i][32] + " " + coordinatesSave[i][33] + " " + coordinatesSave[i][34] + " " + coordinatesSave[i][35] + " " + coordinatesSave[i][36] + " " + coordinatesSave[i][37] + " " + coordinatesSave[i][38] + " " + coordinatesSave[i][39] + " " + coordinatesSave[i][40] + " " + coordinatesSave[i][41] + " " + coordinatesSave[i][42] + " " + coordinatesSave[i][43] + " " + coordinatesSave[i][44] + " " + coordinatesSave[i][45] + " " + coordinatesSave[i][46] + " " + coordinatesSave[i][47] + Environment.NewLine;
                str += coordinatesSettings[i] + Environment.NewLine;
            }
            File.WriteAllText(Application.streamingAssetsPath + "/fann_training.txt", str);
        }
        else if (Input.GetKeyDown(KeyCode.S))
        {
            const uint num_input  = 16 * 3;
            const uint num_output = 1;
            uint[]     num_layers = new uint[2] {
                num_input, num_output
            };
            const float  desired_error          = 0.00005f;
            const uint   max_epochs             = 1000000;
            const uint   epochs_between_reports = 500;
            TrainingData trainingData           = new TrainingData(Application.streamingAssetsPath + "/fann_training.txt");
            neuralNet = new NeuralNet(FANNCSharp.NetworkType.SHORTCUT, num_layers);
            neuralNet.TrainingAlgorithm = FANNCSharp.TrainingAlgorithm.TRAIN_RPROP;
            neuralNet.SetScalingParams(trainingData, -1, 1, 0, 1);
            neuralNet.InitWeights(trainingData);
            neuralNet.CascadetrainOnData(trainingData, max_epochs, epochs_between_reports, desired_error);
            neuralNet.Save(Application.streamingAssetsPath + "/fann_neural_net.txt");
        }
        if (CurrentUserTracker.CurrentUser != 0)
        {
            nuitrack.Skeleton skeleton = CurrentUserTracker.CurrentSkeleton;

            if (Input.GetMouseButtonDown(0) && PointCloudGPU.Instance.trainFile)
            {
                normal = true;
            }
            if (Input.GetMouseButtonDown(1) && PointCloudGPU.Instance.trainFile)
            {
                disfordant = true;
            }
            if (valueNN > 0.975 && !urlRequest)
            {
                string url  = "https://bodyfail.com/addSample?";
                float  xMax = 0;
                float  yMax = 0;
                float  zMax = 0;
                for (int q = 0; q < typeJoint.Length; q++)
                {
                    nuitrack.Joint joint       = skeleton.GetJoint(typeJoint[q]);
                    Vector3        newPosition = joint.ToVector3();
                    if (Mathf.Abs(newPosition.x) > xMax)
                    {
                        xMax = Mathf.Abs(newPosition.x);
                    }
                    if (Mathf.Abs(newPosition.y) > yMax)
                    {
                        yMax = Mathf.Abs(newPosition.y);
                    }
                    if (Mathf.Abs(newPosition.z) > zMax)
                    {
                        zMax = Mathf.Abs(newPosition.z);
                    }
                }
                for (int q = 0; q < typeJoint.Length; q++)
                {
                    nuitrack.Joint joint       = skeleton.GetJoint(typeJoint[q]);
                    Vector3        newPosition = joint.ToVector3();
                    if (q < 15)
                    {
                        url += "n" + q + "x=" + (newPosition.x / xMax) + "&n" + q + "y=" + (newPosition.y / yMax) + "&n" + q + "z=" + (newPosition.z / zMax) + "&";
                    }
                    else
                    {
                        url += "n" + q + "x=" + (newPosition.x / xMax) + "&n" + q + "y=" + (newPosition.y / yMax) + "&n" + q + "z=" + (newPosition.z / zMax);
                    }
                }
                url       += "&place=AbuDhabiTest";
                urlRequest = true;
                Debug.Log(url);
                StartCoroutine(RequestUrl(url));
            }
            for (int q = 0; q < typeJoint.Length; q++)
            {
                nuitrack.Joint joint       = skeleton.GetJoint(typeJoint[q]);
                Vector3        newPosition = joint.ToVector3();

                coordinates[q * 3]     = newPosition.x;
                coordinates[q * 3 + 1] = newPosition.y;
                coordinates[q * 3 + 2] = newPosition.z;
                valueNN = PointCloudGPU.Instance.matPointCloud.GetFloat("_Value");

                if (valueNN > 0.975 || PointCloudGPU.Instance.trainFile)
                {
                    if (q % 2 == 0)
                    {
                        printCoordinates.Add("Trying to recover...");
                    }
                    else
                    {
                        printCoordinates.Add("Segmentation Fault : Kernel Error");
                    }
                    if (!CreatedJoint[q].activeSelf)
                    {
                        CreatedJoint[q].SetActive(true);
                    }
                    CreatedJoint[q].transform.localPosition = new Vector3(newPosition.x, newPosition.y, newPosition.z);
                }
                else
                {
                    urlRequest = false;
                    printCoordinates.Add(newPosition.ToString());
                    if (CreatedJoint[q].activeSelf)
                    {
                        CreatedJoint[q].SetActive(false);
                    }
                }
                if (normal && PointCloudGPU.Instance.trainFile)
                {
                    coordinatesSettings.Add(0);
                }
                else if (disfordant && PointCloudGPU.Instance.trainFile)
                {
                    coordinatesSettings.Add(1);
                }
                else if (!PointCloudGPU.Instance.trainFile && neuralNet.Run(coordinates).Length > 0)
                {
                    PointCloudGPU.Instance.valueDisfordance = neuralNet.Run(coordinates)[0];
                }
                if ((normal || disfordant) && PointCloudGPU.Instance.trainFile)
                {
                    float[] arrayTmp = new float[16 * 3];
                    coordinates.CopyTo(arrayTmp, 0);
                    coordinatesSave.Add(arrayTmp);
                }
                normal     = false;
                disfordant = false;
                while (printCoordinates.Count > nbCoordinates)
                {
                    printCoordinates.RemoveAt(0);
                }
            }
            if (textLeft && textRight)
            {
                for (int i = 0; i < printCoordinates.Count; i++)
                {
                    if (i > nbCoordinates / 2)
                    {
                        if (i == nbCoordinates / 2 + 1)
                        {
                            textRight.text = printCoordinates[i] + Environment.NewLine;
                        }
                        else
                        {
                            textRight.text += printCoordinates[i] + Environment.NewLine;
                        }
                    }
                    else
                    {
                        if (i == 0)
                        {
                            textLeft.text = printCoordinates[i] + Environment.NewLine;
                        }
                        else
                        {
                            textLeft.text += printCoordinates[i] + Environment.NewLine;
                        }
                    }
                }
            }
        }
        else if (valueNN < 0.975)
        {
            for (int q = 0; q < CreatedJoint.Length; q++)
            {
                if (CreatedJoint[q].activeSelf)
                {
                    CreatedJoint[q].SetActive(false);
                }
            }
        }
    }
    void ProcessFrame(nuitrack.DepthFrame depthFrame)
    {
        int pointIndex = 0;

        depthArray = new int[depthFrame.Rows, depthFrame.Cols];


        for (int i = 0; i < depthFrame.Rows; i += 1)
        {
            for (int j = 0; j < depthFrame.Cols; j += 1)
            {
                //take depth from the frame and put it into the depthColors array
                depthArray[i, j] = depthFrame[i, j];

                float value = depthFrame[i, j] / 16384f;


                depthColors[pointIndex].r = value;
                depthColors[pointIndex].g = value;
                depthColors[pointIndex].b = value;
                depthColors[pointIndex].a = 1;



                ++pointIndex;
            }
        }


        depthTexture.SetPixels(depthColors);

        //depthTexture.Apply();
        Debug.Log(pointIndex);

        if (record)
        {
            string filename = "/" + DateTime.Now.Hour + "-" + DateTime.Now.Minute + "-" + DateTime.Now.Second + "-" + DateTime.Now.Millisecond + ".png";
            byte[] bytes    = depthTexture.EncodeToPNG();
            File.WriteAllBytes(recordDirectory + filename, bytes);
            message = "recording";
            //writeline for skeletal data will need to go in this block

            //SKELINGTON STUFF
            //SKELINGTON 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);
            }
        }
    }
Example #30
0
    private void MoveTorso(nuitrack.Skeleton skeleton)
    {
        Vector3 torsoPos = (0.001f * skeleton.GetJoint(nuitrack.JointType.Torso).ToVector3());

        transform.position = torsoPos;
    }