C# 如何阻止Kinect旋转
我正在使用C#和XNA4.0开发一个Kinect项目。现在面临一个我无法解决的问题。当玩家转身时,化身不会转身,但它的手臂和腿正试图转身。这会导致视图不好,所以我想阻止手臂和腿部的旋转运动。虽然我尝试了一些方法,但没有成功。例如,右臂运动:C# 如何阻止Kinect旋转,c#,kinect,game-engine,xna-4.0,kinect-sdk,C#,Kinect,Game Engine,Xna 4.0,Kinect Sdk,我正在使用C#和XNA4.0开发一个Kinect项目。现在面临一个我无法解决的问题。当玩家转身时,化身不会转身,但它的手臂和腿正试图转身。这会导致视图不好,所以我想阻止手臂和腿部的旋转运动。虽然我尝试了一些方法,但没有成功。例如,右臂运动: else if (bone.EndJoint == JointType.ElbowRight || bone.EndJoint == JointType.WristRight) { Matrix tempMat
else if (bone.EndJoint == JointType.ElbowRight || bone.EndJoint == JointType.WristRight)
{
Matrix tempMat = KinectHelper.Matrix4ToXNAMatrix(bone.HierarchicalRotation.Matrix);
if (bone.EndJoint == JointType.ElbowRight)
{
// Add a small adjustment rotation to correct for the avatar skeleton shoulder/upper arm bones.
// The dude should now be able to have arms correctly down at his sides when avateering
Matrix adjustment = Matrix.CreateRotationZ(MathHelper.ToRadians(15)); // 15 degree rotation around the local Kinect z axis for the upper arm bone.
tempMat *= adjustment;
}
// Kinect = +Y along arm, +X up, +Z forward in body coordinate system
// Avatar = +X along arm, +Y back, +Z down
Quaternion kinectRotation = KinectHelper.DecomposeMatRot(tempMat); // XYZ
Quaternion avatarRotation = new Quaternion(kinectRotation.Y, -kinectRotation.Z, -kinectRotation.X, kinectRotation.W); // transform from Kinect to avatar coordinate system
tempMat = Matrix.CreateFromQuaternion(avatarRotation);
this.ReplaceBoneMatrix(bone.EndJoint, tempMat, false, ref boneTransforms);
}
有没有办法阻止旋转
我用以下方法锁定了臀部中心:
if (bone.StartJoint == JointType.HipCenter && bone.EndJoint == JointType.HipCenter)
{
// Unless in seated mode, the hip center is special - it is the root of the NuiSkeleton and describes the skeleton orientation in the world
// (camera) coordinate system. All other bones/joint orientations in the hierarchy have hip center as one of their parents.
// However, if in seated mode, the shoulder center then holds the skeleton orientation in the world (camera) coordinate system.
bindRoot.Translation = Vector3.Zero;
Matrix invBindRoot = Matrix.Invert(bindRoot);
//Matrix hipOrientation = KinectHelper.Matrix4ToXNAMatrix(bone.HierarchicalRotation.Matrix);
// Here we create a rotation matrix for the hips from the inverse of the bind pose
// for the pelvis rotation and the inverse of the bind pose for the root node (0) in the Dude model.
// This multiplication effectively removes the initial 90 degree rotations set in the first two model nodes.
Matrix pelvis = boneTransforms[1];
pelvis.Translation = Vector3.Zero; // Ensure pure rotation as we explicitly set world translation from the Kinect camera below.
Matrix invPelvis = Matrix.Invert(pelvis);
//Matrix combined = (invBindRoot * hipOrientation) * invPelvis;
Matrix combined = invBindRoot * invPelvis;
Matrix adjustment = Matrix.CreateRotationZ(MathHelper.ToRadians(180));
combined *= adjustment;
this.ReplaceBoneMatrix(JointType.HipCenter, combined, true, ref boneTransforms);