// CubeSlide.vtx
// Author - MrC
// Based on CubeSlide.r4 by Gordon Williams

Texture env;
Texture skybox;

int x,y;
float tm,tn,ofs,c;

void Init()
{
	skybox.LoadTexture("skybox.dds");
	env.LoadTexture("tex_edge.png");
}

void reset()
{
   tm = 0;
   tn = 0;
}

float tiltfunc(float p)
{
   return (Sin((ofs+p)*0.1)+Cos((ofs+p)*0.123))*10.0;
}

void Render()
{
	tm = tm + 1 * TIMEPASS * 8;

	if (TREBLE > 0.0)
		tm = tm + ((TREBLE) * TIMEPASS * 20);

	while (tm>1)
	{
		tm = tm-1;
		ofs = ofs + 1;
	}

	tn = tn + ((BASS+1.5)*TIMEPASS);


	gfxSetAspect(0);
	gfxLookAt(Cos(tn*1.23)*5,Sin(tn)*5,(tm*2)-1,Cos(tn*0.6734)*2,Sin(tn*0.2143)*2,(tm*2)+8,0,1,0);   
	gfxRotate(-tiltfunc(0)*tm,0,0,1);

	gfxSetTexture(skybox);
	gfxPushMatrix();
	gfxTranslate(0,0,tm*2);
	gfxRotate(tiltfunc(0)*tm,0,0,1);
	gfxCube(-400,-400,-400,400,400,400);
	gfxPopMatrix();
	gfxSetTexture(env);

	gfxSetBlendMode(BLEND_ADD);

	for (y=0;y<15;y=y+1)
	{
		c = 1.0 - ((y-tm)/15.0);      
		for (x=-3;x<4;x=x+1)
		{
			gfxColour(c,c,c,1);
			gfxCube((x*2)-0.75,-0.375,(y*2)-0.75, (x*2)+0.75,0.375,(y*2)+0.75);
		}
		gfxRotate(tiltfunc(y),0,0,1);
	}
   
}