#if defined _3d_included
  #endinput
#endif
#define _3d_included

#include <core.inc>

enum
{
	// アルファチャンネルの計算方法
	ALPHA_BLEND_OFF			= 0x0000,	// src
	ALPHA_BLEND_MIX			= 0x0001,	// dst + ( src - dst ) * a
	ALPHA_BLEND_ADD			= 0x0002,	// dst + src * a
	ALPHA_BLEND_SUB			= 0x0003,	// dst - src * a
	ALPHA_BLEND_NONE		= 0x0004,	// dst
	ALPHA_BLEND_MODULATE	= 0x0005,	// dst * a
	ALPHA_BLEND_DECAY		= 0x0006,	// dst * ( 1 - a )
	ALPHA_BLEND_AMPLIFY		= 0x0007,	// dst * ( 1 + a )
	ALPHA_BLEND_DIFFERENCE	= 0x0008,	// ( dst - src ) * a
	ALPHA_BLEND_CONTRAST	= 0x0009,	// dst + ( dst - src ) * a

	// アルファの選択
	ALPHA_BLEND_SRCALPHA	= 0x0000,	// a = As
	ALPHA_BLEND_DESTALPHA	= 0x0100,	// a = Ad
	ALPHA_BLEND_FIXEDALPHA	= 0x0200,	// a = fixed ( 128 )

	// デストカラーとソースカラーの入れ替え
	ALPHA_BLEND_ABOVE		= 0x0000,	// blend dst @ src
	ALPHA_BLEND_BELOW		= 0x1000,	// blend src @ dst
};

enum
{
	ROTATE_ORDER_YXZ = 0,
	ROTATE_ORDER_ZYX,
	//ROTATE_ORDER_XYZ, //現在無効
};

enum
{
	ANIM_TIMER_LINEAR	= 1,
	ANIM_TIMER_SLOWER	= 2,
	ANIM_TIMER_FASTER	= 3,
	ANIM_TIMER_INTERPOLATE	= 4,
	ANIM_TIMER_ANGULER	= 5,
	ANIM_TIMER_EXPONENT	= 6,
};

enum
{
	HERMITE_VECTOR_MANUAL = 0,
	HERMITE_VECTOR_AUTO = 1,
};

enum
{
	FONT_HGRSGU = 0,
	FONT_TIMESBI,
};

// アニメーションの種類
// AnimStateの引数として使う
enum
{
	ANIM_TYPE_MOVE = 0,
	ANIM_TYPE_ROTATE,
	ANIM_TYPE_SCALE,
	ANIM_TYPE_COLOR,
	ANIM_TYPE_TIMER,
};
// アニメーションの状態
// AnimStateの返値
enum
{
	ANIM_STATE_NONE = 0,
	ANIM_STATE_STANDBY,
	ANIM_STATE_ACTIVE,
};

// ラベルのアライン
enum
{
	ALIGN_BEGINNING		= 0,
	ALIGN_CENTER,
	ALIGN_END,
	ALIGN_BASELINE,
	ALIGN_TOP,
	ALIGN_BOTTOM,
};

// ZSORTオプション
enum
{
	ZSORT_NORMAL = 0,	// 普通にZ値でソート
	ZSORT_TOP,			// 兄弟の中でTOP
	ZSORT_BOTTOM,		// 兄弟の中でBOTTOM
	ZSORT_TOP_MOST,		// シーンの中でTOP
	ZSORT_BOTTOM_MOST,	// シーンの中でBOTTOM
};

// PRIM 形状
enum {
	PRIM_SHAPE_CUBE,		// 立方体
	PRIM_SHAPE_BALL,		// 球
	PRIM_SHAPE_SQUARE,		// 正方形
	PRIM_SHAPE_CIRCLE,		// 円
	PRIM_SHAPE_PRISM,		// 角柱
	PRIM_SHAPE_COLUMN,		// 円柱
	PRIM_SHAPE_PYRAMID,	// 角錐
	PRIM_SHAPE_CONE,		// 円錐
} ;
enum {
	PRIM_FACE_NONE,		//
	PRIM_FACE_FRONT,	//
	PRIM_FACE_BACK,		//
	PRIM_FACE_BOTH,		//
} ;


native obj: Self();
native obj: Parent( obj:object = obj:0 );
native obj: Scene( obj:object = obj:0 );
native obj: Camera( obj:object = obj:0 );
native obj: Disp2D( obj:object = obj:0 );

native bool: IsValidObject(obj:target);

native obj: CreateNull(obj:parent);
native obj: CreateCube(obj:parent);
native obj: CreatePlane(obj:parent);
native obj: CreatePlane3x3(obj:parent);
native obj: CreateParticle(obj:parent);
native obj: CreateLabel(obj:parent);
native obj: CreateTextbox(obj:parent);
native obj: CreateHermite(obj:parent);
native obj: CreateCrystal(obj:parent);
native obj: CreateDefocus(obj:parent);
native obj: CreateEdit(obj:parent);
native obj: CreatePrim(obj:parent);
native obj: CreateIcon(obj:parent);
native obj: CreateSScope0(obj:parent);

native Destroy(obj:target);
native TimerDie( obj:target, rest_frame );

native Show(obj:target);
native Hide(obj:target);
native ShowChildren(obj:target);
native HideChildren(obj:target);

native SetScreen(obj:cam,float:w,float:h,float:d=-1.0);
native GetScreen(obj:cam,&float:w,&float:h,&float:d);
native SetClipRange(obj:cam,float:near,float:far);
native GetClipRange(obj:cam,&float:near,&float:far);
native SetAmbient(obj:scene,float:r,float:g,float:b);
native EnableLight(obj:scene,index,do_enable);
native SetLightColor(obj:scene,index,float:r,float:g,float:b);
native SetLightVector(obj:scene,index,float:x,float:y,float:z);

native SetPos(obj:target,float:x,float:y,float:z, obj:ref=obj:0);
native GetPos(obj:target,&float:x=0,&float:y=0,&float:z=0, obj:ref=obj:0);
native GetOffPos(obj:target,&float:x=0,&float:y=0,&float:z=0,
				float:offx, float:offy,float:offz, obj:ref=obj:0);

native SetRot(obj:target,float:x,float:y,float:z, obj:ref=obj:0,rotoption=ROTATE_ORDER_YXZ);
native GetRot(obj:target,&float:x=0,&float:y=0,&float:z=0, obj:ref=obj:0,rotoption=ROTATE_ORDER_YXZ);
native SetQuat(obj:target,float:x,float:y,float:z,float:w, obj:ref=obj:0);
native GetQuat(obj:target,&float:x=0,&float:y=0,&float:z=0,&float:w, obj:ref=obj:0);
native LookAt(obj:target,obj:ref,float:x=0.0,float:y=0.0,float:z=0.0,
              obj:up=0,float:x1=0.0,float:y1=0.0,float:z1=0.0);
native SetDir(obj:target,float:zx,float:zy,float:zz,
              float:yx=0.0,float:yy=1.0,float:yz=0.0, obj:ref=obj:0 );

native SetScale(obj:target,float:x,float:y,float:z);
native GetScale(obj:target,&float:x=0,&float:y=0,&float:z=0);
native SetLocalScale(obj:target,float:x,float:y,float:z);
native GetLocalScale(obj:target,&float:x=0,&float:y=0,&float:z=0);

native SetColor(obj:target,float:r,float:g,float:b,float:a);
native GetColor(obj:target,&float:r=0,&float:g=0,&float:b=0,&float:a=0);

native SetTexture( obj:target, texture:_texid_, _option_=0 );

native bool:SetOptionI( obj:target, id, val );
native bool:SetOptionF( obj:target, id, float:val );
native bool:SetOptionS( obj:target, id, const val[] );
native bool:SetOptionP( obj:target, id, const val[] );

native bool:GetOptionI( obj:target, id, & val );
native bool:GetOptionF( obj:target, id, & float:val );
native bool:GetOptionS( obj:target, id, val[], bufsize = sizeof val );
native bool:GetOptionP( obj:target, id, val[], bufsize = sizeof val );

native AnimMoveLine(obj:target,float:x,float:y,float:z,float:time,float:delay=0.0,option=ANIM_TIMER_LINEAR);
native AnimMoveHermite(obj:target,float:x,float:y,float:z,float:time,float:delay=0.0,option=ANIM_TIMER_LINEAR,float:animlink=1.0);
native AnimRotate(obj:target,float:x,float:y,float:z,float:time,float:delay=0.0,option=ANIM_TIMER_LINEAR,rot_order=ROTATE_ORDER_YXZ);
native AnimQuat(obj:target,float:x,float:y,float:z,float:w,float:time,float:delay=0.0,option=ANIM_TIMER_LINEAR);
native AnimColor(obj:target,float:r,float:g,float:b,float:a,float:time,float:delay=0.0,option=ANIM_TIMER_LINEAR);
native AnimScale(obj:target,float:x,float:y,float:z,float:time,float:delay=0.0,option=ANIM_TIMER_LINEAR);

native AnimModMove(obj:target,float:x,float:y,float:z);
native AnimModScale(obj:target,float:x,float:y,float:z);
native AnimModColor(obj:target,float:r,float:g,float:b,float:a);
native AnimModQuat(obj:target,float:x,float:y,float:z,float:w);

native AnimGetState( obj:target, anim_type );
native AnimTimerManager(obj:target,float:time,float:delay=0.0, option=ANIM_TIMER_LINEAR);
native float:AnimDoTimer( obj:target, anim_type=ANIM_TYPE_TIMER );
native float:AnimGetCurrTime( obj:target, anim_type=ANIM_TYPE_TIMER );

native float:Distance(obj:target1,obj:target2);
native float:DistanceXYZ(float:x,float:y,float:z,float:x2,float:y2,float:z2);
native float:RealVelocity(obj:target);
native Normalize(&float:x,&float:y,&float:z);
native QuatInterp(&float:x,&float:y,&float:z,&float:w,
                   float:x1,float:y1,float:z1,float:w1,
                   float:x2,float:y2,float:z2,float:w2,float:rate);
native QuatMultiply(&float:x,&float:y,&float:z,&float:w,
                   float:x1,float:y1,float:z1,float:w1,
                   float:x2,float:y2,float:z2,float:w2);

// for Object hermite
// FIXME : 使用禁止 どうなるかわからない
native InitNodeArray(obj:target, node_num, vect_flag=HERMITE_VECTOR_AUTO);
native SetNodePos(obj:target, float:x,float:y,float:z, node_no);
native GetPosHermite(obj:target, &float:x,&float:y,&float:z,float:rate,node_num);

// font
native FontID( font_idx );

// SetOption* に与えるID生成用
stock TAG(tag[])
	return swapchars(tag[0]);

// SetOptionP - COL4 に与える色生成用
stock MakeCol4( dst[4], const src[16] )
{
	for( new j=0 ; j<4 ; j++ )
	for( new i=0 ; i<4 ; i++ )
    {
        dst{4*j+3-i} = src[4*j+i];
    }
}

// 4つの 0-255 から、32bitの色情報生成
stock COL( const src[4] )
{
	new ret[1];
	for( new i=0 ; i<4 ; i++ )
    {
        ret{3-i} = src[i];
    }
    return ret[0];
}

