1つのスケルトンをkinectフィールドOSビューの目的の位置に移動する拡張メソッドに取り組んでいます。
私のコードは、移動するスケルトンと運命の位置を受け取ります。受け取ったスケルトンの股関節の中心と運命の位置の間の距離を計算して見つけ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;
}
実際には、X位置のみが考慮されます。
さて、問題:
私が負の位置に立って、手を正の位置に動かすと、奇妙な行動をします。この画像を見てください
この動作を再現するには、このコードを使用できます
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);
}
これは単純な数学ですが、なぜこれが起こるのか理解できません。どんな助けでも感謝されます。