Interaction using Kinect in XNA
Posted
by
Sweta Dwivedi
on Game Development
See other posts from Game Development
or by Sweta Dwivedi
Published on 2012-09-29T10:39:19Z
Indexed on
2012/09/29
15:53 UTC
Read the original article
Hit count: 257
So i have written a program to play a sound file when ever my RightHand.Joint touches the 3D model . . It goes like this . . even though the code works somehow but not very accurate . . for example it will play the sound when my hand is slightly under my 3D object not exactly on my 3D object . How do i make it more accurate? here is the code . . (HandX & HandY is the values coming from the Skeleton data RightHand.Joint.X etc) and also this calculation doesnt work with Animated Sprites..which i need to do
foreach (_3DModel s in Solar)
{
float x = (float)Math.Floor(((handX * 0.5f) + 0.5f) * (resolution.X));
float y = (float)Math.Floor(((handY * -0.5f) + 0.5f) * (resolution.Y));
float z = (float)Math.Floor((handZ) / 4 * 20000);
if (Math.Sqrt(Math.Pow(x - s.modelPosition.X, 2) + Math.Pow(y - s.modelPosition.Y, 2)) < 15)
{
//Exit();
PlaySound("hyperspace_activate");
Console.WriteLine("1" + "handx:" + x + "," + " " + "modelPos.X:" + s.modelPosition.X + "," + " " + "handY:" + y + "modelPos.Y:" + s.modelPosition.Y);
}
else
{
Console.WriteLine("2" + "handx:" + x + "," + " " + "modelPos.X:" + s.modelPosition.X + "," + " " + "handY:" + y + "modelPos.Y:" + s.modelPosition.Y);
}
}
© Game Development or respective owner