-- Title: Spiral approach to object -- Author: Chris Laurel -- constants km = 1.0/9460730.4725808 sec = 1.0/86400 deg = math.pi / 180 target = celestia:find("Sol/Jupiter") sun = celestia:find("Sol") startdist = 1000000*km enddist = 250000*km -- moveduration = 10*sec -- startangle = 0 -- angle = math.pi function smoothstep(x) return (3 - 2 * x) * x * x end function spiral_approach(params) local obs = celestia:getobserver() -- Get the parameters local target = params.target or celestia:find("Sol/Earth") local sun = params.sun or celestia:find("Sol") local duration = params.duration or 10*sec local startangle = params.startangle or 0 local endangle = params.endangle or math.pi local startdist = params.startdist or target:radius()*km * 20 local enddist = params.enddist or target:radius()*km * 4 obs:follow(target) celestia:select(target) -- Get the sun direction local dir = sun:getposition():vectorto(target:getposition()) dir = dir:normalize() -- Get the orbital velocity vector for the target local vel = target:getposition(celestia:gettime() + 0.1) - target:getposition() vel = vel:normalize() local start = celestia:gettime() local v = celestia:newvector(0, 0, 0) -- set the observer position over the duration while celestia:gettime() <= start + duration do -- smoothly interpolate distance and angle local t if duration == 0 then t = 1 else t = (celestia:gettime() - start) / duration end t = smoothstep(t) local dist = startdist + t * (enddist - startdist) local theta = startangle + t * (endangle - startangle) v = -math.cos(theta) * dir + math.sin(theta) * vel obs:setposition(target:getposition() + v * dist) obs:lookat(target:getposition(), celestia:newvector(0.0, 1.0, 0.0)) wait(0) end end t0 = celestia:gettime() celestia:find("Sol/Earth"):preloadtexture() celestia:find("Sol/Earth/Moon"):preloadtexture() spiral_approach{ target = celestia:find("Sol/Earth"), sun = celestia:find("Sol"), enddist = 300000*km, endangle = 180*deg, duration = 0 } wait(0) wait(0) celestia:flash((celestia:gettime() - t0)*86400) spiral_approach{ target = celestia:find("Sol/Earth"), sun = celestia:find("Sol"), startdist = 300000*km, enddist = 30000*km, startangle = 180*deg, endangle = 0*deg, duration = 10*sec }