I calculate the sum of angles of the fingers to the palm normal. Except the Thumb which is calculated against the palm.direction.
The greater the sum, the more the fingers are stretched (open hand).
Another thing to notice, is that when the fingers are bent inward, the finger direction can exceed the palm normal towards the wrist. when that happens the angle starts growing again, which is not wanted. So I detect this and ignore it. Anyways the finger direction tracking in that area is not so good.
I find this way very robust, and the derived stretchiness value is not jumpy.
Here is my Java code snippet (sorry I don't know yet how to post code properly) for calculating the "stretchiness" of 1 finger. Just calculate the sum on all fingers and you get the hand stretchiness value.
Enjoy ! And I am open for improvements.
public static float getFingerStretchAngle(Finger finger, Hand hand) {
final Vector fDir = finger.direction();
if (finger.type() == Type.TYPE_THUMB) {
return fDir.angleTo(hand.direction());
} else {
// So fingers bent
// beyond the palm normal not considered facing forward, and are
// ignored.
final boolean facingForward = fDir.angleTo(hand.direction()) < R_90_DEGREE_RADIANS;
if (facingForward) {
// We calculate relative to palm normal since a finger stretch
// angle may be greater than 90 degrees.
return fDir.angleTo(hand.palmNormal());
} else {
return 0;
}
}
}