class Spring { Vector3D loc; Vector3D vel; Vector3D acc; Vector3D origin; Vector3D shift; Vector3D x; float diam; boolean dragging = false; Spring(Vector3D l) { loc = l.copy(); vel = new Vector3D(0.0,0.0); acc = new Vector3D(0.0,0.0); origin = loc.copy(); // save origin //shift = shift_.copy(); diam = 40.0; // set diameter } void go(Vector3D shift) //void go() { //Hooke's Law : F = -kx float k = 1.0f; // spring constant float c = -0.2f; // Drag coefficient //shift.mult(-1); if (shift.magnitude() > 40.0) { loc = origin.copy(); loc.add(shift); // add vector from MEL ... should do some math on it first... } else { Vector3D disp = Vector3D.sub(origin,loc); // "-x" disp.mult(k); // "-kx" spring force acc = disp.copy(); // make accel. spring force } // drag force Vector3D thingVel = vel.copy(); // Velocity of our thing Vector3D dragF = Vector3D.mult(thingVel,c); // Following the formula above acc.add(dragF); // add dragforce vel.add(acc); loc.add(vel); } void render() { fill(255,200); noStroke(); ellipse(loc.x,loc.y,diam,diam); } // This checks to see if we clicked on the pendulum ball void clicked(int mx, int my) { float d = dist(mx,my,loc.x,loc.y); if (d < diam) { dragging = true; } } // This tells us we are not longer clicking on the ball void stopDragging() { dragging = false; } void drag() { // If we are draging the ball, we calculate the angle between the // pendulum origin and mouse location // we assign that angle to the pendulum if (dragging) { loc = new Vector3D(mouseX,mouseY); // Difference between 2 points //theta = atan2(-1*diff.y,diff.x) - radians(90); // Angle relative to vertical axis } } }