CELX: Problem combining gotolocation() and follow() methods
Posted: 19.07.2013, 19:16
Hello!
I have had problems when using gotolocation() celx method next to follow(). It doesn't go to the correct place, in fact it goes to twice the "universal" coordinates that it must go. For example, if it must go to (7.28, 9.8e-4, 14.39) micro-light-years (universal coordinates) it goes to (14.56, 1.96e-3, 28.78) micro-light-years.
An example code is added, next. First, it must go to one side of the moon with the gotolocation() method, center and follow the moon. Next it must go to the other side of the moon with gotolocation(), center and follow the moon. The resulting second position is about 1 AU away from the Moon and Earth. If the first "follow()" method is erased, it goes to the right place, ?fixed! but about 3 hours later.
Best wishes!
I have had problems when using gotolocation() celx method next to follow(). It doesn't go to the correct place, in fact it goes to twice the "universal" coordinates that it must go. For example, if it must go to (7.28, 9.8e-4, 14.39) micro-light-years (universal coordinates) it goes to (14.56, 1.96e-3, 28.78) micro-light-years.
An example code is added, next. First, it must go to one side of the moon with the gotolocation() method, center and follow the moon. Next it must go to the other side of the moon with gotolocation(), center and follow the moon. The resulting second position is about 1 AU away from the Moon and Earth. If the first "follow()" method is erased, it goes to the right place, ?fixed! but about 3 hours later.
Code: Select all
-- Constant
uly = 9460730.4725808 -- km
-- Creating objects
obs = celestia:getobserver()
moon = celestia:find("Sol/Earth/Moon")
Sun = celestia:find("Sol")
-- Reference frame: "universal"
frame = celestia:newframe("universal")
obs:setframe(frame)
-- Functions
-- Special function suited for debugging
-- Special function suited for debugging
function printv(vector_name,vector)
local vx= vector:getx()
local vy= vector:gety()
local vz= vector:getz()
local string= vector_name.."= ("..vx.." , "..vy.." , "..vz..")"
celestia:print(string, 10.0, -1, 0)
wait(10.0)
end
-- Main code:
-- Objects and observer positions
obs_pos = obs:getposition()
moon_pos= moon:getposition()
Sun_pos= Sun:getposition()
eje_r= moon_pos:vectorto(Sun_pos) -- Vector Moon -> Sun
eje = eje_r:normalize() -- eje_r normalized
vector_pt = eje * 4.0 * moon:radius() * uly^(-1)
tar_pos= moon_pos + vector_pt
-- Go to the first target point
celestia:select(moon)
obs:gotolocation(tar_pos, 0.5)
wait(0.5)
obs:center(moon, 0.5)
wait(0.5)
obs:follow(moon) -- Bad thing, gotolocation() mistakes the next target position
wait(3)
-- obs_pos= obs:getposition()
-- printv("obs_pos", obs_pos) -- We can see where the observer is
-- Second gotolocation()
tar_pos= moon_pos - vector_pt
-- Go to the second target point
celestia:select(moon)
obs:gotolocation(tar_pos, 0.5)
wait(0.5)
obs:center(moon, 0.5)
wait(0.5)
obs:follow(moon)
wait(3)
-- obs_pos= obs:getposition()
-- printv("obs_pos", obs_pos) -- We can see where the observer is
celestia:print("Done.")
Best wishes!