Upload
tsukasa-sugiura
View
115
Download
3
Embed Size (px)
DESCRIPTION
2013/3/12 Leap Motion 1st Review Original PowerPoint File Download : http://sdrv.ms/YdnyjD
Citation preview
Leap Motion
1st Review
Tsukasa SUGIURA
@UnaNancyOwen
12
[mm
]
USB 3.0 micro-B
LED
Youtube – Leap Motion (Leap Visualizer) http://youtu.be/cxlpjSUrOa0
C:¥Program Files¥
LeapSDK
include
lib
環境変数
変数 変数値
LEAPMOTION_DIR C:¥Program Files¥LeapSDK¥
Path ;%LEAPMOTION_DIR%lib¥x86
;%LEAPMOTION_DIR%lib¥x64
依存ファイル
構成 ライブラリ
Debug Leapd.lib
Release Leap.lib
インクルード ディレクトリ
$(LEAPMOTION_DIR)include
ライブラリ ディレクトリ $(LEAPMOTION_DIR)lib¥x86
$(LEAPMOTION_DIR)lib¥x64
■システムの設定
■プロジェクトの設定(C++)
■基本的なプログラムの構成
// Include Header #include <Leap.h>
ヘッダファイルのインクルード
// Listener class Listener : public Leap::Listener{ public: virtual void onInit( const Leap::Controller& ); virtual void onConnect( const Leap::Controller& ); virtual void onDisconnect( const Leap::Controller& ); virtual void onExit( const Leap::Controller& ); virtual void onFrame( const Leap::Controller& ); };
Leap::Listenerクラスを継承するサブクラスの定義
void Listener::onInit( const Leap::Controller& controller ){ /* 実装 */ } void Listener::onConnect( const Leap::Controller& controller ){ /* 実装 */ } void Listener::onDisconnect( const Leap::Controller& controller ){ /* 実装 */ } void Listener::onFrame( const Leap::Controller& controller ){ /* 実装 */ } void Listener::onExit( const Leap::Controller& controller ){ /* 実装 */ }
コールバック関数の実装
// Main int _tmain( int argc, _TCHAR* argv[] ){ // Create a listener and controller Listener listener; Leap::Controller controller; // Have the listener receive events from the controller controller.addListener( listener ); // Keep this process running until Enter is pressed std::cout << "Press Enter to quit..." << std::endl; std::cin.get(); // Remove the listener when done controller.removeListener( listener ); return 0; }
メイン関数の実装
virtual void onInit( const Leap::Controller& )
インスタンス化されたときに呼び出される
virtual void onConnect( const Leap::Controller& )
コントローラーに接続(Leap::Controller::addListener())されたときに呼び出される
virtual void onDisConnect( const Leap::Controller& )
Leap Motionが外されたときに呼び出される
virtual void onFrame( const Leap::Controller& )
Leap Motionのフレームが更新されたときに呼び出される
virtual void onExit( const Leap::Controller& )
コントローラーと切断(Leap::Controller::removeListener())され、 インスタンスが破棄されたときに呼び出される
class Leap::Listener
bool addLitener( Leap::Listener &listener )
Leap::Listenerを接続する
bool removeListener( Leap::Listener &listener )
Leap::Listenerを切断する
Leap::Frame frame( int history = 0 ) const
フレーム情報(Leap::Frame)
Leap::ScreenList calibratedScreens() const
キャリブレーションしたスクリーン情報のリスト(Leap::ScreenList)
void enableGesture( Leap::Gesture::Type type, bool enable = true ) const
Leap::Gesture::Typeのジェスチャー検出を有効にする
class Leap::Controller
Leap::Screen operator[]( int index ) const
indexのスクリーン情報(Leap::Screen)を取得する
class Leap::ScreenList
int widthPixels() const
スクリーンの幅 [pixel]
int heightPixels() const
スクリーンの高さ [pixel]
Leap::Vector intersect( const Leap::Pointable &pointable, bool normalize , float clampRatio = 1.0f ) const
Leap::Pointable(指など)とスクリーンの交点
bool isValid() const
スクリーン情報の有効性
Class Leap::Screen
Leap::HandList hands() const
手情報のリスト(Leap::HandList)
Leap::GestureList gestures() const
ジェスチャー情報のリスト(Leap::GestureList)
class Leap::Frame
Leap::Hand operator[]( int index ) const
indexの手情報(Leap::Hand)を取得する
class Leap::HandList
Leap::PointableList pointables() const
ポインター情報のリスト(Leap::PointableList)
Leap::FingerList fingers() const
指情報のリスト(Leap::FingerList)
Class Leap::Hand
bool empty() const
手情報のリストが空
Leap::Finger operator[]( int index ) const
indexの指情報(Leap::Finger)を取得する
class Leap::FingerList
Leap::Vector tipPosition() const
Leap Motion原点からの指先端のミリメートル位置(x, y, z) [mm]
Leap::Vector tipVelocity() const
指先端のミリメートル位置の秒変化率(速度) [mm/s]
class Leap::Finger : Leap::Pointable
bool empty() const
指情報のリストが空
Leap::Gesture operator[]( int index ) const
indexのジェスチャー情報(Leap::Gesture)を取得する
class Leap::GestureList
Leap::Type type() const
検出されたジェスチャーの種類
class Leap::Gesture
int count() const
リストに入っているジェスチャー情報の数
bool empty() const
ジェスチャー情報のリストが空
Leap::Type type() const
検出されたジェスチャーの種類(Leap::Gesture::Type)
class Leap::Gesture
Leap::State state () const
ジェスチャーの状態(Leap::Gesture::State)
TYPE_SWIPE
スワイプ(指で直線運動するジェスチャー)
TYPE_CIRCLE
サークル(指で円運動するジェスチャー)
TYPE_SCREEN_TAP
スクリーンタップ(指で前向きにタッピングするジェスチャー)
TYPE_KEY_TAP
キータップ(指で下向きにタッピングするジェスチャー)
enum Leap::Gesture::Type
STATE_START
ジェスチャーの開始状態
STATE_UPDATE
ジェスチャーの途中状態
STATE_STOP
ジェスチャーの修了状態
enum Leap::Gesture::State
Leap::Vector position() const
ジェスチャーした位置(x, y, z) [mm]
Leap::Vector direction() const
ジェスチャーの方向
class Leap::SwipeGesture : Leap::Gesture
float speed() const
スワイプの速度 [mm/s]
Leap::Vector startPosition() const
スワイプの開始位置(x, y, z)
Leap::Vector position() const
ジェスチャーした位置(x, y, z) [mm]
Leap::Vector direction() const
ジェスチャーの方向(::angleTo)
class Leap::CircleGesture : Leap::Gesture
float radius() const
サークルの半径 [mm]
float progress() const
サークルの回転数
Leap::Vector center () const
サークルの中心位置(x, y, z)
Leap::Vector position() const
ジェスチャーした位置(x, y, z) [mm]
Leap::Vector direction() const
ジェスチャーの方向
class Leap::KeyTapGesture : Leap::Gesture
Leap::Vector position() const
ジェスチャーした位置(x, y, z) [mm]
Leap::Vector direction() const
ジェスチャーの方向
class Leap::ScreenTapGesture : Leap::Gesture
// onFrame void Listener::onFrame( const Leap::Controller& controller ){ // Get first calibrated Screen const Leap::ScreenList screenList = controller.calibratedScreens(); if( screenList.empty() ){ return; } const Leap::Screen screen = screenList[0]; // Get Frame const Leap::Frame frame = controller.frame(); // Get HandList const Leap::HandList handList = frame.hands(); if( !handList.empty() ){ // Get first Hand const Leap::Hand hand = handList[0];
■例:指でマウスポインタを操作する
// Get first Finger pointable const Leap::PointableList pointableList = hand.pointables(); if( pointableList.empty() ){ return; } const Leap::Pointable pointable = pointableList[0]; // Get intersection between screen and ray projecting from finger // normalize true : intersect.x 0…1, intersect.y 0…1 const Leap::Vector intersect = screen.intersect( pointable, true, 1.0f ); if( !intersect.isValid() ){ return; } // Set Mouse Pointer unsigned int x = screen.widthPixels() * intersect.x; unsigned int y = screen.heightPixels() * ( 1.0f - intersect.y ); SetCursorPos( x, y ); // SetCursorPos() defined in #include <windows.h> } }
// onFrame void Listener::onFrame( const Leap::Controller& controller ){ // Get Gesture const Leap::GestureList gestureList = frame.gestures(); for( int count = 0; count < gestureList.count(); ++count ){ Leap::Gesture gesture = gestureList[count]; // Switch Gesture type switch( gesture.type() ){ // Case of Swipe Gesture case Leap::Gesture::TYPE_SWIPE:
■例:ジェスチャー(スワイプ)で左右キーを操作する
// onConnect void Listener::onConnect( const Leap::Controller& controller ){ // Enable detect Gesture controller.enableGesture( Leap::Gesture::TYPE_SWIPE ); }
Leap::SwipeGesture swipe = gesture; // horizontal swipe // Swipe is horizon if diff is positive, vertical if diff is negative. float diff = std::abs( swipe.direction().x ) - std::abs( swipe.direction().y ); if( diff > 0.0f ){ // swipe left ( <- ) if( swipe.direction().x > 0.0f ){ // Check Gesture State Start if( swipe.state() == Leap::Gesture::STATE_START ){ keybd_event( VK_LEFT, 0, 0, 0 ); keybd_event( VK_LEFT, 0, KEYEVENTF_KEYUP, 0 ); } } // swipe right ( -> ) else{ // Check Gesture State Start if( swipe.state() == Leap::Gesture::STATE_START ){ keybd_event( VK_RIGHT, 0, 0, 0 ); keybd_event( VK_RIGHT, 0, KEYEVENTF_KEYUP, 0 ); } }
} break; default: break; } } }