CELX: Problem combining gotolocation() and follow() methods

All about writing scripts for Celestia in Lua and the .cel system
Topic author
jldoreste
Posts: 5
Joined: 02.11.2012
Age: 52
With us: 6 years 10 months
Location: Canary Islands, Spain

CELX: Problem combining gotolocation() and follow() methods

Post #1by jldoreste » 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.

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!
System: openSUSE 12.3 x86_64 GNU/Linux
Processor: AMD PHENOM II X6 1055T, 6-core processor
Main Memory: 12288 MB DDR3-SDRAM
Graphic card: nvidia Geforce GTX 550 Ti, 1GB GDDR5

Topic author
jldoreste
Posts: 5
Joined: 02.11.2012
Age: 52
With us: 6 years 10 months
Location: Canary Islands, Spain

Re: CELX: Problem combining gotolocation() and follow() meth

Post #2by jldoreste » 21.07.2013, 09:45

:idea:
http://en.wikibooks.org/wiki/Celestia/Celx_Scripting/CELX_Lua_Methods/Celx_observer#follow

Follow is the same as setting the frame of reference to "ecliptical" with target as reference object.

So, If you are using a different reference frame than "ecliptical", after using the "follow()" method one must reset the previous frame using

obs:setframe(frame)

Code: Select all

-- 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)
wait(3)
obs:setframe(frame)  -- IMPORTANT, RETURN TO THE PREVIOUS FRAME


In general, when Celestia goes to an unexpected location, it may be by a reference frame conflict like this.
System: openSUSE 12.3 x86_64 GNU/Linux
Processor: AMD PHENOM II X6 1055T, 6-core processor
Main Memory: 12288 MB DDR3-SDRAM
Graphic card: nvidia Geforce GTX 550 Ti, 1GB GDDR5


Return to “Scripting”

Who is online

Users browsing this forum: 13 guests
Bots: Bing [Bot]