/*---------------------------------------------------------------------------
  Shinobi Sample
  COPYRIGHT (C) SEGA ENTERPRISES, LTD.
---------------------------------------------------------------------------*/

#include	<shinobi.h>
#include	<ninja.h>
#include	"Nj.h"

extern NJS_CNK_OBJECT object_t_Teapot01_Teapot01[];
extern Uint32 TPTEX[];

NJS_TEXNAME texname;
NJS_TEXLIST texlist = { &texname, 1 };

void *pDirect;

NJS_VECTOR lt = {  0.6f, -0.5f, -0.7f };

/*---------------------------------------------------------------------------
		初期化
		initialize
---------------------------------------------------------------------------*/
Sint32	UserInit(void)
{
	njPrintSize(12);
	
	njSetTextureName( &texname, &TPTEX, 0, NJD_TEXATTR_TYPE_MEMORY | NJD_TEXATTR_GLOBALINDEX );
	if(nuLoadTexture( &texlist ) < 0){
		return USER_EXIT;
	}
	njSetTexture( &texlist );
	njSetTextureNum( 0 );
	
	njCnkIntensityLoadTexture();
	njCnkIntensityLightInit( 1 );
	njCnkSetIntensityLightDiffColor( 1.0f, 1.0f, 1.0f );
	njCnkSetIntensityLightSpecColor( 1.0f, 1.0f, 1.0f );
	njCnkSetIntensityLightOffset( 0.0f, 0.0f );
	njCnkSetIntensityLightMode( NJD_CNK_INTENSITY_LIGHT_0, NJD_CNK_INTENSITY_MODE_DIR );
	njCnkSetIntensityLightSwitch( NJD_CNK_INTENSITY_LIGHT_0, ON );
	njCnkSetIntensityLightExp( NJD_CNK_INTENSITY_LIGHT_0, NJD_CNK_INTENSITY_EXP_32 );
	njCnkSetIntensityLightSet( NJD_CNK_INTENSITY_LIGHT_0, 1.1f, 1.0f );
	
	njCnkSetEasyMultiLight( 1 );
	njCnkSetEasyMultiAmbient( 0.f, 0.f, 0.f );
	njCnkSetEasyMultiLightSwitch( NJD_CNK_EASY_MULTILIGHT_1, ON );
	njCnkSetEasyMultiLightColor( NJD_CNK_EASY_MULTILIGHT_1, 1.f, 1.f, 1.f );
	
	njCnkSetSimpleMultiLight( 1 );
	njCnkSetSimpleMultiAmbient( 0.f, 0.f, 0.f );
	njCnkSetSimpleMultiLightSwitch( NJD_CNK_SIMPLE_MULTILIGHT_1, ON );
	njCnkSetSimpleMultiLightColor( NJD_CNK_SIMPLE_MULTILIGHT_1, 1.f, 1.f, 1.f );
	
	njCnkSetToonLightIntensity( 0.8f, 0.0f );
	njCnkSetToonShade( 0xfff0f0f0, 0xff202020 );
	
	njCnkSetShadowTexRatio( 6.f, 4.f );
	njCnkSetUvScroll( 0.f,0.f );
	
	njCnkSetEasyLightColor( 1.0f, 1.0f, 1.0f );
	njCnkSetEasyLightIntensity( 1.1f, 0.0f );
	
	njCnkSetSimpleLightColor( 1.0f, 1.0f, 1.0f );
	njCnkSetSimpleLightIntensity( 1.05f, 0.0f );
	
	njSetDirectLightIntensity( 1.1f, 0.0f );
	njSetDirectLightColor( 1.f, 1.f, 1.f );
	
	if((pDirect = syMalloc( njCnkDirectObjectCompileSize( object_t_Teapot01_Teapot01 )) )  == NULL){
		return USER_EXIT;
	}
	njCnkDirectObjectCompile( object_t_Teapot01_Teapot01, pDirect );
	njSetDirectClip();
	
	
	njControl3D( NJD_CONTROL_3D_CNK_CONSTANT_ATTR );
	njSetConstantAttr( 0xffffffff, NJD_FST_ENV );
	
	return USER_CONTINUE;
}
/*---------------------------------------------------------------------------
		終了処理
		exit
---------------------------------------------------------------------------*/
Sint32	UserExit(void)
{
	syFree( pDirect );
	
	njReleaseTexture( &texlist );
	njCnkIntensityReleaseTexture();
	
	return USER_CONTINUE;
}
/*---------------------------------------------------------------------------
		メイン
		main
---------------------------------------------------------------------------*/
Sint32	UserMain(void)
{
	static Float rx=8.f,ry=6.f,rz=-38.f;
	static Angle xx,yy,zz;
	static Sint32 fl = 0;
	
	if (Per->on & PDD_DGT_TL) lt.z += 0.05f;
	if (Per->on & PDD_DGT_TR) lt.z -= 0.05f;
	if (Per->on & PDD_DGT_KU) lt.y -= 0.05f;
	if (Per->on & PDD_DGT_KD) lt.y += 0.05f;
	if (Per->on & PDD_DGT_KL) lt.x += 0.05f;
	if (Per->on & PDD_DGT_KR) lt.x -= 0.05f;
	if (Per->press & PDD_DGT_TA) fl = 1 - fl;
	
	njUnitVector( &lt );
	
	njCnkSetIntensityLightVector( NJD_CNK_INTENSITY_LIGHT_0, lt.x, lt.y, lt.z );
	njCnkSetEasyMultiLightVectorEx( NJD_CNK_EASY_MULTILIGHT_1, lt.x, lt.y, lt.z );
	njCnkSetSimpleMultiLightVectorEx( NJD_CNK_EASY_MULTILIGHT_1, lt.x, lt.y, lt.z );
	njCnkSetToonLight( lt.x, lt.y, lt.z );
	njCnkSetEasyLight( lt.x, lt.y, lt.z );
	njCnkSetSimpleLight( lt.x, lt.y, lt.z );
	njSetDirectLight( lt.x, lt.y, lt.z );
	
	njCnkSetIntensityLightMatrices();
	njCnkSetEasyMultiLightMatrices();
	njCnkSetSimpleMultiLightMatrices();
	
	njPushMatrixEx();
	njTranslate( NULL, +rx, -ry, rz );
	njRotateXYZ( NULL, xx,yy,zz );
	njCnkToonDrawObject( object_t_Teapot01_Teapot01 );
	njPopMatrixEx();
	
	njPushMatrixEx();
	njTranslate( NULL, -rx, -ry, rz );
	njRotateXYZ( NULL, xx,yy,zz );
	njCnkSetShadowTexNum( 0 );
	njCnkShadowTexDrawObject( object_t_Teapot01_Teapot01 );
	njPopMatrixEx();
	
	njPushMatrixEx();
	njTranslate( NULL, +rx, +ry, rz );
	njRotateXYZ( NULL, xx,yy,zz );
	njDirectDrawObject( pDirect );
	njPopMatrixEx();
	
	njPushMatrixEx();
	njTranslate( NULL, -rx, +ry, rz );
	njRotateXYZ( NULL, xx,yy,zz );
	njCnkWireDrawObject( object_t_Teapot01_Teapot01 );
	njPopMatrixEx();
	
	njPushMatrixEx();
	njTranslate( NULL, +rx*2.f, 0.f, rz );
	njRotateXYZ( NULL, xx,yy,zz );
	njCnkEasyDrawObject( object_t_Teapot01_Teapot01 );
	njPopMatrixEx();
	
	njPushMatrixEx();
	njTranslate( NULL, -rx*2.f, 0.f, rz );
	njRotateXYZ( NULL, xx,yy,zz );
	njCnkSimpleDrawObject( object_t_Teapot01_Teapot01 );
	njPopMatrixEx();
	
	njPushMatrixEx();
	njTranslate( NULL, 0.f, -ry*2.f, rz );
	njRotateXYZ( NULL, xx,yy,zz );
	njCnkEasyMultiDrawObject( object_t_Teapot01_Teapot01 );
	njPopMatrixEx();
	
	njPushMatrixEx();
	njTranslate( NULL, 0.f, +ry*2.f, rz );
	njRotateXYZ( NULL, xx,yy,zz );
	njCnkSimpleMultiDrawObject( object_t_Teapot01_Teapot01 );
	njPopMatrixEx();
	
	njPushMatrixEx();
	njTranslate( NULL, 0.f, 0.f, rz );
	njRotateXYZ( NULL, xx,yy,zz );
	njCnkIntensityDrawObject( object_t_Teapot01_Teapot01 );
	njPopMatrixEx();
	
	xx += 257;
	yy += 179;
	zz += 193;
#if	DEBUG
	if (fl==0) {
		njPrintC( NJM_LOCATION(23, 10), "SIMPLE"    );
		njPrintC( NJM_LOCATION(24, 11), "MULTI"     );
		
		njPrintC( NJM_LOCATION(16, 16), "WIRE"      );
		njPrintC( NJM_LOCATION(32, 16), "DIRECT"    );
	 	njPrintC( NJM_LOCATION( 6, 23), "SIMPLE"    );
	 	njPrintC( NJM_LOCATION(22, 23), "INTENSITY" );
	 	njPrintC( NJM_LOCATION(42, 23), "EASY"      );
		njPrintC( NJM_LOCATION(33, 30), "TOON"      );
		njPrintC( NJM_LOCATION(15, 30), "SHADOW"    );
		
		njPrintC( NJM_LOCATION(24, 36), "EASY"      );
		njPrintC( NJM_LOCATION(24, 37), "MULTI"     );
 	}
#endif
	return USER_CONTINUE;
}
/*-------------------------------------------------------------------------*/
