indexing description: "A node animation, using matrices and linear matrix interpolation" date: "$Date$" revision: "$Revision$" class EM3D_ANIMATION create make feature{NONE} -- Initialization make( an_actor: EM3D_ACTOR ) is -- Make a new interpolation do actor := an_actor create keys.make(0,-1) create times.make(0,-1) end feature {NONE} -- internal keys: ARRAY[ EM_MATRIX44 ] times: ARRAY[ DOUBLE ] feature --Animation actor: EM3D_ACTOR set_actor( a_value: like actor ) is -- Specify the actor do actor := a_value end start_time: DOUBLE is -- The starttime of the animation do if times.count>0 then result := times.item(0) end end end_time: DOUBLE is -- The starttime of the animation do if times.count>0 then result := times.item( times.upper ) end end add_key( m: EM_MATRIX44; time: DOUBLE ) is -- add a new animation key local i,j: INTEGER do from i:=times.lower until i>times.upper or times.item(i)>time loop i := i + 1 end from j:=i until j>times.upper loop times.force( times.item(j), j+1) keys.force( keys.item(j), j+1) j := j + 1 end keys.force( m, i ) times.force( time, i ) end animate( a_time: DOUBLE ) is -- Play the animation to a_time local low, up: INTEGER t: DOUBLE do from low := times.upper until low<=times.lower or times.item(low)<=a_time loop low := low - 1 end up := low if low times.item( low ) then t := (a_time - times.item( low )) / (times.item( up ) - times.item( low )) end actor.set_transformation( keys.item(low).scaled(1-t) + keys.item(up).scaled(t) ) end end