axmol/cocos/math/CCMathBase.h

78 lines
2.9 KiB
C
Raw Normal View History

2019-11-23 20:27:39 +08:00
/****************************************************************************
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
2021-12-25 10:04:45 +08:00
2019-11-23 20:27:39 +08:00
http://www.cocos2d-x.org
2021-12-25 10:04:45 +08:00
2019-11-23 20:27:39 +08:00
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
2021-12-25 10:04:45 +08:00
2019-11-23 20:27:39 +08:00
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
2021-12-25 10:04:45 +08:00
2019-11-23 20:27:39 +08:00
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#ifndef __CCMATHBASE_H__
#define __CCMATHBASE_H__
#include <memory>
#include <string.h>
#include "platform/CCPlatformMacros.h"
/**
* @addtogroup base
* @{
*/
/**Util macro for conversion from degrees to radians.*/
2021-12-25 10:04:45 +08:00
#define MATH_DEG_TO_RAD(x) ((x)*0.0174532925f)
2019-11-23 20:27:39 +08:00
/**Util macro for conversion from radians to degrees.*/
2021-12-25 10:04:45 +08:00
#define MATH_RAD_TO_DEG(x) ((x)*57.29577951f)
2019-11-23 20:27:39 +08:00
/**
@{ Util macro for const float such as epsilon, small float and float precision tolerance.
*/
2021-12-25 10:04:45 +08:00
#define MATH_FLOAT_SMALL 1.0e-37f
#define MATH_TOLERANCE 2e-37f
#define MATH_PIOVER2 1.57079632679489661923f
#define MATH_EPSILON 0.000001f
2019-11-23 20:27:39 +08:00
/**@}*/
//#define MATH_PIOVER4 0.785398163397448309616f
//#define MATH_PIX2 6.28318530717958647693f
//#define MATH_E 2.71828182845904523536f
//#define MATH_LOG10E 0.4342944819032518f
//#define MATH_LOG2E 1.442695040888963387f
//#define MATH_PI 3.14159265358979323846f
2021-12-25 10:04:45 +08:00
//#define MATH_RANDOM_MINUS1_1() ((2.0f*((float)rand()/RAND_MAX))-1.0f) // Returns a random float between -1
//and 1. #define MATH_RANDOM_0_1() ((float)rand()/RAND_MAX) // Returns a random float
//between 0 and 1. #define MATH_CLAMP(x, lo, hi) ((x < lo) ? lo : ((x > hi) ? hi : x)) #ifndef M_1_PI #define
//M_1_PI 0.31830988618379067154
2019-11-23 20:27:39 +08:00
#ifdef __cplusplus
2021-12-25 10:04:45 +08:00
# define NS_CC_MATH_BEGIN \
namespace cocos2d \
{
# define NS_CC_MATH_END }
# define USING_NS_CC_MATH using namespace cocos2d
2019-11-23 20:27:39 +08:00
#else
2021-12-25 10:04:45 +08:00
# define NS_CC_MATH_BEGIN
# define NS_CC_MATH_END
# define USING_NS_CC_MATH
2019-11-23 20:27:39 +08:00
#endif
/**
* end of base group
* @}
*/
2021-12-25 10:04:45 +08:00
#endif // __CCMATHBASE_H__