5#include "ManusSDKTypes.h"
14 std::cout <<
"Starting minimal client!\n";
17 std::cout <<
"minimal client is initialized.\n";
23 std::cout <<
"minimal client is done, shutting down.\n";
43 return ClientReturnCode::ClientReturnCode_FailedPlatformSpecificInitialization;
47 if (t_IntializeResult != ClientReturnCode::ClientReturnCode_Success)
49 return ClientReturnCode::ClientReturnCode_FailedToInitialize;
52 return ClientReturnCode::ClientReturnCode_Success;
61 const SDKReturnCode t_InitializeResult = CoreSdk_Initialize(SessionType::SessionType_CoreSDK);
62 if (t_InitializeResult != SDKReturnCode::SDKReturnCode_Success)
64 return ClientReturnCode::ClientReturnCode_FailedToInitialize;
68 if (t_CallBackResults != ::ClientReturnCode::ClientReturnCode_Success)
70 return t_CallBackResults;
77 CoordinateSystemVUH t_VUH;
78 CoordinateSystemVUH_Init(&t_VUH);
79 t_VUH.handedness = Side::Side_Left;
80 t_VUH.up = AxisPolarity::AxisPolarity_PositiveY;
81 t_VUH.view = AxisView::AxisView_ZFromViewer;
82 t_VUH.unitScale = 1.0f;
84 const SDKReturnCode t_CoordinateResult = CoreSdk_InitializeCoordinateSystemWithVUH(t_VUH,
false);
86 if (t_CoordinateResult != SDKReturnCode::SDKReturnCode_Success)
88 return ClientReturnCode::ClientReturnCode_FailedToInitialize;
91 return ClientReturnCode::ClientReturnCode_Success;
99 const SDKReturnCode t_Result = CoreSdk_ShutDown();
100 if (t_Result != SDKReturnCode::SDKReturnCode_Success)
102 return ClientReturnCode::ClientReturnCode_FailedToShutDownSDK;
107 return ClientReturnCode::ClientReturnCode_FailedPlatformSpecificShutdown;
110 return ClientReturnCode::ClientReturnCode_Success;
121 const SDKReturnCode t_RegisterSkeletonCallbackResult = CoreSdk_RegisterCallbackForSkeletonStream(*
OnSkeletonStreamCallback);
122 if (t_RegisterSkeletonCallbackResult != SDKReturnCode::SDKReturnCode_Success)
124 return ClientReturnCode::ClientReturnCode_FailedToInitialize;
126 return ClientReturnCode::ClientReturnCode_Success;
133 std::cout <<
"minimal client is connecting to local host. (make sure it is running)\n";
134 while (
ConnectLocally() != ClientReturnCode::ClientReturnCode_Success)
137 std::cout <<
"minimal client could not connect.trying again in a second.\n";
138 std::this_thread::sleep_for(std::chrono::milliseconds(1000));
140 std::cout <<
"minimal client is connected, setting up skeletons.\n";
160 std::cout <<
"skeleton data obtained for frame: " << std::to_string(
m_FrameCounter) <<
".\n";
164 std::this_thread::sleep_for(std::chrono::milliseconds(33));
177 SDKReturnCode t_StartResult = CoreSdk_LookForHosts(1,
true);
178 if (t_StartResult != SDKReturnCode::SDKReturnCode_Success)
180 return ClientReturnCode::ClientReturnCode_FailedToFindHosts;
183 uint32_t t_NumberOfHostsFound = 0;
184 SDKReturnCode t_NumberResult = CoreSdk_GetNumberOfAvailableHostsFound(&t_NumberOfHostsFound);
185 if (t_NumberResult != SDKReturnCode::SDKReturnCode_Success)
187 return ClientReturnCode::ClientReturnCode_FailedToFindHosts;
190 if (t_NumberOfHostsFound == 0)
192 return ClientReturnCode::ClientReturnCode_FailedToFindHosts;
195 std::unique_ptr<ManusHost[]> t_AvailableHosts;
196 t_AvailableHosts.reset(
new ManusHost[t_NumberOfHostsFound]);
198 SDKReturnCode t_HostsResult = CoreSdk_GetAvailableHostsFound(t_AvailableHosts.get(), t_NumberOfHostsFound);
199 if (t_HostsResult != SDKReturnCode::SDKReturnCode_Success)
201 return ClientReturnCode::ClientReturnCode_FailedToFindHosts;
204 SDKReturnCode t_ConnectResult = CoreSdk_ConnectToHost(t_AvailableHosts[0]);
206 if (t_ConnectResult == SDKReturnCode::SDKReturnCode_NotConnected)
208 return ClientReturnCode::ClientReturnCode_FailedToConnect;
211 return ClientReturnCode::ClientReturnCode_Success;
223 uint32_t t_SklIndex = 0;
225 SkeletonSetupInfo t_SKL;
226 SkeletonSetupInfo_Init(&t_SKL);
227 t_SKL.type = SkeletonType::SkeletonType_Hand;
228 t_SKL.settings.scaleToTarget =
true;
229 t_SKL.settings.targetType = SkeletonTargetType::SkeletonTarget_UserIndexData;
232 t_SKL.settings.skeletonTargetUserIndexData.userIndex = 0;
234 CopyString(t_SKL.name,
sizeof(t_SKL.name), std::string(
"LeftHand"));
236 SDKReturnCode t_Res = CoreSdk_CreateSkeletonSetup(t_SKL, &t_SklIndex);
237 if (t_Res != SDKReturnCode::SDKReturnCode_Success)
248 t_Res = CoreSdk_LoadSkeleton(t_SklIndex, &t_ID);
249 if (t_Res != SDKReturnCode::SDKReturnCode_Success)
271 NodeSetup_Init(&t_Node);
273 CopyString(t_Node.name,
sizeof(t_Node.name), p_Name);
274 t_Node.type = NodeType::NodeType_Joint;
276 t_Node.parentID = p_ParentId;
277 t_Node.settings.usedSettings = NodeSettingsFlag::NodeSettingsFlag_None;
279 t_Node.transform.position.x = p_PosX;
280 t_Node.transform.position.y = p_PosY;
281 t_Node.transform.position.z = p_PosZ;
303 const uint32_t t_NumFingers = 5;
304 const uint32_t t_NumJoints = 4;
308 ManusVec3 t_Fingers[t_NumFingers * t_NumJoints] = {
344 SDKReturnCode t_Res = CoreSdk_AddNodeToSkeletonSetup(p_SklIndex,
CreateNodeSetup(0, 0, 0, 0, 0,
"Hand"));
345 if (t_Res != SDKReturnCode::SDKReturnCode_Success)
352 for (uint32_t i = 0; i < t_NumFingers; i++)
354 uint32_t t_ParentID = 0;
356 for (uint32_t j = 0; j < t_NumJoints; j++)
358 t_Res = CoreSdk_AddNodeToSkeletonSetup(p_SklIndex,
CreateNodeSetup(1 + t_FingerId + j, t_ParentID, t_Fingers[i * 4 + j].x, t_Fingers[i * 4 + j].y, t_Fingers[i * 4 + j].z,
"fingerdigit"));
359 if (t_Res != SDKReturnCode::SDKReturnCode_Success)
361 printf(
"Failed to Add Node To Skeleton Setup. The error given %d.", t_Res);
364 t_ParentID = 1 + t_FingerId + j;
366 t_FingerId += t_NumJoints;
380 ChainSettings t_ChainSettings;
381 ChainSettings_Init(&t_ChainSettings);
382 t_ChainSettings.usedSettings = ChainType::ChainType_Hand;
383 t_ChainSettings.hand.handMotion = HandMotion::HandMotion_IMU;
384 t_ChainSettings.hand.fingerChainIdsUsed = 5;
385 t_ChainSettings.hand.fingerChainIds[0] = 1;
386 t_ChainSettings.hand.fingerChainIds[1] = 2;
387 t_ChainSettings.hand.fingerChainIds[2] = 3;
388 t_ChainSettings.hand.fingerChainIds[3] = 4;
389 t_ChainSettings.hand.fingerChainIds[4] = 5;
392 ChainSetup_Init(&t_Chain);
394 t_Chain.type = ChainType::ChainType_Hand;
395 t_Chain.dataType = ChainType::ChainType_Hand;
396 t_Chain.side = Side::Side_Left;
397 t_Chain.dataIndex = 0;
398 t_Chain.nodeIdCount = 1;
399 t_Chain.nodeIds[0] = 0;
400 t_Chain.settings = t_ChainSettings;
402 SDKReturnCode t_Res = CoreSdk_AddChainToSkeletonSetup(p_SklIndex, t_Chain);
403 if (t_Res != SDKReturnCode::SDKReturnCode_Success)
410 const ChainType t_FingerTypes[5] = { ChainType::ChainType_FingerThumb,
411 ChainType::ChainType_FingerIndex,
412 ChainType::ChainType_FingerMiddle,
413 ChainType::ChainType_FingerRing,
414 ChainType::ChainType_FingerPinky };
415 for (
int i = 0; i < 5; i++)
417 ChainSettings t_ChainSettings;
418 ChainSettings_Init(&t_ChainSettings);
419 t_ChainSettings.usedSettings = t_FingerTypes[i];
420 t_ChainSettings.finger.handChainId = 0;
423 t_ChainSettings.finger.metacarpalBoneId = -1;
424 t_ChainSettings.finger.useLeafAtEnd =
false;
426 ChainSetup_Init(&t_Chain);
428 t_Chain.type = t_FingerTypes[i];
429 t_Chain.dataType = t_FingerTypes[i];
430 t_Chain.side = Side::Side_Left;
431 t_Chain.dataIndex = 0;
434 t_Chain.nodeIdCount = 4;
435 t_Chain.nodeIds[0] = 1;
436 t_Chain.nodeIds[1] = 2;
437 t_Chain.nodeIds[2] = 3;
438 t_Chain.nodeIds[3] = 4;
442 t_Chain.nodeIdCount = 4;
443 t_Chain.nodeIds[0] = (i * 4) + 1;
444 t_Chain.nodeIds[1] = (i * 4) + 2;
445 t_Chain.nodeIds[2] = (i * 4) + 3;
446 t_Chain.nodeIds[3] = (i * 4) + 4;
448 t_Chain.settings = t_ChainSettings;
450 SDKReturnCode t_Res = CoreSdk_AddChainToSkeletonSetup(p_SklIndex, t_Chain);
451 if (t_Res != SDKReturnCode::SDKReturnCode_Success)
466 t_NxtClientSkeleton->
skeletons.resize(p_SkeletonStreamInfo->skeletonsCount);
468 for (uint32_t i = 0; i < p_SkeletonStreamInfo->skeletonsCount; i++)
470 CoreSdk_GetSkeletonInfo(i, &t_NxtClientSkeleton->
skeletons[i].info);
471 t_NxtClientSkeleton->
skeletons[i].nodes =
new SkeletonNode[t_NxtClientSkeleton->
skeletons[i].info.nodesCount];
472 CoreSdk_GetSkeletonData(i, t_NxtClientSkeleton->
skeletons[i].nodes, t_NxtClientSkeleton->
skeletons[i].info.nodesCount);
bool PlatformSpecificInitialization(void)
Initialise things only needed for this platform.
bool GetKeyDown(const int p_Key)
Returns true first time it is called when key is pressed.
static bool CopyString(char *const p_Target, const size_t p_MaxLengthThatWillFitInTarget, const std::string &p_Source)
Copy the given string into the given target.
bool PlatformSpecificShutdown(void)
Shut down things only needed for this platform.
std::vector< ClientSkeleton > skeletons
Used to store all the final animated skeletons received from Core.
static SDKMinimalClient * s_Instance
ClientReturnCode ShutDown()
When you are done with the SDK, don't forget to nicely shut it down this will close all connections t...
ClientSkeletonCollection * m_NextSkeleton
ClientReturnCode Initialize()
Initialize the sample console and the SDK. This function attempts to resize the console window and th...
ClientReturnCode InitializeSDK()
Initialize the sdk, register the callbacks and set the coordinate system. This needs to be done befor...
bool SetupHandChains(uint32_t p_SklIndex)
This function sets up some basic hand chains. Chains are required for a Skeleton to be able to be ani...
ClientReturnCode RegisterAllCallbacks()
Used to register the callbacks between sdk and core. Callbacks that are registered functions that get...
void LoadTestSkeleton()
This function sets up a very minimalistic hand skeleton. In order to have any 3d positional/rotationa...
ClientReturnCode ConnectLocally()
the client will now try to connect to manus core via the SDK.
std::mutex m_SkeletonMutex
static ManusVec3 CreateManusVec3(float p_X, float p_Y, float p_Z)
bool SetupHandNodes(uint32_t p_SklIndex)
This support function sets up the nodes for the skeleton hand In order to have any 3d positional/rota...
NodeSetup CreateNodeSetup(uint32_t p_Id, uint32_t p_ParentId, float p_PosX, float p_PosY, float p_PosZ, std::string p_Name)
Skeletons are pretty extensive in their data setup so we have several support functions so we can cor...
static void OnSkeletonStreamCallback(const SkeletonStreamInfo *const p_SkeletonStreamInfo)
This gets called when the client is connected to manus core.
ClientSkeletonCollection * m_Skeleton
ClientReturnCode
Values that can be returned by this application.