particle.h 1023 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. double invMass;
  22. public:
  23. particle(double x, double y, double mass, double radius = 4.0): radius(radius), position(x, y),
  24. mass(mass)
  25. {
  26. this->invMass = 0;
  27. if (mass != 0.0)
  28. {
  29. this->invMass = 1 / mass;
  30. }
  31. };
  32. ~particle() = default;
  33. void clearForces()
  34. {
  35. this->sum_of_forces = vec2(0, 0);
  36. }
  37. void addForce(const vec2 &force);
  38. void integrate(double dt);
  39. };
  40. #endif /* PHYSICENGINE_PHYSICS_PARTICLE_H */