Beispiel #1
0
    void NuitrackManager_onSkeletonTrackerUpdate(nuitrack.SkeletonData skeletonData)
    {
        if ((skeletonData == null) || (skeletonData.NumUsers == 0))
        {
            currentUser     = 0;
            currentSkeleton = null;
            return;
        }

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

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

        /*Vector3 Position = scalK * currentSkeleton.GetJoint(nuitrack.JointType.RightShoulder).ToVector3();
         *
         * float distSizeofLeg = Vector3.Distance(Position, Floor.gameObject.transform.position);
         *
         * print(distSizeofLeg);*/
    }
    void HandleOnSkeletonUpdateEvent(nuitrack.SkeletonData _skeletonData)
    {
//        Debug.Log("Skeleton Update");
        skeletonData = _skeletonData;
        if (onSkeletonTrackerUpdate != null)
        {
            onSkeletonTrackerUpdate(skeletonData);
        }
    }
    public void CloseUserGen()
    {
        try
        {
            if (DepthSensor != null)
            {
                DepthSensor.OnUpdateEvent -= HandleOnDepthSensorUpdateEvent;
            }

            if (ColorSensor != null)
            {
                ColorSensor.OnUpdateEvent -= HandleOnColorSensorUpdateEvent;
            }

            if (UserTracker != null)
            {
                UserTracker.OnUpdateEvent -= HandleOnUserTrackerUpdateEvent;
            }

            if (SkeletonTracker != null)
            {
                SkeletonTracker.OnSkeletonUpdateEvent -= HandleOnSkeletonUpdateEvent;
            }

            if (GestureRecognizer != null)
            {
                GestureRecognizer.OnNewGesturesEvent -= OnNewGestures;
            }

            if (HandTracker != null)
            {
                HandTracker.OnUpdateEvent -= HandleOnHandsUpdateEvent;
            }

            DepthFrame      = null;
            ColorFrame      = null;
            UserFrame       = null;
            skeletonData    = null;
            handTrackerData = null;

            DepthSensor       = null;
            ColorSensor       = null;
            UserTracker       = null;
            SkeletonTracker   = null;
            GestureRecognizer = null;
            HandTracker       = null;

            nuitrack.Nuitrack.Release();
            Debug.Log("Nuitrack Stop OK");
            nuitrackInitialized = false;
        }
        catch (System.Exception ex)
        {
            Debug.LogError(ex.ToString());
        }
    }
Beispiel #4
0
 void HandleOnSkeletonUpdateEvent(nuitrack.SkeletonData _skeletonData)
 {
     if (skeletonData != null)
     {
         skeletonData.Dispose();
     }
     skeletonData = (nuitrack.SkeletonData)_skeletonData.Clone();
     //Debug.Log("Skeleton Update ");
     sensorConnected = true;
     onSkeletonTrackerUpdate?.Invoke(skeletonData);
 }
Beispiel #5
0
 void ProcessSkeletons(nuitrack.SkeletonData skeletonData)
 {
     if ((skeletonData == null) || (skeletonData.NumUsers == 0))
     {
         Debug.Log("isNull");
         //print(skeletonData.NumUsers);
     }
     else
     {
         Debug.Log("isNotNull");
         print(skeletonData.NumUsers);
     }
 }
Beispiel #6
0
    public void CloseUserGen()
    {
        try
        {
            if (depthSensor != null)
            {
                depthSensor.OnUpdateEvent -= HandleOnDepthSensorUpdateEvent;
            }
            if (colorSensor != null)
            {
                colorSensor.OnUpdateEvent -= HandleOnColorSensorUpdateEvent;
            }
            if (userTracker != null)
            {
                userTracker.OnUpdateEvent -= HandleOnUserTrackerUpdateEvent;
            }
            if (skeletonTracker != null)
            {
                skeletonTracker.OnSkeletonUpdateEvent -= HandleOnSkeletonUpdateEvent;
            }
            if (gestureRecognizer != null)
            {
                gestureRecognizer.OnNewGesturesEvent -= OnNewGestures;
            }
            if (handTracker != null)
            {
                handTracker.OnUpdateEvent -= HandleOnHandsUpdateEvent;
            }

            depthFrame      = null;
            colorFrame      = null;
            userFrame       = null;
            skeletonData    = null;
            handTrackerData = null;

            depthSensor       = null;
            colorSensor       = null;
            userTracker       = null;
            skeletonTracker   = null;
            gestureRecognizer = null;
            handTracker       = null;

            nuitrack.Nuitrack.Release();
            Debug.Log("CloseUserGen");
            nuitrackInitialized = false;
        }
        catch (System.Exception ex)
        {
            Debug.LogError(ex.ToString());
        }
    }
    void HandleOnSkeletonUpdateEvent(nuitrack.SkeletonData _skeletonData)
    {
        if (skeletonData != null)
        {
            skeletonData.Dispose();
        }

        skeletonData    = (nuitrack.SkeletonData)_skeletonData.Clone();
        sensorConnected = true;
        try
        {
            onSkeletonTrackerUpdate?.Invoke(skeletonData);
        }
        catch (Exception ex)
        {
            Debug.LogException(ex);
        }
    }
Beispiel #8
0
    void Update()
    {
        nuitrack.SkeletonData skd = NuitrackManager.SkeletonData;
        if (skd != null)
        {
            float lz = skd.Skeletons[0].GetJoint(nuitrack.JointType.LeftWrist).Real.Z;
            float rz = skd.Skeletons[0].GetJoint(nuitrack.JointType.RightWrist).Real.Z;

            float lx = skd.Skeletons[0].GetJoint(nuitrack.JointType.LeftWrist).Real.X;
            float rx = skd.Skeletons[0].GetJoint(nuitrack.JointType.RightWrist).Real.X;

            float deltaZ = lz - rz;
            float deltaX = lx - rx;

            float alpha = Mathf.Atan2(deltaZ, deltaX) * Mathf.Rad2Deg;

            debugTxt.text = string.Format("dz = " + deltaZ.ToString("0") + System.Environment.NewLine + "dx = " + deltaX.ToString("0") + System.Environment.NewLine + "angle = " + alpha.ToString("0"));
        }
    }
    public void CloseUserGen()
    {
        if (depthSensor != null)
        {
            depthSensor.OnUpdateEvent -= HandleOnDepthSensorUpdateEvent;
        }
        if (colorSensor != null)
        {
            colorSensor.OnUpdateEvent -= HandleOnColorSensorUpdateEvent;
        }
        if (userTracker != null)
        {
            userTracker.OnUpdateEvent -= HandleOnUserTrackerUpdateEvent;
        }
        if (skeletonTracker != null)
        {
            skeletonTracker.OnSkeletonUpdateEvent -= HandleOnSkeletonUpdateEvent;
        }
        if (gestureRecognizer != null)
        {
            gestureRecognizer.OnNewGesturesEvent -= OnNewGestures;
        }
        if (handTracker != null)
        {
            handTracker.OnUpdateEvent -= HandleOnHandsUpdateEvent;
        }
        //		Debug.Log ("preRelease");
        nuitrack.Nuitrack.Release();
        //		Debug.Log ("postRelease");

        depthSensor       = null;
        colorSensor       = null;
        userTracker       = null;
        skeletonTracker   = null;
        gestureRecognizer = null;
        handTracker       = null;

        depthFrame      = null;
        colorFrame      = null;
        userFrame       = null;
        skeletonData    = null;
        handTrackerData = null;
    }
    void NuitrackManager_onSkeletonTrackerUpdate(nuitrack.SkeletonData skeletonData)
    {
        if ((skeletonData == null) || (skeletonData.NumUsers == 0))
        {
            currentUser     = 0;
            currentSkeleton = null;
            return;
        }

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

        if (currentUser == 0)
        {
            currentUser     = skeletonData.Skeletons[0].ID;
            currentSkeleton = skeletonData.Skeletons[0];
        }
    }
Beispiel #11
0
    void ProcessSkeletons(nuitrack.SkeletonData skeletonData)
    {
        Debug.Log("NumUsers: " + skeletonData.NumUsers.ToString());

        foreach (int userId in skeletonParts.Keys)
        {
            if (skeletonData.GetSkeletonByID(userId) == null)
            {
                foreach (GameObject go in skeletonParts[userId])
                {
                    if (go.activeSelf)
                    {
                        go.SetActive(false);
                    }
                }
            }
        }

        foreach (nuitrack.Skeleton skeleton in skeletonData.Skeletons)
        {
            if (!skeletonParts.ContainsKey(skeleton.ID))
            {
                GameObject[] newJoints = new GameObject[skeleton.Joints.Length];
                for (int i = 0; i < newJoints.Length; i++)
                {
                    newJoints[i] = (GameObject)Instantiate(jointPrefab, Vector3.zero, Quaternion.identity);
                }
                skeletonParts.Add(skeleton.ID, newJoints);
            }

            //if we don't have ID in dictionary then we create required array of joint GameObjects and add it to dictionary
            GameObject[] skeletonJoints = skeletonParts[skeleton.ID];

            for (int i = 0; i < skeleton.Joints.Length; i++)
            {
                if (skeleton.Joints[i].Confidence > 0.5f)
                {
                    if (!skeletonJoints[i].activeSelf)
                    {
                        skeletonJoints[i].SetActive(true);
                    }
                    skeletonJoints[i].transform.position = new Vector3(skeleton.Joints[i].Real.X / 1000f, skeleton.Joints[i].Real.Y / 1000f, skeleton.Joints[i].Real.Z / 1000f);

                    //skel.Joints[i].Orient.Matrix:
                    // 0,           1,	        2,
                    // 3,           4,          5,
                    // 6,           7,          8
                    // -------
                    // right(X),	up(Y),      forward(Z)

                    //Vector3 jointRight =  new Vector3(  skeleton.Joints[i].Orient.Matrix[0],  skeleton.Joints[i].Orient.Matrix[3],  skeleton.Joints[i].Orient.Matrix[6] );
                    Vector3 jointUp      = new Vector3(skeleton.Joints[i].Orient.Matrix[1], skeleton.Joints[i].Orient.Matrix[4], skeleton.Joints[i].Orient.Matrix[7]);
                    Vector3 jointForward = new Vector3(skeleton.Joints[i].Orient.Matrix[2], skeleton.Joints[i].Orient.Matrix[5], skeleton.Joints[i].Orient.Matrix[8]);

                    skeletonJoints[i].transform.rotation = Quaternion.LookRotation(jointForward, jointUp);
                }
                else
                {
                    if (skeletonJoints[i].activeSelf)
                    {
                        skeletonJoints[i].SetActive(false);
                    }
                }
            }
        }
    }
    public void ChangeModules(bool depthOn, bool colorOn, bool userOn, bool skeletonOn, bool handsOn, bool gesturesOn)
    {
        try
        {
            //      if (depthSensor != null) depthSensor.OnUpdateEvent -= DepthUpdate;
            //      if (userTracker != null) userTracker.OnUpdateEvent -= UserUpdate;
            //      if (skeletonTracker != null) skeletonTracker.OnSkeletonUpdateEvent -= SkeletonsUpdate;
            //      if (handTracker != null) handTracker.OnUpdateEvent -= HandTrackerUpdate;
            //      if (gestureRecognizer != null) gestureRecognizer.OnNewGesturesEvent -= GesturesUpdate;

            //*
            if (!nuitrackInitialized)
            {
            #if UNITY_IOS
                nuitrack.Nuitrack.Init("", nuitrack.Nuitrack.NuitrackMode.DEBUG);
            #else
                nuitrack.Nuitrack.Init();
            #endif
                Debug.Log("init ok");
                depthSensorInit       = nuitrack.DepthSensor.Create();
                colorSensorInit       = nuitrack.ColorSensor.Create();
                userTrackerInit       = nuitrack.UserTracker.Create();
                skeletonTrackerInit   = nuitrack.SkeletonTracker.Create();
                handTrackerInit       = nuitrack.HandTracker.Create();
                gestureRecognizerInit = nuitrack.GestureRecognizer.Create();

                nuitrack.Nuitrack.Run();
                Debug.Log("run ok");
                nuitrackInitialized = true;
            }
//			*/

            depthFrame      = null;
            colorFrame      = null;
            userFrame       = null;
            skeletonData    = null;
            handTrackerData = null;
            gesturesData    = null;
            //
            //      depthSensor = null;
            //      userTracker = null;
            //      skeletonTracker = null;
            //      handTracker = null;
            //      gestureRecognizer = null;

            //if (issuesProcessor != null) Destroy(issuesProcessor);

            if (prevDepth != depthOn)
            {
                prevDepth = depthOn;
                if (depthOn)
                {
                    depthSensor = depthSensorInit;
                    depthSensorInit.OnUpdateEvent += DepthUpdate;
                }
                else
                {
                    depthSensorInit.OnUpdateEvent -= DepthUpdate;
                    depthSensor = null;
                }
            }

            if (prevColor != colorOn)
            {
                prevColor = colorOn;
                if (colorOn)
                {
                    colorSensor = colorSensorInit;
                    colorSensorInit.OnUpdateEvent += ColorUpdate;
                }
                else
                {
                    colorSensorInit.OnUpdateEvent -= ColorUpdate;
                    colorSensor = null;
                }
            }

            if (prevUser != userOn)
            {
                prevUser = userOn;
                if (userOn)
                {
                    userTracker = userTrackerInit;
                    userTrackerInit.OnUpdateEvent += UserUpdate;
                }

                else
                {
                    userTrackerInit.OnUpdateEvent -= UserUpdate;
                    userTracker = null;
                }
            }

            if (skeletonOn != prevSkel)
            {
                prevSkel = skeletonOn;
                if (skeletonOn)
                {
                    skeletonTracker = skeletonTrackerInit;
                    skeletonTrackerInit.OnSkeletonUpdateEvent += SkeletonsUpdate;
                }
                else
                {
                    skeletonTrackerInit.OnSkeletonUpdateEvent -= SkeletonsUpdate;
                    skeletonTracker = null;
                }
            }

            if (prevHand != handsOn)
            {
                prevHand = handsOn;
                if (handsOn)
                {
                    handTracker = handTrackerInit;
                    handTrackerInit.OnUpdateEvent += HandTrackerUpdate;
                }
                else
                {
                    handTrackerInit.OnUpdateEvent -= HandTrackerUpdate;
                    handTracker = null;
                }
            }

            if (prevGesture != gesturesOn)
            {
                prevGesture = gesturesOn;
                if (gesturesOn)
                {
                    gestureRecognizer = gestureRecognizerInit;
                    gestureRecognizerInit.OnNewGesturesEvent += GesturesUpdate;
                }
                else
                {
                    gestureRecognizerInit.OnNewGesturesEvent -= GesturesUpdate;
                    gestureRecognizer = null;
                }
            }
            //issuesProcessor = (GameObject)Instantiate(issuesProcessorPrefab);
        }
        catch (Exception ex)
        {
            exceptionsLogger.AddEntry(ex.ToString());
        }
    }
    private void InitTrackers(bool depthOn, bool colorOn, bool userOn, bool skeletonOn, bool handsOn, bool gesturesOn)
    {
        if (!nuitrackInitialized)
        {
            nuitrack.Nuitrack.Init();
            Debug.Log("init ok");
            depthSensorInit       = nuitrack.DepthSensor.Create();
            colorSensorInit       = nuitrack.ColorSensor.Create();
            userTrackerInit       = nuitrack.UserTracker.Create();
            skeletonTrackerInit   = nuitrack.SkeletonTracker.Create();
            handTrackerInit       = nuitrack.HandTracker.Create();
            gestureRecognizerInit = nuitrack.GestureRecognizer.Create();

            nuitrack.Nuitrack.Run();
            Debug.Log("run ok");
            nuitrackInitialized = true;
        }

        depthFrame      = null;
        colorFrame      = null;
        userFrame       = null;
        skeletonData    = null;
        handTrackerData = null;
        gesturesData    = null;
        //
        //      depthSensor = null;
        //      userTracker = null;
        //      skeletonTracker = null;
        //      handTracker = null;
        //      gestureRecognizer = null;

        //if (issuesProcessor != null) Destroy(issuesProcessor);

        if (prevDepth != depthOn)
        {
            prevDepth = depthOn;
            if (depthOn)
            {
                depthSensor = depthSensorInit;
                depthSensorInit.OnUpdateEvent += DepthUpdate;
            }
            else
            {
                depthSensorInit.OnUpdateEvent -= DepthUpdate;
                depthSensor = null;
            }
        }

        if (prevColor != colorOn)
        {
            prevColor = colorOn;
            if (colorOn)
            {
                colorSensor = colorSensorInit;
                colorSensorInit.OnUpdateEvent += ColorUpdate;
            }
            else
            {
                colorSensorInit.OnUpdateEvent -= ColorUpdate;
                colorSensor = null;
            }
        }

        if (prevUser != userOn)
        {
            prevUser = userOn;
            if (userOn)
            {
                userTracker = userTrackerInit;
                userTrackerInit.OnUpdateEvent += UserUpdate;
            }

            else
            {
                userTrackerInit.OnUpdateEvent -= UserUpdate;
                userTracker = null;
            }
        }

        if (skeletonOn != prevSkel)
        {
            prevSkel = skeletonOn;
            if (skeletonOn)
            {
                skeletonTracker = skeletonTrackerInit;
                skeletonTrackerInit.OnSkeletonUpdateEvent += SkeletonsUpdate;
            }
            else
            {
                skeletonTrackerInit.OnSkeletonUpdateEvent -= SkeletonsUpdate;
                skeletonTracker = null;
            }
        }

        if (prevHand != handsOn)
        {
            prevHand = handsOn;
            if (handsOn)
            {
                handTracker = handTrackerInit;
                handTrackerInit.OnUpdateEvent += HandTrackerUpdate;
            }
            else
            {
                handTrackerInit.OnUpdateEvent -= HandTrackerUpdate;
                handTracker = null;
            }
        }

        if (prevGesture != gesturesOn)
        {
            prevGesture = gesturesOn;
            if (gesturesOn)
            {
                gestureRecognizer = gestureRecognizerInit;
                gestureRecognizerInit.OnNewGesturesEvent += GesturesUpdate;
            }
            else
            {
                gestureRecognizerInit.OnNewGesturesEvent -= GesturesUpdate;
                gestureRecognizer = null;
            }
        }

        StopThread();
    }
 private void HandleOnSkeletonUpdateEvent(nuitrack.SkeletonData _skeletonData)
 {
     skeletonData          = _skeletonData;
     skeletonDataTimestamp = DateTime.Now.Ticks / 10000;
 }
    public void CloseSensor(KinectInterop.SensorData sensorData)
    {
        if (colorWebCam)
        {
            colorWebCam.Stop();
            colorWebCam = null;
        }

        if (coordMapper != null)
        {
            coordMapper.CleanUp();
            coordMapper = null;
        }

        if (colorSensor != null)
        {
            colorSensor.OnUpdateEvent -= HandleOnColorSensorUpdateEvent;
            colorSensor = null;
            colorFrame  = null;
        }

        if (depthSensor != null)
        {
            depthSensor.OnUpdateEvent -= HandleOnDepthSensorUpdateEvent;
            depthSensor = null;
            depthFrame  = null;
        }

        if (userTracker != null)
        {
            userTracker.OnUpdateEvent -= HandleOnUserTrackerUpdateEvent;
            userTracker = null;
            userFrame   = null;
        }

        if (skeletonTracker != null)
        {
            skeletonTracker.OnSkeletonUpdateEvent -= HandleOnSkeletonUpdateEvent;
            skeletonTracker = null;
            skeletonData    = null;
        }

        if (handTracker != null)
        {
            handTracker.OnUpdateEvent -= HandleOnHandsUpdateEvent;
            handTracker     = null;
            handTrackerData = null;
        }

        if (gestureRecognizer != null)
        {
            gestureRecognizer.OnNewGesturesEvent -= OnNewGestures;
            gestureRecognizer = null;
        }

        if (bNuitrackInited)
        {
            bNuitrackInited = false;

            nuitrack.Nuitrack.onIssueUpdateEvent -= OnIssuesUpdate;
            NuitrackTerm();
        }

        Debug.Log("Nuitrack sensor closed");
    }
Beispiel #16
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;
            }
        }
    }
    void ProcessSkeletons(nuitrack.SkeletonData skeletonData)
    {
        if (skeletonData == null)
        {
            HideAllSkeletons();
            return;
        }
        //Debug.Log("NumUsers: " + skeletonData.NumUsers.ToString());

        int[] skelIds = new int[skeletonsRoots.Keys.Count];
        skeletonsRoots.Keys.CopyTo(skelIds, 0);

        for (int i = 0; i < skelIds.Length; i++)
        {
            if (skeletonData.GetSkeletonByID(skelIds[i]) == null)
            {
                skeletonsRoots[skelIds[i]].SetActive(false);
            }
        }

        foreach (nuitrack.Skeleton skeleton in skeletonData.Skeletons)
        {
            if (!skeletonsRoots.ContainsKey(skeleton.ID)) // if don't have gameObjects for skeleton ID, create skeleton gameobjects (root, joints and connections)
            {
                GameObject skelRoot = new GameObject();
                skelRoot.name = "Root_" + skeleton.ID.ToString();

                skeletonsRoots.Add(skeleton.ID, skelRoot);

                Dictionary <nuitrack.JointType, GameObject> skelJoints = new Dictionary <nuitrack.JointType, GameObject>();


                for (int i = 0; i < jointsInfo.Length; i++)
                {
                    GameObject joint = (GameObject)Instantiate(jointPrefab, Vector3.zero, Quaternion.identity);
                    skelJoints.Add(jointsInfo[i], joint);
                    joint.transform.parent = skelRoot.transform;
                    joint.SetActive(false);
                }

                joints.Add(skeleton.ID, skelJoints);

                GameObject[] skelConnections = new GameObject[connectionsInfo.GetLength(0)];

                for (int i = 0; i < skelConnections.Length; i++)
                {
                    GameObject conn = (GameObject)Instantiate(connectionPrefab, Vector3.zero, Quaternion.identity);
                    skelConnections[i]    = conn;
                    conn.transform.parent = skelRoot.transform;
                    conn.SetActive(false);
                }

                connections.Add(skeleton.ID, skelConnections);
            }

            if (!skeletonsRoots[skeleton.ID].activeSelf)
            {
                skeletonsRoots[skeleton.ID].SetActive(true);
            }

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

                    joints[skeleton.ID][jointsInfo[i]].transform.position = 0.001f * new Vector3(j.Real.X, j.Real.Y, j.Real.Z);

                    //skel.Joints[i].Orient.Matrix:
                    // 0,       1,      2,
                    // 3,       4,      5,
                    // 6,       7,      8
                    // -------
                    // right(X),  up(Y),    forward(Z)

                    //Vector3 jointRight =  new Vector3(  j.Orient.Matrix[0],  j.Orient.Matrix[3],  j.Orient.Matrix[6] );
                    Vector3 jointUp      = new Vector3(j.Orient.Matrix[1], j.Orient.Matrix[4], j.Orient.Matrix[7]);
                    Vector3 jointForward = new Vector3(j.Orient.Matrix[2], j.Orient.Matrix[5], j.Orient.Matrix[8]);
                    joints[skeleton.ID][jointsInfo[i]].transform.rotation = Quaternion.LookRotation(jointForward, jointUp);
                }
                else
                {
                    if (joints[skeleton.ID][jointsInfo[i]].activeSelf)
                    {
                        joints[skeleton.ID][jointsInfo[i]].SetActive(false);
                    }
                }
            }

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

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

                    connections[skeleton.ID][i].transform.position   = joints[skeleton.ID][connectionsInfo[i, 0]].transform.position;
                    connections[skeleton.ID][i].transform.rotation   = Quaternion.LookRotation(diff);
                    connections[skeleton.ID][i].transform.localScale = new Vector3(1f, 1f, diff.magnitude);
                }
                else
                {
                    if (connections[skeleton.ID][i].activeSelf)
                    {
                        connections[skeleton.ID][i].SetActive(false);
                    }
                }
            }
        }
    }
Beispiel #18
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;
    }
Beispiel #19
0
    void ChangeModulsState(bool skel, bool hand, bool depth, bool color, bool gest, bool user)
    {
//		Debug.Log ("" + skel + hand + depth + gest + user);
        if (skeletonTracker == null)
        {
            return;
        }
        if (prevSkel != skel)
        {
            skeletonData = null;
            prevSkel     = skel;
            if (skel)
            {
                skeletonTracker.OnSkeletonUpdateEvent += HandleOnSkeletonUpdateEvent;
            }
            else
            {
                skeletonTracker.OnSkeletonUpdateEvent -= HandleOnSkeletonUpdateEvent;
            }
        }
        if (prevHand != hand)
        {
            handTrackerData = null;
            prevHand        = hand;
            if (hand)
            {
                handTracker.OnUpdateEvent += HandleOnHandsUpdateEvent;
            }
            else
            {
                handTracker.OnUpdateEvent -= HandleOnHandsUpdateEvent;
            }
        }
        if (prevGest != gest)
        {
            prevGest = gest;
            if (gest)
            {
                gestureRecognizer.OnNewGesturesEvent += OnNewGestures;
            }
            else
            {
                gestureRecognizer.OnNewGesturesEvent -= OnNewGestures;
            }
        }
        if (prevDepth != depth)
        {
            depthFrame = null;
            prevDepth  = depth;
            if (depth)
            {
                depthSensor.OnUpdateEvent += HandleOnDepthSensorUpdateEvent;
            }
            else
            {
                depthSensor.OnUpdateEvent -= HandleOnDepthSensorUpdateEvent;
            }
        }
        if (prevColor != color)
        {
            colorFrame = null;
            prevColor  = color;
            if (color)
            {
                colorSensor.OnUpdateEvent += HandleOnColorSensorUpdateEvent;
            }
            else
            {
                colorSensor.OnUpdateEvent -= HandleOnColorSensorUpdateEvent;
            }
        }
        if (prevUser != user)
        {
            userFrame = null;
            prevUser  = user;
            if (user)
            {
                userTracker.OnUpdateEvent += HandleOnUserTrackerUpdateEvent;
            }
            else
            {
                userTracker.OnUpdateEvent -= HandleOnUserTrackerUpdateEvent;
            }
        }
    }
Beispiel #20
0
 void SkeletonUpdate(nuitrack.SkeletonData _skeletonData)
 {
     ProcessSkeletons(_skeletonData);
 }
 void SkeletonsUpdate(nuitrack.SkeletonData _skeletonData)
 {
     skeletonData = _skeletonData;
 }
    public void ChangeModulesState(bool skel, bool hand, bool depth, bool color, bool gest, bool user)
    {
        skeletonTrackerModuleOn    = skel;
        handsTrackerModuleOn       = hand;
        depthModuleOn              = depth;
        colorModuleOn              = color;
        gesturesRecognizerModuleOn = gest;
        userTrackerModuleOn        = user;

        if (SkeletonTracker == null)
        {
            return;
        }
        if (prevSkel != skel)
        {
            skeletonData = null;
            prevSkel     = skel;
            if (skel)
            {
                SkeletonTracker.OnSkeletonUpdateEvent += HandleOnSkeletonUpdateEvent;
            }
            else
            {
                SkeletonTracker.OnSkeletonUpdateEvent -= HandleOnSkeletonUpdateEvent;
            }
        }

        if (prevHand != hand)
        {
            handTrackerData = null;
            prevHand        = hand;
            if (hand)
            {
                HandTracker.OnUpdateEvent += HandleOnHandsUpdateEvent;
            }
            else
            {
                HandTracker.OnUpdateEvent -= HandleOnHandsUpdateEvent;
            }
        }
        if (prevGest != gest)
        {
            prevGest = gest;
            if (gest)
            {
                GestureRecognizer.OnNewGesturesEvent += OnNewGestures;
            }
            else
            {
                GestureRecognizer.OnNewGesturesEvent -= OnNewGestures;
            }
        }
        if (prevDepth != depth)
        {
            DepthFrame = null;
            prevDepth  = depth;
            if (depth)
            {
                DepthSensor.OnUpdateEvent += HandleOnDepthSensorUpdateEvent;
            }
            else
            {
                DepthSensor.OnUpdateEvent -= HandleOnDepthSensorUpdateEvent;
            }
        }
        if (prevColor != color)
        {
            ColorFrame = null;
            prevColor  = color;
            if (color)
            {
                ColorSensor.OnUpdateEvent += HandleOnColorSensorUpdateEvent;
            }
            else
            {
                ColorSensor.OnUpdateEvent -= HandleOnColorSensorUpdateEvent;
            }
        }
        if (prevUser != user)
        {
            UserFrame = null;
            prevUser  = user;
            if (user)
            {
                UserTracker.OnUpdateEvent += HandleOnUserTrackerUpdateEvent;
            }
            else
            {
                UserTracker.OnUpdateEvent -= HandleOnUserTrackerUpdateEvent;
            }
        }
    }