#include xray

// export table
export rotate_init;
export rotate_process;
export energy_init;
export energy_process;
export sky_init;
export sky_process;
export sky2_init;
export sky2_process;
export fire12345_init;
export fire12345_process;

//***********************************************************************
// Rotation
//***********************************************************************
#define SCROLL_SPEED	0.2
#define ROTATE_SPEED	0.05
#define ROTATE_DIST		2.0

void rotate_init(Fmatrix *pM)
{
	xrIdentity(pM);
}
void rotate_process(float *p)
{
	float add;

	add = fTimeDelta * ROTATE_SPEED;
	p[8] = p[8]+add;
	p[9] = p[9]+add;
}

//***********************************************************************
#define ENERGY_SPEED	0.30
void energy_init(Fmatrix *pM)
{
	xrIdentity(pM);
}
void energy_process(float *p)
{
	float add;

	add = fTimeDelta * ENERGY_SPEED;
	p[8] = p[8]+add;
	p[9] = p[9]+add;
}

//***********************************************************************
#define FIRE_SPEED	0.005

float	fire_time;
int	fire_frame;

void fire12345_init(Fmatrix *pM)
{
	xrIdentity(pM);
	fire_time	= FIRE_SPEED;
	fire_frame	= xrRand()%8; 
}
void fire12345_process(float *p)
{
	float	tmp;

	fire_time	-= fTimeDelta;
	if (fire_time<0) 
	{
		// change frame
		fire_frame++;
		if (fire_frame>15) 
			fire_frame=0; 
		tmp = (float) (fire_frame%8);
		p[8] = tmp*0.125;			// U
		tmp = (float) (fire_frame/8);
		p[9] = tmp*0.5;				// V
		fire_time += FIRE_SPEED;
	}
}
//***********************************************************************
/*
int rot_angle = 0;
void rotate_init(Fmatrix *pM)
{
	xrIdentity(pM);
}
void rotate_process(float *p, double fDeltaTime)
{
	rot_angle += fDeltaTime * ROTATE_SPEED;
	p[8] = sin(rot_angle)*ROTATE_DIST;
	p[9] = cos(rot_angle)*ROTATE_DIST;
}
*/

//***********************************************************************
// Rotation
//***********************************************************************
#define SKY_SPEED	0.01
#define SKY_SPEED2	0.03

void sky_init(Fmatrix *pM)
{
	xrIdentity(pM);
}
void sky_process(float *p)
{
	float add;

	add = fTimeDelta * SKY_SPEED;
	p[8] = p[8]+add;
	p[9] = p[9]+add;
}

void sky2_init(Fmatrix *pM)
{
	float *ptr;
	xrIdentity(pM);

	ptr = pM;
	ptr[8] = 0.5;
	ptr[9] = 0.3;
}
void sky2_process(float *p)
{
	float add;

	add = fTimeDelta * SKY_SPEED2;
	p[8] = p[8]+add*0.9;
	p[9] = p[9]+add;
}

