By Shira Wu
image from https://images.app.goo.gl/L3Tn7btihfcvA7UM6
In addition to basic gestures like a fist and an open palm, there are additional gesture recognition requirements. The principle of gesture recognition in "Daydream Fantasy" is stability and avoiding gesture conflicts, with gestures being as few as possible while maximizing their significance.
The core requirement of "Daydream Fantasy" is single-hand gesture recognition, which includes recognizing open palm, fist, and OK gestures. By using Leap Motion's pre-packaged headers, Unity developers can easily define hand models and customize gestures by distinguishing fingers.
using Leap;
using Leap.Unity
public HandModelBase leftHandModel;
Finger.FingerType[] arr12 = { Finger.FingerType.TYPE_THUMB, Finger.FingerType.TYPE_INDEX };
// Custom finger definitions
/*
TYPE_THUMB = 0 for thumb
TYPE_INDEX = 1 for index finger
TYPE_MIDDLE = 2 for middle finger
TYPE_RING = 3 for ring finger
TYPE_PINKY = 4 for pinky finger
*/
// Hand Recognition
bool IsOpenFullHand(Hand hand)
{
return hand.GrabStrength == 0;
}
// Fist recognition by measuring the distance from fingertips to palm center
bool IsCloseHand(Hand hand)
{
List<Finger> listOfFingers = hand.Fingers;
int count = 0;
for (int f = 0; f < listOfFingers.Count; f++)
{
Finger finger = listOfFingers[f];
if ((finger.TipPosition - hand.PalmPosition).Magnitude < 2f)
{
count++;
}
}
return (count == 5);
}
// OK gesture recognition by measuring the distance between different fingertips
if ((listOfFingers[0].TipPosition - listOfFingers[1].TipPosition).Magnitude < deltaCloseFinger)
{
// Recognize OK gesture
}
During the game, gesture control is always on, but Leap Motion can only recognize and validate gestures when the gesture window (which functions as equipment) is open. This allows players to interact with the scene using these gestures. To implement the "equipment" feature of gestures, the game framework is primarily built around the DontDestroyOnLoad
function. This function ensures that objects are not destroyed during scene transitions and remain in their pre-transition state.