⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 imath.h

📁 liu7788414
💻 H
字号:
/*
* ============================================================================
*  Name     : Math from Math.h
*  Part of  : Game
*  Created  : 2004-09-17 by Chen Yong
*  Description:
*     Declares inter math class.
*     Modifyed from the interger math class form highgear.
*     Declares the global function and do not use the class.
*
*  Version  :
*  Copyright: Gameloft S.A.
* ============================================================================
*/

#ifndef _IMATH_H_
#define _IMATH_H_

//==============================================================================//
//              define 
//==============================================================================//

const int HALFSHIFT = 4;
const int SHIFT = 8;
const int SHIFT2 = 16;
const int SHIFTVALUE = 1<<SHIFT;
const int SHIFT2VALUE = 1<<SHIFT2;
const int SHIFTMASK = SHIFTVALUE-1;

const int RECIPBIT = 22;
const int RECIPBITSHIFT = RECIPBIT-SHIFT;
const int RECIPBITSHIFT2 = RECIPBIT-SHIFT2;
const int RECIPVALUE = 1<<RECIPBIT;
const int RECIPSHIFTVALUE = 1<<RECIPBITSHIFT;
const int RECIPSHIFT2VALUE = 1<<RECIPBITSHIFT2;

const int ZBUFFERBIT = 17;
const int ZBUFFERVALUE = 1<<ZBUFFERBIT;

#define RCOLOR(x)	((x)>>11<<3)
#define GCOLOR(x)	(((x)&0x07e0)>>3)
#define BCOLOR(x)	(((x)&0x001f)<<3)
#define HALFCOLORMASK	0x7BEF
#define MAKERGB(x, y, z)	((unsigned short)((x>>3<<11)|(y>>2<<5)|(z>>3)))

#define FP_FRAC_BITS       12
#define FP_MAX_VALUE       0x7fffffff
#define FP_ONE             4096
#define FP_HALF            2048
#define FP_NEG_ONE         -4096
#define FP_TWO             8192
#define FP_NEG_TWO         -8192
#define FP_EPSILON         0x00000001
#define FIX_SHIFT 10 //shift count for fixed point numbers
#define INT2FIX(x) ((x) << FIX_SHIFT)
#define FIX2INT(x) ((x) >> FIX_SHIFT)

// Matrix and trigonometric calculations using integers

#define PI 3.14159265358979323846f               // floating point pi value

#define ANGLE2PI 2048                            // equivalent to 2*PI, must be power of 2
#define PGL_PI (ANGLE2PI>>1)
#define ANGLEMASK (ANGLE2PI-1)                   // angle mask use to acces trigonometric tables

#define ATAN_SIZE 512ul                            // PI/4 precalculated array of atan(x)*ANGLE2PI

#define HALF_PRECISION 8192
#define COS_SIN_SHIFT 14                         // shifted 2^n value for sinus/cosinus result
#define COS_SIN_MUL (1 << COS_SIN_SHIFT)         // sinus/cosinus max value (==1)
#define DownShift16(x) (((x)+0x7FFF) >> 16)
#define DownShift8(x) (((x)+0x7F) >> 8)


extern const int TSIN[ANGLE2PI];               // sinus table

inline int Sinus(int a) {return TSIN[a & ANGLEMASK];}
inline int Cosinus(int a) {return TSIN[ (a + (ANGLE2PI>>2)) & ANGLEMASK]; }

inline void Rotate(int sx, int sy, int &dx, int &dy, int degree)
{
		dx = (sx * Cosinus(degree) - sy * Sinus(degree)) >> COS_SIN_SHIFT;
		dy = (sx * Sinus(degree) + sy * Cosinus(degree)) >> COS_SIN_SHIFT;
}

//inline static int DownShift16(const int x) {return (x + 0x7FFF) >> 16;}
//inline static int DownShift8 (const int x) {return (x + 0x7F  ) >>  8;}
//template<int K> inline static int DownShift(const int x) {return (x + ((1<<K-1)-1)) >> K;}

#define DownShift16(x) (((x)+0x7FFF) >> 16)
#define DownShift8(x) (((x)+0x7F) >> 8)
//template<int K> inline static int DownShift(const int x) {return (x + ((1<<K-1)-1)) >> K;}

inline int Abs(int a)
{
    return a > 0 ? a : -a;
}

inline int Max(int a, int b)
{
    return a > b ? a : b;
}

inline int Min(int a, int b)
{
    return a < b ? a : b;
}

// usefull functions
int Log2(int a);

//int GetYOrient(const Vector4s *Src,const Vector4s *Dest);
//int GetXOrient(const Vector4s *Src,const Vector4s *Dest);
int AngleDiff(int SrcAngle, int TargetAngle);

int GetFovFromXAngle(int in_nXAngle);
int GetFovFromYAngle(int in_nYAngle);
int GetXAngleFromFov(int in_nFov);
int GetYAngleFromFov(int in_nFov);

int Atan2i(int x, int y);


int fMul( int a, int b );
int fDiv( int a, int b );

/////////////Milo 09-28
int convertInto2048(int x, int y, int angle);
int sqrt(int value);
int getSign(int value);
int _rand(int, int);
int getRandomNumber(int range );
int distanceP2P(int x1, int y1, int x2, int y2);
int distanceP2P(int x1, int y1, int z1,int x2, int y2, int z2);
int distanceP2L(int x1, int y1, int x2, int y2, int xp, int yp);





	

	


	

































#endif // _IMATH_H_

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -