Mercurial > hg > Game > Kinect
annotate main.cc @ 1:2afd5c6cc8d2
Class definition export to KinectTrack.h
author | kazz <kazz@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Mon, 31 Jan 2011 03:49:24 +0900 |
parents | 1478aad947a6 |
children | 3b5465899da9 |
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; | |
25 void NIState::XN_CALLBACK_TYPE sessionStarting(const XnPoint3D &ptPosition, void *userCxt) { | |
26 printf("Session start: (%f, %f, %f)\n)", ptPosition.X, ptPosition.Y, ptPosition.Z); | |
27 gSessionState = IN_SESSION; | |
28 } | |
29 void NIState::XN_CALLBACK_TYPE sessionEnding(void *userCxt) { | |
30 printf("Session end\n"); | |
31 gSessionState = NOT_IN_SESSION; | |
32 } | |
33 void NIState::XN_CALLBACK_TYPE focusProgress(const XnChar *strFocus, const XnPoint3D &ptPosition, | |
34 XnFloat fProgress, void *userCxt) { | |
35 //printf("Focus progress: %s @(%f, %f, %f): %f\n)", strFocus, ptPosition.X, ptPosition.Y, ptPosition.Z, fProgress); | |
36 } | |
37 | |
38 int main(int argc, char *argv[]) { | |
39 xn::Context gContext; | |
40 xn::EnumerationErrors errors; | |
41 XnStatus rc = gContext.InitFromXmlFile(INIT_XML_PATH, &errors); | |
42 checkErrors(rc, errors, "InitFromXMLFile"); | |
43 checkRC(rc, "InitFromXMLFile"); | |
44 | |
45 xn::DepthGenerator gDepthGenerator; | |
46 rc = gContext.FindExistingNode(XN_NODE_TYPE_DEPTH, gDepthGenerator); | |
47 checkRC(rc, "Find depth generator"); | |
48 | |
49 xn::HandsGenerator gHandsGenerator; | |
50 rc = gContext.FindExistingNode(XN_NODE_TYPE_HANDS, gHandsGenerator); | |
51 checkRC(rc, "Find hands generator"); | |
52 XnVSessionManager *gPSessionManager = new XnVSessionManager(); | |
53 rc = gPSessionManager->Initialize(&gContext, "Click,Wave", "RaiseHand"); | |
54 checkRC(rc, "SessionManager::Initialize"); | |
55 gPSessionManager->RegisterSession(NULL, NIState::sessionStarting, NIState::sessionEnding, NIState::focusProgress); | |
56 | |
57 return 0; | |
58 } |