Esempio n. 1
0
    // Update the avatar each frame.
    public void Update()
    {
        if (!transform.gameObject.activeInHierarchy)
        {
            return;
        }

        // Get the KinectManager instance
        if (c == null)
        {
            c = client.Instance;
        }

        else if (c.reset)
        {
            Debug.Log("RESETIRAAAM");
            c.reset = false;
            ResetToInitialPosition();
        }

        // move the avatar to its Kinect position
        MoveAvatar();

        for (var boneIndex = 0; boneIndex < bones.Length; boneIndex++)
        {
            if (!bones[boneIndex])
            {
                continue;
            }

            if (boneIndex2JointMap.ContainsKey(boneIndex))
            {
                client.SkeletonPositionIndex joint = boneIndex2JointMap[boneIndex];
                TransformBone(joint, boneIndex);
            }

            /* else if (specIndex2JointMap.ContainsKey(boneIndex))
             * {
             *   // special bones (clavicles)
             *   List<client.SkeletonPositionIndex> alJoints = specIndex2JointMap[boneIndex];
             *
             *   if (alJoints.Count >= 2)
             *   {
             *       //Vector3 baseDir = alJoints[0].ToString().EndsWith("Left") ? Vector3.left : Vector3.right;
             *       //TransformSpecialBone(UserID, alJoints[0], alJoints[1], boneIndex, baseDir, !mirroredMovement);
             *   }
             * }*/
        }
    }
    // Apply the rotations tracked by kinect to the joints.
    protected bool TransformBone(client.SkeletonPositionIndex joint, int boneIndex)
    {
        Transform boneTransform = bones[boneIndex];

        if (boneTransform == null || c == null)
        {
            return(false);
        }

        int iJoint = (int)joint;

        if (iJoint < 0)
        {
            return(false);
        }

        // Get Kinect joint orientation
        Quaternion jointRotation = c.GetJointOrientation(iJoint);

        if (jointRotation == Quaternion.identity)
        {
            return(false);
        }

        // Smoothly transition to the new rotation
        Quaternion newRotation = Kinect2AvatarRot(jointRotation, boneIndex);

        if (smoothFactor != 0f)
        {
            boneTransform.rotation = Quaternion.Slerp(boneTransform.rotation, newRotation, smoothFactor * Time.deltaTime);
        }
        else
        {
            boneTransform.rotation = newRotation;
        }

        return(true);
    }
    public void Update()
    {
        if (!transform.gameObject.activeInHierarchy)
        {
            return;
        }

        // Get the KinectManager instance
        if (c == null)
        {
            c = client.Instance;
        }

        else if (c.reset)
        {
            UnityEngine.Debug.Log("RESETIRAAAM");
            c.reset = false;
            ResetToInitialPosition();
        }

        MoveAvatar();

        for (var boneIndex = 0; boneIndex < bones.Length; boneIndex++)
        {
            if (!bones[boneIndex])
            {
                continue;
            }

            if (boneIndex2JointMap.ContainsKey(boneIndex))
            {
                client.SkeletonPositionIndex joint = boneIndex2JointMap[boneIndex];
                TransformBone(joint, boneIndex);
            }
        }
    }