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";
        }
    }
Exemplo n.º 2
0
    private void MessureHeight()
    {
        float leftHeight  = Vector3.Distance(_leftAnkleJoint.ToVector3(), _headJoint.ToVector3());
        float rightHeight = Vector3.Distance(_rightAnkleJoint.ToVector3(), _headJoint.ToVector3());

        _playerHeight = (leftHeight + rightHeight) / 2000f;
    }
Exemplo n.º 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
        {
        }
    }
Exemplo n.º 4
0
    // 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";
        }
    }
Exemplo n.º 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;
            }
        }
    }
Exemplo n.º 6
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);
                }
            }
        }
    }
    // Update is called once per frame
    void Update()
    {
        if (NuitrackManager.NumUsers > 0)
        {
            if (timer <= waitTime)
            {
                timer += Time.deltaTime;
                BoneScalingProgress.text = "Bone Scaling: In Progress...";
            }
            else if (timer >= waitTime)
            {
                BoneScalingProgress.text = "Bone Scaling: Completed";
            }

            // get ID of user
            nuitrack.User[] users         = NuitrackManager.Users;
            nuitrack.User   CurrentUser   = users[0];
            int             CurrentUserID = CurrentUser.ID;

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

                if (joint.Confidence > 0.5)                         //Currently, there are only two values of confidence: 0 (Nuitrack thinks that this isn't a joint) and 0.75 (a joint).
                {
                    ModelJoint     modeljoint  = riggedJoint.Value; //get modelJoint
                    nuitrack.Joint parentjoint = NuitrackManager.SkeletonData.GetSkeletonByID(CurrentUserID).GetJoint(modeljoint.parentJointType);

                    Vector3 newPos    = 0.001f * joint.ToVector3(); //given in mm
                    Vector3 parentPos = 0.001f * parentjoint.ToVector3();

                    // Coinvert nuitrack joint orientation to quaternion
                    Quaternion jointOrient = joint.ToQuaternion();

                    // Update Model joint to tracked orientation

                    modeljoint.bone.rotation = jointOrient * modeljoint.baseRotOffset;


                    // perform bone  scaling for 5 seconds at the start maybe?
                    if (modeljoint.parentBone != null && timer <= waitTime)
                    {
                        Debug.Log("BONE SCALING PERFORMED...........");
                        // take the transform of the 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 distances (which was recorded at the start)
                        float scaleDif = modeljoint.baseDistanceToParent / Vector3.Distance(newPos, parentPos);
                        // change the size of the bone to the resulting value
                        modeljoint.parentBone.localScale = Vector3.one / scaleDif;
                    }
                }
            }
        }
    }
Exemplo n.º 8
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!";
        }
    }
Exemplo n.º 9
0
    private void CheckDistanceFromCamera()
    {
        if (UseNuitrack && _userDetected)
        {
            if (_leftHipJoint.ToVector3().z / 1000f < 1.5f || _leftHipJoint.ToVector3().z / 1000f > 2.5f)
            {
                _userDetected       = false;
                _currentTimer       = _startTimer;
                StartingPositionSet = false;

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

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

                AddiAC.ResetTrigger("Jump");
            }
        }
    }
Exemplo n.º 10
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";
     }
 }
Exemplo n.º 11
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!";
     }
 }
Exemplo n.º 12
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";
        }
    }
    }// 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 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);
            }
        }
    }
    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);
                }
            }
        }
    }
    /// <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;
    }
Exemplo n.º 17
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";
        }
    }
Exemplo n.º 18
0
    private void CheckForInput()
    {
        if ((Input.GetKeyDown(KeyCode.Space) || Input.GetMouseButtonDown(0)) && Grounded)
        {
            _jump = true;
        }

        if ((Input.GetKey(KeyCode.Space) || Input.GetMouseButton(0)) && !Grounded)
        {
            _glide = true;
        }

        if (Input.GetKeyUp(KeyCode.Space) || Input.GetMouseButtonUp(0))
        {
            _glide = false;
        }

        if (Input.GetKey(KeyCode.LeftControl))
        {
            _crouch = true;
        }

        if (Input.GetKeyUp(KeyCode.LeftControl))
        {
            _crouch = false;
        }

        if (UseNuitrack)
        {
            if (_gameManager.GameState == GameManager.GameStateType.EndGame)
            {
                if (CheckForTPose())
                {
                    if (_currentTimer > 0.0f)
                    {
                        _currentTimer -= Time.deltaTime;
                    }
                    else
                    {
                        _currentTimer = _startTimer;
                        _gameManager.RestartLevel();
                    }
                }
            }

            if (_gameManager.GameState == GameManager.GameStateType.Playing && _userDetected)
            {
                if (Grounded && (_rightHipJoint.ToVector3().y > _rightHipStartingPosition.y + JumpThreshold * _playerHeight || _leftHipJoint.ToVector3().y > _leftHipStartingPosition.y + JumpThreshold * _playerHeight))
                {
                    if (!_jump)
                    {
                        _jump = true;
                        _scoreManager.NumberOfJumps++;
                    }
                }

                if (!Grounded && (_rightShoulderJoint.ToQuaternion().eulerAngles.z > 270 && _rightShoulderJoint.ToQuaternion().eulerAngles.z < 360) ||
                    (_rightShoulderJoint.ToQuaternion().eulerAngles.z >= 0 && _rightShoulderJoint.ToQuaternion().eulerAngles.z < 60))
                {
                    if ((_leftShoulderJoint.ToQuaternion().eulerAngles.z > 0 && _leftShoulderJoint.ToQuaternion().eulerAngles.z < 90) ||
                        (_leftShoulderJoint.ToQuaternion().eulerAngles.z <= 360 && _leftShoulderJoint.ToQuaternion().eulerAngles.z > 300))
                    {
                        if (!_glide)
                        {
                            _scoreManager.NumberOfGlides++;
                        }
                        _glide = true;
                    }
                }

                if ((_rightShoulderJoint.ToQuaternion().eulerAngles.z <= 270 && _rightShoulderJoint.ToQuaternion().eulerAngles.z > 60) ||
                    (_leftShoulderJoint.ToQuaternion().eulerAngles.z >= 90 && _leftShoulderJoint.ToQuaternion().eulerAngles.z <= 300))
                {
                    _glide = false;
                }

                if (_rightHipJoint.ToVector3().y < _rightHipStartingPosition.y - CrouchThreshold * _playerHeight || _leftHipJoint.ToVector3().y < _leftHipStartingPosition.y - CrouchThreshold * _playerHeight)
                {
                    if (!_crouch)
                    {
                        _scoreManager.NumberOfSquats++;
                    }
                    _crouch = true;
                }
                else
                {
                    _crouch = false;
                }
            }

            //print("LEFT: " + _leftShoulderJoint.ToQuaternion().eulerAngles.z + " , RIGHT: " + _rightShoulderJoint.ToQuaternion().eulerAngles.z);
        }
    }
Exemplo n.º 19
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");
            }
        }
    }
Exemplo n.º 20
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);
                }
            }
        }
    }
Exemplo n.º 21
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!";
        }
    }