InteractionBox - みる会図書館


検索対象: Leap Motionプログラミングガイド 改訂版
16件見つかりました。

1. Leap Motionプログラミングガイド 改訂版

《プログラム》 それではコードを見てみ ましよう。 全体のコードは「 lntera ctionBox02 」にあります。 ・ draw ( ) i f ( ! fi nge r. i sval i d ( ) ) { [ 3-1 1 ] rInteractionBox 」を使う 面 0 州 行 0 Side backSide 「 InteractionBox 」の座標に変換します。 / / 人差し指を取得する Leap: :Finger :TYPE_INDEX retu rn ; finger = mLeap. frame ( ) . fingers ( ) .fingerType ( Leap: : Finger: :Type / / InteractionBox の座標に変換する 161 ここでは、あらかじめ取得した人差し指の座標を変換しています。 の位置の割合で変化します。 点となり、それぞれ右、上、手前方向に「 0 」から「 1 」の範囲の「 InteractionBox 」 「 normalizepoint ( ) 」で返される座標系は「 InteractionBox 」の左下奥が原 変換したい座標を「 Leap::InteractionBox::normalizePoint ( ) 」に指定します。 「 InteractionBox 」は、「 Leap::Frame::interactionBox ( ) 」で取得できます。 si ti on ( ) ) ; iBOX . normalizepoint ( finger . stabilizedTippo Leap: :vector normalizedposition Leap: : 工 nteractionBox iBOX = mLeap. frame ( ) . interactionBox ( ) ;

2. Leap Motionプログラミングガイド 改訂版

第 3 章 アプリケーションの開発 「 InteractionBoxJ を使う こでは、「 Leap Motion 」の「座標を変換する方法」について解説します。 「 Leap Motion VI 」では、いくつかの座標変換の方法がありましたが、「 Leap Motion V2 」では「 InteractionBox 」の変換のみとなっています。 ※より正確には、「インターセクション・ポイント」 (lntersection point) および「プロジェク ション・ポイント」 (Projection point) VI .2 から非推奨となりました。 「 InteractionBox 」のイ メージは、次の図です。 rlnteractionBox 」のイメージ 「 Leap Motion 」の逆ピラミッドの中に直方体の検出環境を作ります。この直方 体の左下奥を ( 0 , 0 , 0 ) として、「 0 」から「 1 」までの範囲で値が変化します。 たとえば、この値にウインドウの「幅」や「高さ」を掛けることで、「指がウインドウのど の位置にいるか」ということを知ることができます。 これを使ったプログラムは「 4-2 お絵かきツールを作成する」で解説しています。 変換された位置の動きを見る 「 InteractionBox 」がどのように動作するのか見てみましよう。 《プログラム》 全体のコードは「 InteractionBox01 」 にあります。 「 InteractionBox 」を模した枠の中を、 指の位置を表わした球が動きます。 このプログラムの実行結果 ・ update ( ) フレームの更新と各座標の取得を行ないます。 156

3. Leap Motionプログラミングガイド 改訂版

[ 3-1 1 ] fInteractionBox 」を使う ホノヾー状態 ( 指を検出しているがタッチはしてい ない状態 ) では、指の位置が緑色で表わされます。 ホバー状態 タッチと判定されると、指の位置が赤くなります。 タッチ状態 1 2.041 物 非接触のインターフェイスでは、操作しようとしている位置にこでは指 ) がわかり づらいことが難点です。 ホバー状態を明確に判定することで、これからタッチしようとしている位置をユー ザーに知らせることができ、より使いやすい操作体系を提供できます。 normalizedposition . X ☆ windowwidth; fl oat x / / ウインドウの座標に変換する void draw ( ) います。 ほとんどのコードは「 InteractionBox02 」であり、タッチの判定コードのみ追加して 全体のコードは「 InteractionBox03 」にあります。 それではコードを見てみましよう。 《プログラム》 163 / / ホバー状態 (normalizedposition. y ☆ WindowHeight) ; float y = windowHeight

4. Leap Motionプログラミングガイド 改訂版

[ 3-1 1 ] rInteractionBox 」を使う 「 InteractionBox 」からは、「中心の座標」と「幅」「高さ」「奥行き」がそれぞれ 取得 ( 単位はすべて mm ( ミリメートル ) ) できるので、計算して、「左右」「上下」「前 後」の位置を求めます。 void update ( ) / / フレームの更新 mLastFrame = mCurrentFrame; mCurrentFrame = mLeap. frame ( ) ; iBOX = mCurrentFrame . interactionBox ( ) ; iBOX . center ( ) . X (iBox. width ( ) / 2 ) ; mLeft iBOX. center().x + (iBox. width() / 2 ) ; mRight iBox. center() . y + (iBox. height() / 2 ) ; mTO p mBaottom = iBox. center ( ) . y ー (iBox. height ( ) / 2 ) ; iBox.center ( ) . z (iBox. depth ( ) / 2 ) ; mBacksi de iBox.center ( ) . z + (iBox. depth ( ) / 2 ) ; mFrontSide renderFrameParameter ( ) ; top backSide center frontSide ・ renderFrameParameter ( ) 「幅」「高さ」「奥行き」の値を表示します。 VOid renderFrameParameter ( ) くく iBox . width ( ) くく一 "Yn" くく "width S S くく 157

5. Leap Motionプログラミングガイド 改訂版

[ 4-2 ] 「お絵描きツール」の作成 「 Leap Motion 」から得られる「 3 次元の座標」を「 2 次元の座標」として扱うに は、「 Leap::InteractionBox::normalizePoint() 」を使っています。 これによって、「 Leap Motion 」を中心とした座標系を、次の図の立方体の中の 位置の割合 ( 0 から 1 ) の値に変換します。 位置の割合に対して、アプリケーションウインドウのサイズを掛けることで、座標を計 算しています。 ※ fInteractionBox 」の詳細は、 p. 156 を参照してください。 図 4-6 立方体の中の位置の割合 ( 0 から 1 ) の値に変換 「 X , Y 座標」を使う場合、左下が ( 0 , 0 ) に なります。 ウインドウは右上が ( 0 , 0 ) になるので、上下 方向を逆転させます。 1 0 1 図 4-7 左下が ( 0 , 0 ) 189

6. Leap Motionプログラミングガイド 改訂版

第 3 章アプリケーションの開発 1 S S くく S S くく S S くく 'Height:' "Depth 'center: くく iBOX. height ( ) くく "mm" くく "Yn" くく iBox. depth ( ) くく "mm" くく "Yn" くく iBox.center ( ) くく "Yn" ・ drawLeapObject ( ) 「 drawInteractionBoxFrame ( ) 」で「 InteractionBox 」の枠を描画し、「 draw FingerPoint ( ) 」で「 InteractionBox 」内の指の位置を描画します。 void drawLeapObject ( ) / / 表示処理 drawInteractionBOXFrame ( ) ; drawFingerpoint ( ) ; ・ drawInteractionBoxFrame ( ) 「 update ( ) 」で求めた頂点の座標から、「 InteractionBox 」の枠を描画します。 VOid drawInteractionBoxFrame ( ) / / 中心点 //gl : :drawsphere ( tovec3f ( iBox.center ( ) ) , 5 ) ; / / 上面 gl : :drawLine ( Vec3f ( mRight, mTOP, mFrontSide ) , vec3f ( mRight, mTop, mFrontSide ) ) ; gl : :drawLine ( Vec3f ( mRight, mTOP, mBackSide ) , vec3f ( mRight, mTop, mBackside ) ) ; gl : :drawLine ( vec3f ( mLeft, mTOP, mBackside ) , 158

7. Leap Motionプログラミングガイド 改訂版

第 3 章アプリケーションの開発 Leap: :Finger finger = mLeap.frame ( ) . fingers ( ) . fingerType ( Leap: : Fi nger: :Ty pe: :TYPE-INDEX ) [ 0 ] ; i f ( ! fi nge r. i sval i d ( ) ) { retu rn ; Leap: :vector normalizedposition iBOX. normalizepoint ( finger. tipPOSition ( ) ) ; / / 位置の割合から実際の座標を計算 / / 原点を左下奥にする * iBox. width ( ) ) + mLeft; (normalizedposition . X auto X autO y = (normalizedposition.y ☆ iBOX. height ( ) ) 十 mBaottom; ☆ iBox.depth ( ) ) + mBackside; (normal izedposition. Z autO z gl::drawsphere( vec3f( x, y, z ) , 現在のフレームで検出された指から、「人差し指」を取得します。 その指が有効であれば、指先の座標を「 InteractionBox 」の位置に変換します。 変換された「 x , Y , z 」の位置に「幅」「高さ」「奥行き」の値を掛け、原点 ( 左下 奥 ) 中心にすることとで、「 InteractionBox 」の座標になります。 2 次元の位置座標として利用する 「 InteractionBox 」で変換された位置割 合のうち、「 X,Y 」を使うことで、 2 次元の位置 座標として利用することができます。 川 2. 052 区 752 160

8. Leap Motionプログラミングガイド 改訂版

[ 3-4 ] 「フレーム」について知る (Leap::Frame クラス ) id() currentFramesPerSecond() timestamp() isValid() interactionBox() フレームの ID を取得 現在のフレームレート ( FPS ) を取得 Leap Motion が動作開始してからの経過時間を取得 フレームの有効、無効状態を取得 teractionBox クラスのインスタンスを取得 「手」や「指」「モーション」の情報はそれぞれの項を参照してください。 ここでは、「 Frame クラス」固有のメンノヾ関数について解説します。 フレームの「 ID 」を取得します。 ID は連番になっているので、「ポーリング方式」でデータを取得している場合に、 ID が連続していないときは、フレームを飛ばした可能性があります。 間を抜けないように処理したい場合は、「 Leap::ControIIer::frame() 」を「履 歴」で呼び出し、 ID 間のフレームを処理します。 ・ currentFramesPerSecond() 「 Leap Motion 」が 1 秒間あたりに更新するフレーム数です。 おおよそ、手を検出していないときで「 30FPS 」 (FramesPerSecond : 1 秒間に 30 回データを更新する ) 、手を検出しているときで「 IOOFPS 」ほどになります。 ・ interactionBox() 「 Leap Motion 」の逆ピラミッドの座標系を、立方体の座標系に変換します。 変換された座標は位置の値ではなく、立方体の中の「 0 」から「 1 」の範囲での 割合になります。 ※ [InteractionBox 」の詳細は、 p. 156 を参照してください。 図 3-5 lnte 「 actionBox 83

9. Leap Motionプログラミングガイド 改訂版

CONTENTS 第 4 章サンプルアプリを作る [ 3-1 1 ] rInteractionBox 」を使う [ 3-10 ] 「モーション」を取得する [ 3-9 ] ジェスチャーを検出する [ 3-8 ] 「手」を検出する [ 3- 刀「指」を検出 [ 3-6 ] コードのテンプレート [ 3-5 ] デバイス情報を取得 (Leap::Device クラス ) [ 3-4 ] 「フレーム」について知る (Leap::Frame クラス ) [ 3-3 ] イベント駆動でデータを取得 ( Leap : : Listener クラス ) ・・・ 78 ( 「 Leap::ControIIer クラス」 ) [ 3-2 ] 「 Leap Motion 」はじめの一歩 [ 3-1 ] 「 Leap Motion SDK 」の概要 第 3 章アプリケーションの開発 [ 4-1 ] じゃんけんゲーム [ 4-2 ] 「お絵描きツール」の作成 索引 ・各商品は一般に各社の登録商標または商標ですが、⑧および TM は省略しています。 ・ 82 84 87 92 1 07 147 1 56 62 166 1 78 1 91

10. Leap Motionプログラミングガイド 改訂版

[ 4-2 ] 「お絵描きツール」の作成 VOid drawpoi nts( const std : :vector く Leap: :vector>& points , int si ze , glpointsize( size ) ; C010r ( 010r ) drawvertex( point ) ; points ) { fO 「 ( autO poi nt gl : :begin( GL—POINTS ) ; setDiffuseC010r( C010r ) ; / / 3 次元 if( m1s3D ) { / / 3 次元データで書く VOid drawvertex( Leap: :vector pointable ) / / 座標を設定する gl : : end ( ) ; autO poi nt bOX . normalizepoint( pointable ) ; autO bOX = mCurrentFrame . interactionBox() ; / / 座標変換する ( 0 ー 1 の値 ) el se { / / 2 次元データで書く gl : :vertex( tovec3f( pointable ) ) ; / / 縦( 面が Leap Motion に対して垂直 ) gl : :vertex( point. x ☆ width, Height / / 横 ( 面が Leap Motion に対して水平 ) -(point. y ☆ Height) ) ; //gl::vertex( point. x ☆ width, P0int . z * Height ) ; / / GL—LIGHTO の色を変える 183