Utility.h 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. //
  2. // Utility.h
  3. // cocos2d_libs
  4. //
  5. // Created by 徐俊杰 on 2020/5/7.
  6. //
  7. #ifndef Utility_h
  8. #define Utility_h
  9. //#include "cocos2d.h"
  10. #include "rparticle/Macros/RParticleMacros.h"
  11. NS_RRP_BEGIN
  12. template <class T>
  13. inline T clamp (const T&t, const T& t0, const T& t1)
  14. {
  15. if (t < t0)
  16. return t0;
  17. else if (t > t1)
  18. return t1;
  19. else
  20. return t;
  21. }
  22. template <>
  23. inline float clamp (const float&t, const float& t0, const float& t1)
  24. {
  25. #if UNITY_XENON || UNITY_PS3
  26. return FloatMin(FloatMax(t, t0), t1);
  27. #else
  28. if (t < t0)
  29. return t0;
  30. else if (t > t1)
  31. return t1;
  32. else
  33. return t;
  34. #endif
  35. }
  36. template <class T>
  37. inline T clamp01 (const T& t)
  38. {
  39. if (t < 0)
  40. return 0;
  41. else if (t > 1)
  42. return 1;
  43. else
  44. return t;
  45. }
  46. template <>
  47. inline float clamp01<float> (const float& t)
  48. {
  49. #if UNITY_XENON || UNITY_PS3
  50. return FloatMin(FloatMax(t, 0.0f), 1.0f);
  51. #else
  52. if (t < 0.0F)
  53. return 0.0F;
  54. else if (t > 1.0F)
  55. return 1.0F;
  56. else
  57. return t;
  58. #endif
  59. }
  60. NS_RRP_END
  61. #endif /* Utility_h */