Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
 
 
 

50 rindas
1.2 KiB

  1. //
  2. // Lol Engine
  3. //
  4. // Copyright: (c) 2010-2013 Sam Hocevar <sam@hocevar.net>
  5. // This program is free software; you can redistribute it and/or
  6. // modify it under the terms of the Do What The Fuck You Want To
  7. // Public License, Version 2, as published by Sam Hocevar. See
  8. // http://www.wtfpl.net/ for more details.
  9. //
  10. //
  11. // The Matrix classes
  12. // ------------------
  13. //
  14. #if !defined __LOL_NUMERIC_H__
  15. #define __LOL_NUMERIC_H__
  16. #include <cstdlib>
  17. #include <stdint.h>
  18. namespace lol
  19. {
  20. /* Next power of two. */
  21. template <typename T> static inline T PotUp(T val)
  22. {
  23. val = val - 1;
  24. if (sizeof(val) > 4) val = val | ((uint64_t)val >> 32);
  25. if (sizeof(val) > 2) val = val | ((uint64_t)val >> 16);
  26. if (sizeof(val) > 1) val = val | ((uint64_t)val >> 8);
  27. val = val | ((uint64_t)val >> 4);
  28. val = val | ((uint64_t)val >> 2);
  29. val = val | ((uint64_t)val >> 1);
  30. return val + 1;
  31. }
  32. //Damp for float
  33. template <typename T1, typename T2, typename Tf> static inline T1 damp(const T1 &a, const T2 &b, const Tf &x, const Tf &dt)
  34. {
  35. if (dt <= .0f)
  36. return a;
  37. return lol::lerp(a, b, dt / (dt + x));
  38. }
  39. } /* namespace lol */
  40. #endif // __LOL_NUMERIC_H__