Math.cpp 873 B

12345678910111213141516171819202122232425262728293031323334353637
  1. #define _USE_MATH_DEFINES
  2. #include "Math.h"
  3. namespace TLAC::Utilities
  4. {
  5. float ToDegrees(float radians)
  6. {
  7. return radians * (180.0f / M_PI);
  8. }
  9. float ToRadians(float degrees)
  10. {
  11. return (degrees * M_PI) / 180.0f;
  12. }
  13. Vec2 GetDirection(float degrees)
  14. {
  15. float radians = ToRadians(degrees);
  16. return Vec2(cos(radians), sin(radians));
  17. }
  18. Vec2 PointFromAngle(float degrees, float distance)
  19. {
  20. float radians = ToRadians(degrees + 90.0f);
  21. return Vec2(-1 * std::cos(radians) * distance, -1 * std::sin(radians) * distance);
  22. }
  23. float AngleFromPoints(Vec2 p0, Vec2 p1)
  24. {
  25. return (float)(std::atan2(p1.Y - p0.Y, p1.X - p0.X) * 180.0 / M_PI) + 90.0f;
  26. }
  27. float ConvertRange(float originalStart, float originalEnd, float newStart, float newEnd, float value)
  28. {
  29. return newStart + ((value - originalStart) * (newEnd - newStart) / (originalEnd - originalStart));
  30. }
  31. }