Browse Source

Simulating movement: Particule integration

Godzil 1 year ago
parent
commit
0235c2585d
3 changed files with 11 additions and 3 deletions
  1. 1 2
      source/app.cpp
  2. 2 0
      source/include/physics/particle.h
  3. 8 1
      source/physics/particle.cpp

+ 1 - 2
source/app.cpp

@@ -71,8 +71,7 @@ void application::update()
     this->part->acceleration = vec2(2.0 * PIXELS_PER_METER, 9.8 * PIXELS_PER_METER);
 
     // Integrate the change
-    this->part->velocity += (this->part->acceleration * deltaTime);
-    this->part->position += (this->part->velocity * deltaTime);
+    this->part->integrate(deltaTime);
 
     // check the particles position and keep the particule in the window.
     if ( ((this->part->position.y - this->part->radius) <= 0) ||

+ 2 - 0
source/include/physics/particle.h

@@ -26,6 +26,8 @@ public:
 public:
     particle(double x, double y, double mass): radius(4), position(x, y), mass(mass) {};
     ~particle() = default;
+
+    void integrate(double dt);
 };
 
 #endif /* PHYSICENGINE_PHYSICS_PARTICLE_H */

+ 8 - 1
source/physics/particle.cpp

@@ -7,4 +7,11 @@
  * Created by Manoël Trapier on 07/06/2022.
  */
 
-// TODO
+#include <physics/particle.h>
+
+void particle::integrate(double dt)
+{
+    this->velocity += this->acceleration * dt;
+    this->position += this->velocity * dt;
+}
+