Book Image

Leap Motion Development Essentials

By : Mischa Spiegelmock
Book Image

Leap Motion Development Essentials

By: Mischa Spiegelmock

Overview of this book

Leap Motion is a company developing advanced motion sensing technology for human–computer interaction. Originally inspired by the level of difficulty of using a mouse and keyboard for 3D modeling, Leap Motion believe that moulding virtual clay should be as easy as moulding clay in your hands. Leap Motion now focus on bringing this motion sensing technology closer to the real world. Leap Motion Development Essentials explains the concepts and practical applications of gesture input for developers who want to take full advantage of Leap Motion technology. This guide explores the capabilities available to developers and gives you a clear overview of topics related to gesture input along with usable code samples. Leap Motion Development Essentials shows you everything you need to know about the Leap Motion SDK, from creating a working program with gesture input to more sophisticated applications covering a range of relevant topics. Sample code is provided and explained along with details of the most important and central API concepts. This book teaches you the essential information you need to design a gesture-enabled interface for your application, from specific gesture detection to best practices for this new input. You will be given guidance on practical considerations along with copious runnable demonstrations of API usage which are explained in step-by-step, reusable recipes.
Table of Contents (12 chapters)

A simple gesture recognizer


One of the handy methods we can call on a Leap::Hand is sphereRadius(), which returns the size of an imaginary ball filling up a hand. The more outstretched your fingers are the larger the radius, and a more clenched fist will produce smaller values.

What does our ball gesture recognizer class look like? Feast your eyes on this:

typedef std::shared_ptr<BallGesture> BallGesturePtr;
   
void BallGesture::recognizedControls(const Leap::Controller &controller, std::vector<ControlPtr> &controls) {
    Leap::Frame frame = controller.frame();
    if (frame.hands().empty())
        return;

If no hands are found in the current frame, there's not much else for us to do here. However, if the user is waving some appendages around, we can do our thing.

    for (int i = 0; i < frame.hands().count(); i++) {
        if (i > 1) break;

If one or two hands are detected in the frame, we might be able to do something useful. We can get extra fancy if we return...