|
@@ -33,7 +33,7 @@ void application::setup()
|
|
|
this->millisecsPreviousFrame = SDL_GetTicks();
|
|
|
|
|
|
this->anchor = vec2(graphics::width() / 2.0,30);
|
|
|
- this->bodies.push_back(new body(circleShape(12), graphics::width() / 2.0, graphics::height() / 2.0,
|
|
|
+ this->bodies.push_back(new body(circleShape(50), graphics::width() / 2.0, graphics::height() / 2.0,
|
|
|
2.0));
|
|
|
}
|
|
|
|
|
@@ -161,9 +161,46 @@ void application::update()
|
|
|
this->anchor, this->restLenght, this->k);
|
|
|
this->bodies[0]->addForce(spring);
|
|
|
|
|
|
- for (auto part:this->bodies)
|
|
|
+ for (auto bod:this->bodies)
|
|
|
+ {
|
|
|
+ bod->integrate(deltaTime);
|
|
|
+ }
|
|
|
+
|
|
|
+ for (auto bod:this->bodies)
|
|
|
{
|
|
|
- part->integrate(deltaTime);
|
|
|
+ if (bod->shp->getType() == SHAPE_CIRCLE) {
|
|
|
+ // UGLY HACK
|
|
|
+ circleShape *shp = (circleShape *) bod->shp;
|
|
|
+ if (((bod->position.y - shp->radius) <= 0) ||
|
|
|
+ ((bod->position.y + shp->radius) >= graphics::height()))
|
|
|
+ {
|
|
|
+ if ((bod->position.y - shp->radius) <= 0)
|
|
|
+ {
|
|
|
+ bod->position.y = shp->radius;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ bod->position.y = graphics::height() - shp->radius;
|
|
|
+ }
|
|
|
+
|
|
|
+ bod->velocity.y = -bod->velocity.y;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (((bod->position.x - shp->radius) <= 0) ||
|
|
|
+ ((bod->position.x + shp->radius) >= graphics::width()))
|
|
|
+ {
|
|
|
+ if ((bod->position.x - shp->radius) <= 0)
|
|
|
+ {
|
|
|
+ bod->position.x = shp->radius;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ bod->position.x = graphics::width() - shp->radius;
|
|
|
+ }
|
|
|
+
|
|
|
+ bod->velocity.x = -bod->velocity.x;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
updateTime.stop();
|
|
@@ -185,12 +222,13 @@ void application::render()
|
|
|
0xFF313131);
|
|
|
graphics::draw::fillCircle(this->anchor.x, this->anchor.y, 5, 0xFF001155);
|
|
|
|
|
|
- /*
|
|
|
+
|
|
|
for(auto bod: this->bodies)
|
|
|
{
|
|
|
- graphics::draw::fillCircle(bod->position.x, bod->position.y, bod->radius, 0xFFAA3300);
|
|
|
+ bod->rotation += 0.01;
|
|
|
+ bod->shp->draw(*bod);
|
|
|
}
|
|
|
- */
|
|
|
+
|
|
|
|
|
|
for(auto bod: this->bodies)
|
|
|
{
|