OPENNI实践-体感方向盘玩赛车游戏(2)

这一篇是关于获取到的数据与虚拟手柄之间通信的过程。首先设置要发送的指令,然后通过WriteFile将指令发送给设备。

 

[cpp] view plain copy
 
 在CODE上查看代码片派生到我的代码片
  1. <span style="font-size:14px;">DWORD WINAPI SendofBody_left(LPVOID lpParam)  
  2. {  
  3.     DWORD dwWaitResult_Event=1;  
  4.     static bool mmm=true;  
  5.     while(true)  
  6.     {  
  7.         dwWaitResult_Event=WaitForSingleObject(hEvent_send,INFINITE);  
  8.         if (dwWaitResult_Event==WAIT_OBJECT_0)  
  9.         {  
  10.             *(WORD*)(g_controlreport+LEFTJOYSTICK_X_POS)=nMove_LetfJoystic_X;  
  11.             *(WORD*)(g_controlreport+LEFTJOYSTICK_Y_POS)=nMove_LetfJoystic_Y;  
  12.   
  13.             if (0==nMove_RightJoystic_X)  
  14.             {  
  15.                 *(UCHAR*)(g_controlreport+Xtion_GamePad_Button)=1;//放氮气  
  16.             }  
  17.             *(WORD*)(g_controlreport+LEFTJOYSTICK_X_POS)=nMove_LetfJoystic_X;  
  18.             *(WORD*)(g_controlreport+LEFTJOYSTICK_Y_POS)=nMove_LetfJoystic_Y;  
  19.             WriteControlData(g_controlreport);  
  20.             nMove_LetfJoystic_X=0;  
  21.             nMove_LetfJoystic_Y=0  
  22.             nMove_RightJoystic_X=0x80;  
  23.             nMove_RightJoystic_Y=0x80;  
  24.   
  25.             memset(g_controlreport,0,sizeof(g_controlreport));  
  26.             g_controlreport[0]=REPORTID_CONTROL;  
  27.             g_controlreport[1]=REPORTLEN_GAMEPAD;  
  28.             g_controlreport[2]=REPORTID_GAMEPAD;  
  29.             g_controlreport[6]=0x100;  
  30.             g_controlreport[7]=0x100;  
  31.         }  
  32.         ResetEvent(hEvent_send);  
  33.     }  
  34. }  
  35.   
  36. DWORD WritContorlData(UCHAR* pData)  
  37. {  
  38.     DWORD dwInfo;  
  39.     WriteFile(g_hControlDevice,g_controlreport,REPORTLEN_CONTROLDEVICE,&dwInfo,NULL);  
  40.     return GetLastError();  
  41. }</span>  

posted on 2017-05-12 11:36  飞鱼游戏  阅读(417)  评论(0编辑  收藏  举报

导航