void TransformBone(uint userId, KinectWrapper.SkeletonJoint joint, int boneIndex, bool flip)
{
Transform boneTransform = bones[boneIndex];
if(boneTransform == null)
return;
// Grab the bone we're moving.
int iJoint = (int)joint;
if(iJoint < 0)
return;
// Get Kinect joint orientation
Quaternion jointRotation = KinectManager.Instance.GetJointOrientation(userId, iJoint, flip);
if(jointRotation == Quaternion.identity)
return;
// Apply the new rotation.
Quaternion newRotation = jointRotation * initialRotations[boneIndex];
//If an offset node is specified, combine the transform with its
//orientation to essentially make the skeleton relative to the node
if (offsetNode != null)
{
// Grab the total rotation by adding the Euler and offset's Euler.
Vector3 totalRotation = newRotation.eulerAngles + offsetNode.transform.rotation.eulerAngles;
// Grab our new rotation.
newRotation = Quaternion.Euler(totalRotation);
}
// Smoothly transition to our new rotation.
boneTransform.rotation = Quaternion.Slerp(boneTransform.rotation, newRotation, Time.deltaTime * SmoothFactor);
}