import java.util.ArrayList; import org.lwjgl.opengl.GL11; public class Organism { ArrayList segs; ArrayList legs; float speed ,d; Organism() {} void initialize(Vector3D initialpos, float d_, float speed_) { Segment hold; Legs holdL; Vector3D color, pos; color= new Vector3D(); pos = new Vector3D(); d=d_; speed=speed_; segs = new ArrayList(); legs = new ArrayList(); for(float i=0; i< 15 ; i=i+1) { color.setXYZ(random(.5f),.1f+random(.8f),.1f+random(.8f)); //pos.setXYZ(initialpos.x()+2*i,initialpos.y(),initialpos.z()); pos.setXYZ(initialpos.x()+d*i,initialpos.y(),initialpos.z()); hold = new Segment(pos, d, color); segs.add(hold); holdL = new Legs(pos); legs.add(holdL); } }//END initialize void render() { Segment hold; Legs holdL; for(int i=0; i< segs.size(); i=i+1) { //render segments hold=(Segment) segs.get(i); hold.render(); //render legs holdL=(Legs) legs.get(i); holdL.render(); } }//END render void seek(Vector3D target) { int i; float distm; Vector3D diff; Segment hold1, hold2; Legs holdL; if(segs.size()>0) { i=0; //how deal with updating headpos? hold1=(Segment) segs.get(i); holdL=(Legs) legs.get(i); //MOVE HEAD diff=hold1.XYZ().sub(target); distm=diff.magnitude(); if (distm>d/2) //if (distm>1) { hold1.setXYZ(hold1.XYZ().sub(diff.mult(speed))); holdL.setpos(hold1.XYZ().sub(diff.mult(speed))); holdL.setdir(hold1.XYZ(), target); } //BODY FOLLOWS for(i=1; i2*d) //if (distm>1) { hold2.setXYZ(hold2.XYZ().sub(diff.mult((distm-2*d)/distm))); holdL.setpos(hold2.XYZ().sub(diff.mult((distm-2*d)/distm))); //hold2.setXYZ(hold2.XYZ().sub(diff.mult((distm-2)/distm))); //holdL.setpos(hold2.XYZ().sub(diff.mult((distm-2)/distm))); holdL.setdir(hold1.XYZ(), hold2.XYZ()); }//else move to within } } }//END seek //returns -magnitude to +magnitude float random(float magnitude) { return ((float)Math.random()-.5f)*2*magnitude; } }//END Organism