import controlP5.*; //for closth simulation //for seaching 3D coordinnate from 2D coordinate PGraphics bf; float expo = 1; float rotx, roty; float rate = 0.01; float c1_x = 0; float c1_y = 0; float c1_z = 0; color c1, c2; PFrame f; secondApplet s; ParticleSystem physics; Particle[][] particles; Particle currentParticle; PVector currentParticle_2; Particle [][] triangles; Particle [][] quadrangles; int [] quads; int sizeOfCol = 25;//sizeOfCol = 30; int sizeOfRow = 25; float interval_col = 10.0; float interval_row = 10.0; float massOfParticle = 300/sizeOfCol*sizeOfRow; public int Cloth_x = sizeOfCol; public int Cloth_y = sizeOfRow; public float SPRING_STRENGTH = 100; public float SPRING_DAMPING = 0; boolean cloth = true; boolean startSim = true; public boolean hunger_display = true; boolean signOfHunger2 = false; boolean isFaces = true; int col = 0; int row = 0; int [][] displaySignOfParticles; public int hunger_x = 7; public int hunger_y = 10; int subWindow_x = int(sizeOfCol*interval_col*0.8); int subWindow_y = int(sizeOfRow*interval_row*0.8); ControlP5 controlP5; public int TRANSPARENCY = 255; int[] anchor = new int[50]; int anchornum = 0; int[] force = new int[50]; int forcenum = 0; int[] skelton = new int[500]; public boolean sub_display = false; void setup() { sizeOfCol = Cloth_x; sizeOfRow = Cloth_y; size(700, 700, P3D); // colorMode(HSB, 255); smooth(); //for cloth simulation bf = createGraphics(width, height, P3D); physics = new ParticleSystem(0.0, 0.0, 9.8, 30);//(gravity,drag) setInitialCloth(); // drawSubWindow(); setQuads(); // axis = new Axis(60,60,60); force[forcenum] = particles[sizeOfCol/2-1][sizeOfRow/2-1].id; forcenum = forcenum + 1; setController(); } void draw() { background(100); lights(); stroke(0); translate(width/2, height/1.6); rotateX(rotx); rotateY(roty); scale(expo); drawPointer(); drawPGraphics(); if (isFaces) drawFaces(); if (cloth) drawCloth(); if (startSim) physics.tick(1.5);//speed of simulation if (hunger_display) drawHunger(0); // if(signOfHunger2) drawHunger(200); // axis.display(); setQuads(); gui(); } void resize_cloth() { setSpring(); setup(); } void setSpring() { for (int i=0; i c2) { //pointer visualizer float c2_x = red(c1) * 3; float c2_y = green(c1) * 3; float c2_z = blue(c1) * 3; for (int i=0; i 0) physics.makeSpring(particles[i][j-1], particles[i][j], SPRING_STRENGTH, SPRING_DAMPING, interval_col);//rows id = id + 1; } } //settings of springs of particles for (int j = 0; j < sizeOfRow; j++) { for (int i = 0; i < sizeOfCol; i++) { if (i > 0) physics.makeSpring(particles[i - 1][j], particles[i][j], SPRING_STRENGTH, SPRING_DAMPING, interval_row);//colums if (i+1 < sizeOfCol && j+1 < sizeOfRow) physics.makeSpring(particles[i][j], particles[i+1][j+1], SPRING_STRENGTH, SPRING_DAMPING, interval_col*sqrt(2));//隴∵㈱�∬愾�ウ if (j > 0 && i+1 < sizeOfCol) physics.makeSpring(particles[i][j], particles[i+1][j-1], SPRING_STRENGTH, SPRING_DAMPING, interval_row*sqrt(2));//隴∵㈱�∬淦�ヲ } } //settings of fixed points particles[0][0].makeFixed(); anchor[anchornum] = particles[0][0].id; anchornum = anchornum + 1; particles[0][sizeOfRow - 1].makeFixed(); anchor[anchornum] = particles[0][sizeOfRow - 1].id; anchornum = anchornum + 1; particles[sizeOfCol - 1][0].makeFixed(); anchor[anchornum] = particles[sizeOfCol - 1][0].id; anchornum = anchornum + 1; particles[sizeOfCol - 1][sizeOfRow - 1].makeFixed(); anchor[anchornum] = particles[sizeOfCol - 1][sizeOfRow - 1].id; anchornum = anchornum + 1; currentParticle = particles[0][0]; currentParticle_2 = new PVector(0, 0, 0); } void drawPGraphics() { bf.beginDraw(); bf.background(255); bf.translate(width/2, height/1.6); bf.rotateX(rotx); bf.rotateY(roty); bf.scale(expo); for (int j = 0; j < sizeOfRow; j++) { for (int i = 0; i < sizeOfCol; i++) { bf.pushMatrix(); bf.translate(-sizeOfCol*interval_col/2, -sizeOfRow*interval_row/2, 0); bf.translate(particles[i][j].position().x(), particles[i][j].position().y(), particles[i][j].position().z()); bf.noStroke(); bf.fill(particles[i][j].position().x()/3, particles[i][j].position().y()/3, particles[i][j].position().z()/3); bf.ellipse(0, 0, 10, 10);//box size determine the eria of pointer bf.popMatrix(); } } } void drawPointer() { c1 = bf.get(mouseX, mouseY); c2 = color(0); if (c1 > c2) { //pointer visualizer c1_x = red(c1) * 3; c1_y = green(c1) * 3; c1_z = blue(c1) * 3; pushMatrix(); translate(-sizeOfCol*interval_col/2, -sizeOfRow*interval_row/2, 0); translate(c1_x, c1_y, c1_z); fill(c1_x, c1_y, c1_z); ellipse(0, 0, 10, 10); popMatrix(); } } void drawCloth() { // stroke(0); // fill(0,0,0,100); // float eSize = 0; // for(int i=0; i