コード例 #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);*/
    }
コード例 #2
0
    void NuitrackManager_onSkeletonTrackerUpdate(nuitrack.SkeletonData skeletonData)
    {
        if ((skeletonData == null) || (skeletonData.NumUsers == 0))
        {
            currentUser     = 0;
            currentSkeleton = null;
            return;
        }

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

        if (currentUser == 0)
        {
            currentUser     = skeletonData.Skeletons[0].ID;
            currentSkeleton = skeletonData.Skeletons[0];
        }
    }
コード例 #3
0
    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);
                    }
                }
            }
        }
    }
コード例 #4
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);
                    }
                }
            }
        }
    }