//2D Physics Library //by Michael Chang, UCLA //http://users.design.ucla.edu/~mflux //May 21, 2005 boolean WORLDBORDER=true; float WORLDBORDERBUFFER=0; float FRICTION=0.2; class mass { vec p; //spatial position vec v; //velocity vector vec a; //acceleration vector mass cm[]; float sl[]; float sk[]; float x() { return p.x; } float y() { return p.y; } mass() { p=new vec(); v=new vec(); a=new vec(); } mass(mass m) { this.p=new vec(m.p); this.v=new vec(m.v); this.a=new vec(m.a); if(cm==null) return; cm=new mass[m.cm.length]; for(int i=0;iwidth+buff) p.x=width+buff; if(p.x<-buff) p.x=-buff; if(p.y>height+buff) p.y=height+buff; if(p.y<-buff) p.y=-buff; } void fluidFlow(float k) { if(!useFF) return; if(!(p.x0&&p.y0)) return; vec fi=findFlowVec(p); // println(p.x+" "+p.y); fi.x=constrain(fi.x,0,flowX); fi.y=constrain(fi.y,0,flowY); // println(fi.x+" "+fi.y); // vec vf=new vec(flowField[0][0]); vec vf=new vec(flowField[int(fi.x)][int(fi.y)]); vf.mul(flowMultuiplier*k); v.add(vf); } void affectField(float k) { if(!useFF) return; if(!(p.x0&&p.y0)) return; vec fi=findFlowVec(p); // fi.x=constrain(fi.x,0,flowX); // fi.y=constrain(fi.y,0,flowY); if(fi.x>flowX||fi.x<0||fi.y>flowY||fi.y<0) return; vec vf=flowField[int(fi.x)][int(fi.y)]; vec sv=new vec(v); sv.mul(k); vf.add(sv); } void connectSpringTo(mass m,float springLength,float springConstant) { if(m==null) return; if(cm==null) cm=new mass[0]; mass temp[]=new mass[cm.length+1]; System.arraycopy(cm,0,temp,0,cm.length); temp[cm.length]=m; cm=temp; if(sl==null) this.sl=new float[0]; this.sl=append(sl,springLength); if(sk==null) this.sk=new float[0]; this.sk=append(sk,springConstant); } void connectSpringTo(mass m,float k) { float d=dist(this.p,m.p); connectSpringTo(m,d,k); } void updateSprings() { if(cm==null) return; for(int i=0;i