Main Page | Modules | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members

Fixed-Point math routines


Files

file  Fxp.h
 Function and macro definitions for fixed point math.

file  Fxp_trig.c
 Fixed-point trigenometry tables and routines.


Classes

class  Angle
 Class used to handle fixed-point angles. More...

class  SfxpCoord
 Class used to handle fixed-point x/y coordinates. More...


Fixed point integer definitions

#define SFXP_BITS   10
 Defines the number of bits precision of fixed point #s.

#define SFXP_SCALAR   (1<<SFXP_BITS)
 2^SFXP_BITS

#define TO_SFXP(x)   (((Sint32)(x))<<SFXP_BITS)
 Convert from integer to signed fixed point.

#define FROM_SFXP(x)   ((Sint32)((x+((SFXP_SCALAR>>1)))>>SFXP_BITS))
 Convert from signed fixed point to integer.

#define F_TO_SFXP(x)   ((Sfxp)((x)*SFXP_SCALAR))
 Convert from float to signed fixed point.

#define SFXP_TO_F(x)   ( ((FxpFloat)(x)) / ((FxpFloat)SFXP_SCALAR) )
 Convert from signed fixed point to floating point.

#define MUL_SFXP(x, y)   FROM_SFXP(((Sint64)(x))*((Sint64)(y)))
 Multiplies two signed fixed point numbers.

#define DIV_SFXP(x, y)   ((Sfxp)((TO_SFXP((Sint64)(x)))/y))
 Divides two signed fixed point numbers, x/y.

typedef Sint32 Sfxp
 Definition for the signed fixed-point type.


Fixed point angle definitions

#define AFXP_BITSIZE   (sizeof(Afxp)*8)
 # of bits in angle type

#define AFXP_MAX   (1<<AFXP_BITSIZE)
 Maximum value of angle type, 2^AFXP_BITSIZE.

#define AFXP_BITS   8
 Defines the bits precision in a fixed-point angle.

#define FXP_PI   3.14159f
 Any more digits than this would be superfluous.

#define DEG_TO_AFXP(x)   ((Afxp)((x)*( ((double)AFXP_MAX) /360.)))
 Convert degrees to fixed-point angles.

#define RAD_TO_AFXP(x)   DEG_TO_AFXP((x)*(180./3.14159))
 Convert radians to fixed point angles.

#define AFXP_TO_DEG(x)   ((x)*(360./AFXP_MAX))
 Convert fixed point angles to degrees.

typedef Uint16 Afxp
 Type definition for the fixed-point angular type.


Fixed Point Trigenometry

DECLSPEC void SDLCALL FXP_Init ()
 Initializes fixed-point trig tables.

DECLSPEC Sfxp SDLCALL FXP_Sin (Afxp a)
 Returns fixed-point sin value.

DECLSPEC Afxp SDLCALL FXP_Asin (Sfxp val)
 Returns fixed-point inverse-sin value.

DECLSPEC Sfxp SDLCALL FXP_Cos (Afxp a)
 Returns fixed-point cos value.

DECLSPEC Afxp SDLCALL FXP_Acos (Sfxp val)
 Returns fixed-point inverse-cos value.

DECLSPEC Sfxp SDLCALL FXP_Tan (Afxp a)
 Returns fixed-point tan value.

DECLSPEC Afxp SDLCALL FXP_Atan (Sfxp val)
 Returns fixed-point inverse-tan value.

DECLSPEC Afxp SDLCALL FXP_Traj (Sfxp y, Sfxp x)
 Returns the angle of the vector, valid at any angle.


Defines

#define TABLE_SIZE   2048
 # of elements in trig tables

#define TABLEPOS_TO_ANGLE(n)   ((Afxp)((AFXP_MAX*n)/TABLE_SIZE))
 Converts a table-index to an angle.

#define ANGLE_TO_TABLEPOS(a)   (((TABLE_SIZE*(int)a)/AFXP_MAX)%TABLE_SIZE)
 Converts an angle to a table pos.

#define AVERAGE(x, y)   ((x+y)/2)
 Returns average of two values.


Typedefs

typedef float FxpFloat
 The floating point type used converting to/from floating point.


Functions

int FindInTable (Sfxp val, int min, int max, const Sfxp table[TABLE_SIZE])
 Binary search for specified area, sorted in increasing order.

int FXP_DumpTrig (const char *fname)
 Prints contents of trig tables to a C file.


Variables

const Sfxp __SIN_TABLE []
 Table of sin values vs angle.

const Sfxp __COS_TABLE []
 Table of cos values vs angle.

const Sfxp __TAN_TABLE []
 Table of tan values vs angle.


Detailed Description

Contains routines and macros for platform-independent fixed-point math and triginometry.

Function Documentation

Afxp FXP_Traj Sfxp  y,
Sfxp  x
 

Unlike Tan, this returns the correct angle in the range from 0 to 360 degrees.

Definition at line 258 of file Fxp_trig.c.

References Afxp, DEG_TO_AFXP, DIV_SFXP, FXP_Atan(), and Sfxp.

Referenced by TestFxp(), and SfxpCoord::Trajectory().

Here is the call graph for this function:


Generated on Sat Oct 11 13:19:40 2003 for Spritelib by doxygen 1.3.4