Page 1 of 1

Script method request: observer:getlonglat() method

Posted: 26.04.2011, 20:09
by Marco Klunder
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

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

Posted: 06.06.2011, 19:58
by Marco Klunder
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 :!: :!: :!:

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

Posted: 06.06.2011, 23:56
by Fenerit
Over the hills and far away for those about to rock we salute you.