force.cpp 914 B

12345678910111213141516171819202122232425262728293031323334353637
  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. }
  21. vec2 force::generateFrictionForce(const particle &particleRef, double k)
  22. {
  23. vec2 frictionForce;
  24. vec2 frictionDirection = particleRef.velocity.unitVector() * -1;
  25. double frictionMagnitude = k;
  26. frictionForce = frictionDirection * frictionMagnitude;
  27. return frictionForce;
  28. }