123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- /*
- * 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 <vector>
- #include <physics/vec2.h>
- #include <physics/shape.h>
- 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<vec2> 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 */
|