particle.h 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*
  2. * 2D Physic Engine
  3. * particle.h:
  4. * Based on pikuma.com Learn Game Physics Engine Programming course.
  5. * Copyright (c) 2022 986-Studio. All rights reserved.
  6. *
  7. * Created by Manoël Trapier on 07/06/2022.
  8. */
  9. #ifndef PHYSICENGINE_PHYSICS_PARTICLE_H
  10. #define PHYSICENGINE_PHYSICS_PARTICLE_H
  11. #include <vector>
  12. #include <physics/vec2.h>
  13. class particle
  14. {
  15. public:
  16. double radius;
  17. vec2 position;
  18. vec2 acceleration;
  19. vec2 velocity;
  20. vec2 sum_of_forces;
  21. vec2 frame_sum;
  22. double mass;
  23. double invMass;
  24. /* Only used for debug display */
  25. std::vector<vec2> forces;
  26. public:
  27. particle(double x, double y, double mass, double radius = 4.0): radius(radius), position(x, y),
  28. mass(mass)
  29. {
  30. this->invMass = 0;
  31. if (mass != 0.0)
  32. {
  33. this->invMass = 1 / mass;
  34. }
  35. };
  36. ~particle() = default;
  37. void clearForces()
  38. {
  39. this->sum_of_forces = vec2(0, 0);
  40. }
  41. void forceDebug(bool showVelocity, bool showSum, bool showAll);
  42. void addForce(const vec2 &force);
  43. void integrate(double dt);
  44. };
  45. #endif /* PHYSICENGINE_PHYSICS_PARTICLE_H */