-
Notifications
You must be signed in to change notification settings - Fork 0
/
c_Geometry.pde
134 lines (123 loc) · 5.63 KB
/
c_Geometry.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
127
128
129
130
131
132
133
PVector rightHand;
PVector rightElbow;
PVector rightShoulder;
PVector rightHip;
PVector rightHandVector = new PVector();
PVector rightElbowVector = new PVector();
PVector rightShoulderVector = new PVector();
PVector rightHipVector = new PVector();
PVector leftHand;
PVector leftElbow;
PVector leftShoulder;
PVector leftHip;
PVector leftHandVector = new PVector();
PVector leftElbowVector = new PVector();
PVector leftShoulderVector = new PVector();
PVector leftHipVector = new PVector();
PVector torsoOrientation;
PVector upperLeftArmOrientation;
PVector upperRightArmOrientation;
float angle;
float getAngle(String code) {
angle = 0;
if (code == "a") {
if (rightElbow != null && rightShoulder != null) {
angle = angleOf(rightElbow, rightShoulder, torsoOrientation);
}
} else if (code == "b") {
if (rightHand != null && rightElbow != null) {
return angleOf(rightHand, rightElbow, upperLeftArmOrientation);
}
} else if (code == "c") {
if (leftShoulder != null && leftElbow != null) {
return angleOf(leftShoulder, leftElbow, torsoOrientation);
}
} else if (code == "d") {
if (leftElbow != null && leftHand != null) {
return angleOf(leftElbow, leftHand, upperRightArmOrientation);
}
}
return angle;
}
void displayAngles() {
textSize(26);
}
void initializeVectors(int userId, SimpleOpenNI kinectObject ) {
kinectObject.getJointPositionSkeleton(userId, SimpleOpenNI.SKEL_RIGHT_HAND, rightHandVector);
rightHand = new PVector(rightHandVector.x, rightHandVector.y);
kinectObject.getJointPositionSkeleton(userId, SimpleOpenNI.SKEL_RIGHT_ELBOW, rightElbowVector);
rightElbow = new PVector(rightElbowVector.x, rightElbowVector.y);
kinectObject.getJointPositionSkeleton(userId, SimpleOpenNI.SKEL_RIGHT_SHOULDER, rightShoulderVector);
rightShoulder = new PVector(rightShoulderVector.x, rightShoulderVector.y);
kinectObject.getJointPositionSkeleton(userId, SimpleOpenNI.SKEL_RIGHT_HIP, rightHipVector);
rightHip = new PVector(rightHipVector.x, rightHipVector.y);
kinectObject.getJointPositionSkeleton(userId, SimpleOpenNI.SKEL_LEFT_HAND, leftHandVector);
leftHand = new PVector(leftHandVector.x, leftHandVector.y);
kinectObject.getJointPositionSkeleton(userId, SimpleOpenNI.SKEL_LEFT_ELBOW, leftElbowVector);
leftElbow = new PVector(leftElbowVector.x, leftElbowVector.y);
kinectObject.getJointPositionSkeleton(userId, SimpleOpenNI.SKEL_LEFT_SHOULDER, leftShoulderVector);
leftShoulder = new PVector(leftShoulderVector.x, leftShoulderVector.y);
kinectObject.getJointPositionSkeleton(userId, SimpleOpenNI.SKEL_LEFT_HIP, leftHipVector);
leftHip = new PVector(leftHipVector.x, leftHipVector.y);
if (rightShoulder != null && rightHip != null) {
torsoOrientation = PVector.sub(rightShoulder, rightHip);
}
if (rightElbow != null && rightShoulder != null) {
upperLeftArmOrientation = PVector.sub(rightElbow, rightShoulder);
}
if (leftElbow != null && leftShoulder != null) {
upperRightArmOrientation = PVector.sub(leftElbow, leftShoulder);
}
}
void drawSkeleton(int userId) {
scale(1.15*1280/640, 1.8);
stroke(0);
strokeWeight(5);
kinect.drawLimb(userId, SimpleOpenNI.SKEL_HEAD, SimpleOpenNI.SKEL_NECK);
kinect.drawLimb(userId, SimpleOpenNI.SKEL_NECK, SimpleOpenNI.SKEL_LEFT_SHOULDER);
kinect.drawLimb(userId, SimpleOpenNI.SKEL_LEFT_SHOULDER, SimpleOpenNI.SKEL_LEFT_ELBOW);
kinect.drawLimb(userId, SimpleOpenNI.SKEL_LEFT_ELBOW, SimpleOpenNI.SKEL_LEFT_HAND);
kinect.drawLimb(userId, SimpleOpenNI.SKEL_NECK, SimpleOpenNI.SKEL_RIGHT_SHOULDER);
kinect.drawLimb(userId, SimpleOpenNI.SKEL_RIGHT_SHOULDER, SimpleOpenNI.SKEL_RIGHT_ELBOW);
kinect.drawLimb(userId, SimpleOpenNI.SKEL_RIGHT_ELBOW, SimpleOpenNI.SKEL_RIGHT_HAND);
kinect.drawLimb(userId, SimpleOpenNI.SKEL_LEFT_SHOULDER, SimpleOpenNI.SKEL_TORSO);
kinect.drawLimb(userId, SimpleOpenNI.SKEL_RIGHT_SHOULDER, SimpleOpenNI.SKEL_TORSO);
kinect.drawLimb(userId, SimpleOpenNI.SKEL_TORSO, SimpleOpenNI.SKEL_LEFT_HIP);
kinect.drawLimb(userId, SimpleOpenNI.SKEL_LEFT_HIP, SimpleOpenNI.SKEL_LEFT_KNEE);
kinect.drawLimb(userId, SimpleOpenNI.SKEL_LEFT_KNEE, SimpleOpenNI.SKEL_LEFT_FOOT);
kinect.drawLimb(userId, SimpleOpenNI.SKEL_TORSO, SimpleOpenNI.SKEL_RIGHT_HIP);
kinect.drawLimb(userId, SimpleOpenNI.SKEL_RIGHT_HIP, SimpleOpenNI.SKEL_RIGHT_KNEE);
kinect.drawLimb(userId, SimpleOpenNI.SKEL_RIGHT_KNEE, SimpleOpenNI.SKEL_RIGHT_FOOT);
kinect.drawLimb(userId, SimpleOpenNI.SKEL_RIGHT_HIP, SimpleOpenNI.SKEL_LEFT_HIP);
noStroke();
fill(255, 0, 0);
drawJoint(userId, SimpleOpenNI.SKEL_HEAD);
drawJoint(userId, SimpleOpenNI.SKEL_NECK);
drawJoint(userId, SimpleOpenNI.SKEL_LEFT_SHOULDER);
drawJoint(userId, SimpleOpenNI.SKEL_LEFT_ELBOW);
drawJoint(userId, SimpleOpenNI.SKEL_NECK);
drawJoint(userId, SimpleOpenNI.SKEL_RIGHT_SHOULDER);
drawJoint(userId, SimpleOpenNI.SKEL_RIGHT_ELBOW);
drawJoint(userId, SimpleOpenNI.SKEL_TORSO);
drawJoint(userId, SimpleOpenNI.SKEL_LEFT_HIP);
drawJoint(userId, SimpleOpenNI.SKEL_LEFT_KNEE);
drawJoint(userId, SimpleOpenNI.SKEL_RIGHT_HIP);
drawJoint(userId, SimpleOpenNI.SKEL_LEFT_FOOT);
drawJoint(userId, SimpleOpenNI.SKEL_RIGHT_KNEE);
drawJoint(userId, SimpleOpenNI.SKEL_LEFT_HIP);
drawJoint(userId, SimpleOpenNI.SKEL_RIGHT_FOOT);
drawJoint(userId, SimpleOpenNI.SKEL_RIGHT_HAND);
drawJoint(userId, SimpleOpenNI.SKEL_LEFT_HAND);
scale(1);
}
void drawJoint(int userId, int jointID) {
PVector joint = new PVector();
float confidence = kinect.getJointPositionSkeleton(userId, jointID,
joint);
if (confidence < 0.5) {
return;
}
PVector convertedJoint = new PVector();
kinect.convertRealWorldToProjective(joint, convertedJoint);
ellipse(convertedJoint.x, convertedJoint.y, 5, 5);
}