/* * 2D Physic Engine * body.h: * Based on pikuma.com Learn Game Physics Engine Programming course. * Copyright (c) 2022 986-Studio. All rights reserved. * * Created by Manoƫl Trapier on 07/06/2022. */ #ifndef PHYSICENGINE_PHYSICS_BODY_H #define PHYSICENGINE_PHYSICS_BODY_H #include #include #include class body { public: vec2 position; vec2 acceleration; vec2 velocity; vec2 sum_of_forces; vec2 frame_sum; double mass; double invMass; double rotation; shape *shp; uint32_t colour; /* Only used for debug display */ std::vector forces; public: body(const shape &s, double x, double y, double mass) : position(x, y), mass(mass), rotation(0) { this->colour = 0xFFFFFFFF; this->shp = s.clone(); this->invMass = 0; if (mass != 0.0) { this->invMass = 1 / mass; } }; ~body() { delete this->shp; }; void setColour(uint32_t colour) { this->colour = colour; }; void clearForces() { this->sum_of_forces = vec2(0, 0); } void forceDebug(bool showVelocity, bool showSum, bool showAll); void addForce(const vec2 &force); void integrate(double dt); }; #endif /* PHYSICENGINE_PHYSICS_BODY_H */