1. schlangen
  2. neverkinect

Commits

schlangen  committed 0e54583

its playable. (no camera control yet)

  • Participants
  • Parent commits 77d0e44
  • Branches default

Comments (0)

Files changed (3)

File share/tilt_kinect.c

View file
 	
 	pDepthMD = xnAllocateDepthMetaData();
 
-	
 
 	//depth.Create(context);
 	
-	
-
-
-	//XnNodeHandle hNode;
-//	XnEnumerationErrors errors = new ;
 	nRetVal = xnCreateDepthGenerator(pContext, &hDepth, NULL, NULL);//&errors);
 	// TODO: error handling
-//	XN_IS_STATUS_OK(nRetVal);
 	if (nRetVal != (XnStatus)0){
 	  printf("error at depth generator create!");
 	}
 	
 	if (nRetVal == XN_STATUS_NO_NODE_PRESENT)
 	{
-	    // Iterate over enumeration errors, and print each one
-/*	    for (XnEnumerationErrorsIterator it = xnEnumerationErrorsGetFirst(&errors);  
-		 xnEnumerationErrorsIteratorIsValid(it);
-	         it = xnEnumerationErrorsGetCurrentError(it))
-	    {
-		XnChar strDesc[512];
-		xnProductionNodeDescriptionToString(xnEnumerationErrorsGetCurrentDescription(it), strDesc, 512);
-		printf("%s failed to enumerate: %s\n", xnGetStatusString(xnEnumerationErrorsGetCurrentError(it)));
-	    }
-*/	 //   return (nRetVal);
+	
 	}
 	else if (nRetVal != XN_STATUS_OK)
 	{
 	    printf("Create failed: %s\n", xnGetStatusString(nRetVal));
-	//    return (nRetVal);
 	}
 
-//	hDepth = hNode;
 
-//	XnNodeHandle hNode2;
 	nRetVal = xnCreateUserGenerator(pContext, &hUserGenerator, NULL, NULL);
-	// TODO: error handling
-//	XN_IS_STATUS_OK(nRetVal);
-//	hUserGenerator = &hNode2;
 
 	if (nRetVal != (XnStatus)0){
 	   printf("error at user generator create!");
 	//checkRetVal(userGenerator.GetPoseDetectionCap().RegisterToPoseCallbacks(pose_detected, NULL, NULL, hPoseCallbacks));
 	//checkRetVal(userGenerator.GetSkeletonCap().GetCalibrationPose(g_strPose));
 	//checkRetVal(userGenerator.GetSkeletonCap().SetSkeletonProfile(XN_SKEL_PROFILE_ALL));
-
-	int dummy = 5;
-	void *dummy_cookie = &dummy;
 	
-	checkRetVal(xnRegisterUserCallbacks(hUserGenerator, &new_user, &lost_user, dummy_cookie, &hUserCallbacks));
-	//XnCalibrationEnd ce = calibration_ended;
-	
-	//checkRetVal(xnRegisterCalibrationCallbacks(*userGenerator, calibration_started,ce, NULL, 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(hUserGenerator, &pose_detected, dummy_cookie, &hPoseCallbacks));
+	checkRetVal(xnRegisterUserCallbacks(hUserGenerator, &new_user, &lost_user, NULL, &hUserCallbacks));
+	checkRetVal(xnRegisterToCalibrationStart(hUserGenerator, &calibration_started, NULL, &hCalibrationCallbacks));
+	checkRetVal(xnRegisterToCalibrationComplete(hUserGenerator, &calibration_ended, NULL, &hCalibrationCallbacks));		
+	checkRetVal(xnRegisterToPoseDetected(hUserGenerator, &pose_detected, NULL, &hPoseCallbacks));
 	checkRetVal(xnGetSkeletonCalibrationPose(hUserGenerator, g_strPose));
 	checkRetVal(xnSetSkeletonProfile(hUserGenerator, XN_SKEL_PROFILE_ALL));
-		
-		//	if (filter)
-	//		userGenerator.GetSkeletonCap().SetSmoothing(0.8);
-	
-        // needed?
-	//xnSetMirror(depth, 1);
-
-	
-	//signal(SIGTERM, terminate);
-	//signal(SIGINT, terminate);
-	
-	
 	
 	printf("Initialized Kinect, looking for users...\n\n");
-	//context.StartGeneratingAll();
+	
+	//context.StartGeneratingAll();	
 	xnStartGeneratingAll(pContext);
 
 	
 }
 
 
-
+void free_kinect(){
+  //xnFreeDepthMetaData(pDepthMD);
+  xnContextRelease(pContext);
+}
 
 static int tilt_func(void *data)
 {
        printf("hello kinect world! inited!");
-//     FreespaceDeviceId deviceId;
-//     uint8_t buffer[FREESPACE_MAX_OUTPUT_MESSAGE_SIZE];
-//     int rc;
-//     float x, y, z;
-//     struct freespace_DataMotionControl d;
-//     struct freespace_UserFrame userFrame;
+       
     int running = 1;
-//     int length;
-//     int numIds;
-// 
-//     float quat[4];
-//     float eulerAngles[3];
-
-
-//     rc = freespace_getDeviceList(&deviceId, 1, &numIds);
-//     if (numIds == 0) {
-//         return 1;
-//     }
-// 
-//     rc = freespace_openDevice(deviceId);
-//     if (rc != FREESPACE_SUCCESS) {
-//         return 1;
-//     }
-// 
-//     rc = freespace_flush(deviceId);
-//     if (rc != FREESPACE_SUCCESS) {
-//         return 1;
-//     }
-// 
-//     d.enableBodyMotion = 0;
-//     d.enableUserPosition = 1;
-//     d.inhibitPowerManager = 0;
-//     d.enableMouseMovement = 1;
-//     d.disableFreespace = 0;
-//     rc = freespace_encodeDataMotionControl(&d, buffer, sizeof(buffer));
-//     if (rc > 0) {
-//         rc = freespace_send(deviceId, buffer, rc);
-//         if (rc != FREESPACE_SUCCESS) {
-//             return 1;
-//         }
-//     }
-
 
     SDL_mutexP(mutex);
     state.status = running;
         running = state.status;
         SDL_mutexV(mutex);
 
-//         rc = freespace_read(deviceId, buffer, FREESPACE_MAX_INPUT_MESSAGE_SIZE, 100, &length);
-//         if (rc != FREESPACE_SUCCESS) {
-//             continue;
-//         }
-// 
-//         if (length == 0) {
-//             continue;
-//         }
-// 
-//         if (freespace_decodeUserFrame(buffer, length, &userFrame) == FREESPACE_SUCCESS) {
-//             /* Hillcrest quaternion is rotate the world type, so make it rotate the object type by conjugating*/
-//             quat[0] = userFrame.angularPosA;
-//             quat[1] = -userFrame.angularPosB;
-//             quat[2] = -userFrame.angularPosC;
-//             quat[3] = -userFrame.angularPosD;
-//             q_nrm(quat, quat);
-// 
-//             /* This function does euler decomposition for rotate the object type (ZYX, aerospace) */
-//             q_euler(eulerAngles, quat);
-	
 	    main_loop();
-	    
-
-	    
-	     
+	    	    
             SDL_mutexP(mutex);
             {
              float deltaX, deltaZ;
   
 	      // difference in mm from neck to waist
-	      deltaX = (allJointCoords[XN_SKEL_NECK-1][0] - allJointCoords[XN_SKEL_WAIST-1][0]) / 200;
-	      deltaZ = (allJointCoords[XN_SKEL_NECK-1][2] - allJointCoords[XN_SKEL_WAIST-1][2]) / 100;
+	      deltaX = (allJointCoords[XN_SKEL_NECK-1][0] - allJointCoords[XN_SKEL_WAIST-1][0]) / 20;//200;
+	      deltaZ = (allJointCoords[XN_SKEL_NECK-1][2] - allJointCoords[XN_SKEL_WAIST-1][2] - 10) / 5;//100;
 	      
-	      if (deltaX > 1) deltaX = 1;
+	   /*  if (deltaX > 1) deltaX = 1;
 	      else if (deltaX < -1) deltaX = -1;
 	      if (deltaZ > 1) deltaZ = 1;
-	      else if (deltaZ < -1) deltaZ = -1;
+	      else if (deltaZ < -1) deltaZ = -1;*/
 	      
 	      int button = 0;
 	      
 		printf("button: 2!");
 	      }
 	      
-                state.x = deltaX;
-                state.z = deltaZ;
+                state.x = -deltaZ;
+                state.z = -deltaX;
 		
-		set_button(&state.A, button == 1);  // A/B or U/D or what?
-		set_button(&state.minus, button == 2);
+		set_button(&state.U, button == 1);  // <- make this rotate the camera (needs further changes in main neverball code)
+		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);
-                //set_button(&state.D, userFrame.deltaWheel < 0);
             }
             SDL_mutexV(mutex);
-        
+     //   printf("test");
 
     }
 
     //context.Shutdown();
-    xnShutdown(pContext);
+    free_kinect();
     return 0;
 }
 
+
+
 void tilt_init(void)
 {
     memset(&state, 0, sizeof (struct tilt_state));
         mutex  = NULL;
         thread = NULL;
 
-	printf("bye");
-        xnShutdown(pContext);
+	free_kinect();
     }
 }
 

File share/tilt_kinect.c~

View file
 	
 	pDepthMD = xnAllocateDepthMetaData();
 
-	
 
 	//depth.Create(context);
 	
-	
-
-
-	//XnNodeHandle hNode;
-//	XnEnumerationErrors errors = new ;
 	nRetVal = xnCreateDepthGenerator(pContext, &hDepth, NULL, NULL);//&errors);
 	// TODO: error handling
-//	XN_IS_STATUS_OK(nRetVal);
 	if (nRetVal != (XnStatus)0){
 	  printf("error at depth generator create!");
 	}
 	
 	if (nRetVal == XN_STATUS_NO_NODE_PRESENT)
 	{
-	    // Iterate over enumeration errors, and print each one
-/*	    for (XnEnumerationErrorsIterator it = xnEnumerationErrorsGetFirst(&errors);  
-		 xnEnumerationErrorsIteratorIsValid(it);
-	         it = xnEnumerationErrorsGetCurrentError(it))
-	    {
-		XnChar strDesc[512];
-		xnProductionNodeDescriptionToString(xnEnumerationErrorsGetCurrentDescription(it), strDesc, 512);
-		printf("%s failed to enumerate: %s\n", xnGetStatusString(xnEnumerationErrorsGetCurrentError(it)));
-	    }
-*/	 //   return (nRetVal);
+	
 	}
 	else if (nRetVal != XN_STATUS_OK)
 	{
 	    printf("Create failed: %s\n", xnGetStatusString(nRetVal));
-	//    return (nRetVal);
 	}
 
-//	hDepth = hNode;
 
-//	XnNodeHandle hNode2;
 	nRetVal = xnCreateUserGenerator(pContext, &hUserGenerator, NULL, NULL);
-	// TODO: error handling
-//	XN_IS_STATUS_OK(nRetVal);
-//	hUserGenerator = &hNode2;
 
 	if (nRetVal != (XnStatus)0){
 	   printf("error at user generator create!");
 	//checkRetVal(userGenerator.GetPoseDetectionCap().RegisterToPoseCallbacks(pose_detected, NULL, NULL, hPoseCallbacks));
 	//checkRetVal(userGenerator.GetSkeletonCap().GetCalibrationPose(g_strPose));
 	//checkRetVal(userGenerator.GetSkeletonCap().SetSkeletonProfile(XN_SKEL_PROFILE_ALL));
-
-	int dummy = 5;
-	void *dummy_cookie = &dummy;
 	
-	checkRetVal(xnRegisterUserCallbacks(hUserGenerator, &new_user, &lost_user, dummy_cookie, &hUserCallbacks));
-	//XnCalibrationEnd ce = calibration_ended;
-	
-	//checkRetVal(xnRegisterCalibrationCallbacks(*userGenerator, calibration_started,ce, NULL, 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(hUserGenerator, &pose_detected, dummy_cookie, &hPoseCallbacks));
+	checkRetVal(xnRegisterUserCallbacks(hUserGenerator, &new_user, &lost_user, NULL, &hUserCallbacks));
+	checkRetVal(xnRegisterToCalibrationStart(hUserGenerator, &calibration_started, NULL, &hCalibrationCallbacks));
+	checkRetVal(xnRegisterToCalibrationComplete(hUserGenerator, &calibration_ended, NULL, &hCalibrationCallbacks));		
+	checkRetVal(xnRegisterToPoseDetected(hUserGenerator, &pose_detected, NULL, &hPoseCallbacks));
 	checkRetVal(xnGetSkeletonCalibrationPose(hUserGenerator, g_strPose));
 	checkRetVal(xnSetSkeletonProfile(hUserGenerator, XN_SKEL_PROFILE_ALL));
-		
-		//	if (filter)
-	//		userGenerator.GetSkeletonCap().SetSmoothing(0.8);
-	
-        // needed?
-	//xnSetMirror(depth, 1);
-
-	
-	//signal(SIGTERM, terminate);
-	//signal(SIGINT, terminate);
-	
-	
 	
 	printf("Initialized Kinect, looking for users...\n\n");
-	//context.StartGeneratingAll();
+	
+	//context.StartGeneratingAll();	
 	xnStartGeneratingAll(pContext);
 
 	
 }
 
 
-
+void free_kinect(){
+  //xnFreeDepthMetaData(pDepthMD);
+  xnContextRelease(pContext);
+}
 
 static int tilt_func(void *data)
 {
        printf("hello kinect world! inited!");
-//     FreespaceDeviceId deviceId;
-//     uint8_t buffer[FREESPACE_MAX_OUTPUT_MESSAGE_SIZE];
-//     int rc;
-//     float x, y, z;
-//     struct freespace_DataMotionControl d;
-//     struct freespace_UserFrame userFrame;
+       
     int running = 1;
-//     int length;
-//     int numIds;
-// 
-//     float quat[4];
-//     float eulerAngles[3];
-
-
-//     rc = freespace_getDeviceList(&deviceId, 1, &numIds);
-//     if (numIds == 0) {
-//         return 1;
-//     }
-// 
-//     rc = freespace_openDevice(deviceId);
-//     if (rc != FREESPACE_SUCCESS) {
-//         return 1;
-//     }
-// 
-//     rc = freespace_flush(deviceId);
-//     if (rc != FREESPACE_SUCCESS) {
-//         return 1;
-//     }
-// 
-//     d.enableBodyMotion = 0;
-//     d.enableUserPosition = 1;
-//     d.inhibitPowerManager = 0;
-//     d.enableMouseMovement = 1;
-//     d.disableFreespace = 0;
-//     rc = freespace_encodeDataMotionControl(&d, buffer, sizeof(buffer));
-//     if (rc > 0) {
-//         rc = freespace_send(deviceId, buffer, rc);
-//         if (rc != FREESPACE_SUCCESS) {
-//             return 1;
-//         }
-//     }
-
 
     SDL_mutexP(mutex);
     state.status = running;
         running = state.status;
         SDL_mutexV(mutex);
 
-//         rc = freespace_read(deviceId, buffer, FREESPACE_MAX_INPUT_MESSAGE_SIZE, 100, &length);
-//         if (rc != FREESPACE_SUCCESS) {
-//             continue;
-//         }
-// 
-//         if (length == 0) {
-//             continue;
-//         }
-// 
-//         if (freespace_decodeUserFrame(buffer, length, &userFrame) == FREESPACE_SUCCESS) {
-//             /* Hillcrest quaternion is rotate the world type, so make it rotate the object type by conjugating*/
-//             quat[0] = userFrame.angularPosA;
-//             quat[1] = -userFrame.angularPosB;
-//             quat[2] = -userFrame.angularPosC;
-//             quat[3] = -userFrame.angularPosD;
-//             q_nrm(quat, quat);
-// 
-//             /* This function does euler decomposition for rotate the object type (ZYX, aerospace) */
-//             q_euler(eulerAngles, quat);
-	
 	    main_loop();
-	    
-
-	    
-	     
+	    	    
             SDL_mutexP(mutex);
             {
              float deltaX, deltaZ;
   
 	      // difference in mm from neck to waist
-	      deltaX = (allJointCoords[XN_SKEL_NECK-1][0] - allJointCoords[XN_SKEL_WAIST-1][0]) / 200;
-	      deltaZ = (allJointCoords[XN_SKEL_NECK-1][2] - allJointCoords[XN_SKEL_WAIST-1][2]) / 100;
+	      deltaX = (allJointCoords[XN_SKEL_NECK-1][0] - allJointCoords[XN_SKEL_WAIST-1][0]) / 20;//200;
+	      deltaZ = (allJointCoords[XN_SKEL_NECK-1][2] - allJointCoords[XN_SKEL_WAIST-1][2] - 10) / 5;//100;
 	      
-	      if (deltaX > 1) deltaX = 1;
+	   /*  if (deltaX > 1) deltaX = 1;
 	      else if (deltaX < -1) deltaX = -1;
 	      if (deltaZ > 1) deltaZ = 1;
-	      else if (deltaZ < -1) deltaZ = -1;
+	      else if (deltaZ < -1) deltaZ = -1;*/
 	      
 	      int button = 0;
 	      
 		printf("button: 2!");
 	      }
 	      
-                state.x = deltaX;
-                state.z = deltaZ;
+                state.x = -deltaZ;
+                state.z = -deltaX;
 		
-		set_button(&state.U, button == 1);  // A/B or U/D or what?
+		set_button(&state.U, button == 1);  // <- make this rotate the camera (needs further changes in main neverball code)
 		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);
-                //set_button(&state.D, userFrame.deltaWheel < 0);
             }
             SDL_mutexV(mutex);
-        
+     //   printf("test");
 
     }
 
     //context.Shutdown();
-    xnShutdown(pContext);
+    free_kinect();
     return 0;
 }
 
+
+
 void tilt_init(void)
 {
     memset(&state, 0, sizeof (struct tilt_state));
         mutex  = NULL;
         thread = NULL;
 
-	printf("bye");
-        xnShutdown(pContext);
+	free_kinect();
     }
 }
 

File share/tilt_kinect.o

Binary file modified.