force.cpp 621 B

12345678910111213141516171819202122232425
  1. /*
  2. * 2D Physic Engine
  3. * force.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 17/06/2022.
  8. */
  9. #include <physics/force.h>
  10. vec2 force::generateDragForce(const particle &particleRef, double k)
  11. {
  12. vec2 dragForce;
  13. if (particleRef.velocity.magnitudeSquared() > 0)
  14. {
  15. vec2 dragDirection = particleRef.velocity.unitVector() * -1;
  16. double dragMagnitude = k * particleRef.velocity.magnitudeSquared();
  17. dragForce = dragDirection * dragMagnitude;
  18. }
  19. return dragForce;
  20. }