shithub: musw

Download patch

ref: 265cf72ccfc4922bc96a9e8d265d19a0da96ca34
parent: 5c3edc3ecc7da495f4eab6de4562e9a6157c9b04
author: rodri <[email protected]>
date: Sat Sep 25 05:56:42 EDT 2021

use semi-implicit euler for bullet dynamics.

--- a/physics.c
+++ b/physics.c
@@ -136,6 +136,18 @@
 }
 
 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 @@
 		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);
 	}
 }