作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在研究一种扩展方法,将一个骨架移动到 kinect 字段 os View 中的所需位置。
我的代码接收要移动的骨骼和命运位置,我计算接收到的骨骼臀部中心与命运位置之间的距离以找到how much to move
,然后在关节中应用此因子进行迭代。我的代码,实际上看起来像这样。
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 = Math.Abs(skToBeMoved.Joints[JointType.HipCenter].Position.X - destiny.X);
float howMuchMoveToY = Math.Abs(skToBeMoved.Joints[JointType.HipCenter].Position.Y - destiny.Y);
float howMuchMoveToZ = Math.Abs(skToBeMoved.Joints[JointType.HipCenter].Position.Z - destiny.Z);
float howMuchToMultiply = 1;
// Iterate in the 20 Joints
foreach (JointType item in Enum.GetValues(typeof(JointType)))
{
newJoint = skToBeMoved.Joints[item];
// This adjust, try to keeps the skToBeMoved in the desired position
if (newJoint.Position.X < 0)
howMuchToMultiply = 1; // if the point is in a negative position, carry it to a "more positive" position
else
howMuchToMultiply = -1; // if the point is in a positive position, carry it to a "more negative" position
// applying the new values to the joint
SkeletonPoint pos = new SkeletonPoint()
{
X = newJoint.Position.X + (howMuchMoveToX * howMuchToMultiply),
Y = newJoint.Position.Y, // * (float)whatToMultiplyY,
Z = newJoint.Position.Z, // * (float)whatToMultiplyZ
};
newJoint.Position = pos;
skToBeMoved.Joints[item] = newJoint;
//if (skToBeMoved.Joints[JointType.HipCenter].Position.X < 0)
//{
// if (item == JointType.HandLeft)
// {
// if (skToBeMoved.Joints[item].Position.X > 0)
// {
// }
// }
//}
}
return skToBeMoved;
}
using (SkeletonFrame frame = e.OpenSkeletonFrame())
{
if (frame == null)
return new Skeleton();
if (skeletons == null || skeletons.Length != frame.SkeletonArrayLength)
{
skeletons = new Skeleton[frame.SkeletonArrayLength];
}
frame.CopySkeletonDataTo(skeletons);
Skeleton skeletonToTest = skeletons.Where(s => s.TrackingState == SkeletonTrackingState.Tracked).FirstOrDefault();
Vector4 newPosition = new Vector4();
newPosition.X = -0.03412333f;
newPosition.Y = 0.0407479f;
newPosition.Z = 1.927342f;
newPosition.W = 0; // ignored
skeletonToTest.MoveTo(newPosition);
}
最佳答案
问题解决了。这是代码
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;
}
关于kinect - 如何将 kinect 骨架移动到另一个位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13552564/
我是一名优秀的程序员,十分优秀!