|
@@ -29,8 +29,9 @@ void application::setup()
|
|
|
this->running = graphics::openWindow();
|
|
|
this->millisecsPreviousFrame = SDL_GetTicks();
|
|
|
|
|
|
- this->particles.push_back(new particle(200, 200, 1, 6));
|
|
|
- this->particles.push_back(new particle(500, 500, 20.0, 20));
|
|
|
+ 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));
|
|
|
}
|
|
|
|
|
|
void application::input()
|
|
@@ -141,14 +142,21 @@ void application::update()
|
|
|
|
|
|
for (auto part:this->particles)
|
|
|
{
|
|
|
+ part->addForce(pushForce);
|
|
|
+
|
|
|
vec2 friction = force::generateFrictionForce(*part, 20);
|
|
|
part->addForce(friction);
|
|
|
+
|
|
|
+ vec2 drag = force::generateDragForce(*part, 0.001);
|
|
|
+ part->addForce(drag);
|
|
|
+
|
|
|
+ vec2 weight = vec2(0, part->mass * 9.81 * PIXELS_PER_METER);
|
|
|
+ part->addForce(weight);
|
|
|
}
|
|
|
|
|
|
- vec2 attraction = force::generateGravitationalForce(*this->particles[0], *this->particles[1],
|
|
|
- 1000, 5, 100);
|
|
|
- this->particles[0]->addForce(attraction);
|
|
|
- this->particles[1]->addForce(-attraction);
|
|
|
+ vec2 spring = force::generateSpringForce(*this->particles[0],
|
|
|
+ this->anchor, this->restLenght, this->k);
|
|
|
+ this->particles[0]->addForce(spring);
|
|
|
|
|
|
for (auto part:this->particles)
|
|
|
{
|
|
@@ -203,10 +211,16 @@ void application::render()
|
|
|
this->mouseCursor.x, this->mouseCursor.y, 0xFFFFFFFF);
|
|
|
}
|
|
|
|
|
|
- graphics::draw::fillCircle(this->particles[0]->position.x, this->particles[0]->position.y,
|
|
|
- this->particles[0]->radius, 0xFFAA3300);
|
|
|
- graphics::draw::fillCircle(this->particles[1]->position.x, this->particles[1]->position.y,
|
|
|
- this->particles[1]->radius, 0xFF00FFFF);
|
|
|
+ graphics::draw::line(this->anchor.x, this->anchor.y,
|
|
|
+ this->particles[0]->position.x, this->particles[0]->position.y,
|
|
|
+ 0xFF313131);
|
|
|
+ graphics::draw::fillCircle(this->anchor.x, this->anchor.y, 5, 0xFF001155);
|
|
|
+
|
|
|
+ for(auto part: this->particles)
|
|
|
+ {
|
|
|
+ graphics::draw::fillCircle(part->position.x, part->position.y, part->radius, 0xFFAA3300);
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
if (this->showForceSum || this->showVelocity || this->showAllForces)
|
|
|
{
|