Search code examples
c#kinectkinect.toolboxkinect-interaction

Finding the offset(difference between coordinates) for Kinect


I'm working on a kinect project..I trying to find the offset(the difference between coordinates of a joint) and send it through a network using TCP/IP..However, I am facing the problem of accessing the previous values of the joint.. These are my code so far:

Joint right = skel.Joints[JointType.HandRight];
double right = right.Position.X;


/*        
I need an operation here to calculate the offset of right before sending it
Meaning, offset= right(current coordinate)-right(previous coordinate)
How can I do this in C# ?
I have tried this operation as mentioned below but it is printing all zeros although I moved (if move, previous - current coordinates shall not be zero)
*/

//---------------------------------------------------------------------------   
double offset = 0;
double[] of = new double[2];

  for (int i = 0; i < of.Length; i++)
 {
    if (i > 2)
   {
     break;
   }
     of[i] = right;
     offset = of[1] - of[0];                                  
  }

//---------------------------------------------------------------------------    

//convert the data to bytes before sending
byte[] rh = BitConverter.GetBytes(offset);

//sending the data to the server
client.Send(rh, rh.Length);

Solution

  • // make it global 
    
         double previousval=-1000;
         double currentVal=-1000;
    
    then in your code
    
         Joint right = skel.Joints[JointType.HandRight];
         currentVal=right.Position.X;
    
         double offset = 0;
         if(prev==-1000)
            offset =  currentVal - currentVal;
         else
            offset = previousval - currentVal;  
    
         previousval=currentVal;