CCMathBase.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /****************************************************************************
  2. Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
  3. http://www.cocos.com
  4. Permission is hereby granted, free of charge, to any person obtaining a copy
  5. of this software and associated engine source code (the "Software"), a limited,
  6. worldwide, royalty-free, non-assignable, revocable and non-exclusive license
  7. to use Cocos Creator solely to develop games on your target platforms. You shall
  8. not use Cocos Creator software for developing other software or tools that's
  9. used for developing games. You are not granted to publish, distribute,
  10. sublicense, and/or sell copies of Cocos Creator.
  11. The software or tools in this License Agreement are licensed, not sold.
  12. Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
  13. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  14. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  15. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  16. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  17. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  18. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  19. THE SOFTWARE.
  20. ****************************************************************************/
  21. #ifndef __CCMATHBASE_H__
  22. #define __CCMATHBASE_H__
  23. #include <memory>
  24. #include <string.h>
  25. #include "base/ccMacros.h"
  26. /**
  27. * @addtogroup base
  28. * @{
  29. */
  30. /**Util macro for conversion from degrees to radians.*/
  31. #define MATH_DEG_TO_RAD(x) ((x) * 0.0174532925f)
  32. /**Util macro for conversion from radians to degrees.*/
  33. #define MATH_RAD_TO_DEG(x) ((x)* 57.29577951f)
  34. /**
  35. @{ Util macro for const float such as epsilon, small float and float precision tolerance.
  36. */
  37. #define MATH_FLOAT_SMALL 1.0e-37f
  38. #define MATH_TOLERANCE 2e-37f
  39. #define MATH_PIOVER2 1.57079632679489661923f
  40. #define MATH_EPSILON 0.000001f
  41. /**@}*/
  42. //#define MATH_PIOVER4 0.785398163397448309616f
  43. //#define MATH_PIX2 6.28318530717958647693f
  44. //#define MATH_E 2.71828182845904523536f
  45. //#define MATH_LOG10E 0.4342944819032518f
  46. //#define MATH_LOG2E 1.442695040888963387f
  47. //#define MATH_PI 3.14159265358979323846f
  48. //#define MATH_RANDOM_MINUS1_1() ((2.0f*((float)rand()/RAND_MAX))-1.0f) // Returns a random float between -1 and 1.
  49. //#define MATH_RANDOM_0_1() ((float)rand()/RAND_MAX) // Returns a random float between 0 and 1.
  50. //#define MATH_CLAMP(x, lo, hi) ((x < lo) ? lo : ((x > hi) ? hi : x))
  51. //#ifndef M_1_PI
  52. //#define M_1_PI 0.31830988618379067154
  53. #ifdef __cplusplus
  54. #define NS_CC_MATH_BEGIN namespace cocos2d {
  55. #define NS_CC_MATH_END }
  56. #define USING_NS_CC_MATH using namespace cocos2d
  57. #else
  58. #define NS_CC_MATH_BEGIN
  59. #define NS_CC_MATH_END
  60. #define USING_NS_CC_MATH
  61. #endif
  62. /**
  63. * end of base group
  64. * @}
  65. */
  66. #endif // __CCMATHBASE_H__