|
@@ -13,7 +13,7 @@
|
|
|
#include <imgui_impl_sdl.h>
|
|
|
|
|
|
#include <physics/constants.h>
|
|
|
-#include <physics/particle.h>
|
|
|
+#include <physics/body.h>
|
|
|
#include <physics/vec2.h>
|
|
|
#include <physics/force.h>
|
|
|
|
|
@@ -30,8 +30,8 @@ void application::setup()
|
|
|
this->millisecsPreviousFrame = SDL_GetTicks();
|
|
|
|
|
|
this->anchor = vec2(graphics::width() / 2.0,30);
|
|
|
- this->particles.push_back(new particle(graphics::width() / 2.0, graphics::height() / 2.0,
|
|
|
- 2.0, 10));
|
|
|
+ this->bodies.push_back(new body(graphics::width() / 2.0, graphics::height() / 2.0,
|
|
|
+ 2.0, 10));
|
|
|
}
|
|
|
|
|
|
void application::input()
|
|
@@ -94,9 +94,9 @@ void application::input()
|
|
|
{
|
|
|
if (this->leftButtonPressed)
|
|
|
{
|
|
|
- vec2 impulseDirection = (particles[0]->position - this->mouseCursor).unitVector();
|
|
|
- double impulseMagnitude = (particles[0]->position - this->mouseCursor).magnitude() * 5.0;
|
|
|
- particles[0]->velocity = impulseDirection * impulseMagnitude;
|
|
|
+ vec2 impulseDirection = (bodies[0]->position - this->mouseCursor).unitVector();
|
|
|
+ double impulseMagnitude = (bodies[0]->position - this->mouseCursor).magnitude() * 5.0;
|
|
|
+ bodies[0]->velocity = impulseDirection * impulseMagnitude;
|
|
|
}
|
|
|
this->leftButtonPressed = false;
|
|
|
}
|
|
@@ -140,7 +140,7 @@ void application::update()
|
|
|
this->syncAndDeltatime();
|
|
|
updateTime.start();
|
|
|
|
|
|
- for (auto part:this->particles)
|
|
|
+ for (auto part:this->bodies)
|
|
|
{
|
|
|
part->addForce(pushForce);
|
|
|
|
|
@@ -154,18 +154,18 @@ void application::update()
|
|
|
part->addForce(weight);
|
|
|
}
|
|
|
|
|
|
- vec2 spring = force::generateSpringForce(*this->particles[0],
|
|
|
+ vec2 spring = force::generateSpringForce(*this->bodies[0],
|
|
|
this->anchor, this->restLenght, this->k);
|
|
|
- this->particles[0]->addForce(spring);
|
|
|
+ this->bodies[0]->addForce(spring);
|
|
|
|
|
|
- for (auto part:this->particles)
|
|
|
+ for (auto part:this->bodies)
|
|
|
{
|
|
|
part->integrate(deltaTime);
|
|
|
}
|
|
|
|
|
|
- for (auto part:this->particles)
|
|
|
+ for (auto part:this->bodies)
|
|
|
{
|
|
|
- // check the particles position and keep the particle in the window.
|
|
|
+ // check the bodies position and keep the body in the window.
|
|
|
if ( ((part->position.y - part->radius) <= 0) ||
|
|
|
((part->position.y + part->radius) >= graphics::height()))
|
|
|
{
|
|
@@ -207,22 +207,22 @@ void application::render()
|
|
|
graphics::clearScreen(0xFF0F0721);
|
|
|
if (this->leftButtonPressed)
|
|
|
{
|
|
|
- graphics::draw::line(this->particles[0]->position.x, this->particles[0]->position.y,
|
|
|
+ graphics::draw::line(this->bodies[0]->position.x, this->bodies[0]->position.y,
|
|
|
this->mouseCursor.x, this->mouseCursor.y, 0xFFFFFFFF);
|
|
|
}
|
|
|
|
|
|
graphics::draw::line(this->anchor.x, this->anchor.y,
|
|
|
- this->particles[0]->position.x, this->particles[0]->position.y,
|
|
|
+ this->bodies[0]->position.x, this->bodies[0]->position.y,
|
|
|
0xFF313131);
|
|
|
graphics::draw::fillCircle(this->anchor.x, this->anchor.y, 5, 0xFF001155);
|
|
|
|
|
|
- for(auto part: this->particles)
|
|
|
+ for(auto part: this->bodies)
|
|
|
{
|
|
|
graphics::draw::fillCircle(part->position.x, part->position.y, part->radius, 0xFFAA3300);
|
|
|
}
|
|
|
|
|
|
|
|
|
- for(auto part: this->particles)
|
|
|
+ for(auto part: this->bodies)
|
|
|
{
|
|
|
part->forceDebug(this->showVelocity, this->showForceSum, this->showAllForces);
|
|
|
}
|
|
@@ -243,7 +243,7 @@ void application::render()
|
|
|
void application::destroy()
|
|
|
{
|
|
|
// Nothing for now.
|
|
|
- for (auto part:this->particles)
|
|
|
+ for (auto part:this->bodies)
|
|
|
{
|
|
|
delete part;
|
|
|
}
|