/* 3d Window - aout.97 - par Sylvain Huet */ struct Win3d= [chWin3d:Chn,winWin3d:ObjWin,sizemWin3d:[I I],flagsWin3d:I, endWin3d:fun [] I,clickWin3d:fun[H3d HMat3d I] I,moveWin3d:fun[H3d HMat3d] I, bufWin3d:ObjBitmap,sizeWin3d:[I I],kWin3d:[I I],fondWin3d:I, vectorWin3d:[I I I],angularWin3d:[I I I], refWin3d:[I I], timerWin3d:Timer, s3dWin3d:S3d, camWin3d:H3d, objWin3d:H3d, movobjWin3d:fun [[I I I] [I I I]] I, CBtimerWin3d:fun [] I, cursWin3d:[I I],lastWin3d:H3d,lastmWin3d:HMat3d ]mkWin3d;; var WIN3D_RESIZE=1;; var WIN3D_INTERF=2;; var WIN3D_CONT=4;; var WIN3D_CHILD=8;; proto _ClockE=fun[Timer Win3d] I;; fun _go(b)= if b.s3dWin3d!=nil && b.timerWin3d==nil then set b.timerWin3d = _rfltimer _starttimer b.chWin3d 100 @_ClockE b else nil;; fun _stop(b)= if b.timerWin3d==nil then nil else (_deltimer b.timerWin3d; set b.timerWin3d=nil);; fun _PaintE(x,b)= let b.sizeWin3d ->[w h] in _CPWbitmap b.winWin3d 0 0 b.bufWin3d 0 0 w h;; fun _ClockE(t,b)= if b.s3dWin3d==nil || b.camWin3d==nil then (_stop b; nil) else (exec b.CBtimerWin3d with []; let exec b.movobjWin3d with [b.vectorWin3d b.angularWin3d] -> changed in (let b.cursWin3d->[x y] in let M3scanlinem b.s3dWin3d b.bufWin3d b.camWin3d x y b.fondWin3d -> [h m] in if b.refWin3d!=nil || (h==b.lastWin3d && m==b.lastmWin3d) then nil else (set b.lastWin3d=h; set b.lastmWin3d=m; exec b.moveWin3d with [h m]); let b.sizeWin3d ->[w h] in _CPWbitmap b.winWin3d 0 0 b.bufWin3d 0 0 w h; if changed || (b.flagsWin3d&WIN3D_CONT) || b.refWin3d!=nil then nil else _stop b); 0 );; fun _UnclickE(a,b,x,y,button)= if b.flagsWin3d&WIN3D_CONT then nil else _stop b; set b.vectorWin3d=set b.angularWin3d=[0 0 0]; set b.refWin3d=nil;; fun _ClickE(a,b,x,y,button)= _go b; _SETfocus b.winWin3d ; set b.refWin3d=[x y]; let b.cursWin3d->[xp yp] in let M3scanlineInfo b.s3dWin3d b.bufWin3d b.camWin3d xp yp ->[o m _ _ _] in exec b.clickWin3d with [o m button];; fun movecurs(b,x,y)= let b.kWin3d ->[kv ka] in let b.refWin3d ->[xr yr] in (set x=x-xr; set y=yr-y; set b.vectorWin3d= if _keybdstate&2 then [x*kv y*kv 0] else if _keybdstate&1 then [0 0 0] else [0 0 y*kv]; set b.angularWin3d= if _keybdstate&2 then [0 0 0] else if _keybdstate&1 then [0 y*ka 0] else [(-x*ka) 0 0] );; fun _CursorE(a,b,x,y,c)= _go b; let b.sizeWin3d->[w h] in set b.cursWin3d=[x-(w>>1) (h>>1)-y]; if b.refWin3d==nil then nil else movecurs b x y ;; fun _keydownE (t,b,code,val)= _fooS "key down";0;; /* _go b; let b.kWin3d ->[lv la] in let [lv*30 la*40] -> [kv ka] in (set b.vectorWin3d= if _keybdstate&2 then if val==0xff51 then [(-kv) 0 0] else if val==0xff53 then [kv 0 0] else if val==0xff52 then [0 kv 0] else if val==0xff54 then [0 (-kv) 0] else [0 0 0] else if _keybdstate&1 then [0 0 0] else if val==0xff52 then [0 0 kv] else if val==0xff54 then [0 0 (-kv)] else [0 0 0]; set b.angularWin3d= if _keybdstate&2 then [0 0 0] else if _keybdstate&1 then if val==0xff52 then [0 ka 0] else if val==0xff54 then [0 (-ka) 0] else [0 0 0] else if val==0xff51 then [ka 0 0] else if val==0xff53 then [-ka 0 0] else [0 0 0]) ;; */ fun _keyupE (a,b,code)= if b.flagsWin3d&WIN3D_CONT then nil else _stop b; set b.vectorWin3d=set b.angularWin3d=[0 0 0] ;; fun _DestroyE(x,b)= exec b.endWin3d with [];; fun _ResizeE(a,b,x,y)= _go b; let b.sizemWin3d->[wm hm] in set b.sizeWin3d= [if x>wm then wm else x if y>hm then hm else y]; let b.sizeWin3d->[w h] in if b.camWin3d==nil || b.s3dWin3d==nil then nil else let M3getCamera b.s3dWin3d b.camWin3d -> [[d _] [x _] z] in M3setCamera b.s3dWin3d b.camWin3d [[d*(w>>1)/x d*(w>>1)/x] [w>>1 h>>1] z];; fun iniWin3d(ch,father,pos,wh,whm,title,end,flag)= let pos->[x y] in let wh -> [w h] in let _CRwindow ch father x y w h (if flag&WIN3D_CHILD then WN_CHILDINSIDE|WN_NOCAPTION else WN_MENU+WN_MINBOX)+ (if flag&WIN3D_RESIZE then WN_SIZEBOX else 0) title -> win in let whm -> [wm hm] in let _CRbitmap ch wm hm ->buf in let mkWin3d [ch win whm flag end nil nil buf wh [1 20] 0 nil nil nil nil nil nil nil nil nil [0 0] nil nil] -> b in (_CBwinDestroy win @_DestroyE b; _CBwinPaint win @_PaintE b; _CBwinSize win @_ResizeE b; _CBwinClick win @_ClickE b; _CBwinUnclick win @_UnclickE b; if flag&WIN3D_INTERF then (_CBwinKeydown win @_keydownE b; _CBwinKeyup win @_keyupE b) else nil; _CBwinKeydown win @_keydownE b; _CBcursorMove win @_CursorE b; b );; fun setSceneWin3d(b,s,c)= set b.s3dWin3d=s; set b.camWin3d=c; if s==nil then _stop b else (let b.sizeWin3d->[w h] in if b.camWin3d==nil || b.s3dWin3d==nil then nil else let M3getCamera b.s3dWin3d b.camWin3d -> [[d _] [x _] z] in M3setCamera b.s3dWin3d b.camWin3d [[d*(w>>1)/x d*(w>>1)/x] [w>>1 h>>1] z]; _go b) ;; fun setTitleWin3d(b,s)= _SETwindowName b.winWin3d s;; fun setInterfWin3d(b,kv,ka)= set b.kWin3d=[kv ka];; fun setBackgWin3d(b,col)= set b.fondWin3d=col; _go b; 0;; fun setCBWin3d(b,click,move)= set b.clickWin3d=click; set b.moveWin3d=move;; fun setCBtimerWin3d(b,t)= set b.CBtimerWin3d=t;; fun setMovobjWin3d(b,o,f)= set b.objWin3d=o; set b.movobjWin3d=f;; fun destroyWin3d(b)= set b.s3dWin3d=nil; _DSwindow b.winWin3d; _DSbitmap b.bufWin3d;; fun refreshWin3d(b)= _go b;;