void Particle::integrate(fseconds duration, int type) { // Defaults to Euler // don't move objects that have "infinite mass." if (invMass <= 0.0f) { return; } // Universal properties //lastPos = pos; // Only necessary for position Verlet vec3 resultantAcc = acc + (invMass * accumulatedForces); auto dt = duration.count(); if ( type == 1 ) { // Euler // update position using Euler integration pos = pos + dt * vel; // update velocity using Euler integration vel = vel + dt * resultantAcc; // incorporate damping vel = vel * std::pow(damping, dt); } else if ( type == 2 ) { // RK // Pop RK4 in here at some point because... why not } else { // Velocity Verlet pos = pos + ( vel * dt ) + ( 0.5f * resultantAcc * dt * dt ); // Assumes acc doesn't change between steps - still need to solve for acc+1 to be accurate if a changes vel = vel + ( 0.5f * 2 * resultantAcc ) * dt; } clearForces(); }
void Particle::integrate(fseconds duration) { // don't move objects that have "infinite mass." if (invMass <= 0.0f) { return; } //update velocity using Verlet vel = vel + 1.0f/2.0f*acc*duration.count(); // update position using Velocity Verlet pos = pos + vel * duration.count(); vec3 resultantAcc = (pos+duration.count())-(2.0f*pos+pos)-(duration.count()); // update velocity using Velocity Verlet vel = vel + 1.0f/2.0f*resultantAcc*duration.count(); // incorporate damping vel = vel * damping; clearForces(); }
void Particle::integrate(fseconds duration) { // don't move objects that have "infinite mass." if (invMass <= 0.0f) { return; } // update position using Euler integration pos = pos + duration.count() * vel; vec3 resultantAcc = acc; resultantAcc = resultantAcc + (invMass * accumulatedForces); // update velocity using Euler integration vel = vel + duration.count() * resultantAcc; // incorporate damping vel = vel * damping; clearForces(); }