It’s Just a Flesh Wound
The premise for this assignment was rather vague: tell a story with XML. Basically, we were supposed to design something that would take in camera input and return text output. While trying to figure out how to do this assignment, Heather Velez and I started talking about other projects we wanted to do for this class. Heather had an idea for a project that involved making changes to her limbs. I don’t remember the exact details, but somehow our conversation drifted into the removal of limbs, which naturally led to the Black Knight from “Monty Python and the Holy Grail”:
We designed a program that allows users to chop off the limbs of the Black Knight, and outputs a text file describing the movements of the sword and which limbs had been removed. We adapted Matt Richardson’s “Hand Tracking vs. Skeleton Tracking” assignment to dictate the motion of the sword. When the sword hits one of the limbs, it disappears in a bloody splash.
The entire text file is a bit long and redundant, but here’s a sample that illustrates what it does:
Sword at : (428.41858, 62.20041) Sword at : (426.7242, 54.39093) Sword at : (424.91882, 50.942383) Sword at : (422.85626, 47.382736) Sword at : (419.5735, 44.53174) Sword at : (414.76443, 45.7937) Sword at : (408.78973, 45.679276) Sword at : (403.00497, 47.999252) Sword at : (395.86615, 56.521454) Sword at : (391.11273, 68.21771) Sword at : (382.39648, 88.004944) Sword at : (374.6492, 113.11754) Sword at : (370.87872, 135.67337) Sword at : (369.41296, 157.94109) Sword at : (366.09396, 178.29153) Head is chopped off! It’s just a flesh wound!
Code:
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 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 | import ddf.minim.*; import ddf.minim.signals.*; import ddf.minim.analysis.*; import ddf.minim.effects.*; import SimpleOpenNI.*; SimpleOpenNI kinect; Minim minim; AudioPlayer flesh; AudioPlayer legs; PVector swordPos; PrintWriter output; boolean headOff = false; boolean LArmOff = false; boolean LLegOff = false; boolean RArmOff = false; boolean RLegOff = false; PImage sword; PImage bg; PImage bkBody, bkHead, bkLArm, bkLLeg, bkRArm, bkRLeg; void setup() { kinect = new SimpleOpenNI(this); kinect.enableDepth(); kinect.enableUser(SimpleOpenNI.SKEL_PROFILE_ALL); kinect.setMirror(false); kinect.enableRGB(); size(640, 480); smooth(); minim = new Minim(this); flesh = minim.loadFile("fleshwound.wav"); legs = minim.loadFile("legs.wav"); sword = loadImage("excalibur2.png"); bg = loadImage("forest2.jpg"); bkBody = loadImage("bkBody.png"); bkBody.resize(0, 400); bkHead = loadImage("bkHead.png"); bkHead.resize(0, 400); bkLArm = loadImage("bkLArm.png"); bkLArm.resize(0, 400); bkLLeg = loadImage("bkLLeg.png"); bkLLeg.resize(0, 400); bkRArm = loadImage("bkRArm.png"); bkRArm.resize(0, 400); bkRLeg = loadImage("bkRLeg.png"); bkRLeg.resize(0, 400); PVector swordPos = new PVector(); output = createWriter("blackknight.txt"); } void draw() { kinect.update(); image(kinect.rgbImage(), 0, 0); background(bg); image(bkBody, width/2 - 100, height/2 - 150); if (headOff == false) { head(); } if (LArmOff == false) { lArm(); } if (LLegOff == false) { lLeg(); } if (RArmOff == false) { rArm(); } if (RLegOff == false) { rLeg(); } IntVector userList = new IntVector(); kinect.getUsers(userList); if (userList.size() > 0) { int userId = userList.get(0); float rightArmAngle = getJointAngle(userId, SimpleOpenNI.SKEL_RIGHT_HAND, SimpleOpenNI.SKEL_RIGHT_ELBOW); PVector handPos = new PVector(); kinect.getJointPositionSkeleton(userId, SimpleOpenNI.SKEL_RIGHT_HAND, handPos); PVector convertedHandPos = new PVector(); kinect.convertRealWorldToProjective(handPos, convertedHandPos); swordPos = convertedHandPos; output.println("Sword at : (" + swordPos.x + ", " + swordPos.y +")"); float newImageWidth = map(convertedHandPos.z, 500, 2000, sword.width/4, sword.width/8); float newImageHeight = map(convertedHandPos.z, 500, 2000, sword.height/4, sword.height/8); //newImageWidth = constrain(newImageWidth, 75, 100); newImageWidth = constrain(newImageWidth, 150, 200); pushMatrix(); translate(convertedHandPos.x, convertedHandPos.y); println("x: " + convertedHandPos.x + " y: " + convertedHandPos.y); rotate(rightArmAngle*-1); rotate(PI/4); image(sword, -1 * (newImageWidth/2), 0 - (newImageHeight/2), newImageWidth, newImageHeight); popMatrix(); chop(bkHead, headOff, 316, 400, 171, 271); chop(bkLArm, LArmOff, 186, 400, 70, 300); chop(bkLLeg, LLegOff, 185, 411, 246, 450); chop(bkRArm, RArmOff, 284, 514, 80, 293); chop(bkRLeg, RLegOff, 460, 489, 246, 450); } } float getJointAngle(int userId, int jointID1, int jointID2) { PVector joint1 = new PVector(); PVector joint2 = new PVector(); kinect.getJointPositionSkeleton(userId, jointID1, joint1); kinect.getJointPositionSkeleton(userId, jointID2, joint2); return atan2(joint1.y-joint2.y, joint1.x-joint2.x); } // user-tracking callbacks: void onNewUser(int userId) { kinect.startPoseDetection("Psi", userId); println("Started pose detection."); } void onEndCalibration(int userId, boolean successful) { if (successful) { println("User calibrated."); kinect.startTrackingSkeleton(userId); } else { println("Failed to calibrate user."); kinect.startPoseDetection("Psi", userId); } } void onStartPose(String pose, int userId) { println("Started pose for user."); kinect.stopPoseDetection(userId); kinect.requestCalibrationSkeleton(userId, true); } void head() { chopOff(bkHead, headOff); } void rArm() { chopOff(bkRArm, RArmOff); } void rLeg() { chopOff(bkRLeg, RLegOff); } void lArm() { chopOff(bkLArm, LArmOff); } void lLeg() { chopOff(bkLLeg, LLegOff); } void chop(PImage img, boolean partOff, int x1, int x2, int y1, int y2) { String bodyPart = " "; if (swordPos.x > x1 && swordPos.x < x2 && swordPos.y > y1 && swordPos.y < y2) { if (x1 == 316 && x2 == 400 && y1 == 171 && y2 == 271) { bodyPart = "Head"; output.println(bodyPart + " is chopped off!"); output.println("It's just a flesh wound!"); headOff = true; // println(headOff); } else if (x1 == 186 && x2 == 400 && y1 == 70 && y2 == 300) { bodyPart = "Left arm"; output.println(bodyPart + " is chopped off!"); output.println("It's just a flesh wound!"); LArmOff = true; } else if (x1 == 185 && x2 == 411 && y1 == 276 && y2 == 450) { bodyPart = "Left leg"; output.println(bodyPart + " is chopped off!"); output.println("I'll bite your legs off!"); LLegOff = true; } else if (x1 == 284 && x2 == 514 && y1 == 80 && y2 == 293) { bodyPart = "Right arm"; output.println(bodyPart + " is chopped off!"); output.println("It's just a flesh wound!"); RArmOff = true; } else if (x1 == 460 && x2 == 489 && y1 == 246 && y2 == 450) { bodyPart = "Right leg"; output.println(bodyPart + " is chopped off!"); output.println("I'll bite your legs off!"); RLegOff = true; chopOff(img, partOff); // output.println(bodyPart + " is chopped off!"); //partOff = !partOff; // flesh.play(); // } else { // flesh.rewind(); // } } } } void chopOff(PImage img, boolean partOff) { if (partOff) { tint(255, 0); image (img, width/2 - 100, height/2 - 150); // int sound = int(random(2)); // if (sound == 1) { //flesh.play(); // output.println("It's just a flesh wound!"); } else { tint(255, 255); image (img, width/2 - 100, height/2 - 150); } } void keyPressed() { output.flush(); output.close(); exit(); } public void stop() { flesh.close(); legs.close(); minim.stop(); super.stop(); } |