Mercurial > hg > Game > Kinect
annotate main.cc @ 3:7e112b536f0a
track moving of a hand
author | kazz <kazz@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 01 Feb 2011 06:37:06 +0900 |
parents | 3b5465899da9 |
children |
rev | line source |
---|---|
0 | 1 #include <stdio.h> |
2 #include <XnOpenNI.h> | |
3 #include <XnCppWrapper.h> | |
4 #include <XnVNite.h> | |
5 | |
1
2afd5c6cc8d2
Class definition export to KinectTrack.h
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
6 #include "KinectTrack.h" |
0 | 7 |
1
2afd5c6cc8d2
Class definition export to KinectTrack.h
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
8 #define INIT_XML_PATH "./kinect.xml" |
0 | 9 |
10 void checkRC(const XnStatus &rc, const char *what) { | |
11 if (rc != XN_STATUS_OK) { | |
12 printf("%s faild: %s\n", what, xnGetStatusString(rc)); | |
13 } | |
14 } | |
15 | |
16 void checkErrors(XnStatus &rc, xn::EnumerationErrors &errors, const char *what) { | |
17 if (rc == XN_STATUS_NO_NODE_PRESENT) { | |
18 XnChar strError[1024]; | |
19 errors.ToString(strError, 1024); | |
20 printf("%s\n", strError); | |
21 } | |
22 } | |
23 | |
24 SessionState NIState::gSessionState = NOT_IN_SESSION; | |
2 | 25 XnBool NIState::gBDrawDepthMap = true; |
0 | 26 void NIState::XN_CALLBACK_TYPE sessionStarting(const XnPoint3D &ptPosition, void *userCxt) { |
3 | 27 printf("Session start: (%f, %f, %f)\n", ptPosition.X, ptPosition.Y, ptPosition.Z); |
0 | 28 gSessionState = IN_SESSION; |
29 } | |
30 void NIState::XN_CALLBACK_TYPE sessionEnding(void *userCxt) { | |
31 printf("Session end\n"); | |
32 gSessionState = NOT_IN_SESSION; | |
33 } | |
34 void NIState::XN_CALLBACK_TYPE focusProgress(const XnChar *strFocus, const XnPoint3D &ptPosition, | |
35 XnFloat fProgress, void *userCxt) { | |
3 | 36 printf("Focus progress: %s @(%f, %f, %f): %f\n", strFocus, ptPosition.X, ptPosition.Y, ptPosition.Z, fProgress); |
0 | 37 } |
2 | 38 void NIState::XN_CALLBACK_TYPE noHands(void *UserCxt) { |
39 if (gSessionState != NOT_IN_SESSION) { | |
40 printf("Quick refocus\n"); | |
41 gSessionState = QUICK_REFOCUS; | |
42 } | |
43 } | |
0 | 44 |
45 int main(int argc, char *argv[]) { | |
46 xn::Context gContext; | |
47 xn::EnumerationErrors errors; | |
48 XnStatus rc = gContext.InitFromXmlFile(INIT_XML_PATH, &errors); | |
49 checkErrors(rc, errors, "InitFromXMLFile"); | |
50 checkRC(rc, "InitFromXMLFile"); | |
51 | |
52 xn::DepthGenerator gDepthGenerator; | |
53 rc = gContext.FindExistingNode(XN_NODE_TYPE_DEPTH, gDepthGenerator); | |
54 checkRC(rc, "Find depth generator"); | |
55 | |
56 xn::HandsGenerator gHandsGenerator; | |
57 rc = gContext.FindExistingNode(XN_NODE_TYPE_HANDS, gHandsGenerator); | |
58 checkRC(rc, "Find hands generator"); | |
59 XnVSessionManager *gPSessionManager = new XnVSessionManager(); | |
60 rc = gPSessionManager->Initialize(&gContext, "Click,Wave", "RaiseHand"); | |
61 checkRC(rc, "SessionManager::Initialize"); | |
2 | 62 |
0 | 63 gPSessionManager->RegisterSession(NULL, NIState::sessionStarting, NIState::sessionEnding, NIState::focusProgress); |
2 | 64 |
65 XnVPointDrawer *gPDrawer = new XnVPointDrawer(20, gDepthGenerator); | |
66 XnVFlowRouter *gPFlowRouter = new XnVFlowRouter; | |
67 gPFlowRouter->SetActive(gPDrawer); | |
68 | |
69 gPSessionManager->AddListener(gPFlowRouter); | |
70 | |
71 gPDrawer->RegisterNoPoints(NULL, NIState::noHands); | |
72 gPDrawer->setDepthMap(NIState::gBDrawDepthMap); | |
0 | 73 |
2 | 74 rc = gContext.StartGeneratingAll(); |
75 checkRC(rc, "StartGenerating"); | |
76 | |
77 while (true) { | |
3 | 78 gContext.WaitAndUpdateAll(); |
79 gPSessionManager->Update(&gContext); | |
80 float x, y, z; | |
81 int error = gPDrawer->getPosition(x, y, z); | |
82 if (error > 0) { | |
83 printf("%f, %f, %f\n", x, y, z); | |
84 } | |
85 | |
86 //usleep(10); | |
2 | 87 } |
88 | |
0 | 89 return 0; |
90 } |