From 265cf72ccfc4922bc96a9e8d265d19a0da96ca34 Mon Sep 17 00:00:00 2001 From: rodri Date: Sat, 25 Sep 2021 09:56:42 +0000 Subject: use semi-implicit euler for bullet dynamics. --- physics.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/physics.c b/physics.c index 8d5b05c..737adf0 100644 --- a/physics.c +++ b/physics.c @@ -135,6 +135,18 @@ evalu(Universe *u, Particle *p0, double t, double Δt, Derivative *d, Point2 (*a return res; } +static void +euler1u(Universe *u, Particle *p, double t, double Δt) +{ + static Derivative ZD = {0}; + Derivative d; + + d = evalu(u, p, t, Δt, &ZD); + + p->v = addpt2(p->v, mulpt2(d.dv, Δt)); + p->p = addpt2(p->p, mulpt2(p->v, Δt)); +} + static void rk4u(Universe *u, Particle *p, double t, double Δt, Point2 (*acc)(Universe*,Particle*,double)) { @@ -163,6 +175,6 @@ integrateu(Universe *u, double t, double Δt) rk4u(u, &u->ships[i], t, Δt, accelship); for(j = 0; j < nelem(u->ships[i].rounds); j++) if(u->ships[i].rounds[j].fired) - rk4u(u, &u->ships[i].rounds[j], t, Δt, accelbullet); + euler1u(u, &u->ships[i].rounds[j], t, Δt, accelbullet); } } -- cgit v1.2.3