Script method request: observer:getlonglat() method

The place to discuss creating, porting and modifying Celestia's source code.
Avatar
Topic author
Marco Klunder
Posts: 181
Joined: 20.02.2008
Age: 62
With us: 16 years 9 months
Location: The Netherlands

Script method request: observer:getlonglat() method

Post #1by Marco Klunder » 26.04.2011, 20:09

Within Celestia, there's already the "online" possibility, to obtain the observers longitude, latitude and distance with respect to a target object (except for the Sun), by the Navigation - Goto object ... dropdown menu.
But within CELX scripting there is no equivalent observer method yet, to obtain the actual longitude and latitude with respect to a specified target object.
It should be nice if this new CELX method could also be implemeted within future Celestia releases.

Other ideas for new CELX methods are equivalents for the following new v160 CEL commands, which are still missing within CELX scripting:
- EXIT (not my favorite :wink: )
- RENDERPATH (celestia:getrenderpath() and celestia:setrenderpath() respectively)

Marco
Marco Klunder
email: marco.klunder@xs4all.nl
Windows10 PD 3.0 GHz, 2 GB of RAM, Nvidia GeForce 6700 XL
Celestia161 / SVN + Lua Edu Tools v1.2 Beta9, Celestia160-ED and Celestia1621

Avatar
Topic author
Marco Klunder
Posts: 181
Joined: 20.02.2008
Age: 62
With us: 16 years 9 months
Location: The Netherlands

Re: Script method request: observer:getlonglat() method

Post #2by Marco Klunder » 06.06.2011, 19:58

I just received an update regarding this request from Vincent Giangiulio last weekend, and here's the CELX scripting code I was looking for to obtain the longitude and latitude coordinates for the observer on an object:

Code: Select all

-- Return longitude and latitude for the observer on the source object
get_long_lat = function (obs, source)
    f = source:getinfo().oblateness
    if f == nil then f = 0 end;
    u_pos = obs:getposition()
    e_frame = celestia:newframe("bodyfixed", source)
    e_pos = e_frame:to(u_pos)
    local lambda = -math.atan2(e_pos.z, e_pos.x);
    local beta = math.pi / 2 - math.atan2(math.sqrt(e_pos.x * e_pos.x + e_pos.z * e_pos.z), e_pos.y)
    local phi = math.atan2(math.tan(beta), (1 - f));
    long = math.deg(lambda)
    lat = math.deg(phi)
    return long, lat
end

while true do
    local obs = celestia:getobserver();
    local refObj = obs:getframe():getrefobject();
    if (refObj) then
        if refObj:type() == "location" or refObj:type() == "spacecraft" then
            refObj = refObj:getinfo().parent;
        end
        long, lat = get_long_lat(obs, refObj);
    end
    celestia:flash("Longitude: "..long.."\nLatitude: "..lat)
    wait(0)
end


Vincent Thx :!: :!: :!:
Marco Klunder
email: marco.klunder@xs4all.nl
Windows10 PD 3.0 GHz, 2 GB of RAM, Nvidia GeForce 6700 XL
Celestia161 / SVN + Lua Edu Tools v1.2 Beta9, Celestia160-ED and Celestia1621

Avatar
Fenerit M
Posts: 1880
Joined: 26.03.2007
Age: 17
With us: 17 years 7 months
Location: Thyrrenian sea

Re: Script method request: observer:getlonglat() method

Post #3by Fenerit » 06.06.2011, 23:56

Over the hills and far away for those about to rock we salute you.
Never at rest.
Massimo


Return to “Development”