Kinect Skeleton缩放和定​​位

时间:2013-01-06 20:17:57

标签: c# xna kinect

使用颜色和深度流我已经获得了一张我的图像,并且我已经设法缩放并改变它的位置。但是,我无法对Skeleton数据做同样的事情。我想要做的是将骨架缩放并定位到我的图像上,这样我就可以将Gus面罩放在我的头上,并以合适的尺寸将排球放在我的手上。我怎么能对骨架做同样的事情呢?

这是我缩放和定位图像的行:

spriteBatch.Draw(activeSkeletons[p.Key].image, position1, activeSkeletons[p.Key].image.Bounds, Color.White, 0f, Vector2.Zero, 1f, SpriteEffects.None, 0f);

绘图功能:

private void DrawSkeleton(SpriteBatch spriteBatch, Vector2 resolution, Texture2D img)
{

    foreach (KeyValuePair<int, Player> p in activeSkeletons)
    {
        if (activeSkeletons[p.Key].image != null)
        {
            if (p.Key == indexes[0])
            {
                //Drawing the image - first player
                spriteBatch.Draw(activeSkeletons[p.Key].image, position1, activeSkeletons[p.Key].image.Bounds, Color.White, 0f, Vector2.Zero, 1f, SpriteEffects.None, 0f);
            }
            else {
                //Drawing the image - second player
                spriteBatch.Draw(activeSkeletons[p.Key].image, position2, activeSkeletons[p.Key].image.Bounds, Color.White, 0f, Vector2.Zero, 1f, SpriteEffects.None, 0f);
            }
        }

        foreach (Joint joint in p.Value.skeleton.Joints)
        {
            if (joint.TrackingState == JointTrackingState.Tracked)
            {
                //Drawing the skeleton
                var colorPoint = kinect.CoordinateMapper.MapSkeletonPointToColorPoint(joint.Position, kinect.ColorStream.Format);
                spriteBatch.Draw(img, new Rectangle(Convert.ToInt32(colorPoint.X), Convert.ToInt32(colorPoint.Y), 10, 10), Color.White);
                if (joint.JointType == JointType.HandRight && joint.TrackingState == JointTrackingState.Tracked)
                {
                    //Volleyball
                    dopKonum = new Vector2(colorPoint.X - dop.Width / 2, colorPoint.Y - dop.Height / 2);
                    spriteBatch.Draw(dop, dopKonum, Color.White);
                }
                else if (joint.JointType == JointType.Head && joint.TrackingState != JointTrackingState.NotTracked)
                {
                    //Gus Fring
                    gusKonum = new Vector2(colorPoint.X - gus.Width / 2, colorPoint.Y - gus.Height / 2);
                    spriteBatch.Draw(gus, gusKonum, Color.White);
                }
            }
        }
    }
}

这就是它的样子:

Kinect

希望我解释得很好。

0 个答案:

没有答案