/*****************************************************************************
  Name : SGLTools.h
  Date : July 1998
  Platform : ANSI compatible
 
  Description : Header file of Tools library for SGL (SGLTools.lib).
				Contains structure definitions and prototypes 
				of all functions in the library.
  
  Copyright : 1998 by VideoLogic Limited. All rights reserved.
******************************************************************************/
#ifndef _SGLTOOLS_H_
#define _SGLTOOLS_H_

#define _KM_USE_VERTEX_MACRO_L3_

#include	"kamui.h"		/* for Kamui Call */
#include	"kamuix.h"		/* for Kamui Call */

#include <math.h>
#include <stdio.h>
#include <stdarg.h>

#ifdef __cplusplus
extern "C" {
#endif

typedef float km_vector[3];

/************
** Defines **
************/
#ifndef PI
#define PI 3.14159f
#endif

/* Colour macros */
#define MAKE_RGB(R,G,B)		((DWORD)( ((R)<<16) | ((G)<<8) | (B) ))
#define MAKE_RGBA(R,G,B,A)	((DWORD)( ((A)<<24) | ((R)<<16) | ((G)<<8) | (B) ))
#define GET_ALPHA(Colour)	((BYTE)( (Colour & 0xFF000000)>>24 ))
#define GET_RED(Colour)		((BYTE)( (Colour & 0x00FF0000)>>16 ))
#define GET_GREEN(Colour)	((BYTE)( (Colour & 0x0000FF00)>>8 ))
#define GET_BLUE(Colour)	((BYTE)  (Colour & 0x000000FF))

#define UINT32 unsigned long
#define UINT8  unsigned char


/*************
** Typedefs **
*************/
/* MATRIX type */
typedef struct _MATRIX {
    float _11, _12, _13, _14;
    float _21, _22, _23, _24;
    float _31, _32, _33, _34;
    float _41, _42, _43, _44;
} MATRIX, *LPMATRIX;


/* BOUNDINGBOX type */
typedef struct BoundingBoxTAG
{
	km_vector	Point[8];
} BOUNDINGBOX, LPBOUNDINGBOX;


/***************
** Prototypes **
***************/
/* From KMMatrix.c */
void	KMMatrixReset(MATRIX *pMatrix);
void	KMMatrixMultiply(MATRIX *pResultMatrix, const MATRIX *pMatrixA, const MATRIX *pMatrixB);
void	KMMatrixTranslate(MATRIX *pMatrix, const float fX, const float fY, const float fZ);
void	KMMatrixScale(MATRIX *pMatrix, const float fFactor);
void	KMMatrixRotate(MATRIX *pMatrix, const float fXAngle, const float fYAngle, const float fZAngle);
void	KMMatrixInverse(MATRIX *pMatrix);
void	KMMatrixCopy(MATRIX *pDstMatrix, const MATRIX *pSrcMatrix);
float	KMMatrixDotProduct(const km_vector VectorA, const km_vector VectorB);
void	KMMatrixCrossProduct(km_vector ResultVector, const km_vector VectorA, const km_vector VectorB);
void	KMMatrixNormalize(km_vector Vector);

/* From KMTrans.c */
void	KMTransComputeBoundingBox(const int nNumberOfVertices, const float *pVertex, BOUNDINGBOX *pBoundingBox);
BOOL	KMTransIsBoundingBoxVisible(const MATRIX *pWorldMatrix, const BOUNDINGBOX *pBoundingBox, 
							 const km_vector CamFrom, const km_vector CamTo, const float fRoll,
							 const float D, const float F, const float fViewAngle,
							 BOOL *pNeedsZClipping);
void	KMTransTransformVertices(const MATRIX *pWorldMatrix, 
						  const int nNumberOfVertices, const float *pVertex, float *pTransformedVertex);
void	KMTransTransformProjectVertices(MATRIX *pWorldMatrix, 
								 int nNumberOfVertices, float *pVertex, KMVERTEX_03 *pTLVertex,
								 const km_vector CamFrom, const km_vector CamTo, const float fRoll,
								 const float D, const float F, const float fViewAngle);
void	KMTransPerspectiveVertices(const int nNumberOfVertices, KMVERTEX_03 *pTLVertex,
							const int nViewportWidth, const int nViewportHeight,
							const float D, const float F, const float fViewAngle);
int	    KMTransTransformProjectPerspective(MATRIX *pWorldMatrix, 
											int nNumberOfVertices, float *pVertex, KMVERTEX_03 *pTLVertex,
											int nViewportWidth, int nViewportHeight,
											const km_vector CamFrom, const km_vector CamTo, const float fRoll,
											const float D, const float F, const float fViewAngle);
void	KMTransZClipProjectedVertices(int nNumberOfVertices, KMVERTEX_03 *pTLVertex,
			  				   int nNumberOfTriangles, int *pTriangleList, int *pNumberOfVisibleTriangles,
							   const float D, const float F, const float fViewAngle);

/* From KMLight.c */
void KMLightSmoothShade(MATRIX *pMatrix, 
				 int nNumberOfVertices, float *pNormals, KMVERTEX_03 *pTLVertex, 
				 km_vector LightVector, DWORD dwLightColour, int bUseSpecular);



/* From KMTimer.c */
double	KMTimerGetFPS (void);

/* From KMTexture.c */
KMDWORD KMTextureLoad(KMSURFACEDESC *pTexSurfaceDesc, unsigned long *pSourceTex,
					KMINT32 Size, KMTEXTURETYPE nTextureType);


/* From KMABCTable.c */
KMDWORD KMABCTableInit (int IsTranslucent);
void	KMABCTablePrint3D (float XPos, float YPos, float fScale, int Color,char *Format, ...);
void	KMABCTableRelease (void);

/* From KMBump.c */
void KMBumpShade(MATRIX *pMatrix, 
				 unsigned nNumberOfVertices, float *pBumpCoords, float *pNormals,
				 KMVERTEX_03 *pTLVertexBump, KMVERTEX_03 *pTLVertexObject,
				 km_vector LightVector);

void KMBumpCalculateLocalCoords (unsigned nNumberOfVertices, float *pNormals, float *pBumpCoords,
							   unsigned nNumFaces, unsigned short *pFaces, float *pVertex, float *pUV);

/* From KMMisc.c */
long		KMMiscRand					(void);
void		KMMiscSeedRand				(unsigned long Seed);


#ifdef __cplusplus
}
#endif


#endif

