CCMathBase.h 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /****************************************************************************
  2. Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
  3. http://www.cocos2d-x.org
  4. Permission is hereby granted, free of charge, to any person obtaining a copy
  5. of this software and associated documentation files (the "Software"), to deal
  6. in the Software without restriction, including without limitation the rights
  7. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. copies of the Software, and to permit persons to whom the Software is
  9. furnished to do so, subject to the following conditions:
  10. The above copyright notice and this permission notice shall be included in
  11. all copies or substantial portions of the Software.
  12. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  13. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  14. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  15. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  16. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  17. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  18. THE SOFTWARE.
  19. ****************************************************************************/
  20. #ifndef __CCMATHBASE_H__
  21. #define __CCMATHBASE_H__
  22. #include <memory>
  23. #include <string.h>
  24. #include "platform/CCPlatformMacros.h"
  25. /**
  26. * @addtogroup base
  27. * @{
  28. */
  29. /**Util macro for conversion from degrees to radians.*/
  30. #define MATH_DEG_TO_RAD(x) ((x) * 0.0174532925f)
  31. /**Util macro for conversion from radians to degrees.*/
  32. #define MATH_RAD_TO_DEG(x) ((x)* 57.29577951f)
  33. /**
  34. @{ Util macro for const float such as epsilon, small float and float precision tolerance.
  35. */
  36. #define MATH_FLOAT_SMALL 1.0e-37f
  37. #define MATH_TOLERANCE 2e-37f
  38. #define MATH_PIOVER2 1.57079632679489661923f
  39. #define MATH_EPSILON 0.000001f
  40. /**@}*/
  41. //#define MATH_PIOVER4 0.785398163397448309616f
  42. //#define MATH_PIX2 6.28318530717958647693f
  43. //#define MATH_E 2.71828182845904523536f
  44. //#define MATH_LOG10E 0.4342944819032518f
  45. //#define MATH_LOG2E 1.442695040888963387f
  46. //#define MATH_PI 3.14159265358979323846f
  47. //#define MATH_RANDOM_MINUS1_1() ((2.0f*((float)rand()/RAND_MAX))-1.0f) // Returns a random float between -1 and 1.
  48. //#define MATH_RANDOM_0_1() ((float)rand()/RAND_MAX) // Returns a random float between 0 and 1.
  49. //#define MATH_CLAMP(x, lo, hi) ((x < lo) ? lo : ((x > hi) ? hi : x))
  50. //#ifndef M_1_PI
  51. //#define M_1_PI 0.31830988618379067154
  52. #ifdef __cplusplus
  53. #define NS_CC_MATH_BEGIN namespace cocos2d {
  54. #define NS_CC_MATH_END }
  55. #define USING_NS_CC_MATH using namespace cocos2d
  56. #else
  57. #define NS_CC_MATH_BEGIN
  58. #define NS_CC_MATH_END
  59. #define USING_NS_CC_MATH
  60. #endif
  61. /**
  62. * end of base group
  63. * @}
  64. */
  65. #endif // __CCMATHBASE_H__