none
interacting with objects in XNA . . skeleton to 3D object mapping RRS feed

  • Question

  • 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)

      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);
                                 }

                             }
                         }



    • Edited by Sweptica Friday, September 28, 2012 9:57 PM
    Friday, September 28, 2012 9:27 PM