Maths.cpp 1.0 KB

1234567891011121314151617181920212223242526272829303132
  1. #include "Maths.h"
  2. using namespace WallpaperEngine::Maths;
  3. float WallpaperEngine::Maths::randomFloat (std::mt19937& rng, float min, float max) {
  4. if (max < min) {
  5. std::swap (min, max);
  6. }
  7. std::uniform_real_distribution<float> dist (min, max);
  8. return dist (rng);
  9. }
  10. glm::vec3 WallpaperEngine::Maths::randomVec3 (std::mt19937& rng, const glm::vec3& min, const glm::vec3& max) {
  11. return glm::vec3 (
  12. randomFloat (rng, min.x, max.x), randomFloat (rng, min.y, max.y), randomFloat (rng, min.z, max.z)
  13. );
  14. }
  15. // Helper: Linear interpolation
  16. float WallpaperEngine::Maths::lerp (float t, float a, float b) { return a + t * (b - a); }
  17. // Helper: Fade value change over lifetime
  18. float WallpaperEngine::Maths::fadeValue (float life, float startTime, float endTime, float startValue, float endValue) {
  19. if (life <= startTime) {
  20. return startValue;
  21. } else if (life >= endTime) {
  22. return endValue;
  23. } else {
  24. float t = (life - startTime) / (endTime - startTime);
  25. return lerp (t, startValue, endValue);
  26. }
  27. }