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

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

#define	TEXLIST		texlist_aiueo_ok
#define	OBJECT		object_aiueo_ok_aiueo_null
#define	SHAPELIST	cshapelist_aiueo_ok
#define	SHAPE		cshape_motion_aiueo_ok
#define	MOTION		motion_aiueo_ok

extern	NJS_CSHAPELIST		SHAPELIST[];
extern	NJS_MOTION			MOTION[];
extern	NJS_MOTION			SHAPE[];
extern	NJS_CNK_OBJECT		OBJECT[];
extern	NJS_TEXLIST			TEXLIST[];

Float	buf[100*16];
Float	buf2[100*16];

NJS_MOTION_LINK		mlink;
NJS_MOTION_LINK		slink;

#define	FUNC	njCnkEasyDrawModel

/*---------------------------------------------------------------------------
		初期化
		initialize
---------------------------------------------------------------------------*/
Sint32	UserInit(void)
{
	njInitShape( buf, 100 );
	njInitShapeLink( buf2, 100 );
	
	njCnkSetEasyLight( 0.5f, 0.5f, -0.5f );
	njCnkSetEasyLightColor( 1.0f, 1.0f, 1.0f );
	njCnkSetEasyLightIntensity( 0.8f, 0.2f );

	if(nuLoadTexture( TEXLIST ) < 0){
		return USER_EXIT;
	}
	njSetTexture( TEXLIST );

	njSetShapeList( SHAPELIST );
	njSetShapeLinkList( SHAPELIST );
	
	mlink.motion[0] = MOTION;
	mlink.motion[1] = MOTION;
	mlink.frame[0] = 0.f;
	mlink.frame[1] = 0.f;
	slink.motion[0] = SHAPE;
	slink.motion[1] = SHAPE;

//	njSetBackColor( 0x80808080, 0x80808080, 0x80808080 );

	return USER_CONTINUE;
}
/*---------------------------------------------------------------------------
		終了処理
		exit
---------------------------------------------------------------------------*/
Sint32	UserExit(void)
{
	return USER_CONTINUE;
}
/*---------------------------------------------------------------------------
		メイン
		main
---------------------------------------------------------------------------*/
Sint32	UserMain(void)
{
	static	Float	frame = 0;
	static	Float	frame2 = 0;
	static	Float	rate = 0.5f;
	static	Float	zzz = -4.5f;
	static	Sint32	yy=0,f1=0,f2=0,f3=0;
	NJS_COLOR	col;
	
	njPushMatrixEx();	
	njTranslate( NULL, -1.5f, 0.7f, zzz );
	njRotateXYZ( NULL, 0, njSin(f1)*0x2000, 0 );


	njCnkDrawShapeMotion(  OBJECT, MOTION, SHAPE, frame, frame, FUNC );
	njPopMatrixEx();

	njPushMatrixEx();	
	njTranslate( NULL, 1.5f, 0.7f, zzz );
	njRotateXYZ( NULL, 0, njSin(f2)*0x2000, 0 );
	njCnkDrawShapeMotion(  OBJECT, MOTION, SHAPE, frame2, frame2, FUNC );
	njPopMatrixEx();

	slink.frame[0] = frame;
	slink.frame[1] = frame2;

	njPushMatrixEx();	
	njTranslate( NULL, 0, -0.7f, zzz );
	njRotateXYZ( NULL, 0, njSin(f3)*0x1000, yy );
	njCnkDrawShapeLink( OBJECT, &mlink, &slink, rate, FUNC );
	njPopMatrixEx();

	yy += 200;

	frame += 0.97f;
	frame2 += 0.71f;

	f1 += 111;
	f2 += 139;
	f3 += 499;
	
	col.argb.a = 0xff;
	col.argb.r = njSin(f1)*100+100;
	col.argb.g = njSin(f2)*100+100;
	col.argb.b = njSin(f3)*100+100;
	njCnkSetToonEdge( 0.03f, col.color );

	if (Per->on & PDD_DGT_KU) 	frame += 0.2f;
	if (Per->on & PDD_DGT_KD) 	frame -= 0.2f;
	if (Per->on & PDD_DGT_KR) 	frame2 += 0.2f;
	if (Per->on & PDD_DGT_KL) 	frame2 -= 0.2f;

	if (Per->on & PDD_DGT_TR) 	rate += 0.01f;
	if (Per->on & PDD_DGT_TL) 	rate -= 0.01f;
//	if( rate < 0 ) rate = 0;
//	if( rate > 1 ) rate = 1;
	
	if( frame >= MOTION->nbFrame ) frame -= MOTION->nbFrame;
	if( frame2 >= MOTION->nbFrame ) frame2 -= MOTION->nbFrame;
	if( frame < 0 ) frame = MOTION->nbFrame-0.2f;
	if( frame2 < 0 ) frame2 = MOTION->nbFrame-0.2f;
	
	njPrintD( NJM_LOCATION(2,2), frame, 3 );
	njPrintD( NJM_LOCATION(35,2), frame2, 3 );
	njPrintD( NJM_LOCATION(25,25), rate*100, 3 );



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