particle.h 905 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  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 <physics/vec2.h>
  12. class particle
  13. {
  14. public:
  15. uint16_t radius;
  16. vec2 position;
  17. vec2 acceleration;
  18. vec2 velocity;
  19. vec2 sum_of_forces;
  20. double mass;
  21. public:
  22. particle(double x, double y, double mass): radius(4), position(x, y), mass(mass) {};
  23. particle(double x, double y, double mass, double radius): radius(radius), position(x, y), mass(mass) {};
  24. ~particle() = default;
  25. void clearForces()
  26. {
  27. this->sum_of_forces = vec2(0, 0);
  28. }
  29. void addForce(const vec2 &force);
  30. void integrate(double dt);
  31. };
  32. #endif /* PHYSICENGINE_PHYSICS_PARTICLE_H */