#ifndef PI
#define PI	      3.14159265358979323846	// matches value in gcc v2 math.h
#define TWOPI     (PI * 2.0)
#define HALFPI    (PI / 2.0)
#endif

#define MAX_SURFACES  32
#define MAX_TEXTURES  50

#define TT_PLANAR        0
#define TT_CYLINDRICAL   1
#define TT_SPHERICAL     2

#define TA_X  0
#define TA_Y  1
#define TA_Z  2

enum
{
	SRFS,
	PNTS,
	POLS,
	SURF,
	UVIM,
	UVCV
};

typedef struct 
{
	short id;
	vec3_t	verts[3];
} lwtriangle_t;

// local structures for reading lwo files
// not used in daikatana
typedef struct
{
	short   id;
	short	p[3];
	short	surface;
} lwpoly_t;

typedef struct
{
	short   id;             // point order in lwo file
	float	v[3];
	int     s, t;           // texture coords
	float   uu, vv;           // uv coords from chunk
} lwpoint3d_t;

typedef struct 
{
	float   vv[3];
	int     lightnormalindex;
} lwtrivert_t;

typedef struct
{
	int            numverts;
	lwtrivert_t    *verts;
} lwframe_t;

typedef struct
{
	char		*name;
	int			textureType;
	int			textureAxis;
	char		*fileName;
	float		x_size, y_size, z_size;
	float		x_cent, y_cent, z_cent;
	lwpoint3d_t	*points;
	int			pointCount;
	lwpoly_t	*polys;
	int			polyCount;
	int			tWidth, tHeight;
	int			tCount;
	char		*tData[MAX_TEXTURES];
	int			numframes;
	lwframe_t	*frames;
	int			skip;
} surface_t;

int align (int len);
void LWO_OpenFile (char *filename, byte **start, byte **end);
void LWO_CloseFile (void);
void LWO_ReadSRFS (byte *buffer, int chunklength);
void LWO_ReadPNTS (byte *buffer, int chunklength);
void LWO_ReadPOLS (byte *buffer, int chunklength);
void LWO_ReadSURF (byte *buffer, int chunklength);
void LWO_ReadUVIM (byte *buffer, int chunklength);
void LWO_ReadUVCV (byte *buffer, int chunklength);
void LWO_LoadTextures (void);
void LWO_SurfacePolys (void);
void LWO_BuildST(void);
void LWO_SwapYZ(void);
void LWO_LoadPolys(lwtriangle_t **pptri, int *numtriangles);
