public Quaternion GetJointOrientation(uint UserId, int joint, bool flip) { KinectWrapper.GetJointTransformation(UserId, joint, ref jointTransform); KinectWrapper.SkeletonJointOrientation ori = jointTransform.ori; Quaternion quat = ConvertMatrixToQuat(ori, joint, flip); return(quat); }
// convert the matrix to quaternion, taking care of the mirroring private Quaternion ConvertMatrixToQuat(KinectWrapper.SkeletonJointOrientation ori, int joint, bool flip) { Vector3 vZ = Vector3.zero; Vector3 vY = Vector3.zero; if (ori.confidence > 0.5) { if (flip) { // For the spine and waist, we flip y rotation. //if(joint <= 4) { vZ = new Vector3(ori.m02, -ori.m12, ori.m22); vY = new Vector3(-ori.m01, ori.m11, -ori.m21); } // // Everything else, we flip in a way that doesn't break the model (MAGICAL) // else // { // vZ = new Vector3(-ori.m02, ori.m12, -ori.m22); // vY = new Vector3(ori.m01, -ori.m11, ori.m21); // } } else { vZ = new Vector3(-ori.m02, -ori.m12, ori.m22); vY = new Vector3(ori.m01, ori.m11, -ori.m21); } if (vZ.x != 0.0f || vZ.y != 0.0f || vZ.z != 0.0f) { return(Quaternion.LookRotation(vZ, vY)); } } return(Quaternion.identity); }