Commits

schlangen  committed 77d0e44

it compiles and is somewhat working. now checking value ranges for neverball api etc.

  • Participants
  • Parent commits 668fb21

Comments (0)

Files changed (3)

File share/tilt_kinect.c

 // openni variables
 
 
-static XnContext *context= NULL;
-static XnNodeHandle *depth= NULL;
-static XnDepthMetaData *depthMD;
-static XnNodeHandle *userGenerator= NULL;
+static XnContext *pContext;
+static XnNodeHandle hDepth;
+static XnDepthMetaData *pDepthMD;
+static XnNodeHandle hUserGenerator;
 
 static XnChar g_strPose[20] = "";
 
 
 
 int jointPos(XnUserID player, XnSkeletonJoint eJoint) {
-
+        
 	XnSkeletonJointTransformation jointTrans;
 
 	//userGenerator.GetSkeletonCap().GetSkeletonJoint(player, eJoint, jointTrans);
 	
-	xnGetSkeletonJoint(*userGenerator, player, eJoint, &jointTrans);
+	xnGetSkeletonJoint(hUserGenerator, player, eJoint, &jointTrans);
 
 	//cout<< jointTrans.position.fConfidence << endl;
 	//recentConfidence[eJoint-1] = jointTrans.position.fConfidence;
 	realwordPoint.X = 0; realwordPoint.Y = 0; realwordPoint.Z = 0;
 	
 	//depth.ConvertProjectiveToRealWorld(1, &jointTrans.position.position, &realwordPoint); 
-	xnConvertProjectiveToRealWorld(*depth, 1, &jointTrans.position.position, &realwordPoint); 
+	xnConvertProjectiveToRealWorld(hDepth, 1, &jointTrans.position.position, &realwordPoint); 
 	
 	allJointCoords[eJoint-1][0] = realwordPoint.X;
 	allJointCoords[eJoint-1][1] = realwordPoint.Y;
 
 void get_body_positions(){
   
-        int userCount = xnGetNumberOfUsers(userGenerator);
+        int userCount = xnGetNumberOfUsers(hUserGenerator);
 	XnUserID *aUsers = malloc(userCount*sizeof(XnUserID));
 	XnUInt16 nUsers = userCount * sizeof(XnUserID);
 	//userGenerator.GetUsers(aUsers, nUsers);
 	for(int i = 0;i<userCount;i++){
 	  aUsers[i] = 0;
 	}
-	xnGetUsers(userGenerator, aUsers, &nUsers);
+	xnGetUsers(hUserGenerator, aUsers, &nUsers);
 	if (nUsers > 0){
 	
 		//if (userGenerator.GetSkeletonCap().IsTracking(aUsers[0])) {
-		 if (xnIsSkeletonTracking(*userGenerator,0)){
+		 if (xnIsSkeletonTracking(hUserGenerator,aUsers[0])){
+		  printf("is skeleton tracking");
 		  for(int j=1;j<25;j++){
 		    jointPos(aUsers[0], (XnSkeletonJoint) j);
 		  }		
 void main_loop() {
 	// Read next available data
 	//context.WaitAnyUpdateAll();
-	xnWaitAnyUpdateAll(context);
+	xnWaitAnyUpdateAll(pContext);
 	// Process the data
 	//depth.GetMetaData(depthMD);
 
-// segfaults, do we need that?
-//	xnGetDepthMetaData(*depth, depthMD);
+	xnGetDepthMetaData(hDepth, pDepthMD);
 	
 	get_body_positions();
 	
 
 
 	//context.Init();
-	xnInit(&context);
+	xnInit(&pContext);
 	
-	depthMD = xnAllocateDepthMetaData();
+	pDepthMD = xnAllocateDepthMetaData();
 
 	
 
 	
 
 
-	XnNodeHandle hNode;
+	//XnNodeHandle hNode;
 //	XnEnumerationErrors errors = new ;
-	nRetVal = xnCreateDepthGenerator(context, &hNode, NULL, NULL);//&errors);
+	nRetVal = xnCreateDepthGenerator(pContext, &hDepth, NULL, NULL);//&errors);
 	// TODO: error handling
 //	XN_IS_STATUS_OK(nRetVal);
 	if (nRetVal != (XnStatus)0){
 	//    return (nRetVal);
 	}
 
-	depth = &hNode;
+//	hDepth = hNode;
 
-	XnNodeHandle hNode2;
-	nRetVal = xnCreateUserGenerator(context, &hNode2, NULL, NULL);
+//	XnNodeHandle hNode2;
+	nRetVal = xnCreateUserGenerator(pContext, &hUserGenerator, NULL, NULL);
 	// TODO: error handling
 //	XN_IS_STATUS_OK(nRetVal);
-	userGenerator = &hNode2;
+//	hUserGenerator = &hNode2;
 
 	if (nRetVal != (XnStatus)0){
 	   printf("error at user generator create!");
 	int dummy = 5;
 	void *dummy_cookie = &dummy;
 	
-	checkRetVal(xnRegisterUserCallbacks(*userGenerator, &new_user, &lost_user, dummy_cookie, &hUserCallbacks));
+	checkRetVal(xnRegisterUserCallbacks(hUserGenerator, &new_user, &lost_user, dummy_cookie, &hUserCallbacks));
 	//XnCalibrationEnd ce = calibration_ended;
 	
 	//checkRetVal(xnRegisterCalibrationCallbacks(*userGenerator, calibration_started,ce, NULL, hCalibrationCallbacks));
 	
-	checkRetVal(xnRegisterToCalibrationStart(*userGenerator, &calibration_started, dummy_cookie, &hCalibrationCallbacks));
-	checkRetVal(xnRegisterToCalibrationComplete(*userGenerator, &calibration_ended, dummy_cookie, &hCalibrationCallbacks));
+	checkRetVal(xnRegisterToCalibrationStart(hUserGenerator, &calibration_started, dummy_cookie, &hCalibrationCallbacks));
+	checkRetVal(xnRegisterToCalibrationComplete(hUserGenerator, &calibration_ended, dummy_cookie, &hCalibrationCallbacks));
 	
 	//XnPoseDetectionCallback pd = pose_detected;
 	//checkRetVal(xnRegisterToPoseCallbacks(*userGenerator, pd, NULL, NULL, hPoseCallbacks));
-	checkRetVal(xnRegisterToPoseDetected(*userGenerator, &pose_detected, dummy_cookie, &hPoseCallbacks));
-	checkRetVal(xnGetSkeletonCalibrationPose(*userGenerator, g_strPose));
-	checkRetVal(xnSetSkeletonProfile(*userGenerator, XN_SKEL_PROFILE_ALL));
+	checkRetVal(xnRegisterToPoseDetected(hUserGenerator, &pose_detected, dummy_cookie, &hPoseCallbacks));
+	checkRetVal(xnGetSkeletonCalibrationPose(hUserGenerator, g_strPose));
+	checkRetVal(xnSetSkeletonProfile(hUserGenerator, XN_SKEL_PROFILE_ALL));
 		
 		//	if (filter)
 	//		userGenerator.GetSkeletonCap().SetSmoothing(0.8);
 	
 	printf("Initialized Kinect, looking for users...\n\n");
 	//context.StartGeneratingAll();
-	xnStartGeneratingAll(context);
+	xnStartGeneratingAll(pContext);
 
 	
 }
 	      
 	      if (allJointCoords[XN_SKEL_RIGHT_HAND][1] < allJointCoords[XN_SKEL_HEAD][1]){  // small y -> high object, ie if hand.y < head.y -> hand is above head
 		button = 1;
+		printf("button: 1!");
 	      }else if (allJointCoords[XN_SKEL_LEFT_HAND][1] < allJointCoords[XN_SKEL_HEAD][1]){
 		button = 2;
+		printf("button: 2!");
 	      }
 	      
                 state.x = deltaX;
                 state.z = deltaZ;
 		
-		set_button(&state.A, button == 1);  // or U/D?
-		set_button(&state.B, button == 2);
+		set_button(&state.A, button == 1);  // A/B or U/D or what?
+		set_button(&state.minus, button == 2);
+		
+		//printf("deltax: %s, deltaz: %s, button: %s", deltaX, deltaZ, button);
 
                 //set_button(&state.home, userFrame.button3);
                 //set_button(&state.U, userFrame.deltaWheel > 0);
     }
 
     //context.Shutdown();
-    xnShutdown(context);
+    xnShutdown(pContext);
     return 0;
 }
 
         thread = NULL;
 
 	printf("bye");
-        xnShutdown(context);
+        xnShutdown(pContext);
     }
 }
 

File share/tilt_kinect.c~

 // openni variables
 
 
-static XnContext *context= NULL;
-static XnNodeHandle *depth= NULL;
-static XnDepthMetaData *depthMD;
-static XnNodeHandle *userGenerator= NULL;
+static XnContext *pContext;
+static XnNodeHandle hDepth;
+static XnDepthMetaData *pDepthMD;
+static XnNodeHandle hUserGenerator;
 
 static XnChar g_strPose[20] = "";
 
 
 
 int jointPos(XnUserID player, XnSkeletonJoint eJoint) {
-
+        
 	XnSkeletonJointTransformation jointTrans;
 
 	//userGenerator.GetSkeletonCap().GetSkeletonJoint(player, eJoint, jointTrans);
 	
-	xnGetSkeletonJoint(*userGenerator, player, eJoint, &jointTrans);
+	xnGetSkeletonJoint(hUserGenerator, player, eJoint, &jointTrans);
 
 	//cout<< jointTrans.position.fConfidence << endl;
 	//recentConfidence[eJoint-1] = jointTrans.position.fConfidence;
 	realwordPoint.X = 0; realwordPoint.Y = 0; realwordPoint.Z = 0;
 	
 	//depth.ConvertProjectiveToRealWorld(1, &jointTrans.position.position, &realwordPoint); 
-	xnConvertProjectiveToRealWorld(*depth, 1, &jointTrans.position.position, &realwordPoint); 
+	xnConvertProjectiveToRealWorld(hDepth, 1, &jointTrans.position.position, &realwordPoint); 
 	
 	allJointCoords[eJoint-1][0] = realwordPoint.X;
 	allJointCoords[eJoint-1][1] = realwordPoint.Y;
 
 void get_body_positions(){
   
-        int userCount = xnGetNumberOfUsers(*userGenerator);
+        int userCount = xnGetNumberOfUsers(hUserGenerator);
 	XnUserID *aUsers = malloc(userCount*sizeof(XnUserID));
 	XnUInt16 nUsers = userCount * sizeof(XnUserID);
 	//userGenerator.GetUsers(aUsers, nUsers);
 	for(int i = 0;i<userCount;i++){
 	  aUsers[i] = 0;
 	}
-	xnGetUsers(*userGenerator, aUsers, &nUsers);
+	xnGetUsers(hUserGenerator, aUsers, &nUsers);
 	if (nUsers > 0){
 	
 		//if (userGenerator.GetSkeletonCap().IsTracking(aUsers[0])) {
-		 if (xnIsSkeletonTracking(*userGenerator,0)){
+		 if (xnIsSkeletonTracking(hUserGenerator,aUsers[0])){
+		  printf("is skeleton tracking");
 		  for(int j=1;j<25;j++){
 		    jointPos(aUsers[0], (XnSkeletonJoint) j);
 		  }		
 void main_loop() {
 	// Read next available data
 	//context.WaitAnyUpdateAll();
-	xnWaitAnyUpdateAll(context);
+	xnWaitAnyUpdateAll(pContext);
 	// Process the data
 	//depth.GetMetaData(depthMD);
 
-// segfaults, do we need that?
-//	xnGetDepthMetaData(*depth, depthMD);
+	xnGetDepthMetaData(hDepth, pDepthMD);
 	
 	get_body_positions();
 	
 
 
 	//context.Init();
-	xnInit(&context);
+	xnInit(&pContext);
 	
-	depthMD = xnAllocateDepthMetaData();
+	pDepthMD = xnAllocateDepthMetaData();
 
 	
 
 	
 
 
-	XnNodeHandle hNode;
+	//XnNodeHandle hNode;
 //	XnEnumerationErrors errors = new ;
-	nRetVal = xnCreateDepthGenerator(context, &hNode, NULL, NULL);//&errors);
+	nRetVal = xnCreateDepthGenerator(pContext, &hDepth, NULL, NULL);//&errors);
 	// TODO: error handling
 //	XN_IS_STATUS_OK(nRetVal);
 	if (nRetVal != (XnStatus)0){
 	//    return (nRetVal);
 	}
 
-	depth = &hNode;
+//	hDepth = hNode;
 
-	XnNodeHandle hNode2;
-	nRetVal = xnCreateUserGenerator(context, &hNode2, NULL, NULL);
+//	XnNodeHandle hNode2;
+	nRetVal = xnCreateUserGenerator(pContext, &hUserGenerator, NULL, NULL);
 	// TODO: error handling
 //	XN_IS_STATUS_OK(nRetVal);
-	userGenerator = &hNode2;
+//	hUserGenerator = &hNode2;
 
 	if (nRetVal != (XnStatus)0){
 	   printf("error at user generator create!");
 	int dummy = 5;
 	void *dummy_cookie = &dummy;
 	
-	checkRetVal(xnRegisterUserCallbacks(*userGenerator, &new_user, &lost_user, dummy_cookie, &hUserCallbacks));
+	checkRetVal(xnRegisterUserCallbacks(hUserGenerator, &new_user, &lost_user, dummy_cookie, &hUserCallbacks));
 	//XnCalibrationEnd ce = calibration_ended;
 	
 	//checkRetVal(xnRegisterCalibrationCallbacks(*userGenerator, calibration_started,ce, NULL, hCalibrationCallbacks));
 	
-	checkRetVal(xnRegisterToCalibrationStart(*userGenerator, &calibration_started, dummy_cookie, &hCalibrationCallbacks));
-	checkRetVal(xnRegisterToCalibrationComplete(*userGenerator, &calibration_ended, dummy_cookie, &hCalibrationCallbacks));
+	checkRetVal(xnRegisterToCalibrationStart(hUserGenerator, &calibration_started, dummy_cookie, &hCalibrationCallbacks));
+	checkRetVal(xnRegisterToCalibrationComplete(hUserGenerator, &calibration_ended, dummy_cookie, &hCalibrationCallbacks));
 	
 	//XnPoseDetectionCallback pd = pose_detected;
 	//checkRetVal(xnRegisterToPoseCallbacks(*userGenerator, pd, NULL, NULL, hPoseCallbacks));
-	checkRetVal(xnRegisterToPoseDetected(*userGenerator, &pose_detected, dummy_cookie, &hPoseCallbacks));
-	checkRetVal(xnGetSkeletonCalibrationPose(*userGenerator, g_strPose));
-	checkRetVal(xnSetSkeletonProfile(*userGenerator, XN_SKEL_PROFILE_ALL));
+	checkRetVal(xnRegisterToPoseDetected(hUserGenerator, &pose_detected, dummy_cookie, &hPoseCallbacks));
+	checkRetVal(xnGetSkeletonCalibrationPose(hUserGenerator, g_strPose));
+	checkRetVal(xnSetSkeletonProfile(hUserGenerator, XN_SKEL_PROFILE_ALL));
 		
 		//	if (filter)
 	//		userGenerator.GetSkeletonCap().SetSmoothing(0.8);
 	
 	printf("Initialized Kinect, looking for users...\n\n");
 	//context.StartGeneratingAll();
-	xnStartGeneratingAll(context);
+	xnStartGeneratingAll(pContext);
 
 	
 }
 	      
 	      if (allJointCoords[XN_SKEL_RIGHT_HAND][1] < allJointCoords[XN_SKEL_HEAD][1]){  // small y -> high object, ie if hand.y < head.y -> hand is above head
 		button = 1;
+		printf("button: 1!");
 	      }else if (allJointCoords[XN_SKEL_LEFT_HAND][1] < allJointCoords[XN_SKEL_HEAD][1]){
 		button = 2;
+		printf("button: 2!");
 	      }
 	      
                 state.x = deltaX;
                 state.z = deltaZ;
 		
-		set_button(&state.A, button == 1);  // or U/D?
-		set_button(&state.B, button == 2);
+		set_button(&state.U, button == 1);  // A/B or U/D or what?
+		set_button(&state.D, button == 2);
+		
+		//printf("deltax: %s, deltaz: %s, button: %s", deltaX, deltaZ, button);
 
                 //set_button(&state.home, userFrame.button3);
                 //set_button(&state.U, userFrame.deltaWheel > 0);
     }
 
     //context.Shutdown();
-    xnShutdown(context);
+    xnShutdown(pContext);
     return 0;
 }
 
         thread = NULL;
 
 	printf("bye");
-        xnShutdown(context);
+        xnShutdown(pContext);
     }
 }
 

File share/tilt_kinect.o

Binary file modified.