diff options
author | Paul Oliver <contact@pauloliver.dev> | 2024-02-29 19:27:35 +0100 |
---|---|---|
committer | Paul Oliver <contact@pauloliver.dev> | 2024-02-29 19:27:49 +0100 |
commit | 17909d029c6a8872b2fddf4e171d7925bbbe9c5c (patch) | |
tree | cbb08af84cd68d24acc362d593a2048b0fa79689 /Simulation/Tank.cpp |
Diffstat (limited to 'Simulation/Tank.cpp')
-rw-r--r-- | Simulation/Tank.cpp | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/Simulation/Tank.cpp b/Simulation/Tank.cpp new file mode 100644 index 0000000..7d0c6d1 --- /dev/null +++ b/Simulation/Tank.cpp @@ -0,0 +1,52 @@ +#include "Tank.hpp" +#include "SimBase.hpp" + +void Tank::create(SimBase *sim) +{ + hSim = sim; + + // Prepare tank graphics + setCenterRad(worldEdges, hSim->prms.worldRad); + worldEdges.setPointCount(360); + worldEdges.setFillColor(hSim->prms.worldColor); + worldEdges.setOutlineColor(hSim->prms.zapperColor); + worldEdges.setOutlineThickness(hSim->prms.worldRad / 100.f); + + // Prepare tank physics + world.SetAllowSleeping(true); + contactListener.hSim = hSim; + world.SetContactListener(&contactListener); + + // Create edge of the world + b2BodyDef worldDef; + worldDef.type = b2_staticBody; + + tankEdge = world.CreateBody(&worldDef); + + b2ChainShape shape; + b2Vec2 vrtx[360]; + for (int dgr = 0; dgr < 360; ++dgr) + { + vrtx[dgr].Set(cosf((float)dgr / Params::RAD_DGRS), sinf((float)dgr / Params::RAD_DGRS)), + vrtx[dgr] *= hSim->prms.worldRad; + } + shape.CreateLoop(vrtx, 360); + + b2FixtureDef worldFix; + worldFix.shape = &shape; + worldFix.friction = 1.f; + + tankEdge->CreateFixture(&worldFix); +} + + +void Tank::updateAllPhysics() +{ + world.Step(1.f / 60.f, 8, 3); +} + + +void Tank::draw() +{ + hSim->window.draw(worldEdges); +} |