/*
	Ninja Library
	
	COPYRIGHT (C) SEGA ENTERPRISES,LTD.

*/
#ifndef _NJ_COLLISION_H_
#define _NJ_COLLISION_H_

#define NJD_COL_DELTA		0.025f
#define	NJD_COL_VERTICAL	0.0000001f
#define	NJD_COL_PARALLEL	0.0000001f


//	媴
typedef struct{
    NJS_POINT3 c;
    Float      r;
} NJS_SPHERE;

//	僇僾僙儖
typedef struct{
    NJS_POINT3 c1;
    NJS_POINT3 c2;
    Float      r;
} NJS_CAPSULE;

//	榋柺懱
typedef struct{
    NJS_POINT3 v[8];
} NJS_BOX;

//	暯峴榋柺懱(榋柺懱:HEXAHEDRON, 捈曽懱:CUBOID, 棫曽懱:CUBE乯
typedef struct{
	NJS_POINT3		p;
    NJS_VECTOR		v[3];
} NJS_PARAHEXA;


/*
	徴撍敾掕
*/
/*	媴偲僇僾僙儖偺徴撍敾掕	*/
Sint32  njCollisionCheckSS( const NJS_SPHERE *sphere1, const NJS_SPHERE *sphere2 );
Sint32  njCollisionCheckCC( const NJS_CAPSULE *h1, const NJS_CAPSULE *h2 );
Sint32  njCollisionCheckSC( const NJS_SPHERE *sphere, const NJS_CAPSULE *capsule );

/*	暯峴榋柺懱偲偺徴撍	*/
Sint32	njCollisionCheckB2B2( const NJS_PARAHEXA *ca, const NJS_PARAHEXA *cb );
Sint32	njCollisionCheckB2C( const NJS_PARAHEXA *cubo, const NJS_CAPSULE *cp );
Sint32	njCollisionCheckB2S( const NJS_PARAHEXA *cubo, const NJS_SPHERE *sp );

/*	媽BOX 偲偺徴撍敾掕	*/
Sint32  njCollisionCheckBB( const NJS_BOX *h1, const NJS_BOX *h2 );
Sint32  njCollisionCheckBS( const NJS_BOX *box, const NJS_SPHERE *sphere );
Sint32  njCollisionCheckBC( const NJS_BOX *box, const NJS_CAPSULE *capsule );

/*
	暯峴敾掕
*/
Bool	njIsParalellL2L( const NJS_LINE *l1, const NJS_LINE *l2 );
Bool	njIsParalellL2PL( const NJS_LINE *l, const NJS_PLANE *pl );
Bool	njIsParalellPL2PL( const NJS_PLANE *pl1, const NJS_PLANE *pl2 );


/*
	嫍棧嶼弌
*/
Float	njDistanceP2P( const NJS_POINT3 *p1, const NJS_POINT3 *p2 );
Float	njDistanceP2L( const NJS_POINT3 *p, const NJS_LINE *l, NJS_POINT3 *cp );
Float	njDistanceP2PL( const NJS_POINT3 *p, const NJS_PLANE *pl, NJS_POINT3 *cp );
Float	njDistanceL2L( const NJS_LINE *l1, const NJS_LINE *l2, NJS_POINT3 *cp1, NJS_POINT3 *cp2 );
Float	njDistanceL2PL( const NJS_LINE *l, const NJS_PLANE *pl, NJS_POINT3 *cp );
Float	njDistancePL2PL( const NJS_PLANE *pl1, const NJS_PLANE *pl2, NJS_LINE *l );

/*
	暯柺偺朄慄偺庢摼
*/
void	njGetPlaneNormal( const NJS_POINT3 *p, NJS_VECTOR *v );
void	njGetPlaneNormal2( const NJS_POINT3 *p0, const NJS_POINT3 *p1, const NJS_POINT3 *p2, NJS_VECTOR *v );


/*
	Bounding Box 偺嶼弌
*/
void	njGetBoxMinMax( const NJS_BOX *hull, NJS_POINT3 *min, NJS_POINT3 *max );
void	njGetSphereMinMax( const NJS_SPHERE *hull, NJS_POINT3 *min, NJS_POINT3 *max );
void	njGetCapsuleMinMax( const NJS_CAPSULE *hull, NJS_POINT3 *min, NJS_POINT3 *max );
void	njGetBox2MinMax( const NJS_PARAHEXA *cubo, NJS_POINT3 *min, NJS_POINT3 *max );

#endif	/*_NJ_COLLISION_H_*/
