1
\$\begingroup\$

I have created a game using Kinect + XNA and the game runs on full screen mode.. However when i try to touch or reach a certain area on the screen using hand.. I cant reach it.. I will already be outside the range of the sensor trying to touch the object on the game screen..

Is there anyway I can scale the skeletal values so that the users can easily touch objects on the screen without having to stretch or bend too much?

Game screen showing the problematic areas to reach in red

\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

You can get a position relative to the screen resolution, then it's just a matter of tweaking the values to find what works.

From http://kinectxna.blogspot.ie/2012/02/tutorial-5-skeletal-tracking.html :

foreach (Joint joint in skeleton.Joints)
{
     Vector2 position = new Vector2((((0.5f * joint.Position.X) + 0.5f) * (resolution.X)), (((-0.5f * joint.Position.Y) + 0.5f) * (resolution.Y)));
     spriteBatch.Draw(img, new Rectangle(Convert.ToInt32(position.X), Convert.ToInt32(position.Y), 10, 10), Color.White);
}

Instead of drawing to this position you could use it in your update logic. The values aren't perfect but they should get you on the right track.

Edit:

If in fullscreen you'll want to find the current resolution of the user's monitor. You can find it using:

GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Width GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Height

Just put this in place of resolution in the above code and you should be good to go.

If this doesn't work try:

graphics.PreferredBackBufferWidth

graphics.PreferredBackBufferHeight

Where graphics is the GraphicsDeviceManager (declared in the game's constructor when creating a new XNA game). Depending on the scaling of the game one or the other of these should work.

\$\endgroup\$
4
  • \$\begingroup\$ I am using that formula and it doesnt help \$\endgroup\$ Commented Dec 15, 2012 at 15:04
  • \$\begingroup\$ The only thing I can think of in this case is that either resolution in the equation isn't correct or that it's stretching strangely for widescreen. I've only tried it out with 640x480 (to display on top of the color frame). Do you get different positions or is it all in the top left corner as in the screenshot? \$\endgroup\$
    – kiliki
    Commented Dec 15, 2012 at 22:41
  • \$\begingroup\$ In xna .. I'm doing toggle full screen mode!! and use graphic viewport to get the maxwidth and maxheight to use in place of resolution.X and resolution.Y \$\endgroup\$ Commented Dec 16, 2012 at 12:23
  • \$\begingroup\$ Forgot about the fullscreen. Edited answer to include a fix. I can't remember exactly how scaling works and there are a few different ways, but it should either be the preferred dimensions of your GraphicsDeviceManager or the current resolution of the user's monitor. \$\endgroup\$
    – kiliki
    Commented Dec 16, 2012 at 19:10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .