Problems with animated object lifetime and transformation controls
Please help! Hi 3DS people, I've spent the last 2 days trying to resolve some tricky (but probably very simple) problems with an air-traffic animation I'm working on. This is getting really urgent now so I'd be super-grateful for assistance. I attach the code and data file. Problems are:
1. objects are supposed to be created at specific times, but for some reason they are all in the animation (mostly motionless) from t=1.
2. grateful for any suggestions as to how to kill (delete) planes once they've reached their destination? I can code to kill them if they don't move, but can't figure out how to remove objects from the animation.
3. the code is nearly controlling object rotation correctly, but some objects briefly spin for some reason when they turn anti-clockwise (possibly through an axis). I've spent hours adjusting the atan code (as well as trying atan2) but can't figure out why this is happening, and it really undermines the whole animation.
The arrays are:
- frame: the time index position for each data row
- flight: flight number
- points: flight x-y-z position data
- planes/listlastpos/listlastdir: remembers IDs, positions and directions
*** PLEASE NOTE THE ANIMATION IS A QUITE LARGE SCALE - YOU NEED TO ZOOM OUT TO SEE IT ***
resetMaxFile #noPrompt ( --Initialise arrays global frame = #() global flight = #() global points = #() --Read in the movement data local theFile = openFile "C:\\flights.txt" while not eof theFile do ( t = (readValue theFile as integer) f = (readValue theFile as string) append frame t append flight f p = Point3 (readValue theFile as float) (readValue theFile as float) (readValue theFile as float) append points p ) close theFile -- Initialise unique plane data arrays global planes = #() global listlastpos = #() global listlastdir = #() ) --Animate objects animate on ( animationRange = interval 1 frame[frame.count] --Initialise row-counter 'k' k = 1 for t in 1 to frame[frame.count] do ( at time (t) ( while t == frame[k] do --Undertake action in relevant frames only ( -- Initialise new plane if appendIfUnique planes flight[k] then ( --Create new object - WHY DO THEY ALL APPEAR AT FRAME 1? Plane length:2000 width:2000 pos:points[k] isSelected:on $Plane001.name = flight[k] append listlastpos points[k] append listlastdir 0 ) else -- Plane already exists ( -- Move plane to new position execute ("select $" + flight[k] as string) $.pos = points[k] --Retreive data on last transformations id = findItem planes (flight[k] as string) lastpos = listlastpos[id] lastdir = listlastdir[id] --Calculate current direction vector dirVec = normalize(points[k] - lastpos) --Calculate intended rotation rot = atan (dirVec.y/dirVec.x) if dirVec.x < 0 and dirVec.y > 0 then rot = 180+rot if dirVec.x < 0 and dirVec.y < 0 then rot = -180+rot --Unapply last transformations and apply new ones rot_obj = eulerangles 0 0 -lastdir -- Undo direction rotate $ rot_obj rot_obj = eulerangles 0 0 rot -- New direction rotate $ rot_obj -- WHY DO SOME OF THE OBJECTS SPIN WHEN TURNING ANTI-CLOCKWISE? --Remember current position and rotation listlastpos[id] = points[k] listlastdir[id] = rot ) --Kill old planes (how to make them disappear when they've stopped moving? k = k+1 ) ) ) print "done" )