/* Trajectory - DMS - Nov 98 - by Sylvain HUET */ /* Trajectory - DMS2 - May 99 - by Patrice FAVRE */ /* modified on the 7th of Jun 99 by Christophe LOREK */ /* Trajectory2 - January 2003 - by Bob Le Gob */ typeof class=S;; struct TrajAnim = [TAname:S, TAframerate:I, TAplaystop:I, TAlooponce:I, TAinterpoflag:I, TAtick:I, TAfel:[I r1]] mkTrajAnim;; fun OptSingleAng(p, q) = let (abs (q - p)) -> path1 in let (abs (q + 65536 - p)) -> path2 in let (abs (q - 65536 - p)) -> path3 in let min path1 min path2 path3 -> minpath in if (minpath == path1) then q else if (minpath == path2) then (q + 65536) else (q - 65536);; fun OptimizeDestinationsAngle(ap, aq, bp, bq, cp, cq) = [(OptSingleAng ap aq) (OptSingleAng bp bq) (OptSingleAng cp cq)];; fun slidepos2(x,param)= let param -> [z interpoflag prevframe] in if interpoflag then /* trajectory with interpolation */ ( let x->[o sz l] in let z->[lastframe currentframe _ _ flagPosAng] in let o->[h _ _ _] in let sz*currentframe/lastframe -> i in let mod sz*currentframe lastframe -> kq in let lastframe-kq-> kp in let endlist l i ->[p [q _]] in match p with (posAnchor [_ [xp yp zp] [ap bp cp]]-> match q with (posAnchor [_ [xq yq zq] [aq bq cq]]-> ( M3setObjVec session h [(xp*kp+xq*kq)/lastframe (yp*kp+yq*kq)/lastframe (zp*kp+zq*kq)/lastframe]; if flagPosAng then ( let OptimizeDestinationsAngle ap aq bp bq cp cq -> [aq2 bq2 cq2] in M3setObjAng session h [(ap*kp+aq2*kq)/lastframe (bp*kp+bq2*kq)/lastframe (cp*kp+cq2*kq)/lastframe]; 0; ) else 0; ) ) ) ) else /* trajectory without interpolation */ ( let x->[o sz l] in let z->[lastframe currentframe _ _ flagPosAng] in let o->[h _ _ _] in let sz*currentframe/lastframe -> i in let nth_list l i ->p in match p with (posAnchor [n v w]-> (M3setObjVec session h v;if flagPosAng then M3setObjAng session h w else nil)) |(_->nil); nil );; fun testFrameEvent(fel,prevframe, curframe, fpos)= if fel == nil then nil else let fel -> [keyframe nfel] in if ((prevframe < keyframe) && (keyframe <= curframe)) || ((prevframe < keyframe) && (curframe < prevframe))then fpos else testFrameEvent nfel prevframe curframe fpos+1;; fun slidepos(o,z,a)= if a.TAplaystop then ( if a.TAtick == nil then set a.TAtick = _tickcount else nil; let _tickcount -> currenttick in let ((currenttick - a.TAtick) * a.TAframerate) -> timeframe in let mod timeframe 1000 -> accum in let (timeframe / 1000) -> deltaframe in let z->[lastframe currentframe accumulator x _] in let currentframe -> prevframe in ( set accumulator = accumulator + accum; if accumulator > 1000 then (set deltaframe = deltaframe + 1; set accumulator = accumulator - 1000;) else nil; set currentframe = currentframe + deltaframe; let (testFrameEvent a.TAfel prevframe currentframe 0)-> fpos in if fpos == nil then nil else _DMSevent this (strcatn (ObName o)::".Frame#"::(itoa (nth_list a.TAfel fpos))::nil) nil nil; if currentframe <= lastframe then (set a.TAtick = currenttick; mutate z<-[_ currentframe accumulator _ _]) else ( if a.TAlooponce then (set a.TAplaystop = 0; set a.TAtick = nil) else (set a.TAplaystop = 1; set a.TAtick = nil); mutate z<-[_ 0 0 _ _] ); apply_on_list x @slidepos2 [z a.TAinterpoflag prevframe] ); ) else nil; 0;; fun prepanch(l)= if l==nil then [nil nil] else let l->[a n] in let prepanch n ->[lp lo] in match a with (objAnchor o -> [nil [o (sizelist lp)-1 lp]::lo]) |(posAnchor _ -> [a::lp lo]);; fun activate(o,from,action,param,reply,a)= if !strcmp action (strcat (ObName o) ".playonce") then (set a.TAplaystop = 1; set a.TAlooponce = 1; set a.TAtick = _tickcount; 0) else if !strcmp action (strcat (ObName o) ".playloop") then (set a.TAplaystop = 1; set a.TAlooponce = 0; set a.TAtick = _tickcount; 0) else if !strcmp action (strcat (ObName o) ".stop") then (set a.TAplaystop = 0; set a.TAtick = nil; 0) else nil;; fun cbcomm(ui,action,param,a)= if !strcmp action "playonce" then (set a.TAplaystop = 1; set a.TAlooponce = 1; set a.TAtick = _tickcount; 0) else if !strcmp action "playloop" then (set a.TAplaystop = 1; set a.TAlooponce = 0; set a.TAtick = _tickcount; 0) else if !strcmp action "stop" then (set a.TAplaystop = 0; set a.TAtick = nil; 0) else nil;; fun FrameEventList(l)= if l == nil then nil else let l -> [[name r] nl] in if !strcmp name "FrameEvent" then let r -> [frameNum _] in (atoi frameNum)::(FrameEventList nl) else FrameEventList nl;; fun newOb(o)= let UgetParams ObUi o -> paramlist in let atoi hd UgetParam ObUi o "Interpolate" -> interpolateflag in let atoi hd UgetParam ObUi o "Framerate" -> framerate in let atoi hd UgetParam ObUi o "Ini" -> ini in let !atoi hd UgetParam ObUi o "Loop" -> looponce in let hd UgetParam ObUi o "PosAng" -> PosAng in let atoi hd UgetParam ObUi o "NbFrames" -> nbframes in let atoi hd UgetParam ObUi o "SrvAnimAutoStart" -> srvAnimAutoStart in let prepanch ObAnchor o -> [_ l] in let mkTrajAnim [(ObName o) framerate ini looponce interpolateflag nil (FrameEventList paramlist)] -> ta in ( ObCbAnim o mkfun2 mkfun3 @slidepos ta [nbframes 0 0 l (!strcmpi PosAng "All")]; UcbComm this ObUi o mkfun4 @cbcomm ta; ObRegisterAction o (strcatn (ObName o)::".playonce"::nil) mkfun6 @activate ta; ObRegisterAction o (strcatn (ObName o)::".playloop"::nil) mkfun6 @activate ta; ObRegisterAction o (strcatn (ObName o)::".stop"::nil) mkfun6 @activate ta; if srvAnimAutoStart then UsendSrv this (ObUi o) "newclient" (ObName o) else nil; 0 );; fun IniPlug(file)= set class=getInfo strextr _getpack _checkpack file "name"; PlugRegister class @newOb nil; 0;;