/* 3d objects manager - nov 97 - par Sylvain Huet*/

/* gestion de reflexes 3d */
struct O3d=[hO3d:H3d, mO3d:HMat3d, pointerO3d:fun[I] I, clickO3d:fun[I] I]mkO3d;;

typeof listO3d=[O3d r1];;

fun O3dbyHM(p,z)=let z->[h m] in p.hO3d==h && p.mO3d==m;;

fun _O3dInit()= set listO3d=nil; 0;;

fun _O3dAddObj(h,mat,pnt,clk)=
 set listO3d=(mkO3d [h mat pnt clk]):: 
  remove_from_list listO3d search_in_list listO3d @O3dbyHM [h mat];
 h;;

fun _O3dCbPointer(h,m,f)=
 let search_in_list listO3d @O3dbyHM [h m] -> o in
 if o==nil then nil
 else set o.pointerO3d=f;
 h;;

fun _O3dCbClick(h,m,f)=
 let search_in_list listO3d @O3dbyHM [h m] -> o in
 if o==nil then nil
 else set o.clickO3d=f;
 h;;

fun _O3dGetObj(h,m)=
 let search_in_list listO3d @O3dbyHM [h m] -> o in
 [o.hO3d o.pointerO3d o.clickO3d];;

fun _O3dDelObj(h,m)=
 set listO3d=remove_from_list listO3d search_in_list listO3d @O3dbyHM [h m];
 h;;

fun _O3dPointer(h,m,b)=
 let search_in_list listO3d @O3dbyHM [h m] -> o in
 if o==nil then 0
 else (exec o.pointerO3d with [b]; 1);;

fun _O3dClick(h,m,b)=
 let search_in_list listO3d @O3dbyHM [h m] -> o in
 if o==nil then 0
 else (exec o.clickO3d with [b]; 1);;