Check if Zigfu and Unity3D's hands are up

Using Zigfu in Unity3D, how can I check if my hands are raised?

+3


source to share


2 answers


I'm not familiar with Zigfu , but if background mechanics no longer exist to test this fact (as George Profenza points out in the comments), then you can easily roll your own test that will check this condition.

Each of the Kinect APIs (official or third party) has a joint breakdown for the skeleton. the official API breaks the skeleton into the following joints, and I believe NITE breaks the skeleton into the same joints.

Kinect Skeleton Joints

You can check the position of one joint in relation to the position of the other joint to ensure that the "raise arm" condition is met.

For example, you can simply check if the player's elbows are above their shoulders:

private void OnSkeletonFrameReady()
{
    if ((JointId[ElbowRight].Y > JointId[ShoulderRight].Y) &&
        (JointId[ElbowLeft].Y > JointId[ShoulderLeft].Y)
    {
        // arms have been raised
    }
}

      

This is obviously pseudo code that needs to be updated to the Zigfu API references.



The advantage of using your own (versus using what may already be defined) is that you can decide what "weapon" means.

  • Should your arms be higher than your shoulders?
  • Should both arms have elbows higher than the shoulders?
  • Do you only need your hands to be above the joint HipCenter

    or Spine

    ?
  • Should your arms stretch or bend your elbows?

All others (and more) can be defined as "hands up". The joint configuration can be tested against to determine if they are correct.

If you want to make sure the player keeps his hands up for a specified period of time before recognizing the condition, you can simply add a timer to the gesture test. Example pseudocode:

DispatherTimer _gestureTimer = new DispatcherTimer();
_gestureTimer.Interval = TimeSpan.FromSeconds(5);
_gestureTimer.Tick += OnGestureTimerTick();

bool _armsRaisedFlag = false;

private void OnSkeletonFrameReady()
{
    if ((JointId[ElbowRight].Y > JointId[ShoulderRight].Y) &&
        (JointId[ElbowLeft].Y > JointId[ShoulderLeft].Y)
    {
        _argsRaisedFlag = true;
        _gestureTimer.Start();
    }
    else
    {
        _armsRaisedFlag = false;
        _gestureTimer.Stop();
    }
}

private void OnGestureTimerTick()
{
    _gestureTimer.Stop();
    if (_armsRaisedFlag == true)
    {
        // player arms have been raised long enough for gesture to pass
    }
}

      

In this case, every time the raise hand condition is met, a flag is set and a timer is started. If the player keeps their hands up for 5 seconds, the condition is met and you can do what you want.

+3


source


Its a sipmle, Just write the ZigSkeleton.

In your ZigSkeleton file create a varialbe to hold the leverage id

public int TrackedLeftArm = (int)ZigJointId.LeftArm;

      

and in the UpdateRotation function,



Quaternion newRotation = transform.rotation * orientation * initialRotations[(int)joint];

      

now check

if((int)joint==TrackedLeftArm)
{


   if(newRotation.x> DesiredANgle)
    Debug.Log("Hands raised");

}

      

+1


source







All Articles