// Handle new position of an existing hand void XnVPointDrawer::OnPointUpdate(const XnVHandPointContext* cxt) { XnPoint3D hole; hole.X = -1; hole.Y = -1; hole.Z = 0; m_hole[cxt->nID] = hole; // positions are kept in projective coordinates, since they are only used for drawing XnPoint3D ptProjective(cxt->ptPosition); if (bShouldPrint)printf("Point (%f,%f,%f)", ptProjective.X, ptProjective.Y, ptProjective.Z); m_DepthGenerator.ConvertRealWorldToProjective(1, &ptProjective, &ptProjective); if (bShouldPrint)printf(" -> (%f,%f,%f)\n", ptProjective.X, ptProjective.Y, ptProjective.Z); if (ptProjective.Z < MIN_DEPTH || ptProjective.Z > MAX_DEPTH){ return; } // Add new position to the history buffer m_History[cxt->nID].push_front(ptProjective); trackHand(cxt->nID); // Keep size of history buffer if (m_History[cxt->nID].size() > m_nHistorySize) m_History[cxt->nID].pop_back(); bShouldPrint = false; }
// Handle new position of an existing hand void XnVPointDrawer::OnPointUpdate(const XnVHandPointContext* cxt) { // positions are kept in projective coordinates, since they are only used for drawing XnPoint3D ptProjective(cxt->ptPosition); if (bShouldPrint)printf("Point (%f,%f,%f)", ptProjective.X, ptProjective.Y, ptProjective.Z); m_DepthGenerator.ConvertRealWorldToProjective(1, &ptProjective, &ptProjective); //if (true)printf(" -> (%f,%f,%f)\n", ptProjective.X, ptProjective.Y, ptProjective.Z); pos[0] = ptProjective.X; pos[1] = ptProjective.Y; pos[2] = ptProjective.Z; // printf("DEBUG: depthVal:%d pos[2]:%f\n",depthVal, pos[2]); if (depthVal - pos[2] < 450){ annotateMode = true; } else{ pIndex.push_back(pointIndex); cIndex.push_back(curr_color); annotateMode = false; } // printf("JHS: %f\n",ptProjective.Z); // Add new position to the history buffer m_History[cxt->nID].push_front(ptProjective); // Keep size of history buffer if (m_History[cxt->nID].size() > m_nHistorySize) m_History[cxt->nID].pop_back(); bShouldPrint = false; }
// Handle new position of an existing hand void XnVPointDrawer::OnPointUpdate(const XnVHandPointContext* cxt) { // positions are kept in projective coordinates, since they are only used for drawing //****************************************************************************** //原始程序部分 /*XnPoint3D ptProjective(cxt->ptPosition); if (bShouldPrint)printf("Point (%f,%f,%f)", ptProjective.X, ptProjective.Y, ptProjective.Z); m_DepthGenerator.ConvertRealWorldToProjective(1, &ptProjective, &ptProjective); if (bShouldPrint)printf(" -> (%f,%f,%f)\n", ptProjective.X, ptProjective.Y, ptProjective.Z); // Add new position to the history buffer m_History[cxt->nID].push_front(ptProjective); // Keep size of history buffer if (m_History[cxt->nID].size() > m_nHistorySize) m_History[cxt->nID].pop_back(); bShouldPrint = false;*/ //****************************************************************************** //**************************************************************************** //PPT演示 XnPoint3D ptProjective(cxt->ptPosition); if (bShouldPrint)printf("Point (%f,%f,%f)", ptProjective.X, ptProjective.Y, ptProjective.Z); m_DepthGenerator.ConvertRealWorldToProjective(1, &ptProjective, &ptProjective); if (bShouldPrint)printf(" -> (%f,%f,%f)\n", ptProjective.X, ptProjective.Y, ptProjective.Z); m_History[cxt->nID].push_front(ptProjective); if (m_History[cxt->nID].size() > m_nHistorySize) m_History[cxt->nID].pop_back(); bShouldPrint = false; POINT point; point.x=(int)ptProjective.X; point.y=(int)ptProjective.Y; int screenWidth=GetSystemMetrics(SM_CXSCREEN); int screenHeight=GetSystemMetrics(SM_CYSCREEN); float scaleW=((float)screenWidth)/640.0f; float scaleH=((float)screenWidth)/480.0f; point.x=(int)(point.x*scaleW); point.y=(int)(point.y*scaleH); if (m_bSelect) { m_ptStart.x=point.x; m_ptStart.y=point.y; m_zOrigin=ptProjective.Z; keybd_event(VK_F5,0,0,0); keybd_event(VK_F5,0,KEYEVENTF_KEYUP,0); m_bSelect=FALSE; } int xDis=point.x-m_ptStart.x; int yDis=point.y-m_ptStart.y; double zDis=ptProjective.Z-m_zOrigin; //上、下方向键 if (yDis<(-200)) { if (m_bYDis) { keybd_event(VK_UP,0,0,0); keybd_event(VK_UP,0,KEYEVENTF_KEYUP,0); printf("Up success!"); m_bUpToDown=FALSE; m_bYDis=FALSE; } else { } } else { if(yDis>200) { if (m_bYDis) { if (m_bUpToDown) { keybd_event(VK_DOWN,0,0,0); keybd_event(VK_DOWN,0,KEYEVENTF_KEYUP,0); printf("Down success!"); m_bYDis=FALSE; } else { m_bUpToDown=TRUE; m_bYDis=FALSE; } } else { } } else { m_bYDis=TRUE; } } //左、右方向键 if (xDis<(-100)) { if (m_bXDis) { keybd_event(VK_RIGHT,0,0,0); keybd_event(VK_RIGHT,0,KEYEVENTF_KEYUP,0); printf("Up success!"); m_bRightToLeft=FALSE; m_bXDis=FALSE; } else { } } else { if(xDis>100) { if (m_bXDis) { if (m_bRightToLeft) { keybd_event(VK_LEFT,0,0,0); keybd_event(VK_LEFT,0,KEYEVENTF_KEYUP,0); printf("Down success!"); m_bXDis=FALSE; } else { m_bRightToLeft=TRUE; m_bXDis=FALSE; } } else { } } else { m_bXDis=TRUE; } } #if 0 //Esc退出键 if (xDis>300) { if (m_bXDis) { keybd_event(VK_ESCAPE,0,0,0); keybd_event(VK_ESCAPE,0,KEYEVENTF_KEYUP,0); printf("Esc success!"); m_bXDis=FALSE; } else { } } else { m_bXDis=TRUE; } #endif //shift+F5功能 if (zDis<-100.0) { if (m_bZDis) { keybd_event(VK_SHIFT,0,0,0); keybd_event(VK_F5,0,0,0); keybd_event(VK_F5,0,KEYEVENTF_KEYUP,0); keybd_event(VK_SHIFT,0,KEYEVENTF_KEYUP,0); printf("shift and f5 success!"); m_bZDis=FALSE; } else { } } else { m_bZDis=TRUE; } }