Browse Source

Applying forces: Gravity is weighty.

Godzil 1 year ago
parent
commit
886ff86aaf
1 changed files with 4 additions and 3 deletions
  1. 4 3
      source/app.cpp

+ 4 - 3
source/app.cpp

@@ -25,7 +25,7 @@ void application::setup()
     this->millisecsPreviousFrame = SDL_GetTicks();
 
     this->particles.push_back(new particle(50, 100, 1.0, 4));
-    this->particles.push_back(new particle(50, 200, 3.0, 12));
+    this->particles.push_back(new particle(200, 100, 3.0, 12));
 }
 
 void application::input()
@@ -80,6 +80,7 @@ void application::syncAndDeltatime()
 void application::update()
 {
     vec2 wind = vec2(0.2 * PIXELS_PER_METER, 0);
+    vec2 weight = vec2(0, 9.81 * PIXELS_PER_METER);
     this->syncAndDeltatime();
 
     updateTime.start();
@@ -87,9 +88,10 @@ void application::update()
     for (auto part:this->particles)
     {
         part->addForce(wind);
+        part->addForce(weight * part->mass);
         part->integrate(deltaTime);
 
-        // check the particles position and keep the particule in the window.
+        // check the particles position and keep the particle in the window.
         if ( ((part->position.y - part->radius) <= 0) ||
              ((part->position.y + part->radius) >= graphics::height()))
         {
@@ -101,7 +103,6 @@ void application::update()
         {
             part->velocity.x = -part->velocity.x;
         }
-
     }
 
     updateTime.stop();