Kinect Upgrade Exception

I make very simple material, my goal is to move one skeleton based on the position of another skeleton, because I'm based on the position of the HipCenter. (This algorithm may not be correct, this question is about the exception that occurs in the foreach loop)

Here is my actual code:

public static Skeleton MoveTo(this Skeleton skOrigin, Skeleton skDestiny)
{
     Skeleton skReturn = skOrigin; // just making a copy

        // find the factor to move, based on the HipCenter.
        float whatToMultiplyX = skOrigin.Joints[JointType.HipCenter].Position.X / skDestiny.Joints[JointType.HipCenter].Position.X;
        float whatToMultiplyY = skOrigin.Joints[JointType.HipCenter].Position.Y / skDestiny.Joints[JointType.HipCenter].Position.Y;
        float whatToMultiplyZ = skOrigin.Joints[JointType.HipCenter].Position.Z / skDestiny.Joints[JointType.HipCenter].Position.Z;


        SkeletonPoint movedPosition = new SkeletonPoint();
        Joint movedJoint = new Joint();
        foreach (JointType item in Enum.GetValues(typeof(JointType)))
        {
            // Updating the position
            movedPosition.X = skOrigin.Joints[item].Position.X * whatToMultiplyX;
            movedPosition.Y = skOrigin.Joints[item].Position.Y * whatToMultiplyY;
            movedPosition.Z = skOrigin.Joints[item].Position.Z * whatToMultiplyZ;

            // Setting the updated position to the skeleton that will be returned.
            movedJoint.Position = movedPosition;
            skReturn.Joints[item] = movedJoint;
        }

        return skReturn;
    }

With F10 for debugging, everything works fine, doing a second pass in the foreach loop. When I go to foreach a second time, I get an exception on this line

skReturn.Joints[item] = movedJoint;

An exception:

JointType index value must match Joint.JointType 

But the value is relevant for Spine.

What's wrong?

+1
source share
1 answer

Solved, here is the solution

 Joint newJoint = new Joint(); // declare a new Joint

// 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 + (someNumber)),
                Y = (float)(newJoint.Position.Y + (someNumber)),
                Z = (float)(newJoint.Position.Z + (someNumber))
            };

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

This will work.

+2
source

All Articles