0

I am creating a project on Kinect where I need to translate and rotate the skeleton of the user so that it would be always facing the Kinect.

I do know that I cannot change the actual values of the Skeleton, so I created an avatar skeleton called littleGuy. littleGuy is an array of SkeletonPoints having all the SkeletonPoints of the actual Skeleton assigned to each element respectively.

All manipulations happen to the littleGuy skeleton and then saved in a different skeleton called transGuy (translated guy). The problem is whenever I edit the values of the transGuy and then try to map them to the colorImage, I get an overflow of values and the skeleton is never rendered.

In the below code I assign the Center Hip to littleGuy[0], and then I choose the offset to be -CHip, since all translations will be based on this centerHip. I then add the offset to transGuy.

if (joint.JointType == JointType.HipCenter)
                {
                    littleguy_chip = skeleton.Joints[JointType.HipCenter].Position;
                    littleGuy[0] = littleguy_chip;

                    TransValue.X = -littleguy_chip.X;
                    TransValue.Y = -littleguy_chip.Y;
                    TransValue.Z = -littleguy_chip.Z;

                    transGuy[0] = littleGuy[0];
                    transGuy[0].X = littleGuy[0].X + TransValue.X;
                    transGuy[0].Y = littleGuy[0].Y + TransValue.Y;
                    transGuy[0].Z = littleGuy[0].Z + TransValue.Z;

                    prevPositions[0] = joint.Position;
                }

After that, I draw each joint by looping on transGuy and mapping the value to the skeleton, but I always get the value 2147483648

 for (int j = 0; j < transGuy.Length; j++)
                {
                    if ((transGuy[i] == littleguy_head && transGuy[j] == littleguy_cshoulder)
                        || (transGuy[i] == littleguy_cshoulder && transGuy[j] == littleguy_spine)
                        || (transGuy[i] == littleguy_spine && transGuy[j] == littleguy_chip))
                    {
                        var p2 = kinect.CoordinateMapper.MapSkeletonPointToColorPoint(
                            transGuy[j], ColorImageFormat.RgbResolution640x480Fps30);

                        spriteBatch.Draw(lineTex, new Vector2(p.X + 80, p.Y),
                            null, Color.White, (float)Math.Atan2(p2.Y - p.Y, (p2.X + 80) - (p.X + 80)), new Vector2(0f, (float)lineTex.Height / 2),
                            new Vector2(Vector2.Distance(new Vector2(p.X + 80, p.Y), new Vector2(p2.X + 80, p2.Y)), 1f), SpriteEffects.None, 0f);

                    }

I really need to manipulate the points before Mapping them to the color image... what do I do?

4

1 回答 1

0

我解决了这个问题。因为 SkeletonPoint 中 X,Y,Z 的值是浮动的。在添加偏移量时键入 Cast to decimal,然后键入将整个内容转换回浮点数。新代码如下所示:

if (joint.JointType == JointType.Spine)
                {
                    littleguy_spine = skeleton.Joints[JointType.Spine].Position;
                    littleGuy[1] = littleguy_spine;

                    transGuy[1] = littleGuy[1];
                    transGuy[1].X = (float)((decimal)(littleGuy[1].X) + (decimal)(TransValue.X));
                    transGuy[1].Y = (float)((decimal)(littleGuy[1].Y) + (decimal)(TransValue.Y));
                    transGuy[1].Z = (float)((decimal)(littleGuy[1].Z) + (decimal)(TransValue.Z));

                    prevPositions[1] = joint.Position;
                }
于 2013-05-21T09:41:28.230 回答