XnStatus hiKinect::init(const FB::JSObjectPtr &cb){ XnStatus nRetVal = XN_STATUS_OK; callbackPtr = &cb; nRetVal = context.Init(); (*callbackPtr)->InvokeAsync("", FB::variant_list_of("CONTEXT_INIT") (nRetVal)(xnGetStatusString(nRetVal))); if (nRetVal != XN_STATUS_OK) return nRetVal; // Create the user generator nRetVal = g_UserGenerator.Create(context); (*callbackPtr)->InvokeAsync("", FB::variant_list_of("USERGENERATOR_CREATE") (nRetVal)(xnGetStatusString(nRetVal))); if (nRetVal != XN_STATUS_OK) return nRetVal; XnCallbackHandle h1, h2, h3; g_UserGenerator.RegisterUserCallbacks(User_NewUser, User_LostUser, this, h1); g_UserGenerator.GetPoseDetectionCap() .RegisterToPoseCallbacks(Pose_Detected, NULL, this, h2); g_UserGenerator.GetSkeletonCap() .RegisterCalibrationCallbacks(Calibration_Start, Calibration_End, this, h3); // Set the profile g_UserGenerator.GetSkeletonCap().SetSkeletonProfile(XN_SKEL_PROFILE_ALL); FBLOG_INFO("contextInit", "Init finish"); // Start generating nRetVal = context.StartGeneratingAll(); (*callbackPtr)->InvokeAsync("", FB::variant_list_of("START_GENERATING") (nRetVal)(xnGetStatusString(nRetVal))); if (nRetVal != XN_STATUS_OK) return nRetVal; while (getTrackedUserID() == 0){ contextWaitAndUpdateAll(); } return nRetVal; }
void hiKinect::getPosition(XnSkeletonJoint joint, XnSkeletonJointPosition &pos){ XnUserID id = getTrackedUserID(); if (id != 0) { g_UserGenerator.GetSkeletonCap().GetSkeletonJointPosition(id, joint, pos); }else{ return; } }
void UserDetector::getSkeletonJointInfo(XuSkeletonJointIndex jointIndex, XuSkeletonJointInfo* pJointInfo) { XuUserID userID = getTrackedUserID(); if (userID) { m_userProvider->getSkeletonJointInfo(userID, jointIndex, pJointInfo); } else { pJointInfo->fConfidence = 0; pJointInfo->position.assign(0, 0, 0); } }
XV3 UserDetector::getUpVector() { XuUserID userID = getTrackedUserID(); if (userID) { XV3 v0(getSkeletonJointPosition(XU_SKEL_TORSO)); XV3 v1(getSkeletonJointPosition(XU_SKEL_NECK)); return (v1 - v0).normalize(); } else { return XV3(); } }
XV3 UserDetector::getForwardVector() { XuUserID userID = getTrackedUserID(); if (userID) { XV3 v0(getSkeletonJointPosition(XU_SKEL_RIGHT_SHOULDER)); XV3 v1(getSkeletonJointPosition(XU_SKEL_TORSO)); XV3 v2(getSkeletonJointPosition(XU_SKEL_LEFT_SHOULDER)); return ((v1 - v0).cross(v2 - v1)).normalize(); } else { return XV3(); } }