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

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

Float			xxx = 0.f;
Float			yyy = 0.f;
Float			zzz = -10.f;
Sint32			xx = 0;
Sint32			yy = 0;
Sint32			zz = 0;

#define RATIOU	(288.f/512.f)		// テクスチャに対するムービーのU比率
#define RATIOV	(160.f/256.f)		// テクスチャに対するムービーのV比率

/***************************************************************************
 *      変数定義
 *		Variable Declaration
 ***************************************************************************/
/*	アプリケーションオブジェクト									*/
/*	Application Object												*/
AP_OBJ ap_obj = {
	OFF,						//	Execute App.
	ON,							//	Display Info.
	OFF,						//	not puase
	OFF,						//	not puase
	"SAMPLE.SFD",				//	File name
	NULL,						//	Player
};

/*---------------------------------------------------------------------------
		初期化
		initialize
---------------------------------------------------------------------------*/
Sint32	UserInit(void)
{


	if(nuLoadTexture( &TEXLIST ) < 0){
		return USER_CONTINUE;
	}
	njSetTexture( &TEXLIST );
	
	njCnkIntensityLoadTexture();
	njCnkIntensityLightInit( 1 );
	njCnkSetIntensityLightDiffColor( 1.0f, 1.0f, 1.0f );
	njCnkSetIntensityLightSpecColor( 1.0f, 1.0f, 1.0f );
	njCnkSetIntensityLightOffset( 0.0f, 0.3f );
	
	njCnkSetIntensityLightEnvRatio( RATIOU * 0.5f, RATIOV * 0.5f );
	njCnkSetUvScroll( RATIOU * 0.5f, RATIOV * 0.5f );
	
	njCnkSetIntensityLightMode(
						NJD_CNK_INTENSITY_LIGHT_0, NJD_CNK_INTENSITY_MODE_DIR );
	njCnkSetIntensityLightSwitch(
						NJD_CNK_INTENSITY_LIGHT_0, ON );
	njCnkSetIntensityLightVector(
						NJD_CNK_INTENSITY_LIGHT_0,  0.0f, 0.0f, -1.0f );
	njCnkSetIntensityLightExp(
						NJD_CNK_INTENSITY_LIGHT_0, NJD_CNK_INTENSITY_EXP_32 );
	njCnkSetIntensityLightSet(
						NJD_CNK_INTENSITY_LIGHT_0, 0.8f, 0.7f );
	
	
	njControl3D( NJD_CONTROL_3D_ENV_UV_SCROLL );
	njSetConstantAttr( 0xFFFFFFFF, NJD_FST_ENV );

	/*	ミドルウェアライブラリ初期化								*/
	/*	Initialize middleware										*/
	ApInitMw(&ap_obj);

	return USER_CONTINUE;
}
/*---------------------------------------------------------------------------
		終了処理
		exit
---------------------------------------------------------------------------*/
Sint32	UserExit(void)
{
	
	njClearTextureSurfaceNum(0);

	/*	アプリケーション終了処理	*/
	/*	Finalize application		*/
	ApFinishMw(&ap_obj);	/*	ミドルウェアの終了					*/
							/*	Finalize Middleware					*/

	njCnkIntensityReleaseTexture();
	return USER_CONTINUE;
}
/*---------------------------------------------------------------------------
		メイン
		main
---------------------------------------------------------------------------*/
Sint32	UserMain(void)
{
	if( Per->on & PDD_DGT_KL ) xxx -= 1;
	if( Per->on & PDD_DGT_KR ) xxx += 1;
	if( Per->on & PDD_DGT_KU ) yyy += 1;
	if( Per->on & PDD_DGT_KD ) yyy -= 1;
	if( Per->on & PDD_DGT_TL ) zzz -= 1;
	if( Per->on & PDD_DGT_TR ) zzz += 1;

	njCnkSetIntensityLightMatrices();
	
	/*	Operation of display Teapot	*/
	njSetTexture( &TEXLIST );
	ApSetMvSurface(&ap_obj,&TEXLIST,0);
	njSetTextureNum( 0 );
	njPushMatrixEx();	
	njTranslate( NULL, xxx, yyy, zzz );
	njRotateXYZ( NULL, xx, yy, zz );
	njCnkIntensityDrawObject( OBJECT );
	njPopMatrixEx();

	xx += 219;
	yy += 197;
	zz += 359;

	return USER_CONTINUE;
}
/*-------------------------------------------------------------------------*/
