//------------------------------------------------------------ // Metaball Class //------------------------------------------------------------ class Metaball { private Vector3D loc; private Vector3D vel; private Vector3D acc; private float maxvel; // These need to be replaced by loc.x & loc.y float center_x, center_y; int center_i, center_j; int scan_iMin, scan_iMax, scan_jMin, scan_jMax; float dx, dy; float strength = 30000; float isoValue = 16.0f; float R; int sqR; float timer; /* Metaball(float isoV) { this.isoValue = isoV; this.getRadius(); this.center_x = 0; this.center_y = 0; } */ Metaball(Vector3D a, Vector3D v, Vector3D l) { acc = a.copy(); vel = v.copy(); loc = l.copy(); /* acc = a; vel = v; loc = l; */ maxvel = 8; //this.isoValue = isoV; this.getRadius(); //this.center_x = l.x; //this.center_y = l.y; //timer = 400.0; } /*Add functions to our thing object to access the location, velocity and acceleration from outside the class*/ Vector3D getVel() { return vel.copy(); } Vector3D getAcc() { return acc.copy(); } Vector3D getLoc() { return loc.copy(); } void setLoc(Vector3D v) { loc = v.copy(); } void setVel(Vector3D v) { vel = v.copy(); } void setAcc(Vector3D v) { acc = v.copy(); } //function to update location void update() { vel.add(acc); loc.add(vel); //limit speed to max if (vel.magnitude() > maxvel) { vel.normalize(); vel.mult(maxvel); } timer -= 1.0; } void setStrength(float s) { this.strength = s; this.getRadius(); } /* void setCenterTo(Vector3D loc) { this.center_x = loc.x; this.center_y = loc.y; } */ void setCenterTo(float x, float y) { this.center_x = x; this.center_y = y; } void getRadius() { this.R = (float) Math.sqrt( (double) (strength/isoValue) ); this.sqR = (int) R/(256/64); } float getFieldAt(float x, float y) { dx = (loc.x - x); dy = (loc.y - y); return strength/(dx*dx + dy*dy+0.01f); } void SquareCoords(float res_x, float res_y) { center_i = (int)(center_x/res_x); center_j = (int)(center_y/res_y); } int getSquareCoords_i(float res_x, float res_y) { center_i = (int)(center_x/res_x); return center_i; } int getSquareCoords_j(float res_x, float res_y) { center_j = (int)(center_y/res_y); return center_j; } // Is the particle still useful? boolean dead() { if (timer <= 0.0) { return true; } else { return false; } } }