int[][] edges = { { 6, 25, 3, 22 }, { 0, 40, 1, 39, 14, 33, 21 }, { 14, 5, 17 }, { 5, 18, 19, 8 }, { 18, 19, 7 }, { 33, 24, 36 }, { 24, 37, 38, 27 }, { 37, 38, 26 }, { 9, 28, 4, 23 }, { 9, 11, 15 }, { 11, 2, 13 }, { 2, 10, 16, 12 }, { 23, 30, 34 }, { 30, 20, 32 }, { 20, 29, 35, 31 } }; float[][] frames; float[] boxesX; float[] boxesY; float[] boxesZ; int currentFrame = 0; int numPoints = 0; int frameStep = 8; void setup() { size(400,400); String[] lines = loadStrings("EricCamper04.txt"); if (lines.length > 0) { String[] cols = splitStrings(lines[0],'\t'); numPoints = (cols.length - 2) / 3; frames = new float[lines.length][cols.length]; for (int i = 1; i < lines.length; i++) { // i = 1 will skip headers frames[i] = splitFloats(lines[i],'\t'); } } boxesX = new float[numPoints]; boxesY = new float[numPoints]; boxesZ = new float[numPoints]; for (int i = 0; i < numPoints; i++) { boxesX[i] = 0.0f; boxesY[i] = 0.0f; boxesZ[i] = 0.0f; } framerate(30); fill(255); noLights(); } void loop() { // fix weird overlay problems clearZbuffer(); // fade last frame // fill(200,200,200,16); // rect(0,0,width,height); background(200); push(); translate(width/2.0f, 1.5f*height, -800.0f); rotateX(HALF_PI); scale(0.4f); // "bones"... stroke(128,0,0,128); strokeWeight(1); for (int i = 0; i < edges.length; i++) { for (int j = 0; j < edges[i].length; j++) { for (int k = j + 1; k < edges[i].length; k++) { line(boxesX[edges[i][j]], boxesY[edges[i][j]], boxesZ[edges[i][j]], boxesX[edges[i][k]], boxesY[edges[i][k]], boxesZ[edges[i][k]] ); } } } // points... noStroke(); fill(255, 255, 255, 255); for (int i = 0; i < numPoints; i++) { push(); boxesX[i] += (frames[currentFrame][3*i+2] - boxesX[i]) / 5.0f; boxesY[i] += (frames[currentFrame][3*i+3] - boxesY[i]) / 5.0f; boxesZ[i] += (frames[currentFrame][3*i+4] - boxesZ[i]) / 5.0f; translate(boxesX[i],boxesY[i],boxesZ[i]); box(45.0f); pop(); } pop(); // position indicator stroke(0); fill(200); rect( 3, height - 22, width-6,9); fill(255); rect( 5 + (((width-15) * currentFrame) / frames.length), height - 20,5,5); // adavance frames if (!mousePressed) { currentFrame+=frameStep; if (currentFrame < 0 || currentFrame >= frames.length) { frameStep *= -1; // bounce back currentFrame+=frameStep; } } } void mouseClicked() { if (mouseX > 0 && mouseX < width) { currentFrame = int(floor(float(frames.length) * float(mouseX) / float(width))); } } void mouseDragged() { if (mouseX > 0 && mouseX < width) { currentFrame = int(floor(float(frames.length) * float(mouseX) / float(width))); } } void clearZbuffer() { int pc = g.pixelCount; float[] zb = g.zbuffer; for (int i = 0; i < pc; i++) { zb[i] = MAX_FLOAT; } }