/*----------------------------------------------------------------
	Almost the simplest Shinobi Program in the world
	Thomas Szirtes / SEGA Europe
	COPYRIGHT (C) SEGA ENTERSRISES,LTD.

  ----------------------------------------------------------------*/

#include <Shinobi.h>

extern NJS_OBJECT object_test_cube_cube[];

extern NJS_MATRIX      matrix[128];
extern NJS_VERTEX_BUF  vbuf[4096];

NJS_TEXMEMLIST	tex[10];

NJS_VIEW		view;
NJS_LIGHT		light;

Angle			xx,yy,zz = NJM_DEG_ANG(0.f);

Int	i = 0;
Uint32	time;
long	poly,wpoly=0;
long	disp,wdisp=0;
long	frame,wframe=0;
long	count = 0;

float	tx,ty=0.f;

NJS_PERIPHERAL *per,*per1;
PDS_PERIPHERAL		*perpds;

void njUserInit(void)
{

    sbInitSystem            ( NJD_RESOLUTION_VGA, NJD_FRAMEBUFFER_MODE_RGB565, 1 );
	njInitVertexBuffer	( 500000, 0, 500000, 0 );
	njInitMatrix		( matrix, 128 , 1);
	njInit3D			( vbuf, 4096 );
	njInitView			( &view );
	njCreateLight		( &light, NJD_SPEC_DIR );
	njSetLightIntensity	( &light, 0.0f, 1.0f, 0.5f );
	njSetView			( &view );

	njClipZ				( -1.0f, -10000.f );
	njSetAspect			( 1.0f, 1.0f );

	njControl3D			( NJD_CONTROL_3D_CONSTANT_ATTR );
	njSetConstantAttr	( 0xffffffff, NJD_FILTER_BILINEAR );

}

Sint32 njUserMain(void)
{

	perpds = pdGetPeripheral(PDD_PORT_A0);

	njClearMatrix	();
	njTranslate		( NULL, tx, ty, -4.5f );
	njRotateXYZ		( NULL, xx, yy, zz );
	njDrawObject	( object_test_cube_cube );

	if (perpds->on & PDD_DGT_KL)	tx-=0.2f;
	if (perpds->on & PDD_DGT_KR)	tx+=0.2f;
	if (perpds->on & PDD_DGT_KU)	ty-=0.2f;
	if (perpds->on & PDD_DGT_KD)	ty+=0.2f;

	xx += NJM_DEG_ANG(2.0f);
	yy += NJM_DEG_ANG(1.0f);
	zz += NJM_DEG_ANG(1.5f);

	return NJD_USER_CONTINUE;
}

void njUserExit(void)
{
        sbExitSystem();
}