// Attraction // Daniel Shiffman // A class to describe a thing in our world, has vectors for location, velocity, and acceleration // Also includes scalar values for mass, maximum velocity, and elasticity // Created 2 May 2005 class Thing { Vector3D loc; Vector3D vel; Vector3D acc; float mass; float max_vel; float bounce = 1.0f; // How "elastic" is the object Thing(Vector3D a, Vector3D v, Vector3D l, float m_) { acc = a.copy(); vel = v.copy(); loc = l.copy(); mass = m_; max_vel = 20.0f; } Vector3D getLoc() { return loc; } Vector3D getVel() { return vel; } float getMass() { return mass; } void add_force(Vector3D force) { force.div(mass); acc.add(force); if (showVectors) { drawVector(force,loc,1000); } } // Main method to operate object void go() { update(); render(); } // Method to update location void update() { vel.add(acc); vel.limit(max_vel); loc.add(vel); acc.setXYZ(0.0,0.0,0.0); } // Method to display void render() { ellipseMode(CENTER); noStroke(); fill(200,30); //ellipse(loc.x-7,loc.y,mass*2,mass*2); //ellipse(loc.x+7,loc.y,mass*2,mass*2); pushMatrix(); translate(loc.x,loc.y); rotate(45); ellipse(-7,0,mass*2,mass*2); ellipse(+7,0,mass*2,mass*2); popMatrix(); if (showVectors) { drawVector(vel,loc,20); drawVector(acc,loc,10000); } } }