Skip to content

Instantly share code, notes, and snippets.

@UnaNancyOwen
Last active October 18, 2016 13:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save UnaNancyOwen/3c957e40d3ae0643836b272996f5ab5c to your computer and use it in GitHub Desktop.
Save UnaNancyOwen/3c957e40d3ae0643836b272996f5ab5c to your computer and use it in GitHub Desktop.
How to Retrieve Specific Joint Position
// Retrieve Joints
std::array<Joint, JointType::JointType_Count> joints;
ERROR_CHECK( body->GetJoints( JointType::JointType_Count, &joints[0] ) );
// Retrieve Specific Joint Position ( e.g. Left Hand )
const Joint joint = joints[JointType::JointType_HandLeft];
if( joint.TrackingState == TrackingState::TrackingState_Tracked ){
const CameraSpacePoint position = joint.Position;
const float x = position.X; // X coordinate (+/-1.0)
const float y = position.Y; // Y coordinate (+/-1.0)
const float z = position.Z; // Z coordinate (meters)
std::cout << x << ", " << y << ", " << z << std::endl;
}
// Retrieve Joints
std::array<Joint, JointType::JointType_Count> joints;
ERROR_CHECK( body->GetJoints( JointType::JointType_Count, &joints[0] ) );
// e.g. Convert Joint Position of Left Hand to Depth Space
{
// Retrieve Specific Joint Position of Left Hand
const Joint joint = joints[JointType::JointType_HandLeft];
if( joint.TrackingState == TrackingState::TrackingState_Tracked ){
// Convert Joint Position to Depth Space
const CameraSpacePoint position = joint.Position;
DepthSpacePoint point;
ERROR_CHECK( coordinateMapper->MapCameraPointToDepthSpace( position, &point ) );
// Joint Position in Depth Sapce
const int x = static_cast<int>( point.X + 0.5f );
const int y = static_cast<int>( point.Y + 0.5f );
const float z = position.Z;
if( ( 0 <= x ) && ( x < Width ) && ( 0 <= y ) && ( y < Height ) ){
std::cout << "LeftHand : " << x << ", " << y << ", " << z << std::endl;
}
}
}
// e.g. Convert Joint Position of Right Hand to Depth Space
{
// Retrieve Specific Joint Position of Right Hand
const Joint joint = joints[JointType::JointType_HandRight];
if( joint.TrackingState == TrackingState::TrackingState_Tracked ){
// Convert Joint Position to Depth Space
const CameraSpacePoint position = joint.Position;
DepthSpacePoint point;
ERROR_CHECK( coordinateMapper->MapCameraPointToDepthSpace( position, &point ) );
// Joint Position in Depth Sapce
const int x = static_cast<int>( point.X + 0.5f );
const int y = static_cast<int>( point.Y + 0.5f );
const float z = position.Z;
if( ( 0 <= x ) && ( x < Width ) && ( 0 <= y ) && ( y < Height ) ){
std::cout << "RightHand : " << x << ", " << y << ", " << z << std::endl;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment