CY_glass_simulation_1028

//code for Processing 1.48
import javax.media.opengl.*;
import javax.media.opengl.glu.*;
import com.sun.opengl.util.FPSAnimator;
import java.nio.*;

GLCanvas canvas;
GLCapabilities capabilities;

int myFrameCount = 0;
int lastMillis = 0;
int fps = 0;

int startedDrop = 0;

myTimer time;
boolean paused = false;
boolean leftPressed = false;
boolean rightPressed = false;
boolean altPressed = false;
boolean ctrlPressed = false;

int myMouseX;
int myMouseY;

boolean printScreen = false;
boolean screenPrinted = false;
int updateCount = 0;
int currentAgent = 0;

agentGroup[] myAgents;
gString myString;

float gravity = 10;
float maintain = 10;
float adherence = 5;
float inertia = 0.5;
float speed = 3*3;
int meshDensity = 6;
float solidifacation = 0.002*3;

boolean stopped = false;

float meshMin = 20;

boolean toggleShadeDisplay = true;
int toggleHistoryDisplay = 0;
boolean toggleSmoothShade = true;

float mouseXX;
float mouseYY;

float cameraRXX;
float cameraRZZ;
float cameraYY;

float cameraX;
float cameraY;
float cameraZ;

float cameraRX;
float cameraRY;
float cameraRZ;

float cameraTZ;
float cameraTX;
float cameraTZZ;
float cameraTXX;

boolean automated = false;

gDrop[] dropArray;
String myTrace = “”;
PFont font;
FPSAnimator animator;
void setup(){
capabilities = new GLCapabilities();
capabilities.setSampleBuffers(true);
capabilities.setNumSamples(8);

canvas = new GLCanvas(capabilities);
canvas.setSize(720, 480);
canvas.addGLEventListener(new GLRenderer());
canvas.addMouseMotionListener(new mouseMotion());
canvas.addMouseListener(new mouseClick());
canvas.addKeyListener(new keyPress());
animator = new FPSAnimator(canvas, 120);
animator.start();
add(canvas);

size(720, 500);

font = createFont(“Tahoma”, 12);
textFont(font);

cameraX = 0;
cameraY = 1800;
cameraZ = 400;
cameraRX = 0;
cameraRY = 0;
cameraRZ = 45;
cameraTZ = -150;
cameraTX = 0;

background(0);
time = new myTimer();

//set up string
myString = new gString(meshMin);
//set up the agents
float wid = 1200;
int agentNumber = 12;
/*float[][] p = new float[agentNumber/3][2];
float[] r = new float[agentNumber/3];
for(int i=0;i<(agentNumber/3);i++){
p[i][0] = random(-wid,wid);
p[i][1] = random(-wid,wid);
r[i] = random(360);
}*/
agent[] a = new agent[agentNumber];
/*for(int i=0;i<agentNumber;i++){
//a[i] = new agent(createArray3(p[i/3][0]+150*sin(radians(r[i/3]+120*i)),p[i/3][1]+150*cos(radians(r[i/3]+120*i)),15.0), 30, createArray3(0.0,0.0,1.0));
a[i] = new agent(createArray3(random(-wid,wid),random(-wid,wid),15.0), 30, createArray3(0.0,0.0,1.0));
}*/
for(int i=0;i<agentNumber;i++){
a[i] = new agent(createArray3(800*sin(radians((360/agentNumber)*i))+random(400)-200,800*cos(radians((360/agentNumber)*i))+random(400)-200,15.0), 30, createArray3(0.0,0.0,1.0));
}

myAgents = new agentGroup[agentNumber];
for(int i=0;i<agentNumber;i++){
myAgents[i] = new agentGroup(a[i], i);
}

/*
for(int i=0;i<myAgents.length;i++){
myAgents[i].phase = 1;
myAgents[i].chase = new int[1];
myAgents[i].avoid = new int[1];
myAgents[i].chase[0] = floor(i/3)*3+((i+2)%3);
myAgents[i].avoid[0] = floor(i/3)*3+((i+1)%3);
myAgents[i].tailon = floor(i/3)*3+((i+2)%3);
}*/
}

void draw(){
time.update();
//update——————————
updateCount = 0;
if(dropArray != null){
for(int i=0; i<dropArray.length; i++){
if(dropArray[i].updating){
dropArray[i].update();
updateCount ++;
}
}
}

fill(255);
noStroke();
rect(0,height-20,width,20);
stroke(0);
line(5,height-18,width-5,height-18);
if(dropArray !=null){
myTrace = “FPS: “+float(fps)/10+ ” FPS: “+round(frameRate)+” / “+dropArray.length+” drops, “+updateCount+” updating”+” “+month()+”/”+day()+” “+hour()+”:”+minute()+”:”+second();
}
else{
myTrace = “FPS: “+float(fps)/10+ ” FPS: “+round(frameRate)+” / “+updateCount+” updating”+” “+month()+”/”+day()+” “+hour()+”:”+minute()+”:”+second();
}
if(paused){
myTrace +=” PAUSED!”;
}
fill(0);
text(myTrace, 5, height-5);
if(screenPrinted){
screenPrinted = false;
saveFrame(month()+”_”+day()+”_”+hour()+”_”+minute()+”_”+second()+”.png”);
println(“Screenshot saved”);
}
}

class GLRenderer implements GLEventListener {
GL gl;
GLU glu;

public void init(GLAutoDrawable drawable) {
this.gl = drawable.getGL();
this.glu = new GLU();
gl.glClearColor(1, 1, 1, 0);
canvas.setLocation(0, 0);
gl.glEnable(GL.GL_CULL_FACE);
gl.glEnable(GL.GL_BLEND);
gl.glEnable(GL.GL_DEPTH_TEST);
gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
gl.glShadeModel(GL.GL_SMOOTH);
gl.glEnable(GL.GL_COLOR_MATERIAL);

float[] light_ambient ={
0.0, 0.0, 0.0, 1.0 };
float[] light_diffuse = {
1.0, 1.0, 1.0, 1 };
float[] light_specular = {
1.0, 1.0, 1.0, 1.0 };
float[] light_position = {
10.0, 10.0, 10.0, 0 };

gl.glLightfv(GL.GL_LIGHT0, GL.GL_AMBIENT, light_ambient, 0);
gl.glLightfv(GL.GL_LIGHT0, GL.GL_DIFFUSE, light_diffuse, 0);
gl.glLightfv(GL.GL_LIGHT0, GL.GL_SPECULAR, light_specular, 0);
gl.glLightfv(GL.GL_LIGHT0, GL.GL_POSITION, light_position, 0);

gl.glEnable(GL.GL_LIGHT0);

float[] light_ambient1 ={
0.0, 0.0, 0.0, 1.0 };
float[] light_diffuse1 = {
0.3, 0.3, 0.3, 1.0 };
float[] light_specular1 = {
1.0, 1.0, 1.0, 1.0 };
float[] light_position1 = {
-10.0, -10.0, -10.0, 0 };

gl.glLightfv(GL.GL_LIGHT1, GL.GL_AMBIENT, light_ambient1, 0);
gl.glLightfv(GL.GL_LIGHT1, GL.GL_DIFFUSE, light_diffuse1, 0);
gl.glLightfv(GL.GL_LIGHT1, GL.GL_SPECULAR, light_specular1, 0);
gl.glLightfv(GL.GL_LIGHT1, GL.GL_POSITION, light_position1, 0);

gl.glEnable(GL.GL_LIGHT1);

gl.glEnable(GL.GL_LIGHTING);
gl.glHint(GL.GL_PERSPECTIVE_CORRECTION_HINT, GL.GL_NICEST);
}
//————-rendering loop here———————-
//——————————————————
public void display(GLAutoDrawable drawable) {
//FPS
if(myFrameCount <119){
myFrameCount++;
}
else if(myFrameCount == 119){
int timeUsed = millis() – lastMillis;
fps = round(1200000/timeUsed);
lastMillis = millis();
myFrameCount = 0;
}
//
gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT );
gl.glMatrixMode(GL.GL_PROJECTION); // Select The Projection Matrix
gl.glLoadIdentity();
glu.gluPerspective(45,1.5,0.1,10000.0);
glu.gluLookAt(cameraX, cameraY, cameraZ,0,0,0,0,-1,0 );
gl.glMatrixMode(GL.GL_MODELVIEW);
gl.glLoadIdentity();

//————————-
gl.glPushMatrix();
gl.glRotatef(cameraRX,1,0,0);
gl.glRotatef(cameraRY,0,1,0);
gl.glRotatef(cameraRZ,0,0,1);

gl.glTranslatef(cameraTX, 0, cameraTZ);
/*gl.glDisable(GL.GL_LIGHTING);
gl.glColor3f(0.5,0.5,0.5);
int w = 1000;
gl.glBegin(GL.GL_QUADS);
gl.glNormal3f(0,0,1);
gl.glVertex3f(-w,-w,0);
gl.glVertex3f(w,-w,0);
gl.glVertex3f(w,w,0);
gl.glVertex3f(-w,w,0);
gl.glEnd();*/
//
gl.glEnable(GL.GL_LIGHTING);
if(dropArray != null){
for(int i=0; i<startedDrop; i++){
if(toggleShadeDisplay){
dropArray[i].plot(gl);
}
}
}
//draw history
if(toggleHistoryDisplay == 1){
myString.plot(gl);
}
else if(toggleHistoryDisplay == 2){
for(int i=0;i<myAgents.length;i++){
myAgents[i].plotHistory(gl);
}
}

gl.glPopMatrix();

if(printScreen){
FloatBuffer fb=ByteBuffer.allocateDirect(width*(height-20)*12).order(ByteOrder.nativeOrder()).asFloatBuffer();
loadPixels();
gl.glReadPixels( 0,0,width,height-20,GL.GL_RGB,GL.GL_FLOAT,fb);
for(int i=0;i<height-20;i++){
for(int j=0;j2){
toggleHistoryDisplay = 0;
}
}
else if(e.getKeyCode()==80){//p
paused = !paused;
}
else if(e.getKeyCode() == 77){//m
mayaExport();
mayaExportDrop();
mayaExportString();
mayaExportHistory();
}
else if(e.getKeyCode() == 78){//n
printScreen = true;
}
else if(e.getKeyCode() == 18){//alt
if(!altPressed){
altPressed = true;
}
}
else if(e.getKeyCode() == 17){//ctrl
if(!ctrlPressed){
ctrlPressed = true;
}
}
}
public void keyReleased(KeyEvent e){
//println(e.getKeyCode());
if(e.getKeyCode() == 18){//alt
altPressed = false;
}
else if(e.getKeyCode() == 17){//ctrl
ctrlPressed = false;
}
}
public void keyTyped(KeyEvent e){
if(e.getKeyCode() == 90){//y
print(“y”);
}
}
}

class mouseClick implements MouseListener{
public void mouseClicked(MouseEvent e){
}
public void mouseEntered(MouseEvent e){
}
public void mouseExited(MouseEvent e){
}
public void mousePressed(MouseEvent e){
//println(e.getButton());
mouseXX = myMouseX;
mouseYY = myMouseY;
cameraRXX = cameraRX;
cameraRZZ = cameraRZ;
cameraTXX = cameraTX;
cameraTZZ = cameraTZ;
cameraYY = cameraY;
if(e.getButton()==1){
if(!leftPressed){
leftPressed = true;
}
}
if(e.getButton()==3){
if(!rightPressed){
rightPressed = true;
}
}
}
public void mouseReleased(MouseEvent e){
if(e.getButton()==1){
leftPressed = false;
}
if(e.getButton()==3){
rightPressed = false;
}
}
}

class mouseMotion implements MouseMotionListener{
public void mouseMoved(MouseEvent e){
myMouseX = e.getX();
myMouseY = e.getY();
}
public void mouseDragged(MouseEvent e){
myMouseX = e.getX();
myMouseY = e.getY();
if(leftPressed){
if(altPressed){
//println(“mouse”);
cameraRZ = cameraRZZ + (myMouseX – mouseXX)/2;
cameraRX = cameraRXX – (myMouseY – mouseYY)/2;
}
else if(ctrlPressed){
cameraTZ = cameraTZZ – (myMouseY – mouseYY)/2;
//cameraTX = cameraTXX + (myMouseX – mouseXX)/2;
}
}
else if(rightPressed){
cameraY = cameraYY – (myMouseY – mouseYY)*5;
}
}
}

class agent{
float[] pos = new float[3];
float radius;
float[] direction = new float[3];
float[][] history;

agent(float[] p, float r, float[] d){
pos = p;
radius = r;
direction = d;
}
void update(int id){
//adjust the radius randomly
float lastRadius = radius+1;
lastRadius–;
radius = random(25,50);

float[] tempV = new float[3];
tempV = unifyVector(direction);
for(int i = 0; i<3; i++){
pos[i] += tempV[i]*(radius+lastRadius)*0.7;
}
if(pos[2]<radius/2){
pos[2] = radius/2;
}

//check on collision
boolean collision = true;
int detectTime = 0;
while(collision && detectTime 9){
println(“can’t avoid collision”);
}
}
}

boolean checkCollision(){
boolean out = false;
if(dropArray != null){
for(int i=0;i<dropArray.length;i++){
for(int j=0;j<dropArray[i].rings.length;j++){
float d = getDistance(dropArray[i].rings[j].pos, pos);
if(d< (dropArray[i].rings[j].radius+radius)*0.6){
//println(“collision!”);
d = (dropArray[i].rings[j].radius+radius)*0.8-d;
out = true;
float[] tV = new float[3];
for(int k = 0;k<3;k++){
tV[k] = pos[k] – dropArray[i].rings[j].pos[k];
}
if(tV[2] ==0){
tV[2] = 1;
}
else if(tV[2]<0){
tV[2] = -tV[2];
}
tV = unifyVector(tV);
for(int k = 0;k<3;k++){
pos[k] += tV[k]*d;
}
}
}
}
}
return out;
}
}

class agentGroup{
int ID;
int phase = 0;
int[] chase;
int[] avoid;
int tailon;
agent[] agents = new agent[2];
float[] oDirection = new float[3];
float[][] history;
int lastEmergedID;

agentGroup(agent a1, int id){
agents[0] = a1;
float[] t1 = {
0,0,0 };
float[] t2 = {
0,0,0 };
agents[1] = new agent(t1, 20, t2);
ID = id;
lastEmergedID = id;
//parent = p;
for(int i=0;i<3;i++){
oDirection[i] = agents[0].direction[i];
}
}

void update(){
float[] tD = new float[3];
for(int i=0;i<3;i++){
agents[0].direction[i] = random(-agents[0].pos[2]/200,agents[0].pos[2]/200);
tD[i] = random(-1,1);
}
//agents[0].direction[2] +=0.5;
//move toward the center
/*float[] tC = new float[3];
for(int i=0;i<2;i++){
tC[i] = agents[0].pos[i];
}
tC[2] = 0;
tC = unifyVector(tC);
agents[0].direction[0] -=tC[0]*(agents[0].pos[2])/1000;
agents[0].direction[1] -=tC[1]*(agents[0].pos[2])/1000;*/
//
//move toward the closest but not the last one
float[] tClose = new float[3];
float range = 2000;
for(int i=0;i<myAgents.length;i++){
if(i != ID){
if(i != lastEmergedID){
float dis = getDistance(agents[0].pos, myAgents[i].agents[0].pos);
if(dis<50){
lastEmergedID = i;
}
else if(dis myAgents.length-1){
next = 0;
}

tNext = getVector(agents[0].pos, myAgents[next].agents[0].pos);
tNext = unifyVector(tNext);

agents[0].direction = addVector(agents[0].direction, tNext);
//agents[0].direction = addVector(agents[0].direction, tClose);
agents[0].direction = addVector(agents[0].direction, tRandom);
agents[0].direction = addVector(agents[0].direction, aRandom);
/*if(agents[0].pos[2]<1000){
agents[0].direction[2] +=1;
agents[0].direction[2] +=2*(1000-agents[0].pos[2])/1000;
}
else{
agents[0].direction[2] +=0.5;
}*/
agents[0].direction = unifyVector(agents[0].direction);
agents[0].update(ID);
//if the tail has no direction
if(agents[1].direction[0]==0&&agents[1].direction[1]==0&&agents[1].direction[2]==0){
tD = unifyVector(tD);
agents[1].direction = tD;
}
else{
tD = rotateZZ(agents[1].direction[0],agents[1].direction[1],agents[1].direction[2],radians(random(-60,60)));
tD = unifyVector(tD);
agents[1].direction = tD;
}
for(int i=0;i<2;i++){
agents[1].pos[i] = agents[0].pos[i]-tD[i]*random(40,480);
}
agents[1].pos[2] = agents[0].pos[2]+random(40,480);
//addString
myString.update(agents[0].pos[0],agents[0].pos[1],agents[0].pos[2],
agents[1].pos[0],agents[1].pos[1],agents[1].pos[2],agents[0].radius,random(3.5,4));
myString.createDrop();
//float sX, float sY, float sZ, float eX, float eY, float eZ, float rr, float rDecrease
addHistory(createArray3(agents[0].pos[0],agents[0].pos[1],agents[0].pos[2]));
}

void addHistory(float[] h){
if(history != null){
float[][] tempH = new float[history.length+1][3];
arraycopy(history, tempH);
tempH[history.length] = h;
history = tempH;
}
else{
history = new float[1][3];
history[0] = h;
}
}
void plotHistory(GL _gl){
if(history != null){
_gl.glDisable(GL.GL_LIGHTING);
_gl.glColor3f(0,0.5,0.5);
_gl.glBegin(GL.GL_LINE_STRIP);
for(int i=0;i<history.length;i++){
_gl.glVertex3f(history[i][0],history[i][1],history[i][2]);
// println(history[i][0]);
}
_gl.glEnd();
_gl.glEnable(GL.GL_LIGHTING);
}
}
}

//—————————————————
//GLASSDROP CLASS DROP/RING/PARTICLE
class gDrop{
//float[] pos = new float[3];
int ID;
gRing[] rings;
gRing capStart;
gParticle[] cap = new gParticle[2];
float[] direction = new float[3];
boolean updating = true;
boolean ended = false;
float range;

gDrop(int id, float x1, float y1, float z1, float x2, float y2, float z2, float r){
ID = id;
direction[0] = x2-x1;
direction[1] = y2-y1;
direction[2] = z2-z1;
int[] tempid = {
id, 0 };
int[] tempid2 = {
id, -1 };
rings = new gRing[1];
//unify direction
float[] dir = {
x2,y2,z2 };
dir = unifyVector(dir);
rings[0] = new gRing(tempid, x1, y1, z1, dir[0], dir[1], dir[2], r);
capStart = new gRing(tempid2, x1 – dir[0]*(r/2), y1- dir[1]*(r/2), z1- dir[2]*(r/2), x2, y2, z2, r/2);
cap[0] = new gParticle(tempid, 0,0,0);
cap[1] = new gParticle(tempid, 0,0,0);
range = r;
}

void addRing(float x1, float y1, float z1, float x2, float y2, float z2, float r){
int[] tempid = {
ID, rings.length };
gRing tempRing = new gRing(tempid, x1, y1, z1, x2, y2, z2, r);
gRing[] tempArray = new gRing[rings.length+1];
arraycopy(rings, tempArray);
tempArray[rings.length] = tempRing;
rings = tempArray;
range = getDistance(rings[rings.length-1].pos, rings[0].pos);
}

void deleteRing(){
gRing[] tempArray = new gRing[rings.length-1];
arraycopy(rings,0, tempArray,0,rings.length-1);
rings = tempArray;
}
void update(){
int solid = 0;
for(int i = 0; i0){
if(rings[i].liquefaction !=0){
rings[i].update(true);
}
else{
rings[i].update(false);
solid++;
}
}
else{
rings[i].update(false);
solid++;
}
}
if(ended){
if(solid == rings.length){
updating = false;
}
}
if(capStart !=null){
capStart.update(false);
cap[0].pos = capStart.pos;
cap[1].pos = rings[rings.length-1].pos;
}
updateFaceNormal();
for(int i=0;i<rings.length;i++){
for(int j=0;j<rings[i].particles.length;j++){
rings[i].particles[j].updateNormal();
}
}
for(int j=0;j<capStart.particles.length;j++){
capStart.particles[j].updateNormal();
}
cap[0].updateNormal();
cap[1].updateNormal();
}
void getQuadNormal(int r1, int r2, int p1, int p2){
float[] v1 = new float[3];
float[] v2 = new float[3];
for(int i=0;i<3;i++){
v1[i] = rings[r1].particles[p1].pos[i]-rings[r1].particles[p2].pos[i];
v2[i] = rings[r2].particles[p1].pos[i]-rings[r1].particles[p1].pos[i];
}
float[] nor = crossProduct(v1, v2);
nor = unifyVector(nor);
rings[r1].particles[p1].addFaceNormal(nor);
rings[r1].particles[p2].addFaceNormal(nor);
rings[r2].particles[p1].addFaceNormal(nor);
rings[r2].particles[p2].addFaceNormal(nor);
}
void getQuadNormal(int r1, int p1, int p2){
float[] v1 = new float[3];
float[] v2 = new float[3];
for(int i=0;i<3;i++){
v1[i] = capStart.particles[p1].pos[i]-capStart.particles[p2].pos[i];
v2[i] = rings[r1].particles[p1].pos[i]-capStart.particles[p1].pos[i];
}
float[] nor = crossProduct(v1, v2);
nor = unifyVector(nor);
rings[r1].particles[p1].addFaceNormal(nor);
rings[r1].particles[p2].addFaceNormal(nor);
capStart.particles[p1].addFaceNormal(nor);
capStart.particles[p2].addFaceNormal(nor);
}
void getTriNormal(int r1, int p1,int p2){
float[] v1 = new float[3];
float[] v2 = new float[3];
for(int i=0;i<3;i++){
v1[i] = rings[r1].particles[p1].pos[i]-rings[r1].particles[p2].pos[i];
v2[i] = cap[1].pos[i]-rings[r1].particles[p1].pos[i];
}
float[] nor = crossProduct(v1, v2);
nor = unifyVector(nor);
rings[r1].particles[p1].addFaceNormal(nor);
rings[r1].particles[p2].addFaceNormal(nor);
cap[1].addFaceNormal(nor);
}
void getTriNormal(int p1,int p2){
float[] v1 = new float[3];
float[] v2 = new float[3];
for(int i=0;i<3;i++){
v2[i] = capStart.particles[p1].pos[i]-cap[0].pos[i];
v1[i] = cap[0].pos[i]-capStart.particles[p2].pos[i];
}
float[] nor = crossProduct(v1, v2);
nor = unifyVector(nor);
capStart.particles[p1].addFaceNormal(nor);
capStart.particles[p2].addFaceNormal(nor);
cap[0].addFaceNormal(nor);
}

void updateFaceNormal(){
for(int i = 0; i<rings.length; i++){
if(i<rings.length-1){
for(int j = 0; jmeshDensity-1){
t=0;
}
getQuadNormal(i, i+1, t, j);
}
}
}
for(int j = 0; jmeshDensity-1){
t=0;
}
getQuadNormal(0, t, j);
getTriNormal(rings.length-1, t,j);
getTriNormal(t,j);
}
}

void plotRings(GL _gl){
if(rings != null){
for(int i = 0; i<rings.length; i++){
//if(rings[i].myAxis[2][0]==0 ){
_gl.glBegin(GL.GL_LINES);
_gl.glColor3f(0,0,1);
_gl.glVertex3f(rings[i].pos[0], rings[i].pos[1],rings[i].pos[2]);
_gl.glVertex3f(rings[i].pos[0]+rings[i].myAxis[2][0]*rings[i].radius, rings[i].pos[1]+rings[i].myAxis[2][1]*rings[i].radius,rings[i].pos[2]+rings[i].myAxis[2][2]*rings[i].radius);
_gl.glEnd();
_gl.glBegin(GL.GL_LINES);
_gl.glColor3f(1,0,0);
_gl.glVertex3f(rings[i].pos[0], rings[i].pos[1],rings[i].pos[2]);
_gl.glVertex3f(rings[i].pos[0]+rings[i].myAxis[0][0]*rings[i].radius, rings[i].pos[1]+rings[i].myAxis[0][1]*rings[i].radius,rings[i].pos[2]+rings[i].myAxis[0][2]*rings[i].radius);
_gl.glEnd();
_gl.glBegin(GL.GL_LINES);
_gl.glColor3f(0,1,0);
_gl.glVertex3f(rings[i].pos[0], rings[i].pos[1],rings[i].pos[2]);
_gl.glVertex3f(rings[i].pos[0]+rings[i].myAxis[1][0]*rings[i].radius, rings[i].pos[1]+rings[i].myAxis[1][1]*rings[i].radius,rings[i].pos[2]+rings[i].myAxis[1][2]*rings[i].radius);
_gl.glEnd();
// }
}
}
}

void plot(GL _gl){
//plotRings(_gl);
_gl.glColor3f(1,1,1);
if(rings != null){
for(int i = 0; i<rings.length; i++){
if(i<rings.length-1){
for(int j = 0; jmeshDensity-1){
t=0;
}
if(!toggleSmoothShade){
drawQuad2(_gl, rings[i].particles[t].pos,rings[i+1].particles[t].pos, rings[i+1].particles[j].pos,rings[i].particles[j].pos );
}
else{
drawQuad(_gl, rings[i].particles[t].pos,rings[i+1].particles[t].pos, rings[i+1].particles[j].pos,rings[i].particles[j].pos,
rings[i].particles[t].myNormal, rings[i+1].particles[t].myNormal, rings[i+1].particles[j].myNormal, rings[i].particles[j].myNormal );
}
}
}
}

//draw the starting and ending cap
for(int j = 0; jmeshDensity-1){
t=0;
}
if(!toggleSmoothShade){
drawQuad2(_gl, capStart.particles[t].pos, rings[0].particles[t].pos,rings[0].particles[j].pos,capStart.particles[j].pos );
drawTri2(_gl,capStart.pos, capStart.particles[t].pos,capStart.particles[j].pos );
drawTri2(_gl, rings[rings.length-1].particles[j].pos, rings[rings.length-1].particles[t].pos, rings[rings.length-1].pos);
}
else{
drawQuad(_gl, capStart.particles[t].pos, rings[0].particles[t].pos,rings[0].particles[j].pos,capStart.particles[j].pos,
capStart.particles[t].myNormal, rings[0].particles[t].myNormal , rings[0].particles[j].myNormal,capStart.particles[j].myNormal );
drawTri(_gl,capStart.pos, capStart.particles[t].pos,capStart.particles[j].pos,
cap[0].myNormal, capStart.particles[t].myNormal, capStart.particles[j].myNormal);
drawTri(_gl,rings[rings.length-1].particles[j].pos, rings[rings.length-1].particles[t].pos, rings[rings.length-1].pos,
rings[rings.length-1].particles[j].myNormal, rings[rings.length-1].particles[t].myNormal, cap[1].myNormal);
}
}
}
}
}

class gRing{
int[] ID;
float[] pos = new float[3];
float[] direction = new float[3];
float[] motion = new float[3];
float radius;
float liquefaction = 1;
float[][] myAxis = new float[3][3];
gParticle[] particles = new gParticle[meshDensity];

gRing(int[] id, float x1, float y1, float z1, float x2, float y2, float z2, float r){
ID = id;
pos[0] = x1;
pos[1] = y1;
pos[2] = z1;
direction[0] = x2;
direction[1] = y2;
direction[2] = z2;
motion[0] =0;
motion[1] =0;
motion[2] =0;
radius = r;

for(int i =0; i<meshDensity; i++){
int[] tempID = new int[3];
tempID[0] = id[0];
tempID[1] = id[1];
tempID[2] = i;
particles[i] = new gParticle(tempID, 0, 0, 0);
}
//updateParticles();
}

void updateParticles(){
//uniify the direction
myAxis[2] = unifyVector(direction);
float[] t = {
0,0,1 };
float angle = getVectorAngle(myAxis[2],t);
//println(angle);
if(angle-1){
//use the drop direction as axis
float[] tempDirection = unifyVector(dropArray[ID[0]].direction);
//float[] tempDirection = unifyVector(t);
// println(“x direction: “+tempDirection[0]);
myAxis[0] = unifyVector(crossProduct(myAxis[2], tempDirection));
myAxis[1] = unifyVector(crossProduct(myAxis[2], myAxis[0]));
}
else{
myAxis[0] = unifyVector(crossProduct(myAxis[2], t));
myAxis[1] = unifyVector(crossProduct(myAxis[2], myAxis[0]));
}
for(int i =0; i<meshDensity; i++){
float[] temp2 = new float[3];
for(int j=0; j0){
if(move){
//movement
float[] tempD = new float[3];
//add the garvity
//
tempD[2] -= gravity;
//move toward the center of next and last rings
if(ID[1] >0 && ID[1] <dropArray[ID[0]].rings.length-1){
float[] goal = new float[3];
float d1 = dropArray[ID[0]].rings[ID[1]-1].radius+radius;
float d2 = dropArray[ID[0]].rings[ID[1]+1].radius+radius;
if(d1<meshMin){
d1 = meshMin;
}
if(d2<meshMin){
d2 = meshMin;
}
float d3 = getDistance(pos, dropArray[ID[0]].rings[ID[1]-1].pos);
float d4 = getDistance(pos, dropArray[ID[0]].rings[ID[1]+1].pos);
float d5 = d3 + d4 – d1 – d2;
for(int i=0;i<3;i++){
goal[i] = dropArray[ID[0]].rings[ID[1]+1].pos[i]-dropArray[ID[0]].rings[ID[1]-1].pos[i];
// goal[i] *= getDistance(dropArray[ID[0]].rings[ID[1]-1].pos,dropArray[ID[0]].rings[ID[1]+1].pos)*(d1)/(d1+d2);
goal[i] *= (d1)/(d1+d2);
goal[i] += dropArray[ID[0]].rings[ID[1]-1].pos[i];
}
float[] tempDDD = getMaintainForce(0, pos, goal, maintain/3);
for(int i =0;i0){
float distanceT = dropArray[ID[0]].rings[ID[1]-1].radius+radius;
if(distanceT<meshMin){
distanceT = meshMin;
}
float[] tempDD = getMaintainForce(distanceT, pos, dropArray[ID[0]].rings[ID[1]-1].pos, maintain);
for(int i=0; i<3;i++){
tempD[i] += tempDD[i];
}
}
//the force with nextRing
/*if(ID[1] <dropArray[ID[0]].rings.length-1){
float distanceT2 = dropArray[ID[0]].rings[ID[1]+1].radius+radius;
if(distanceT2<meshMin){
distanceT2 = meshMin;
}
float[] tempDDDD = getMaintainForce(distanceT2, pos, dropArray[ID[0]].rings[ID[1]+1].pos, maintain);
for(int i=0; i<3;i++){
tempD[i] += tempDDDD[i];
}
}*/
//adhere to solid surface
//check the distance between all existing rings
for(int i=0; i<dropArray.length;i++){
if(i != ID[0]){//check if its self
//check the distance with the first ring
float dis = getDistance(pos, dropArray[i].rings[0].pos);
if(dis < radius + dropArray[i].range){
for(int j=0;j<dropArray[i].rings.length;j++){
float d = getDistance(pos, dropArray[i].rings[j].pos);
if(d < (radius + dropArray[i].rings[j].radius)*0.8){
liquefaction = 0;
}
}
}
}
}

//unify the vector
tempD = unifyVector(tempD);
//move the vector
for(int i=0;i<3;i++){
pos[i] += tempD[i]*liquefaction*speed;
}
if(pos[2] 0){//if its not the first ring
for(int i=0;i<3;i++){
dArray[i] = pos[i] – dropArray[ID[0]].rings[ID[1]-1].pos[i];
}
dArray = unifyVector(dArray);
//direction = dArray;
for(int i=0;i<3;i++){
tempD[i] += dArray[i];
}
ringNum++;
}
if(ID[1] -1){//get the direction to next ring
//if(ID[1] ==0){//get the direction to next ring
//if(dropArray[ID[0]].rings.length > ID[1]+1){

for(int i=0;i<3;i++){
dArray2[i] = dropArray[ID[0]].rings[ID[1]+1].pos[i] – pos[i];
}
dArray2 = unifyVector(dArray2);
//direction = dArray;
for(int i=0;i150){
println(“angle: “+angle);
}
}*/
if(ID[1] == -1){//if its the capstart ring
//get the new position, direction, r
dArray = unifyVector(dropArray[ID[0]].rings[0].direction);
float r = dropArray[ID[0]].rings[0].radius/2;
for(int i=0;i<3;i++){
pos[i] = dropArray[ID[0]].rings[0].pos[i] – dArray[i]*r;
}
radius = r;
dArray = unifyVector(dArray);
//direction = dArray;
for(int i=0;i0){
direction = unifyVector(tempD);
}
//update the particles position
updateParticles();
}

float[] getMaintainForce(float originDist, float[] sp, float[] p, float m){
float distance = getDistance(sp, p);
//distance -= originDist;
float[] out = new float[3];
for(int i =0;i<3;i++){
out[i] = p[i] – sp[i];
}
out = unifyVector(out);
for(int i =0;i<3;i++){
out[i] = out[i]*(distance-originDist)*m;
}
return out;
}
}

class gParticle{
int[] ID;
float[] pos = new float[3];
//vertexNormal
float[] myNormal = new float[3];
float[][] faceNormal;
boolean updated = false;
int count = 0;

gParticle(int[] id, float x, float y, float z){
ID = id;
pos[0] = x;
pos[1] = y;
pos[2] = z;
}
void addFaceNormal(float[] fn){
if(!updated){//refresh the whole array
faceNormal = new float[1][3];
faceNormal[0] = fn;
updated = true;
}
else{//add the face normal to the array
float[][] tempN = new float[faceNormal.length+1][3];
arraycopy(faceNormal, tempN);
tempN[faceNormal.length] = fn;
faceNormal = tempN;
}
}
void updateNormal(){
if(updated){//average all face Normal
for(int i=0;i<3;i++){
myNormal[i] = 0;
for(int j=0;j<faceNormal.length;j++){
myNormal[i] += faceNormal[j][i];
}
myNormal[i] = myNormal[i]/faceNormal.length;
}
updated = false;
}
}
}

float[] createArray3(float x, float y, float z){
float[] out = {
x,y,z };
return out;
}

class gString{
float[][] pPos;
stringHistory[] history;
float[] radius;
float[] lastPos = new float[3];
float[] endPos = new float[3];
float lastR;
boolean started = false;
float maxDist;
gString(float md){
maxDist = md;
}

void plot(GL _gl){
//sphereDetail(12);
/* _gl.glDisable(GL.GL_LIGHTING);
_gl.glColor4f(1,1,1,.8);
_gl.glPointSize(10);
_gl.glBegin(GL.GL_POINTS);
for(int i=0;i<radius.length;i++){
_gl.glVertex3f(pPos[i][0],pPos[i][1],pPos[i][2]);
}
_gl.glEnd();
_gl.glEnable(GL.GL_LIGHTING);*/
if(history != null){
plotHistory(_gl);
}
}
void update(float sX, float sY, float sZ, float eX, float eY, float eZ, float rr, float rDecrease){
started = false;
float xDist = eX-sX;
float yDist = eY – sY;
float xyDist = sqrt(sq(xDist)+sq(yDist));
float a = (eZ – sZ)/sq(xyDist);
addParticle(sX, sY, sZ, rr);
int i=1;
while(i<(eZ – sZ)){
float r = rr-sqrt(i)*rDecrease;
if(r maxDist){
range = r + lastR;
}
if(d>range){
addParticle(sX+sqrt(i/a)*xDist/xyDist,sY+sqrt(i/a)*yDist/xyDist, sZ+i ,r);
}
i++;
}
addHistory(pPos);
}
void addParticle(float x, float y, float z,float r){
if(!started){
pPos = new float[1][3];
radius = new float[1];
pPos[0][0] = x;
pPos[0][1] = y;
pPos[0][2] = z;
radius[0] = r;
started = true;
}
else{
float[][] tempP = new float[pPos.length+1][3];
arraycopy(pPos, tempP);
tempP[pPos.length][0] = x;
tempP[pPos.length][1] = y;
tempP[pPos.length][2] = z;
pPos = tempP;
float[] tempR = new float[radius.length+1];
arraycopy(radius, tempR);
tempR[radius.length] = r;
radius= tempR;
}
lastPos[0] = x;
lastPos[1] = y;
lastPos[2] = z;
lastR = r;
}
void addHistory(float[][] h){
if(history == null){
history = new stringHistory[1];
history[0] = new stringHistory(h);
}
else{
stringHistory[] tempH = new stringHistory[history.length+1];
arraycopy(history, tempH);
tempH[history.length] = new stringHistory(h);
history = tempH;
}
}
void plotHistory(GL _gl){
if(history != null){
for(int i=0;i<history.length;i++){
history[i].plot(_gl);
}
}
}
void createDrop(){
int tempID;
if(dropArray == null){
tempID = 0;
dropArray = new gDrop[1];
}
else{
tempID = dropArray.length;
gDrop[] tempArray = new gDrop[dropArray.length+1];
arraycopy(dropArray, tempArray);
dropArray = tempArray;
}
dropArray[tempID] = new gDrop(tempID, pPos[0][0],pPos[0][1],pPos[0][2],pPos[pPos.length-1][0],pPos[pPos.length-1][1],pPos[pPos.length-1][2],radius[0]);

for(int i=1;i<pPos.length;i++){
dropArray[tempID].addRing(pPos[i][0],pPos[i][1],pPos[i][2],0,0,1,radius[i]);
}
startedDrop++;
dropArray[tempID].ended = true;
}
}

class stringHistory{
float[][] pPos;
stringHistory(float[][] p){
pPos = p;
}
void plot(GL _gl){
_gl.glDisable(GL.GL_LIGHTING);
_gl.glColor3f(0,0,0);
_gl.glBegin(GL.GL_LINE_STRIP);
for(int i=0;i<pPos.length;i++){
_gl.glVertex3f(pPos[i][0],pPos[i][1],pPos[i][2]);
}
_gl.glEnd();
_gl.glEnable(GL.GL_LIGHTING);

}
}

//—————————————————
//opengl draw
void drawQuad(GL _gl, float[] p1, float[] p2, float[] p3, float[] p4,float[] v1, float[] v2, float[] v3, float[] v4){
_gl.glBegin(GL.GL_QUADS);//GL.GL_QUADS, GL.GL_LINE_LOOP
_gl.glNormal3f(v1[0], v1[1], v1[2]);
_gl.glVertex3f(p1[0], p1[1], p1[2]);
_gl.glNormal3f(v2[0], v2[1], v2[2]);
_gl.glVertex3f(p2[0], p2[1], p2[2]);
_gl.glNormal3f(v3[0], v3[1], v3[2]);
_gl.glVertex3f(p3[0], p3[1], p3[2]);
_gl.glNormal3f(v4[0], v4[1], v4[2]);
_gl.glVertex3f(p4[0], p4[1], p4[2]);
_gl.glEnd();
}
void drawQuad2(GL _gl, float[] p1, float[] p2, float[] p3, float[] p4){
//get the normal first
float[] v1 = new float[3];
float[] v2 = new float[3];
for(int i=0;i<3;i++){
v1[i] = p2[i] – p1[i];
v2[i] = p3[i] – p2[i];
}
float[] v3 = crossProduct(v1, v2);
v3 = unifyVector(v3);
_gl.glBegin(GL.GL_QUADS);//GL.GL_QUADS, GL.GL_LINE_LOOP
_gl.glNormal3f(v3[0], v3[1], v3[2]);
_gl.glVertex3f(p1[0], p1[1], p1[2]);
_gl.glVertex3f(p2[0], p2[1], p2[2]);
_gl.glVertex3f(p3[0], p3[1], p3[2]);
_gl.glVertex3f(p4[0], p4[1], p4[2]);
_gl.glEnd();
}
void drawTri(GL _gl, float[] p1, float[] p2, float[] p3,float[] v1, float[] v2, float[] v3){
_gl.glBegin(GL.GL_TRIANGLES);//GL.GL_QUADS, GL.GL_LINE_LOOP
_gl.glNormal3f(v1[0], v1[1], v1[2]);
_gl.glVertex3f(p1[0], p1[1], p1[2]);
_gl.glNormal3f(v2[0], v2[1], v2[2]);
_gl.glVertex3f(p2[0], p2[1], p2[2]);
_gl.glNormal3f(v3[0], v3[1], v3[2]);
_gl.glVertex3f(p3[0], p3[1], p3[2]);
_gl.glEnd();
}

void drawTri2(GL _gl, float[] p1, float[] p2, float[] p3){
//get the normal first
float[] v1 = new float[3];
float[] v2 = new float[3];
for(int i=0;i<3;i++){
v1[i] = p2[i] – p1[i];
v2[i] = p3[i] – p2[i];
}
float[] v3 = crossProduct(v1, v2);
v3 = unifyVector(v3);
_gl.glBegin(GL.GL_TRIANGLES);
_gl.glNormal3f(v3[0], v3[1], v3[2]);
_gl.glVertex3f(p1[0], p1[1], p1[2]);
_gl.glVertex3f(p2[0], p2[1], p2[2]);
_gl.glVertex3f(p3[0], p3[1], p3[2]);
_gl.glEnd();
}

//—————————————————
//MATH

float[] unifyVector(float[] v){
float[] out = {
0,0,0 };
if(v[0] ==0 && v[1]==0 && v[2]==0){
//println(“unifyVector error!! length == 0”);
}
else{
float[] zero = {
0,0,0 };
float d = getDistance(zero, v);
for(int i =0; i<3; i++){
out[i] = v[i]/d;
}
}
return out;
}

float[] multiplyVector(float[] v, float m){
float[] out = new float[v.length];

for(int i =0; i<v.length; i++){
out[i] = v[i]*m;
}

return out;
}

float getDistance(float[] x1, float[] x2){
float temp = 0;
for(int i = 0; i<x1.length; i++){
float temp2 = x1[i] – x2[i];
temp2 = temp2*temp2;
temp += temp2;
}
if(temp != 0){
temp = sqrt(temp);
}
return temp;
}

float getLength(float[] x1){
float temp = 0;
for(int i = 0; i<x1.length; i++){
temp += sq(x1[i]);
}
if(temp != 0){
temp = sqrt(temp);
}
return temp;
}
float[] crossProduct(float[] v1, float[] v2){
//A x B =
float[] out = new float[3];
out[0] = v1[1]*v2[2] – v1[2]*v2[1];
out[1] = v1[2]*v2[0] – v1[0]*v2[2];
out[2] = v1[0]*v2[1] – v1[1]*v2[0];
/*if(out[0] ==0 && out[1]==0 && out[2]==0){
println(“crossproduct error!!”);
}*/
return out;
}

float dotProduct(float[] v1, float[] v2){
v1 = unifyVector(v1);
v2 = unifyVector(v2);
float out = 0;
for(int i=0;i<3;i++){
out += v1[i]*v2[i];
}
return out;
}

float getVectorAngle(float[] v1, float[] v2){
float out=0;
//float l1 = getLength(v1);
//float l2 = getLength(v2);
float dot = dotProduct(v1,v2);
out = degrees(acos(dot));
return out;
}

float[] getVector(float[] v1, float[] v2){
float[] out=new float[v1.length];
for(int i=0;i<v1.length;i++){
out[i] = v2[i] – v1[i];
}
return out;
}

float[] addVector(float[] v1, float[] v2){
float[] out=new float[v1.length];
for(int i=0;i<v1.length;i++){
out[i] = v2[i] + v1[i];
}
return out;
}

float[] rotateXX(float x, float y, float z, float x2){
float[] temp = new float[3];
temp[1] = y*cos(x2) – z*sin(x2);
temp[2] = z*cos(x2) + y*sin(x2);

temp[0] = x;
return temp;
}

float[] rotateYY(float x, float y, float z, float y2){
float[] temp = new float[3];
temp[0] = x*cos(y2) + z*sin(y2);
temp[2] = z*cos(y2) – x*sin(y2);

temp[1] = y;
return temp;
}

float[] rotateZZ(float x, float y, float z, float z2){
float[] temp = new float[3];
temp[0] = x*cos(z2) – y*sin(z2);
temp[1] = x*sin(z2) + y*cos(z2);

temp[2] = z;
return temp;
}

//—————————————————
//export
void mayaExportDrop(){
PrintWriter mayaOutput = createWriter(month()+”_”+day()+”_”+hour()+”_”+minute()+”_”+second()+”_drop.mel”);
mayaOutput.println(“select -all;”);
mayaOutput.println(“hide -all;”);
for(int i=0;i<dropArray.length;i++){
mayaOutput.print(“curve”);
for(int j=0;j<dropArray[i].rings.length;j++){
mayaOutput.print(” -p “+dropArray[i].rings[j].pos[0]+” ” +dropArray[i].rings[j].pos[1]+” “+dropArray[i].rings[j].pos[2]);
}
if(dropArray[i].rings.length<3){
mayaOutput.println(“-d 1”);
}
mayaOutput.println(“;”);
}
mayaOutput.flush(); // Writes the remaining data to the file
mayaOutput.close(); // Finishes the file
println(“MEL saved (drops)”);
}

void mayaExportString(){
PrintWriter mayaOutput = createWriter(month()+”_”+day()+”_”+hour()+”_”+minute()+”_”+second()+”_string.mel”);
mayaOutput.println(“select -all;”);
mayaOutput.println(“hide -all;”);
for(int i=0;i<myString.history.length;i++){
mayaOutput.print(“curve”);
for(int j=0;j<myString.history[i].pPos.length;j++){
mayaOutput.print(” -p “+myString.history[i].pPos[j][0]+” ” +myString.history[i].pPos[j][1]+” “+myString.history[i].pPos[j][2]);
}
mayaOutput.print(“-d 1”);
mayaOutput.println(“;”);
}

mayaOutput.flush(); // Writes the remaining data to the file
mayaOutput.close(); // Finishes the file
println(“MEL saved (strings)”);
}

void mayaExportHistory(){
PrintWriter mayaOutput = createWriter(month()+”_”+day()+”_”+hour()+”_”+minute()+”_”+second()+”_history.mel”);
mayaOutput.println(“select -all;”);
mayaOutput.println(“hide -all;”);
for(int i=0;i<myAgents.length;i++){
mayaOutput.print(“curve”);
for(int j=0;j<myAgents[i].history.length;j++){
mayaOutput.print(” -p “+myAgents[i].history[j][0]+” ” +myAgents[i].history[j][1]+” “+myAgents[i].history[j][2]);
}
mayaOutput.print(“-d 1”);
mayaOutput.println(“;”);
}

mayaOutput.flush(); // Writes the remaining data to the file
mayaOutput.close(); // Finishes the file
println(“MEL saved (history)”);
}

void mayaExport(){
int total = ceil(float(dropArray.length)/200);
println(“exporting “+total+” MEL…”);
for(int i=0;i<total;i++){
mayaExport2((i+1), total);
}
}

void mayaExport2(int id, int total){
PrintWriter mayaOutput = createWriter(month()+”_”+day()+”_”+hour()+”_”+minute()+”_”+second()+”_”+id+”of”+total+”.mel”);
mayaOutput.println(“select -all;”);
mayaOutput.println(“hide -all;”);
int l;
int start;
if(id == total){
l = dropArray.length;
}
else{
l=id*200;
}
start = (id-1)*200;
if(dropArray != null){
for(int i=start;i<l;i++){
for(int j=0;j<dropArray[i].rings.length;j++){
//export the main geometry
if(j<dropArray[i].rings.length-1){
for(int k=0;kmeshDensity-1){
t=0;
}
mayaOutput.println(exportQuad(dropArray[i].rings[j].particles[k].pos, dropArray[i].rings[j+1].particles[k].pos, dropArray[i].rings[j+1].particles[t].pos, dropArray[i].rings[j].particles[t].pos));
}
}
}
//export the added starting ring
//export the starting and ending cap
int ringLength = dropArray[i].rings.length-1;
for(int k=0;kmeshDensity-1){
t=0;
}
mayaOutput.println(exportQuad(dropArray[i].capStart.particles[k].pos, dropArray[i].rings[0].particles[k].pos, dropArray[i].rings[0].particles[t].pos, dropArray[i].capStart.particles[t].pos));
mayaOutput.println(exportTri(dropArray[i].capStart.particles[k].pos, dropArray[i].capStart.particles[t].pos, dropArray[i].capStart.pos));
mayaOutput.println(exportTri(dropArray[i].rings[ringLength].particles[k].pos, dropArray[i].rings[ringLength].particles[t].pos, dropArray[i].rings[ringLength].pos));
}
mayaOutput.println(“select -all -vis;”);
mayaOutput.println(“polyUnite;”);
mayaOutput.println(“delete -ch;”);
}
}
mayaOutput.println(“select -all -vis;”);
mayaOutput.println(“polyMergeVertex -d 0.1;”);
mayaOutput.println(“select -all -vis;”);
mayaOutput.println(“polySoftEdge -a 180;”);
mayaOutput.println(“select -all -vis;”);
mayaOutput.println(“polyCleanupArgList 3 { \”1\”,\”1\”,\”0\”,\”0\”,\”0\”,\”0\”,\”0\”,\”0\”,\”0\”,\”1e-005\”,\”0\”,\”1e-005\”,\”0\”,\”1e-005\”,\”0\”,\”1\”,\”1\” };”);
mayaOutput.println(“delete -ch;”);
mayaOutput.flush(); // Writes the remaining data to the file
mayaOutput.close(); // Finishes the file
println(“MEL saved (“+id+” of “+total+”)”);
}

String exportQuad(float[] pos1, float[] pos2, float[] pos3, float[] pos4){
String out;
out = “polyCreateFacet”;
out += ” -p “+pos1[0]+” “+pos1[1]+” “+pos1[2];
out += ” -p “+pos2[0]+” “+pos2[1]+” “+pos2[2];
out += ” -p “+pos3[0]+” “+pos3[1]+” “+pos3[2];
out += ” -p “+pos4[0]+” “+pos4[1]+” “+pos4[2];
out += “;”;
return out;
}

String exportTri(float[] pos1, float[] pos2, float[] pos3){
String out;
out = “polyCreateFacet”;
out += ” -p “+pos1[0]+” “+pos1[1]+” “+pos1[2];
out += ” -p “+pos2[0]+” “+pos2[1]+” “+pos2[2];
out += ” -p “+pos3[0]+” “+pos3[1]+” “+pos3[2];
out += “;”;
return out;
}

class myTimer{
int counter;
myTimer(){
counter = 0;
}
void update(){
if(!paused){
if(counter>240){
counter-=240;
loopEvent();
}
counter++;
}
}
void loopEvent(){
if(myAgents != null){
for(int i=0;i<myAgents.length;i++){
myAgents[i].update();
}
}
}
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s