aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrodri <rgl@antares-labs.eu>2021-09-25 09:56:42 +0000
committerrodri <rgl@antares-labs.eu>2021-09-25 09:56:42 +0000
commit265cf72ccfc4922bc96a9e8d265d19a0da96ca34 (patch)
tree215807d702400900a9211e2cad99993b566ce53d
parent5c3edc3ecc7da495f4eab6de4562e9a6157c9b04 (diff)
downloadmusw-265cf72ccfc4922bc96a9e8d265d19a0da96ca34.tar.gz
musw-265cf72ccfc4922bc96a9e8d265d19a0da96ca34.tar.bz2
musw-265cf72ccfc4922bc96a9e8d265d19a0da96ca34.zip
use semi-implicit euler for bullet dynamics.
-rw-r--r--physics.c14
1 files changed, 13 insertions, 1 deletions
diff --git a/physics.c b/physics.c
index 8d5b05c..737adf0 100644
--- a/physics.c
+++ b/physics.c
@@ -136,6 +136,18 @@ evalu(Universe *u, Particle *p0, double t, double Δt, Derivative *d, Point2 (*a
}
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))
{
static Derivative ZD = {0};
@@ -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);
}
}