/
shapeForms.pde
126 lines (86 loc) · 3.05 KB
/
shapeForms.pde
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/*
** shapeForms
** Experiment with Leap Motion for Processing Beta
** https://github.com/voidplus/leap-motion-processing/tree/beta
** Beware, there are many libs with the same class LeapMotion
**
** ©2014 Joseph Gray
*/
import de.voidplus.leapmotion.*;
LeapMotion leap;
void setup() {
size(displayWidth, displayHeight, P3D);
background(0);
noStroke();
ellipseMode(CENTER);
rectMode(CENTER);
colorMode(HSB);
leap = new LeapMotion(this);
}
void draw() {
// ambientLight(0, 0, 0);
pushMatrix();
translate(width*.5, height*.5, 0);
rotateY(millis()*.00007);
pointLight( 196, 196, 255, 0, 0, 999);
fill(255, 77);
sphere(1000);
popMatrix();
// ...
int fps = leap.getFrameRate();
// ========= HANDS =========
for (Hand hand : leap.getHands ()) {
// ----- BASICS -----
int hand_id = hand.getId();
PVector hand_position = hand.getPosition();
PVector hand_stabilized = hand.getStabilizedPosition();
PVector hand_direction = hand.getDirection();
PVector hand_dynamics = hand.getDynamics();
float hand_roll = radians(hand.getRoll());
float hand_pitch = radians(hand.getPitch());
float hand_yaw = radians(hand.getYaw());
boolean hand_is_left = hand.isLeft();
boolean hand_is_right = hand.isRight();
float hand_grab = hand.getGrabStrength();
float hand_pinch = hand.getPinchStrength();
float hand_time = hand.getTimeVisible();
PVector sphere_position = hand.getSpherePosition();
float sphere_radius = hand.getSphereRadius();
// println("hand_roll: "+hand_roll);
// println("hand_pitch: "+hand_pitch);
// println("hand_yaw: "+hand_yaw);
pointLight( 255, 255, 255, hand_stabilized.x, hand_stabilized.y-200, hand_stabilized.z);
// ========= FINGERS =========
fill(196, 196, 196);
noStroke();
beginShape(QUAD_STRIP);
for (int i=1; i<5; i++) {
Finger finger_last = hand.getFinger(i-1);
Finger finger_current = hand.getFinger(i);
PVector pjoint = finger_last.getPositionOfJointTip();
PVector joint = finger_current.getPositionOfJointTip();
drawBoneWeb(pjoint, joint);
pjoint = finger_last.getPositionOfJointDip();
joint = finger_current.getPositionOfJointDip();
drawBoneWeb(pjoint, joint);
pjoint = finger_last.getPositionOfJointPip();
joint = finger_current.getPositionOfJointPip();
drawBoneWeb(pjoint, joint);
pjoint = finger_last.getPositionOfJointMcp();
joint = finger_current.getPositionOfJointMcp();
drawBoneWeb(pjoint, joint);
}
endShape();
}
}
void drawBoneWeb(PVector pjoint, PVector joint){
PVector norm;
norm = new PVector(pjoint.x, pjoint.y, pjoint.z);
norm.normalize();
normal(norm.x, norm.y, norm.z);
vertex(pjoint.x, pjoint.y, pjoint.z);
norm = new PVector(joint.x, joint.y, joint.z);
norm.normalize();
normal(norm.x, norm.y, norm.z);
vertex(joint.x, joint.y, joint.z);
}