home *** CD-ROM | disk | FTP | other *** search
- #ifndef __SWFIXED__
- #define __SWFIXED__
- //---------------------------------------------------------------------------------------
- // SWFixed - fixed point routines for SpriteWorld
- //---------------------------------------------------------------------------------------
- #ifndef __MACTYPES__
- #include <MacTypes.h>
- #endif
- #ifndef __ERRORS__
- #include <Errors.h>
- #endif
- #ifndef __Memory__
- #include <Memory.h>
- #endif
-
- typedef long SWFixed;
-
- // call this once before using trig functions (sin/cos)
- OSErr SWInitTrigTables(short numAngles);
-
- // Conversion macros
- SWFixed SW_FLOAT2FIX(float x);
- float SW_FIX2FLOAT(SWFixed x);
-
- SWFixed SW_INT2FIX(int x);
- int SW_FIX2INT(SWFixed x);
-
- // Trigonometry macros
- SWFixed SW_SIN(int x);
- SWFixed SW_COS(int x);
-
- //---------------------------------------------------------------------------------------
-
- #define SW_FIX_SHIFT 8 // a bit low, to avoid user causing overflows
-
- #define SW_FIX_MULT (1L << SW_FIX_SHIFT)
- #define SW_FIX_ROUND (SW_FIX_MULT-1)
-
- #define SW_FLOAT2FIX(x) ((x) * SW_FIX_MULT)
- #define SW_FIX2FLOAT(x) ((x) * (1.0 / SW_FIX_MULT))
-
- #define SW_INT2FIX(x) ((long)(x) << SW_FIX_SHIFT)
- #define SW_FIX2INT(x) ((x) >> SW_FIX_SHIFT)
-
- //---------------------------------------------------------------------------------------
-
- #define SW_NUMANGLES 360 // "normal" number of angles (degrees)
-
- extern long gSWNumAngles;
- extern SWFixed *gSWSinTable; // gSWSinTable[gSWNumAngles]
- extern SWFixed *gSWCosTable; // gSWCosTable[gSWNumAngles]
-
- #if SW_ASSERT_ON == 1
-
- #define SW_SIN(x) (gSWSinTable != NULL ? gSWSinTable[x % gSWNumAngles] : 0), \
- SW_ASSERT(gSWSinTable != NULL && x >= 0 && x < gSWNumAngles)
- #define SW_COS(x) (gSWCosTable != NULL ? gSWCosTable[x % gSWNumAngles] : 0), \
- SW_ASSERT(gSWCosTable != NULL && x >= 0 && x < gSWNumAngles)
- #else
- #define SW_SIN(x) (gSWSinTable[x])
- #define SW_COS(x) (gSWCosTable[x])
- #endif
-
- //---------------------------------------------------------------------------------------
- #endif /*__SWFIXED__*/
-