none
Move a media element in x,y direction and zoom in and zoom out based on Head Joint movement as tracked by a Kinect device RRS feed

  • Question

  • Here I’m able to move the media element in accordance to the head movement in left and right direction (i.e. on x – axis) and upwards and downwards (i.e. on y-axis).

    The problem is when I try to move it in accordance to the z-direction. Individually all three things work fine the problem is when I try to integrate z with x and y.

    Here in the Code below:

    myMediaElement is the WPF media Element.

    private const double MLeft = -1000;
      private const double MRight = -1000;
      private const double MTop = -300;
      private const double MBottom = -300;
    
      private const double xMax = 1280;
      private const double xMean = xMax / 2;
      private const double yMax = 720;
      private const double yMean = yMax / 2;
    
       myMediaElement.Margin = new Thickness(MLeft, MTop, MRight, MBottom);
    
      #region XY
                if (Headx < xMax)
                {
                    double percentChange = (xMean - Headx) / 100;
                    double change = percentChange / 8;
                    mediaLeft = MLeft + (change * MLeft);
                    mediaRight = MRight - (change * MRight);
                    if (mediaLeft > 0)
                    {
                        mediaLeft = 0;
                    }
                    if (mediaRight > 0)
                    {
                        mediaRight = 0;
                    }
                    myMediaElement.Margin = new Thickness(mediaLeft, mediaTop, mediaRight, mediaBottom);
    
                }
                if (Heady < yMax)
                {
                    double percentChange = (160 - Heady) / 100;
                    double change = percentChange;
                    mediaTop = MTop + (change * MTop);
                    mediaBottom = MBottom - (change * MBottom);
                    if (mediaTop > 0)
                    {
                        mediaTop = 0;
                    }
                    if (mediaBottom > 0)
                    {
                        mediaBottom = 0;
                    }
                    myMediaElement.Margin = new Thickness(mediaLeft, mediaTop, mediaRight, mediaBottom);
                }
    
                #endregion XY
    
    //#region z-index
                //if (Headz < 4)
                //{
                //    double percentChange = (3 - Headz) / 100;
                //    double change = percentChange*80 ;
                //    mediaTop = MTop + (change * MLeft);
                //    mediaBottom = MBottom + (change * MRight);
                //    mediaLeft = MLeft + (change * MLeft);
                //    mediaRight = MRight + (change * MRight);
                //    if (mediaLeft > 0)
                //    {
                //        mediaLeft = 0;
                //    }
                //    if (mediaRight > 0)
                //    {
                //        mediaRight = 0;
                //    }
                //    if (mediaBottom > 0)
                //    {
                //        mediaBottom = 0;
                //    }
                //    if (mediaTop > 0)
                //    {
                //        mediaTop = 0;
                //    }
                //    myMediaElement.Margin = new Thickness(mediaLeft, mediaTop, mediaRight, mediaBottom);
    
                //}
                //#endregion z-index 
    

    Here as I’m using constant value for left,right,top,bottom margins as MLeft,MTop,MRight,MBottom.

    And now when I change it according to Z coordinate of head joint. But the screen flikkers and the mediaelement goes to its original size as it enters the XY region of code.

    What I want to do is zoom out when I move close to Kinect and zoom in when I move away from it.

    the above code is in a function which I'm calling when All Frames are Ready .

    Any help or suggestions are much appreciated.


    Tuesday, October 30, 2012 5:14 AM