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;
}
}