How to move a kinect skeleton to another position

北战南征 提交于 2019-12-03 12:50:16

Problem solved. This is the code

public static Skeleton MoveTo(this Skeleton skToBeMoved, Vector4 destiny)
    {
        Joint newJoint = new Joint();

        ///Based on the HipCenter (i dont know if it is reliable, seems it is.)
        float howMuchMoveToX = (skToBeMoved.Joints[JointType.HipCenter].Position.X - destiny.X) * -1;
        float howMuchMoveToY = (skToBeMoved.Joints[JointType.HipCenter].Position.Y - destiny.Y) * -1;
        float howMuchMoveToZ = (skToBeMoved.Joints[JointType.HipCenter].Position.Z - destiny.Z) * -1;

        // Iterate in the 20 Joints
        foreach (JointType item in Enum.GetValues(typeof(JointType)))
        {
            newJoint = skToBeMoved.Joints[item];

            // applying the new values to the joint
            SkeletonPoint pos = new SkeletonPoint()
            {
                X = (float)(newJoint.Position.X + (howMuchMoveToX)),
                Y = (float)(newJoint.Position.Y + (howMuchMoveToY)),
                Z = (float)(newJoint.Position.Z + (howMuchMoveToZ))
            };

            newJoint.Position = pos;
            skToBeMoved.Joints[item] = newJoint;
        }

        return skToBeMoved;
    }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!