2014-11-21 2 views
0

나는 kinect 프로젝트에서 작업 중입니다. 오프셋 (접합 좌표 간의 차이)을 찾고 TCP/IP를 사용하여 네트워크를 통해 보내려고합니다. 그러나, 나는 공동의 이전 값에 액세스하는 문제에 직면하고있다 .. 을이 지금까지 내 코드입니다 : 코드 bro..inKinect에 대한 오프셋 (좌표의 차이) 찾기

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

답변

0
// 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; 
+0

감사하는 것은, 유 = 이전 현재 오프셋 사용하는 ? 그것은 현재 - 이전해야합니다 .. 어떻게 전 - 이전에 대한 변경 사항을 hv합니까? 내 코드를 작동하는 방법을 설명해 주시고 내 코드에서 내가 뭘 잘못 했습니까? – Thale

+0

@Thale for 루프에서 i = 0 인 경우 0 번째 인덱스에 값을 저장하고 i = 1과 함께 제공되면 첫 번째 인덱스에 동일한 값을 저장하므로 오프셋 = 0을 항상 얻습니다 –