From f18fb0f5b417164be74484804e8757eab75a2605 Mon Sep 17 00:00:00 2001 From: Julian Date: Thu, 16 Feb 2023 15:01:17 +0100 Subject: [PATCH] update to .net7, clarify particle math --- .../Newtonian-Particle-Simulator.csproj | 2 +- .../res/shaders/particles/vertex.glsl | 13 ++++++++----- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/Newtonian-Particle-Simulator/Newtonian-Particle-Simulator.csproj b/Newtonian-Particle-Simulator/Newtonian-Particle-Simulator.csproj index 70b815e..c6d0bd2 100644 --- a/Newtonian-Particle-Simulator/Newtonian-Particle-Simulator.csproj +++ b/Newtonian-Particle-Simulator/Newtonian-Particle-Simulator.csproj @@ -2,7 +2,7 @@ Exe - net5.0 + net7.0 Newtonian_Particle_Simulator AnyCPU;x64 diff --git a/Newtonian-Particle-Simulator/res/shaders/particles/vertex.glsl b/Newtonian-Particle-Simulator/res/shaders/particles/vertex.glsl index c0fcac9..31fe48a 100644 --- a/Newtonian-Particle-Simulator/res/shaders/particles/vertex.glsl +++ b/Newtonian-Particle-Simulator/res/shaders/particles/vertex.glsl @@ -31,13 +31,16 @@ void main() const vec3 toMass = pointOfMass - particle.Position; /// Implementation of Newton's law of gravity - const float G = 1.0; // gravitational constant - const float m1_m2 = 176.0; // mass of both objects multiplied + const float m1 = 1.0; // constant particle mass + const float m2 = 176.0; // (user controlled) pointOfMass mass + const float G = 1.0; // gravitational constant + const float m1_m2 = m1 * m2; // mass of both objects multiplied const float rSquared = max(dot(toMass, toMass), EPSILON * EPSILON); // distance between objects squared - const float force = G * ((m1_m2) / rSquared); + // Technically toMass would have to be normalized but feels better without + const vec3 force = toMass * (G * ((m1_m2) / rSquared)); - // acceleration = toMass * force. Technically toMass would have to be normalized but feels better without - const vec3 acceleration = toMass * force * isRunning * isActive; + // acceleration = force / m. + const vec3 acceleration = (force * isRunning * isActive) / m1; particle.Velocity *= mix(1.0, exp(DRAG_COEF * dT), isRunning); // https://stackoverflow.com/questions/61812575/which-formula-to-use-for-drag-simulation-each-frame particle.Position += (dT * particle.Velocity + 0.5 * acceleration * dT * dT) * isRunning; // Euler integration