I have this simple euler integrator. For finding precise collision times it should handle negative dt's as well (I divide the frame time and simulate back when I detect a collision).
For some reason
someBody.update(1.0); someBody.update(-0.3); someBody.update(-0.3); someBody.update(0.6); gives different results than:
someBody.update(1.0); It might be because I use euler instead of RK4 or verlet?
Here's the code for the integrator:
void Body::update(double dt) { if (dt > 0) velocity += acceleration * (dt*dt); else velocity -= acceleration * (dt*dt); pos += velocity * dt; rotation += angularVelocity * dt; } Thanks a lot!
Maarten
velocity += acceleration * (dt*dt);? Isn't $v=at$?someBody.update(1.0);will result in the same values assomeBody.update(0.5); someBody.update(0.5);I don't think your current formulas do it correctly. Also check that when at x=0, v=0, a=1, aftersomeBody.update(1.0);you'll be at x=0.5, v=1.