<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Takepepe.com &#187; LeapMotion</title>
	<atom:link href="https://takepepe.com/tag/leapmotion/feed/" rel="self" type="application/rss+xml" />
	<link>https://takepepe.com</link>
	<description>Designer::develop</description>
	<lastBuildDate>Sun, 16 Jun 2013 15:40:24 +0000</lastBuildDate>
	<language>ja</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<item>
		<title>Processing #001 LeapMotion x Box2D</title>
		<link>https://takepepe.com/processing-001-leapmotion-x-box2d/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=processing-001-leapmotion-x-box2d</link>
		<comments>https://takepepe.com/processing-001-leapmotion-x-box2d/#comments</comments>
		<pubDate>Sun, 16 Jun 2013 10:32:37 +0000</pubDate>
		<dc:creator>Takepepe</dc:creator>
				<category><![CDATA[Processing]]></category>
		<category><![CDATA[Box2D]]></category>
		<category><![CDATA[LeapMotion]]></category>

		<guid isPermaLink="false">http://takepepe.com/?p=488</guid>
		<description><![CDATA[Processing #001 LeapMotion x Box2D from Takepepe on Vim [...]]]></description>
				<content:encoded><![CDATA[<p><iframe src="http://player.vimeo.com/video/68469264" width="720" height="405" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>
<p><a href="http://vimeo.com/68469264">Processing #001 LeapMotion x Box2D</a> from <a href="http://vimeo.com/user16458913">Takepepe</a> on <a href="http://vimeo.com">Vimeo</a>.</p>
<p>ご無沙汰してます、Takepepeです。<br />
世間は梅雨、ついにクーラーをかけながらデモムービーを撮る季節に突入しました。<br />
すっかり月１更新になってしまった今日このごろ。反省しないと！</p>
<p>さて、今日は動画のとおり、Leapを使ってお絵描きするインスタレーションをProcessingで作成しました。<br />
今回のキモはLeapSDKをラップしているライブラリから提供される<br />
標準のジェスチャーや座標を、意図した値に変換するところです。</p>
<p>使用しているライブラリは以下</p>
<div class="gray-rect">
JBox2D : <a href="http://www.jbox2d.org" target="_blank">http://www.jbox2d.org</a><br />
BoxWrap2d : <a href="http://wiki.processing.org/w/BoxWrap2d" target="_blank">http://wiki.processing.org/w/BoxWrap2d</a><br />
LeapMotionP5 : <a href="https://github.com/mrzl/LeapMotionP5" target="_blank">https://github.com/mrzl/LeapMotionP5</a>
</div>
<p>コードはEclipseで書いていますので、このままProcessingのIDEにはっつけても動かないのでご注意を。<br />
OPENGLの恩恵を受けていないコードですが、レンダリングモードをOPENGLにしています。<br />
EclipseでProcessingを書く場合、OPENGLの使用にはcore.jarだけではなく<br />
他にも入れないといけない.jarがありますので適当にググってください。</p>
<p>いつもの様に、順をおって解説していきます。</p>
<ol>
<li>LeapPointerP5の作成</li>
<li>Box2Dの初期設定</li>
<li>LeapPointerP5の座標をBox2Dに落とし込む</li>
<li>両手の状態で描画判定</li>
</ol>
<h2>1.LeapPointerP5の作成</h2>
<p>P001っていうのはPAppletを継承したやつです。<br />
コンストラクタに引数として渡して保持しておけば、<br />
Processingの便利APIを外からでも使用できます。</p>
<p>update()は、そのP001からdraw()内で呼ばれるループ関数です。<br />
このクラスは、冒頭で述べたキモにあたる部分を担っています。</p>
<p>執筆時現在の開発環境での話ですが、<br />
前回解説したとおり、LeapはFrameオブジェクトからpointable（指か棒）を取得できますが、<br />
これらをロストした時のカバーを自分でやらなければいけません。</p>
<p>今回のインスタレーションでは、ポインターを１つに限定しています。<br />
getPointable()でそのポインターを固定する処理をして、<br />
ポインターが属する手と反対側の手が「グー」なら「つかんでいる」状態というのを<br />
publicなisGrabbed()から参照出来るようになっています。</p>
<h3>LeapPointerP5.java</h3>
<pre class="brush: java; title: ; notranslate">

import com.leapmotion.leap.Frame;
import com.leapmotion.leap.Pointable;
import com.leapmotion.leap.Hand;
import com.onformative.leap.LeapMotionP5;

public class LeapPointerP5 {
	
	private P001 p;
	
	private LeapMotionP5 leap;
	private Frame frame;
	private Pointable pointable;
	private Hand currentHand;
	private Hand contraryHand;
	
	private boolean isDoubleHand = false;
	private boolean isGrabbing = false;
	private float offset = 6.0f;
	private float x;
	private float y;
	
	public LeapPointerP5(P001 p,LeapMotionP5 leap){
		this.p = p;
		this.leap = leap;
		this.pointable = leap.getFrame().pointables().get(0);
	}

	//------------------------------------------------------------
	// @　Loop
	
	public void update(){
		
		frame = leap.getFrame();
		pointable = getPointable();
		setHands();
		setPosition();

	}
	
	//------------------------------------------------------------
	// @ private 
	
	private Pointable getPointable() {
		
		// 前のフレームで取得したPointableがある場合、前フレームで取得したPointableを返す。無ければ新しいPointableを返す。
		
		Pointable _pointable = frame.pointables().get(0);
		int count = frame.pointables().count();
		for(int i=0 ; i&lt;count ; i++){
			if(pointable.id() == frame.pointables().get(i).id()){
				_pointable = frame.pointables().get(i);
			}
		}
		return _pointable;
	}
	
	private void setHands(){
		
		// pointableの手を格納。手を2つ取得できた場合、反対側の手を格納
		
		if(pointable.isFinger()){
			currentHand = pointable.hand();
			if(frame.hands().count() == 2){
				contraryHand = frame.hands().get(1);
				if(currentHand == contraryHand){
					contraryHand = frame.hands().get(0);
				}
				isDoubleHand = true;
			}else{
				contraryHand = null;
				isDoubleHand = false;
			}
		}
	}
	
	private void setPosition(){
		
		// pointableから、pointerの座標を算出
		
		float px = pointable.tipPosition().getX()*offset;
		float py = pointable.tipPosition().getY()*offset;
		this.x += ((p.width/2 + px) - this.x)/10;
		this.y += ((p.height/0.6 - py) - this.y)/10;
	}
	
	
	//------------------------------------------------------------
	// @ getter
	
	public float getX(){
		return this.x;
	}
	
	public float getY(){
		return this.y;
	}
	
	public boolean isPointed(){
		boolean res = false;
		if(frame.pointables().count() != 0){
			res = true;
		}
		return res;
	}
	
	public boolean isGrabbed(){
		
		// 描画している手と反対側の手が存在しつつ、その手がグーの時trueを返す。
		
		boolean res = false;
		if(isDoubleHand){
			if(!isGrabbing){
				if(contraryHand.fingers().count() == 0){
					res = true;
					isGrabbing = true;
				}
			}else{
				res = true;
				if(contraryHand.fingers().count() == 5){
					res = false;
					isGrabbing = false;
				}
			}
		}
		return res;
	}
	
}

</pre>
<h2>2.Box2Dの初期設定</h2>
<p>ここからはPAppletのコードです。<br />
Box2Dはあんまり新しくはなく、日本語のドキュメントがかなり少ないため苦戦しました。<br />
Physicsという、ProcessingでBox2Dを使用するためのインスタンスを生成し、<br />
それに対して、jbox2dのクラス群を利用していく感じになります。<br />
createPointerBody()ではLeapPointerP5で定義した座標をBox2D上に落とし込むためのインスタンスを生成しています。</p>
<h3>P001.java(抜粋)</h3>
<pre class="brush: java; title: ; notranslate">
	private void createPysics(){
		float gravX = 0.0f;
		float gravY = -100.0f;
		float AABBWidth = 2*width;
		float AABBHeight = 2*height;
		float borderBoxWidth = width+11;
		float borderBoxHeight = height+11;
		physics = new Physics(this, width, height, gravX, gravY, AABBWidth, AABBHeight, borderBoxWidth, borderBoxHeight, pixelsPerMeter);
		physics.setDensity(110.1f);
		physics.setCustomRenderingMethod(this, &quot;myCustomRenderer&quot;);
	}
	
	private void createPointerBody(){
		
		// LeapPointerP5の座標を用いたpointerBodyを生成。
		
		pointerDef = new BodyDef();
		pointerBody = physics.getWorld().createBody(pointerDef);
		pointerCircleDef = new CircleDef();
		pointerCircleDef.radius = 0.5f;
		pointerCircleDef.friction = physics.getFriction();
		pointerCircleDef.restitution = physics.getRestitution();
		pointerCircleDef.isSensor = physics.getSensor();
		pointerBody.createShape(pointerCircleDef);
		pointerBody.setMassFromShapes();
		updatePointerBody();
	}
	
</pre>
<h2>3.LeapPointerP5の座標をBox2Dに落とし込む</h2>
<p>以下のupdatePointerBody()はdraw()内でコールされている関数です。<br />
getColor()は、フレームにあわせて虹色を返してくれる関数です。</p>
<h3>P001.java(抜粋)</h3>
<pre class="brush: java; title: ; notranslate">
	private void updatePointerBody(){
		
		// 描画中は描画が始まった段階のpalletColorを使用。描画中でない時は随時描画色を更新。
		
		UserData data = new UserData();
		if(isDrawing){
			data.color = palletColor;
		}else{
			data.color = getColor();
		}
		pointerBody.setUserData(data);
		
		// Box2Dの座標系に変換しつつpointerBodyを移動。
		
		float x = (pointer.getX() - width/2)/pixelsPerMeter;
		float y = (-pointer.getY() + height/2)/pixelsPerMeter;
		pointerBody.setPosition(new Vec2(x,y));
		
	}
</pre>
<h2>4.両手の状態で描画判定</h2>
<p>LeapPointerP5で反対の手が「グー」と判定された場合、描画中になります。<br />
まず、verticesというArrayListが生成され、<br />
「グー」の間、ポインターの座標をどんどんverticesにつっこんでいき、<br />
「パー」になった時、もしくは反対の手がなくなった時、<br />
描画が終了し、verticesを使用したCircleが新しいbodyとして追加されます。</p>
<h3>P001.java(抜粋)</h3>
<pre class="brush: java; title: ; notranslate">
	private void brushBody(){
		if(isDrawing != pointer.isGrabbed()){
			if(isDrawing){
				onEndDrawing();
			}else{
				onStartDrawing();
			}
		}
		if(isDrawing == pointer.isGrabbed() &amp;&amp; isDrawing){
			onProcessDrawing();
		}

		// 描画中であれば、ProcessingのAPIでラインを描く。（ verticesの数だけellipseを描く ）
		
		if(isDrawing){
			this.fill(palletColor);
			for(int i=0 ; i&lt;vertices.size() ; i++){
				this.ellipse(vertices.get(i).x*pixelsPerMeter+width/2, vertices.get(i).y*-pixelsPerMeter+height/2, 30 ,30);
			}
		}
	}
	
	private void onStartDrawing(){
		
		// 描画が開始した時の処理。 vertices に格納した座標を元に Box2D で body を生成。
		
		isDrawing = true;
		vertices = new ArrayList&lt;Vec2&gt;();
		palletColor = getColor();
	}
	
	private void onProcessDrawing(){
		
		// 描画中の処理。 vertices に格納した座標を格納。
		
		Vec2 point = physics.screenToWorld(pointer.getX(),pointer.getY());
		vertices.add(point);
	}
	
	private void onEndDrawing(){
		
		// 描画が終了した時の処理。verticesに格納した座標を元にBox2Dでbodyを生成。
		
		isDrawing = false;
		BodyDef bd = new BodyDef();
		Body body = physics.getWorld().createBody(bd);
		for(int i =0 ; i&lt;vertices.size() ; i++){
			CircleDef cd = new CircleDef();
			cd.radius = 0.5f;
			cd.density = physics.getDensity();
			cd.friction = physics.getFriction();
			cd.restitution = physics.getRestitution();
			cd.isSensor = physics.getSensor();
			cd.localPosition.set(vertices.get(i));
			body.createShape(cd);
			body.setMassFromShapes();
		}
		
		// 描画したBodyに色を持たせる。必要なメンバはUserDataクラスで定義しておく。
		
		UserData data = new UserData();
		data.color = palletColor;
		body.setUserData(data);
		vertices = null;
	}
</pre>
<h2>P001.java</h2>
<pre class="brush: java; title: ; notranslate">
import java.util.List;
import java.util.ArrayList;

import processing.core.PApplet;

import org.jbox2d.common.Vec2;
import org.jbox2d.dynamics.World;
import org.jbox2d.dynamics.Body;
import org.jbox2d.dynamics.BodyDef;
import org.jbox2d.collision.CircleShape;
import org.jbox2d.collision.CircleDef;
import org.jbox2d.collision.Shape;
import org.jbox2d.collision.ShapeType;
import org.jbox2d.p5.Physics;

import com.onformative.leap.LeapMotionP5;

public class P001 extends PApplet{
	private static final long serialVersionUID = 0;
	
	// @ Box2D (JBox2D + BoxWrap2d)
	// JBox2D : http://www.jbox2d.org/
	// BoxWrap2d : http://wiki.processing.org/w/BoxWrap2d
	private Physics physics;
	private List&lt;Vec2&gt; vertices;
	private float pixelsPerMeter = 30;
	private BodyDef pointerDef;
	private Body pointerBody;
	private CircleDef pointerCircleDef;
	
	//  LeapMotionP5
	//  https://github.com/mrzl/LeapMotionP5
	//  auther @ mrzl
	private LeapMotionP5 leap;
	
	//  LeapPointerP5
	//  auther @ Takeppe
	private LeapPointerP5 pointer;
	
	private int palletColor;
	private boolean isDrawing = false;
	
	//------------------------------------------------------------
	// @ Setup
		
	public void setup(){
		size(2560,1390,OPENGL);
		frameRate(60);
		colorMode(HSB, 360, 100, 100);
		noStroke();
		
		leap = new LeapMotionP5(this);
		pointer = new LeapPointerP5(this,leap);
		
		createPysics();
		createPointerBody();
	}
	
	//------------------------------------------------------------
	// @ Box2D 
	
	private void createPysics(){
		float gravX = 0.0f;
		float gravY = -100.0f;
		float AABBWidth = 2*width;
		float AABBHeight = 2*height;
		float borderBoxWidth = width+11;
		float borderBoxHeight = height+11;
		physics = new Physics(this, width, height, gravX, gravY, AABBWidth, AABBHeight, borderBoxWidth, borderBoxHeight, pixelsPerMeter);
		physics.setDensity(110.1f);
		physics.setCustomRenderingMethod(this, &quot;myCustomRenderer&quot;);
	}
	
	private void createPointerBody(){
		
		// LeapPointerP5の座標を用いたpointerBodyを生成。
		
		pointerDef = new BodyDef();
		pointerBody = physics.getWorld().createBody(pointerDef);
		pointerCircleDef = new CircleDef();
		pointerCircleDef.radius = 0.5f;
		pointerCircleDef.friction = physics.getFriction();
		pointerCircleDef.restitution = physics.getRestitution();
		pointerCircleDef.isSensor = physics.getSensor();
		pointerBody.createShape(pointerCircleDef);
		pointerBody.setMassFromShapes();
		updatePointerBody();
	}
	
	public void myCustomRenderer(World world){
		
		// BoxWrap2d のカスタムレンダラーを使用。参照は以下。
		// http://wiki.processing.org/w/BoxWrap2d#Using_a_custom_renderer
		
		Body body;
		for (body = world.getBodyList(); body != null; body = body.getNext()) {
			Shape shape;
			for (shape = body.getShapeList(); shape != null; shape = shape.getNext()) {
				ShapeType st = shape.getType();
				if (st == ShapeType.POLYGON_SHAPE) {
				}else if (st == ShapeType.CIRCLE_SHAPE) {
					UserData data = (UserData)shape.getBody().getUserData();
					if(data != null){
						fill(data.color);
					}
					CircleShape circle = (CircleShape) shape;
					Vec2 pos = physics.worldToScreen(body.getWorldPoint(circle.getLocalPosition()));
					float radius = physics.worldToScreen(circle.getRadius());
					this.ellipseMode(CENTER);
					this.ellipse(pos.x, pos.y, radius*2, radius*2);
				}
			}
		}
	}
	
	//------------------------------------------------------------
	// @ Loop
	
	@Override
	public void draw() {
		this.background(0);
		pointer.update();
		updatePointerBody();
		brushBody();
	}
	
	private void updatePointerBody(){
		
		// 描画中は描画が始まった段階のpalletColorを使用。描画中でない時は随時描画色を更新。
		
		UserData data = new UserData();
		if(isDrawing){
			data.color = palletColor;
		}else{
			data.color = getColor();
		}
		pointerBody.setUserData(data);
		
		// Box2Dの座標系に変換しつつpointerBodyを移動。
		
		float x = (pointer.getX() - width/2)/pixelsPerMeter;
		float y = (-pointer.getY() + height/2)/pixelsPerMeter;
		pointerBody.setPosition(new Vec2(x,y));
		
	}
	
	private void brushBody(){
		if(isDrawing != pointer.isGrabbed()){
			if(isDrawing){
				onEndDrawing();
			}else{
				onStartDrawing();
			}
		}
		if(isDrawing == pointer.isGrabbed() &amp;&amp; isDrawing){
			onProcessDrawing();
		}

		// 描画中であれば、ProcessingのAPIでラインを描く。（ verticesの数だけellipseを描く ）
		
		if(isDrawing){
			this.fill(palletColor);
			for(int i=0 ; i&lt;vertices.size() ; i++){
				this.ellipse(vertices.get(i).x*pixelsPerMeter+width/2, vertices.get(i).y*-pixelsPerMeter+height/2, 30 ,30);
			}
		}
	}
	
	private void onStartDrawing(){
		
		// 描画が開始した時の処理。 vertices に格納した座標を元に Box2D で body を生成。
		
		isDrawing = true;
		vertices = new ArrayList&lt;Vec2&gt;();
		palletColor = getColor();
	}
	
	private void onProcessDrawing(){
		
		// 描画中の処理。 vertices に格納した座標を格納。
		
		Vec2 point = physics.screenToWorld(pointer.getX(),pointer.getY());
		vertices.add(point);
	}
	
	private void onEndDrawing(){
		
		// 描画が終了した時の処理。verticesに格納した座標を元にBox2Dでbodyを生成。
		
		isDrawing = false;
		BodyDef bd = new BodyDef();
		Body body = physics.getWorld().createBody(bd);
		for(int i =0 ; i&lt;vertices.size() ; i++){
			CircleDef cd = new CircleDef();
			cd.radius = 0.5f;
			cd.density = physics.getDensity();
			cd.friction = physics.getFriction();
			cd.restitution = physics.getRestitution();
			cd.isSensor = physics.getSensor();
			cd.localPosition.set(vertices.get(i));
			body.createShape(cd);
			body.setMassFromShapes();
		}
		
		// 描画したBodyに色を持たせる。必要なメンバはUserDataクラスで定義しておく。
		
		UserData data = new UserData();
		data.color = palletColor;
		body.setUserData(data);
		vertices = null;
	}
	
	private int getColor(){
		int hue = this.frameCount%360;
		return this.color(hue,100,100);
	}

	//------------------------------------------------------------
	// @ KeybordEvent
		
	@Override
	public void keyPressed(){
		
		// 初期化処理
		
		World world = physics.getWorld();
		if(keyCode == 32){
			Body body;
			for (body = world.getBodyList(); body != null; body = body.getNext()) {
				world.destroyBody(body);
			}
			physics.destroy();
			createPysics();
			createPointerBody();
		}
	}
	
}

</pre>
<p>余談ですが、先日Processingが2になりましたね！<br />
LeapSDKもバージョンアップがあった様子ですが、ちゃんと見れてません。<br />
（というか、ライブラリ頼みなのでバージョンあがっても対応できないという…むむむ）</p>
]]></content:encoded>
			<wfw:commentRss>https://takepepe.com/processing-001-leapmotion-x-box2d/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>LeapMotion #001 Starling</title>
		<link>https://takepepe.com/leapmotion-001-starling/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=leapmotion-001-starling</link>
		<comments>https://takepepe.com/leapmotion-001-starling/#comments</comments>
		<pubDate>Mon, 06 May 2013 11:50:42 +0000</pubDate>
		<dc:creator>Takepepe</dc:creator>
				<category><![CDATA[Flash]]></category>
		<category><![CDATA[LeapMotion]]></category>
		<category><![CDATA[Starling]]></category>

		<guid isPermaLink="false">http://takepepe.com/?p=426</guid>
		<description><![CDATA[LeapMotion #001 Starling from Takepepe on Vimeo. １ヶ月ぶりの [...]]]></description>
				<content:encoded><![CDATA[<p><iframe src="http://player.vimeo.com/video/65551480" width="720" height="405" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>
<p><a href="http://vimeo.com/65551480">LeapMotion #001 Starling</a> from <a href="http://vimeo.com/user16458913">Takepepe</a> on <a href="http://vimeo.com">Vimeo</a>.</p>
<p>１ヶ月ぶりの投稿です。GW最終日、皆様いかがお過ごしですか？<br />
今回の投稿は、個人的に今年最も気になるガジェット「LeapMotion」についてです。</p>
<h6><a href="https://www.leapmotion.com/" target="_blank">・Leap Motion</a></h6>
<p><img src="http://takepepe.com/wp-content/uploads/2013/05/leap_logo.png" /></p>
<p>LeapMotionは端末の上1m四方空間内で、1ミリ単位で指やツール（ペン等）を検知するセンサーです。<br />
また、SDKレベルで数種類のジェスチャーを認識します。</p>
<p>つい先日、プレオーダーした人への発送延期がアナウンスされたばかりですが、<br />
自分は3月末にプレオーダー、デベロッパー登録したところ、2週間ほどで手元に届きました。<br />
発送延期の理由としては、完璧な状態として世に送り出したい、というような内容でした。<br />
7月22日が発送予定日とされていますが、実際どうなるかはまだわかりませんね。</p>
<p>まだ日本語のリソースが少ない状態ですので、コード解説にはいる前に<br />
DeveloperPortalの概要を写したものを交えて、簡単に解説したいと思います。</p>
<h2>Frame</h2>
<p>LeapMotionで値を取得するために使用するFrameオブジェクトの中には以下のものが含まれます。</p>
<h6>・Lists of tracking data</h6>
<div class="gray-rect">
Hands — すべての手<br />
Pointables — Pointableオブジェクトとして、すべての指とツール<br />
Fingers — すべての指<br />
Tools — すべてのツール<br />
Gestures — 開始、更新、終了のハンドラーを含むすべてのジェスチャー</div>
<h6>・Frame motion</h6>
<div class="gray-rect">
Rotation Axis — 回転軸を表現する方向ベクトル。<br />
Rotation Angle — 回転軸(右手の法則を使用して)のまわりで右回りの回転角。<br />
Rotation Matrix — 回転を表現するtransformマトリックス。<br />
Scale Factor — 拡大縮小を表現するファクター。<br />
Translation — 直線運動を表現するベクトル。
</div>
<h2>Hand model</h2>
<p>手について様々な情報を提供します。2本の手を認識しますが、右手左手の識別はしていません。</p>
<h6>・Hand attributes</h6>
<div class="gray-rect">
Palm Position — Leapの起点から計測した手のひら中心座標<br />
Palm Velocity — 秒速ミリメートル単位の、手のひらの移動速度<br />
Palm Normal —  手のひらの中心から、下方へ指す垂直方向のベクトル<br />
Direction — 手のひらの中心から、指へ向かうベクトル。<br />
Sphere Center — 手の屈曲に適当な球体の中心。(手でボールを持っているような感じ)<br />
Sphere Radius — 手の屈曲に適当な球体の半径。半径は手の形とともに変化します。
</div>
<h6>・Hand motion</h6>
<div class="gray-rect">
Rotation Axis — 回転軸を表現する方向ベクトル。<br />
Rotation Angle — 回転軸(右手の法則を使用して)のまわりで右回りの回転角。<br />
Rotation Matrix —回転を表現するtransformマトリックス。<br />
Scale Factor — 拡大縮小を表現するファクター。<br />
Translation — 直線運動を表現するベクトル。
</div>
<h6>・Finger and Tool lists</h6>
<p>検知した手に属する、指やツールの情報を取得できます。</p>
<div class="gray-rect">
Pointables — Pointableオブジェクトとして、すべての指とツール<br />
Fingers — すべての指<br />
Tools — すべてのツール
</div>
<h2>Finger and Tool models</h2>
<p>Leapはその視界内の指およびツールの両方を検知するおよび追跡します。</p>
<div class="gray-rect">
Length — オブジェクト(手から先端に及ぶ)の可視部の長さ。<br />
Width — オブジェクトの可視部の平均幅。<br />
Direction — オブジェクト(つまり基礎から先端まで)と同じ方角に指すユニット方向ベクトル。<br />
Tip Position — Leapの起点から計測した指先の座標<br />
Tip Velocity — 秒速ミリメートル単位の、指先の移動速度
</div>
<h2>Gestures</h2>
<p>Leapは特定の移動パターンをGesturesとして認識します。</p>
<div class="gray-rect">
Circle — 円をトレースする単一の指。<br />
Swipe — 手の直線運動。<br />
Key Tap — キーボード・キーを軽く打つかのような指の動作。<br />
Screen Tap — コンピューター・スクリーンを軽く打つかのような指の動作。
</div>
<h6>開発環境について</h6>
<p>現在サポートされている言語は、C++、C#、Objective-C、Java、Python、JavaScriptになります。<br />
DevelperPortalでは前述の概要の他に、各フレームワークに対応したライブラリの配布、<br />
ガイドライン、コミュニティ、アプリストア概要などが掲載されています。<br />
Leapに興味があるかたは是非覗いてみてください。</p>
<h6><a href="https://developer.leapmotion.com/documentation/guide/Leap_Overview">・Leap Motion Developer Portal</a></h6>
<h2>LeapMotion × Adobe AIR Starling</h2>
<p>
今回作成したデモについての解説です。<br />
AdobeAIRでStarlingのParticleSystemを使用して作成しています。
</p>
<h6><a href="http://gamua.com/starling/" target="_blank">・Starling Framework</a><br />
<a href="https://github.com/PrimaryFeather/Starling-Extension-Particle-System" target="_blank">・Starling-Extension-Particle-System</a></h6>
<p>
StarlingはStage3Dを使用しているのでapp.xmlに以下の設定を忘れずにしましょう。
</p>
<div class="gray-rect">
&lt;renderMode&gt;direct&lt;/renderMode&gt;<br />
&lt;depthAndStencil&gt;false&lt;/depthAndStencil&gt;
</div>
<p>
LeapをActionScriptで使用するために、以下のライブラリと付属のC++SDKをラップしているANEを使用します。<br />
導入方法については、下記ページの下部に書いてあるので、それぞれ開発環境にあったものを選んでください。<br />
自分はFlashBuilder4.7でした。
</p>
<h6><a href="https://github.com/logotype/LeapMotionAS3" target="_blank">・LeapMotionAS3</a></h6>
<p>
Starlingを使用したパーティクルのデモは<a href="http://clockmaker.jp/blog/" target="_blank">Clockmakerさん</a>や<a href="http://www.project-nya.jp/" target="_blank">にゃあプロジェクトさん</a>が充実していますので、<br />
そちらを参考にさせていただきました。
</p>
<h3>FL001.as</h3>
<pre class="brush: as3; title: ; notranslate">
package {
	
	import flash.display.Sprite;
	import flash.display.StageAlign;
	import flash.display.StageDisplayState;
	import flash.display.StageScaleMode;
	import flash.events.KeyboardEvent;
	import starling.core.Starling;
	
	[SWF(backgroundColor=&quot;#00164a&quot;, width=&quot;1440&quot;, height=&quot;900&quot;, frameRate=&quot;60&quot;)]
	
	public class FL001 extends Sprite {
		
		private var starling:Starling;
		
		public function FL001() {
			
			stage.align = StageAlign.TOP_LEFT;
			stage.scaleMode = StageScaleMode.NO_SCALE;
			stage.addEventListener(KeyboardEvent.KEY_DOWN,onKeyDown);
			
			starling = new Starling(MainView, stage);
			starling.start();
			
		}
		
		private function onKeyDown(e:KeyboardEvent):void {
			
			if(stage.displayState == StageDisplayState.NORMAL){
				stage.displayState = StageDisplayState.FULL_SCREEN;
			} else {
				stage.displayState = StageDisplayState.NORMAL
			}
			
		}
		
		
	}
}

</pre>
<h3>MainView.as</h3>
<pre class="brush: as3; title: ; notranslate">
package {
	
	import flash.geom.Rectangle;
	import starling.core.Starling;
	import starling.display.Sprite;
	import starling.events.Event;
	import starling.events.ResizeEvent;
	import starling.extensions.ParticleDesignerPS;
	import starling.textures.Texture;
	import com.leapmotion.leap.LeapMotion;
	import com.leapmotion.leap.Pointable;
	import com.leapmotion.leap.events.LeapEvent;
	
	internal class MainView extends Sprite { 
		
		// 事前に「online particle editor」で.pexファイルとtexture.pngを用意しておきます
		// http://onebyonedesign.com/flash/particleeditor/
		
		[Embed(source = &quot;assets/particle.pex&quot;, mimeType = &quot;application/octet-stream&quot;)]
		private static var ParticleData:Class;
		
		[Embed(source = &quot;assets/texture.png&quot;)]
		private static var ParticleImage:Class;
		
		private var particles:Vector.&lt;ParticleDesignerPS&gt;;		
		private var count:int = 10;
		private var leap:LeapMotion;
		
		public function MainView() {
			addEventListener(Event.ADDED_TO_STAGE, onAddStage);
		}
		
		private function onAddStage(e:Event):void {
			
			setParticles();
			leap = new LeapMotion();
			leap.controller.addEventListener( LeapEvent.LEAPMOTION_FRAME, onLeapFrame );
			stage.addEventListener(ResizeEvent.RESIZE, onResizeStage);
			
		}
		
		private function setParticles():void{
			
			particles = new Vector.&lt;ParticleDesignerPS&gt;(10);
			for(var i:int = 0; i&lt;count ; i++){
				particles[i] = new ParticleDesignerPS( XML(new ParticleData()), Texture.fromBitmap(new ParticleImage()));
				particles[i].startSize = 100;
				particles[i].endSize = 100;
				particles[i].speed = 0;
				particles[i].start();
				Starling.juggler.add(particles[i]);
				addChild(particles[i]);
			}
			
		}
		
		private function onResizeStage(e:ResizeEvent):void {
			
			Starling.current.viewPort = new Rectangle(0, 0, e.width, e.height);
			stage.stageWidth = e.width;
			stage.stageHeight = e.height;
			
		}
		
		private function onLeapFrame(e:LeapEvent):void {
			
			var max:int = e.frame.pointables.length;
			for(var i:int = 0; i&lt;count ; i++){
				if( i &lt; max ){
					var pointable:Pointable = e.frame.pointables[i];
					particles[i].emitterX = (pointable.tipPosition.x)*3+stage.stageWidth/2;
					particles[i].emitterY = (pointable.tipPosition.y)*-3+stage.stageHeight;
					particles[i].gravityX = pointable.tipVelocity.x*-5;
					particles[i].gravityY = pointable.tipVelocity.y*5;
					particles[i].maxNumParticles = 50;
				}else{
					particles[i].maxNumParticles = 1;
				}
			}
			
		}
		
	}
}

</pre>
<p>１ヶ月いじった上で得た感想（というかぶちあたっている壁）です。</p>
<ol>
<li>指がLeapに向かって垂直に重なると検知できない。</li>
<li>細かなUI操作に向いていない</li>
<li>ジェスチャーはそのままでは利用しづらい</li>
</ol>
<p>
あくまで、現状公開されているSDKとライブラリを使用した上での感想です。<br />
概要を読む限りではワクワクするばかりですが、ちゃんとアプリケーションに落とし込むためには<br />
上記の問題をカバーしたフレームワークが必要だなと思いました。
</p>
<p>
今回の投稿はさらっと紹介しただけになってしまったので、<br />
次回はちょっとしたフレームワークと何か面白いネタで投稿できればいいなー。</p>
]]></content:encoded>
			<wfw:commentRss>https://takepepe.com/leapmotion-001-starling/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

 Served from: takepepe.com @ 2026-04-07 08:00:48 by W3 Total Cache -->