12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- /*
- * 2D Physic Engine
- * particle.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_PARTICLE_H
- #define PHYSICENGINE_PHYSICS_PARTICLE_H
- #include <vector>
- #include <physics/vec2.h>
- class particle
- {
- public:
- double radius;
- vec2 position;
- vec2 acceleration;
- vec2 velocity;
- vec2 sum_of_forces;
- vec2 frame_sum;
- double mass;
- double invMass;
- /* Only used for debug display */
- std::vector<vec2> forces;
- public:
- particle(double x, double y, double mass, double radius = 4.0): radius(radius), position(x, y),
- mass(mass)
- {
- this->invMass = 0;
- if (mass != 0.0)
- {
- this->invMass = 1 / mass;
- }
- };
- ~particle() = default;
- 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_PARTICLE_H */
|