Kinect.AvatarController.TransformSpecialBone C# (CSharp) Method

TransformSpecialBone() protected method

protected TransformSpecialBone ( System.Int64 userId, KinectInterop joint, KinectInterop jointParent, int boneIndex, Vector3 baseDir, bool flip ) : void
userId System.Int64
joint KinectInterop
jointParent KinectInterop
boneIndex int
baseDir Vector3
flip bool
return void
        protected void TransformSpecialBone(Int64 userId, KinectInterop.JointType joint, KinectInterop.JointType jointParent, int boneIndex, Vector3 baseDir, bool flip)
        {
            Transform boneTransform = bones[boneIndex];
            if (boneTransform == null || kinectManager == null)
                return;

            if (!kinectManager.IsJointTracked(userId, (int)joint) ||
               !kinectManager.IsJointTracked(userId, (int)jointParent))
            {
                return;
            }

            Vector3 jointDir = kinectManager.GetJointDirection(userId, (int)joint, false, true);
            Quaternion jointRotation = jointDir != Vector3.zero ? Quaternion.FromToRotation(baseDir, jointDir) : Quaternion.identity;

            if (!flip)
            {
                Vector3 mirroredAngles = jointRotation.eulerAngles;
                mirroredAngles.y = -mirroredAngles.y;
                mirroredAngles.z = -mirroredAngles.z;

                jointRotation = Quaternion.Euler(mirroredAngles);
            }

            if (jointRotation != Quaternion.identity)
            {
                // 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;
            }
        }