particle.cpp 553 B

1234567891011121314151617181920212223242526
  1. /*
  2. * 2D Physic Engine
  3. * particules.cpp:
  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. #include <physics/particle.h>
  10. void particle::integrate(double dt)
  11. {
  12. this->acceleration = this->sum_of_forces * this->invMass;
  13. this->velocity += this->acceleration * dt;
  14. this->position += this->velocity * dt;
  15. this->clearForces();
  16. }
  17. void particle::addForce(const vec2 &force)
  18. {
  19. this->sum_of_forces += force;
  20. }