Browse Source

Particle Physics: class

Godzil 1 year ago
parent
commit
16cd218a29
3 changed files with 26 additions and 6 deletions
  1. 8 5
      source/app.cpp
  2. 3 0
      source/include/app.h
  3. 15 1
      source/include/physics/particle.h

+ 8 - 5
source/app.cpp

@@ -19,7 +19,9 @@ void application::parseParameters(int argc, char *argv[])
 
 void application::setup()
 {
-    running = graphics::openWindow();
+    this->running = graphics::openWindow();
+
+    this->part = new particle(50, 100, 1.0);
 }
 
 void application::input()
@@ -33,13 +35,13 @@ void application::input()
         switch(event.type)
         {
         case SDL_QUIT:
-            running = false;
+            this->running = false;
             break;
 
         case SDL_KEYDOWN:
             if (event.key.keysym.sym == SDLK_ESCAPE)
             {
-                running = false;
+                this->running = false;
             }
             break;
         }
@@ -54,8 +56,7 @@ void application::update()
 void application::render()
 {
     graphics::clearScreen(0xFF056263);
-    graphics::draw::fillCircle(200, 200, 40, 0xFFFFFFFF);
-    graphics::draw::text(10, 10, graphics::makeColour(255, 12, 98), "Hello world!");
+    graphics::draw::fillCircle(this->part->position.x, this->part->position.y, 4, 0xFFFFFFFF);
 
     graphics::renderFrame();
 }
@@ -65,4 +66,6 @@ void application::destroy()
     // Nothing for now.
 
     graphics::closeWindow();
+
+    delete this->part;
 }

+ 3 - 0
source/include/app.h

@@ -10,10 +10,13 @@
 #ifndef PHYSICENGINE_APP_H
 #define PHYSICENGINE_APP_H
 
+#include <physics/particle.h>
+
 class application
 {
 private:
     bool running;
+    particle *part;
 
 public:
     application() : running(false) {};

+ 15 - 1
source/include/physics/particle.h

@@ -10,6 +10,20 @@
 #ifndef PHYSICENGINE_PHYSICS_PARTICLE_H
 #define PHYSICENGINE_PHYSICS_PARTICLE_H
 
-// TODO
+#include <physics/vec2.h>
+
+class particle
+{
+public:
+    vec2 position;
+    vec2 acceleration;
+    vec2 velocity;
+
+    double mass;
+
+public:
+    particle(double x, double y, double mass): position(x, y), mass(mass) {};
+    ~particle() = default;
+};
 
 #endif /* PHYSICENGINE_PHYSICS_PARTICLE_H */