Leap Motion touch Simulation

Source: Internet
Author: User

Leap Motion translation series Article http://52coding.com/leap-motion-official-doc-translation

Touch Simulation

The Leap Motion API provides information that can be simulated in your application. The Touch Information is provided through the tip class.

Overview

Leap defines an adaptive touch plane. You can combine it with two-dimensional elements in your application. The plane is roughly rotated to parallel to the x-y plane, but dynamically adjusted based on the user's finger and hand position. However, when a user's hand or tool reaches the plane from the front, Leap will report whether the tip object is close to or touched to the virtual plane. The API reports information related to the plane through two values: the distance from the touch plane to the touch plane.

: Virtual touch plane

 

The Touch zone identifies whether the Leap Motion software determines whether the tip is suspended on the touch plane, whether it is penetrating the touch plane or far from the screen (or pointing to the wrong direction ). Areas include "floating", "Touch", and "NONE ". The transformation of the touch zone lags behind the transformation of the touch distance. This lag is used to avoid sudden and repeated changes. If you use this touch interaction in an application, you may not need to consider it frequently.

 

The Touch distance is valid only when the tip is in the floating and touch areas. The distance is the value of [-1, + 1. When a tip object first enters the floating area, the touch distance is + 1, and the distance is continuously reduced to 0, it means that the tip object is close to the touch plane. However, the distance between the tip and the point passing through the plane is 0. Because the tip object continues to push toward the touch area, the distance keeps approaching but does not exceed-1 (always tends to-1 ).

 

You can use the zone value to determine when to update the Interface Element Based on the floating or touch. You can also use the distance to further change the Interface Element [A rough, a fine] based on whether it is close to the plane. For example, when the finger is on the control body and in a floating area, you can highlight the control body and change the cursor Pattern Based on how close the user is to the control body.


As part of the touch simulation API, Leap Motion provides an additional stable coordinate relative to the standard coordinate for the tip object. The Leap Motion software uses an adaptive filter to stabilize this position and smooth and reduce Motion, making it easier to interact with users in the area of the screen (such as buttons and links. However, slow motion is more smooth, so that users can adjust the distance and easily touch specific points. [This effect is very good, just like what people do in the real world].

Get touch Zone

The Touch zone is described by the touchZone attribute of the tip class. All of these zones are identified by the enumeration type. There are three statuses in total:

# NONE --- the tip is too far from the touch screen, which is greater than the touch distance. Or it points to a user in the opposite direction (that is, the user's finger before the user's front by default is an inappropriate operation)

# HOVERING-the top of the tip object has reached the floating area, but is not considered as a touch.

# TOUCHING --- the tip reaches the virtual plane.

The following code snippet shows how to retrieve the belt ID of the front finger:

    Leap::Frame frame = leap.frame();    Leap::Pointable pointable = frame.pointables().frontmost();    Leap::Pointable::Zone zone = pointable.touchZone();
Get touch distance

The Touch distance is described by the touchDistance attribute of the tip class. The distance ranges from + 1 to-1, indicating that the finger moves to and passes through the Virtual touch plane. This distance has no physical significance, but the Leap Motion software determines how close it is to touch.

 

The following code snippet shows how to obtain the touch distance of the frontend finger:

    Leap::Frame frame = leap.frame();    Leap::Pointable pointable = frame.pointables().frontmost();    float distance = pointable.touchDistance();
Obtain the stable coordinates of the tip.

The stable coordinates are described in the stabilizedTipPosition attribute of the tip class. This position is obtained based on the reference of the standard Leap Motion coordinate system, but it has a filter with a large amount of contextual data, so it is very stable.

The following code snippet describes how to obtain the stable position of the front-end finger:

    Leap::Frame frame = leap.frame();    Leap::Pointable pointable = frame.pointables().frontmost();    Leap::Vector stabilizedPosition = pointable.stabilizedTipPosition();
From Leap Motion coordinate system to application Coordinate System

However, when using Touch simulation, you must convert the coordinate space of Leap Motion to the screen space of the application. To make this operation easier, the Leap Motion API provides an interactive box class [interactive box class] (IneractionBox ). This interactive box class describes the linear object Motion in the Leap Motion field of view. This class provides a way to normalize the coordinates in the object range to the range of [0, 1. You can normalize a distance and scale the result coordinates based on the application size to obtain the coordinates of an application.

 

For example, if you have a window in the customer region with two metric values, the following code gets the two-dimensional pixel coordinates of the touch points in the window:

    Leap::Frame frame = leap.frame();    Leap::Finger finger = frame.fingers().frontmost();    Leap::Vector stabilizedPosition = finger.stabilizedTipPosition();    Leap::InteractionBox iBox = leap.frame().interactionBox();    Leap::Vector normalizedPosition = iBox.normalizePoint(stabilizedPosition);    float x = normalizedPosition.x * windowWidth;    float y = windowHeight - normalizedPosition.y * windowHeight;
Contact example

The following example uses the touch simulation API to display all the tip objects detected in the application window. This example uses the touch to bring the color of the set point, and the touch distance to set the alpha value. The stable vertex position of the interactive box is mapped to the application window.

: Touch point example

#include "cinder/app/AppNative.h"#include "cinder/gl/gl.h"#include "Leap.h"#include "LeapMath.h"using namespace ci;using namespace ci::app;using namespace std;class TouchPointsApp : public AppNative {  public:        void setup();        void draw();  private:    int windowWidth = 800;    int windowHeight = 800;    Leap::Controller leap;};void TouchPointsApp::setup(){    this->setWindowSize(windowWidth, windowHeight);    this->setFrameRate(120);    gl::enableAlphaBlending();}void TouchPointsApp::draw(){        gl::clear( Color( .97, .93, .79 ) );    Leap::PointableList pointables = leap.frame().pointables();    Leap::InteractionBox iBox = leap.frame().interactionBox();    for( int p = 0; p < pointables.count(); p++ )    {        Leap::Pointable pointable = pointables[p];        Leap::Vector normalizedPosition = iBox.normalizePoint(pointable.stabilizedTipPosition());        float x = normalizedPosition.x * windowWidth;        float y = windowHeight - normalizedPosition.y * windowHeight;        if(pointable.touchDistance() > 0 && pointable.touchZone() != Leap::Pointable::Zone::ZONE_NONE)        {            gl::color(0, 1, 0, 1 - pointable.touchDistance());        }        else if(pointable.touchDistance() <= 0)        {            gl::color(1, 0, 0, -pointable.touchDistance());        }        else        {            gl::color(0, 0, 1, .05);        }        gl::drawSolidCircle(Vec2f(x,y), 40);    }}CINDER_APP_NATIVE( TouchPointsApp, RendererGl )

This example uses the Cinder library to create an application window for painting. [The example is so simple. How can I run it?]

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.