Last active
July 15, 2016 10:35
-
-
Save myy/ca466e79938bce85ddae3603257f2369 to your computer and use it in GitHub Desktop.
Processing で LeapMotion を使うためのお試しコード.手のひらや指の位置を描画しようとしている.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.leapmotion.leap.*; | |
Controller controller = new Controller(); | |
void setup() { | |
size(1000, 1000); | |
// ジェスチャーを有効にする | |
controller.enableGesture(Gesture.Type.TYPE_SWIPE); | |
controller.enableGesture(Gesture.Type.TYPE_CIRCLE); | |
controller.enableGesture(Gesture.Type.TYPE_SCREEN_TAP); | |
controller.enableGesture(Gesture.Type.TYPE_KEY_TAP); | |
} | |
void draw() { | |
background(0); | |
Frame frame = controller.frame(); | |
text("BASIC INFORMATION", 50, 10); | |
text("Frame id: " + frame.id(), 50, 30); | |
text("Timestamp: " + frame.timestamp(), 50, 50); | |
text(frame.hands().count() + " Hands", 50, 70); | |
text(frame.fingers().count() + " Fingers", 50, 90); | |
// text("tools: " + frame.tools().count(), 50, 110); | |
text("gestures: " + frame.gestures().count(), 50, 110); | |
text("HANDS INFORMATION", 50, 150); | |
for(Hand hand : frame.hands()) { | |
String handType = hand.isLeft() ? "Left hand" : "Right hand"; | |
text(handType + ", id: " + hand.id() + ", palm pos: " + hand.palmPosition(), 50, 170); | |
// ellipse(hand.palmPosition().getX()+(width/2), (height*2/3)-hand.palmPosition().getY(), 50, 50); | |
// Vector normal = hand.palmNormal(); | |
// Vector direction = hand.direction(); | |
// | |
// text("pitch: " + Math.toDegrees(direction.pitch()) + " degrees", 50, 190); | |
// text("roll: " + Math.toDegrees(normal.roll()) + " degrees", 50, 210); | |
// text("yaw: " + Math.toDegrees(direction.yaw()) + " degrees", 50, 230); | |
for(Finger finger : hand.fingers()) { | |
// text(finger.type() + ", id: " + finger.id() + ", length: " + finger.length() + "mm, width: " + finger.width() + "mm", 50, 270+finger.id()); | |
println(finger.type() + ", id: " + finger.id() + ", tip pos: " + finger.tipPosition()); | |
if(finger.type().toString() == "TYPE_INDEX") { // 人差し指だけ描画 | |
ellipse(finger.tipPosition().getX()+(width/2), (height*2/3)-finger.tipPosition().getY(), 10, 10); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
手のひらの位置情報をもとに,描画を試みているところ.