//=================================================
//HighTide - Helper Functions
//Gos2 Test App
//
//Written by Matt Bronder
//Ported to GOS2 by Bob Crocco 8/2000
//=================================================
//------------------------------
//Macros & preproc defs
//------------------------------
#define M_PI        3.14159265359f
#define M_2PI       6.28318530718f
#define M_PIDIV2    1.57079632680f
#define M_3PIDIV2   4.71238898039f
#define M_PIDIV4    0.78539816340f
#define M_3PIDIV4   2.35619449019f
#define M_5PIDIV4   3.92699081699f
#define M_7PIDIV4   5.49778714378f

typedef float (* RADPROC)(float y, float fLength, LPVOID pvContext);

#define RND()       ((float)rand() / (float)RAND_MAX)

	/*
	* Format of RGB colors is
	*  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
	*  |    ignored    |      red      |     green     |     blue      |
	*  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
	*/
#define RGB_MAKE(r, g, b)       ((D3DCOLOR) (((r) << 16) | ((g) << 8) | (b)))
	/*
	* Format of RGBA colors is
	*  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
	*  |    alpha      |      red      |     green     |     blue      |
	*  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
	*/
#define RGBA_GETALPHA(rgb)      ((rgb) >> 24)
#define RGBA_GETRED(rgb)        (((rgb) >> 16) & 0xff)
#define RGBA_GETGREEN(rgb)      (((rgb) >> 8) & 0xff)
#define RGBA_GETBLUE(rgb)       ((rgb) & 0xff)
#define RGBA_MAKE(r, g, b, a)   ((D3DCOLOR) (((a) << 24) | ((r) << 16) | ((g) << 8) | (b)))


//------------------------------------
//Function Prototypes
//------------------------------------
void				GenerateBeachNormals(PHHVERTEX pr);
void				GenerateCliffNormals(PHHVERTEX pr);
static D3DXVECTOR3 SubtractVertex(PHHVERTEX pr1, PHHVERTEX pr2);
static D3DVECTOR SubtractVertexVector(VERTEX r1, VERTEX r2);
static void NormalizeVertexNormal(PVERTEX pr);
void				SetLight(D3DLIGHT8* plight, D3DLIGHTTYPE d3dlt,
                             D3DXVECTOR3 vPos, D3DXVECTOR3 vDir, 
                             D3DCOLOR cDiffuse, D3DCOLOR cSpecular,
                             D3DCOLOR cAmbient,
                             float fRange, float fFalloff, 
                             float fAttenuation0, float fAttenuation1, 
                             float fAttenuation2, float fTheta, 
                             float fPhi);
void SetMaterial(D3DMATERIAL8* pmaterial,
                       D3DCOLOR cDiffuse, D3DCOLOR cAmbient,
                       D3DCOLOR cSpecular, D3DCOLOR cEmissive,
                       float fPower);
void InitMatrix(D3DMATRIX* pd3dm,
                float _11, float _12, float _13, float _14,
                float _21, float _22, float _23, float _24,
                float _31, float _32, float _33, float _34,
                float _41, float _42, float _43, float _44);
BOOL CreateRevolution(PREVOLUTION prv, float fLength, UINT uSteps, 
                        UINT uRevolutions, RADPROC pfnRadius, LPVOID pvContext,
                        float fThreshold, BOOL bConvex, 
                        float fScaleU, float fScaleV); 
static void GetSteps(float fLength, UINT* puSteps, float* pfSteps,
                     RADPROC pfnRadius, LPVOID pvContext, float fThreshold); 

float BaseRadius(float y, float fHeight, LPVOID pvContext);
float BalconyRadius(float y, float fHeight, LPVOID pvContext);
float PortalRadius(float y, float fHeight, LPVOID pvContext);
float RoofRadius(float y, float fHeight, LPVOID pvContext);
float TrunkRadius(float y, float fHeight, LPVOID pvContext);
void ReleaseRevolution(PREVOLUTION prv);
void InitWaveSources(PWAVESOURCE pws);
void GenerateWaveNormals(PHHVERTEX pr, float* m_pfSqrtLookup);
void SetMaterialTranslucency(D3DMATERIAL8* pmaterial, float fAlpha);
float LightConeRadius(float y, float fHeight, LPVOID pvContext);
void SetSpotLight(D3DLIGHT8* plight, D3DXVECTOR3 vPos, 
                                D3DXVECTOR3 vDir, D3DCOLOR c, float fRange, 
                                float fFalloff, float fAttenuation0, 
                                float fAttenuation1, float fAttenuation2, 
                                float fTheta, float fPhi);