mathutils.h
来自「Symbian s60 游戏编程示例」· C头文件 代码 · 共 117 行
H
117 行
#ifndef __MATH_UTILS_H
#define __MATH_UTILS_H
#include <e32math.h>
// __USE_TLS should be enabled if project is built as an APP (DLL)
// It should be disabled for an EXE
// #define __USE_TLS
//
// Static class of utils
//
/*
* Pregenerated sin and cos tables
*/
#include "sincostables.h"
/*
MathUtils - For when Math is just not fast enoug
*/
class MathUtils
{
public:
// Fast Square root
static TInt32 SquareRoot(TInt32 aNum);
// Distance between two integer points
static TInt Distance(const TPoint& aA, const TPoint& aB);
inline static TReal Sin(TReal aNumber);
inline static TReal Cos(TReal aNumber);
// Fast Cos for whole angles between 0 and 360
static inline TReal Cos(TInt aAngle);
// Fast Sin for whole angles between 0 and 360
static inline TReal Sin(TInt aAngle);
// Fast Cos for whole angles between 0 and 360
static void ConstructL();
static inline TInt Round(TReal aNumber);
inline static TInt Random(TInt aA, TInt aB);
// return x bounded between a and b
template<class T>
inline T Bound(T x, T a, T b);
static void Reset();
static TBool Intersect(TPoint l1p1, TPoint l1p2, TPoint l2p1, TPoint l2p2);
};
inline TReal MathUtils::Sin(TReal aNumber)
{
TReal result;
Math::Sin(result, aNumber);
return result;
}
inline TReal MathUtils::Cos(TReal aNumber)
{
TReal result;
Math::Cos(result, aNumber);
return result;
}
/*
Fast Cos for whole angles between 0 and 360
*/
inline TReal MathUtils::Cos(TInt aAngle)
{
return KCosLookup[aAngle%360];
}
/*
Fast Sin for whole angles between 0 and 360
*/
inline TReal MathUtils::Sin(TInt aAngle)
{
return KSinLookup[aAngle%360];
}
/*
Faster replacement for Math::Round
*/
inline TInt MathUtils::Round(TReal aNumber)
{
TInt whole = (TInt)aNumber;
TReal frac = aNumber-whole;
if(frac>=0.5)
return whole+1;
else
return whole;
}
// Random number between a and b
TInt MathUtils::Random(TInt aA, TInt aB)
{
if(aA == aB)
return aA;
return Math::Random()%(aB - aA) + aA;
}
// return x bounded between a and b
template<class T>
T MathUtils::Bound(T x, T a, T b)
{
if(x<a) x=0;
if(x>b) x=b;
return x;
}
#endif
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?