Page 1 of 2

Converting a cel:URL position into a celx command

Posted: 28.01.2010, 21:29
by fsgregs
Hi everyone. I need your help. I am trying to write a short script to go to this position in a celx script, within Vincent's Lua Edu tools feature. Celx scripts do not currently recognize cel:URL's, without calling a special function. When I use that function inside Lua Edu Tools, it does not work because the Lua Edu Tools feature uses its own internal scripts. Its complicated.

Anyway, here is the place I want to go:

cel://Follow/Milky%20Way/2010-01-12T01:00:51.92234?x=AAAAAAAAEA+YkcBQWP///w&y=AAAAAAAAN+aA47qVEQ&z=AAAAAAAAwk0ZLPk5x////w&ow=-0.385606&ox=-0.677335&oy=-0.378058&oz=0.499597&select=Milky%20Way&fov=32&ts=1&ltd=0&p=0&rf=513943&lm=128&tsrc=0&ver=3

I need the exact celx script "gotoposition" commands that I can add to a celx script, to go to that spot. Can anyone please help me?

Thanks in advance

Frank

Re: Converting a cel:URL position into a celx command

Posted: 29.01.2010, 21:37
by Chuft-Captain
fsgregs wrote:Hi everyone. I need your help. I am trying to write a short script to go to this position in a celx script, within Vincent's Lua Edu tools feature. Celx scripts do not currently recognize cel:URL's, without calling a special function. When I use that function inside Lua Edu Tools, it does not work because the Lua Edu Tools feature uses its own internal scripts. Its complicated.
Frank,
Are you saying that the setURL command doesn't work inside the Lua Tools? This would work in any normal celX script.
(I haven't downloaded Vincent's tools yet, so I can't confirm this problem, but I gather that is what you are saying.)

CC

Re: Converting a cel:URL position into a celx command

Posted: 30.01.2010, 02:00
by fsgregs
Are you saying that the setURL command doesn't work inside the Lua Tools? This would work in any normal celX script.

My problem occurs because I am trying to call a celx script, from within another script, a lua script. One lua script cannot be called from within another one, according to Vincent. Here is what he said about the problem:

Actually, the problem doesn't come from the Lua Tools, but from the
fact that your script is launched from within another script -- a Lua
script. You'd have the same problem if you tried to call your script
from another celx script. The problem comes from the loadfile() or
dofile() functions thar are used to run the second script. Using these
functions, Celestia doesn't recognize the second script as a Celestia
script, and some special functions like CEL(source) or even the wait()
command are simply ignored, which can be quite anoying.

I'm about to add a celestia:runscript command to Celestia 1.6.1 that
will fix this issue. With this command, the second script, whatever
its content, will run correctly.


Its a bit complicated, but simply put, I need to use a gotoposition command to travel to the spot that my celURL would take me to if I clicked on it separately. If you click on that celURL and go to that spot, what would I type in a celx script to go to that same time and place without the use of a celURL? I have no idea how to find my position and I am a total illiterate in celx scripting. If anyone can help me, I'd most appreciate it.

Thanks

Frank

Re: Converting a cel:URL position into a celx command

Posted: 30.01.2010, 05:49
by John Van Vliet
--- edit ---

Re: Converting a cel:URL position into a celx command

Posted: 01.02.2010, 18:07
by Chuft-Captain
John,
Nice to see you thinking outside the box, but unfortunately, even if that was to work, it's OS specific. We need a solution that works across Windows, Mac, and Linux platforms.

Frank,
I think that rather than call one celx file from another, what we need really is to be able to place several scripts in the same folder and have access to any of their methods from any other script in the same folder. ie. Execute the function, rather than the file.
(Essentially a library of functions, if you get my drift).

I don't know enough about LUA/celX at present to know whether this is possible, but maybe Vincent knows.
Would this also solve your problem?

Re: Converting a cel:URL position into a celx command

Posted: 01.02.2010, 18:14
by t00fri
Chuft-Captain wrote:John,
Nice to see you thinking outside the box, but unfortunately, even if that was to work, it's OS specific. We need a solution that works across Windows, Mac, and Linux platforms.
...

CC,

that's NOT at all an OS specific proposal. The 'bash' and other clever shells from UNIX are all available under Windows, of course. I would never even touch Windows, without these shells. This would mean spending my time with CLICKING ...my God what a horror!

I am not joking here:
For most IT experts who are usually VERY fast with the keyboard, every click means interrupting your typing, grabbing the mouse and then returning to some standard "10 finger typing" position. This takes a LOT of unnecessary time and concentration...

Fridger

Re: Converting a cel:URL position into a celx command

Posted: 01.02.2010, 20:34
by John Van Vliet
--- edit ---

Re: Converting a cel:URL position into a celx command

Posted: 01.02.2010, 22:18
by Chuft-Captain
t00fri wrote:that's NOT at all an OS specific proposal. The 'bash' and other clever shells from UNIX are all available under Windows, of course. I would never even touch Windows, without these shells
Perhaps I need to rephrase the statement... "We need a solution that works across standard Windows, Mac, and Linux platforms, without the installation of additional environments."

Of course Unix environments are available under Windows, but my point was that any given CELX script written in one environment should (at least IMO) be able to run correctly in the other OS's without the pre-requisite installation of additional environments like Cygwin. (Otherwise we're just adding complexity and creating an additional requirement/dependency for running CELX scripts in those other environments.)
ie. Ideally the solution needs to be based in LUA or C++ (both platform independent from a software development perspective), rather than being dependent on the presence of any additional shell or other tool in a given user's configuration.
If a Celestia user doesn't have these shells installed, or the where-with-all to install them, they still should be able to run the scripts.

Re: Converting a cel:URL position into a celx command

Posted: 01.02.2010, 22:38
by t00fri
Chuft-Captain wrote:
t00fri wrote:that's NOT at all an OS specific proposal. The 'bash' and other clever shells from UNIX are all available under Windows, of course. I would never even touch Windows, without these shells
Perhaps I need to rephrase the statement... "We need a solution that works across standard Windows, Mac, and Linux platforms, without the installation of additional environments."

Of course Unix environments are available under Windows, but my point was that any given CELX script written in one environment should (at least IMO) be able to run correctly in the other OS's without the pre-requisite installation of additional environments like Cygwin. (Otherwise we're just adding complexity and creating an additional requirement/dependency for running CELX scripts in those other environments.)
ie. Ideally the solution needs to be based in LUA or C++ (both platform independent from a software development perspective), rather than being dependent on the presence of any additional shell or other tool in a given user's configuration.
If a Celestia user doesn't have these shells installed, or the where-with-all to install them, they still should be able to run the scripts.

CC,

these shells are standard both in MAC OS and Linux. No further installation necessary. The bash comes with the OS. So what is left is Windows. It all depends on what people want to do. E.g. if you don't install VS 2008 Express in addition, you won't be able to build Celestia under Windows. That's too bad, isn't it since meanwhile Celestia-compilation is done with a single CLICK after downloading the sources. For me a compiler is a standard configuration in ANY OS, notably a (free) compiler by Microsoft in Windows...

So what's the difference that one would be unable to run those scripts without clicking ONCE more: namely to install the stand-alone win-bash.

http://win-bash.sourceforge.net/

The win-bash needs no special environment or DLLs. There is just one binary and that's it.

You will presumably reply that some of the Noops will be unable to install the win-bash with a CLICK (after having installed Celestia with a previous CLICK ;-) ) ...

Fridger

Re: Converting a cel:URL position into a celx command

Posted: 02.02.2010, 02:04
by Chuft-Captain
t00fri wrote:CC,

these shells are standard both in MAC OS and Linux. No further installation necessary. The bash comes with the OS. So what is left is Windows. It all depends on what people want to do. E.g. if you don't install VS 2008 Express in addition, you won't be able to build Celestia under Windows. That's too bad, isn't it since meanwhile Celestia-compilation is done with a single CLICK after downloading the sources. For me a compiler is a standard configuration in ANY OS, notably a (free) compiler by Microsoft in Windows...

So what's the difference that one would be unable to run those scripts without clicking ONCE more: namely to install the stand-alone win-bash.

http://win-bash.sourceforge.net/

The win-bash needs no special environment or DLLs. There is just one binary and that's it.

You will presumably reply that some of the Noops will be unable to install the win-bash with a CLICK (after having installed Celestia with a previous CLICK ;-) ) ...

Fridger
Ha,
Your mind-reading always amuses me. :wink:

Ok, I'll bite! ...
I would say that MOST of the Celestia Users in the world would probably expect to install the Celestia executable and then have everything just work out of the box.
Unlike you, I don't think that's an unreasonable expectation (regardless of their CLICK proficiency. :LOL:).
I don't know how many (Windows) Celestia Users there are in total worldwide, maybe 100,000, 1,000,000?? ... Chris may have some idea from download stats, but I'm sure that the vast majority wouldn't know (or want) to check either here or at CM in order to keep up to date with the latest DLL they need to install into their OS in order to run scripts.

So, to cater for these users (the majority), if win-bash was to be a pre-requisite to running certain types of scripts, then really it should be packaged (if it's license permits) with the (Windows) Celestia Installation.

I'm not however advocating that, as I still contend that the more elegant solution is to find a way to achieve what we want within LUA... which would make the whole bash argument moot.
That's in an ideal world of course, but anyway that's my 4CW. :wink:

I suspect the elegant solution probably won't be possible as LUA's a scripting language rather than a compiled language, and may have some limitations wrt. cross-file exposure of methods/functions.

CC

PS. Chris, if you're following this, I'd be interested to know what is your estimate of Celestia Users worldwide?? MAC/LINUX/WIN
(Number of downloads with each major release might give an idea.)

Re: Converting a cel:URL position into a celx command

Posted: 02.02.2010, 10:32
by t00fri
CC,

it is quite obvious that the best solution would be staying within lua.

But sorry, I see our little discussion more generally. So many Windows users don't even KNOW they are having cmd.exe, the Windows console that accepts commands. Same for MAC OS users: many don't even KNOW that they are having a complete UNIX OS underneath with a most clever 'bash' etc.

win-bash or bash via CYGWIN is such a versatile console tool that cmd.exe just looks like a prehistoric something. Quite seriously once more: I would not mess around with Windows without having one of these UNIX shells as a fast and most powerful interface for my daily work.

Fridger

PS: The Celestia download statistic is easily inspected at SourceForge. The total download numbers range around 7 million meanwhile. Windows is certainly the dominant fraction. But this doesn't mean that all Windows users share the same attitudes ...

Re: Converting a cel:URL position into a celx command

Posted: 03.02.2010, 04:23
by Chuft-Captain
t00fri wrote:But sorry, I see our little discussion more generally...
... whereas I've been trying hard to remain on the subject of how best to get CELX scripts calling each others methods, which may in fact solve Franks problem. (regardless of the usual arguments about the merits of the different platforms)....Of course, it's quite possible that there is no way to do this keeping within LUA.
... Apology accepted! :wink:

t00fri wrote:PS: The Celestia download statistic is easily inspected at SourceForge. The total download numbers range around 7 million meanwhile. Windows is certainly the dominant fraction. But this doesn't mean that all Windows users share the same attitudes ...
Thanks for that. -- I didn't know those stats were there.
If you're interested, see here: Celestia D/L stats from Sourceforge presented graphically

CC

Re: Converting a cel:URL position into a celx command

Posted: 03.02.2010, 15:35
by Vincent
Here are the different options we currently have to launch a second celx script from within a Lua or celx script:

1- Use the Lua dofile() or loadfile() commands.
However, these functions will run the content of the second script as a Lua chunk that won't be
recognized by celestiacore as a celestia script. And thus, special commands like wait() or celscript:tick()
will be simply ignored. This can be quite annoying since the wait() command is pretty frequently used.
A workaround would be to run the second script in a different thread, and use coroutines to yield and
resume the script. But this is really complex and I've never managed to make it work correctly...

2- Use the Lua os.execute() function to execute an operating system shell command.

Code: Select all

os.execute([[start "" "D:\TortoiseSVN\celestia 1.6.1\celestia.exe" --once --url "scripts/test2.celx"]])

However, the os.execute function is highly system dependent. Moreover, the celestia path and the script path
may vary from a system to another...

3- Use the new celestia:runscript() celx function that I'm about to add to celestia 1.6.1.
Indeed, Celestia already has it own runScript method which is part of the CelestiaCore class.
So I made a very simple fix by adding a couple of lines to celx.cpp so as to create the
celestia:runscript() celx function.

So all we have to do now is to wait for Celestia 1.6.1 to be released... :wink:

Re: Converting a cel:URL position into a celx command

Posted: 03.02.2010, 17:30
by t00fri
Chuft-Captain wrote:... Apology accepted! :wink:

...
CC

CC,

sure enough my above reply was NOT meant to be an apology! ;-)

I was rather trying to tell you that John's proposal was not OS dependent in any way, since --even in Windows-- many users would miss a lot without one-click-installing AND using one of the powerfui UNIX shells. Given my non-negligible familiarity with Lua, I was actually quite convinced that a pure Lua solution was possible and thus preferred.

I think all this was pretty well on topic, albeit seen from a more general perspective that reflected my substantial knowledge in this area.

Fridger

Re: Converting a cel:URL position into a celx command

Posted: 03.02.2010, 18:10
by fsgregs
Thank you all for the efforts you've taken to analyze the problem. I guess we can wait til the release of 1.6.1, but in the interim, I believe there already are celx commands to take a viewer to a specific location in space, without the need to read one script from another, or to activate a cel:URL. Is it the "gotoposition" commands? I really don't know. I've tried to figure out the code, but ... :?

Anyway, given the celURL that I posted in the first post, is there a way to go there by activating the celURL from this post, then identifying what gotoposition code lines would be needed to go to that same position in a celx script? In this case, the time is not important.

Frank

Re: Converting a cel:URL position into a celx command

Posted: 03.02.2010, 19:08
by Marco Klunder
Frank,

As far as I can analyse the CELurl, the following CELX code must do the goto position, observer orientation and many other important CELurl settings:

Code: Select all

-- Because Celestia v1.6.1 supports the celestia:seturl() method, the following line of code can be called.
-- celestia:seturl("cel://Follow/Milky%20Way/2010-01-12T01:00:51.92234?x=AAAAAAAAEA+YkcBQWP///w&y=AAAAAAAAN+aA47qVEQ&z=AAAAAAAAwk0ZLPk5x////w&ow=-0.385606&ox=-0.677335&oy=-0.378058&oz=0.499597&select=Milky%20Way&fov=32&ts=1&ltd=0&p=0&rf=513943&lm=128&tsrc=0&ver=3", obs)

-- For older Celestia versions (including the actual v1.6.0), you can use the following methods instead:

-- Initialize renderflags according seturl
celestia:setrenderflags{atmospheres = true,
                        automag = true,
                        boundaries = false,
                        cloudmaps = true,
                        cloudshadows = false,
                        comettails = true,
                        constellations = false,
                        eclipseshadows = true,
                        galaxies = true,
                        grid = false,
                        markers = true,
                        nebulae = true,
                        nightmaps = true,
                        orbits = false,
                        planets = true,
                        ringshadows = true,
                        stars = true,
                        smoothlines = false,
                        lightdelay = false,
                        partialtrajectories = false,
                        ecliptic = false,       -- Comment line if NOT using Celestia v1.6.0 or later
                        equatorialgrid = false, -- Comment line if NOT using Celestia v1.6.0 or later
                        galacticgrid = false,   -- Comment line if NOT using Celestia v1.6.0 or later
                        eclipticgrid = false,   -- Comment line if NOT using Celestia v1.6.0 or later
                        horizontalgrid = false  -- Comment line if NOT using Celestia v1.6.0 or later
                       }

-- Initialize orbitflags according seturl
celestia:setorbitflags{Planet = true,
                       Moon = false,
                       Asteroid = false,
                       Comet = false,
                       Spacecraft = false,
                       Invisible = false,
                       Unknown = false,
                       DwarfPlanet = true,      -- Comment line if NOT using Celestia v1.6.0 or later
                       MinorMoon = false,       -- Comment line if NOT using Celestia v1.6.0 or later
                       Star = false             -- Comment line if NOT using Celestia v1.6.0 or later
                      }

-- Initialize labelflags according seturl
celestia:setlabelflags{planets = false,
                       moons = false,
                       spacecraft = false,
                       asteroids = false,
                       comets = false,
                       stars = false,
                       galaxies = false,
                       locations = false,
                       constellations = false,
                       i18nconstellations = true,
                       openclusters = false,
                       nebulae = false,
                       dwarfplanets = false,    -- Comment line if NOT using Celestia v1.6.0 or later
                       minormoons = false,      -- Comment line if NOT using Celestia v1.6.0 or later
                       globulars = false        -- Comment line if NOT using Celestia v1.6.0 or later
                      }

-- Initialize some other settings
celestia:setambient(0.10)
celestia:setfaintestvisible(7.01)
-- celestia:setstarstyle("point")
celestia:setstarstyle("fuzzy")
-- celestia:setstarstyle("disc")
wait(0.0)

-- Set Field Of View
obs = celestia:getobserver()
obs:setfov(math.rad(32.0))

-- find, select and follow the Milky Way according the seturl
milkyway = celestia:find("Milky Way")
celestia:select(milkyway)
obs:follow(milkyway)

-- Set the mentioned data/time and timerate
tdb_dt = celestia:utctotdb(2010, 01, 12, 01, 00, 51.92234)
celestia:settime(tdb_dt)
celestia:settimescale(1)

-- Goto the seturl position and set the observer orientation accordingly
newpos = celestia:newposition("AAAAAAAAEA+YkcBQWP///w", "AAAAAAAAN+aA47qVEQ", "AAAAAAAAwk0ZLPk5x////w")
newrot = celestia:newrotation(-0.385606, -0.677335, -0.378058, 0.499597)
obs:setorientation(newrot)
obs:goto(newpos,0.0)
wait(0.0)


Hope you can use it now.
These newposition and newrotation methods at the end of the celx were especially designed to pretty easy use the given CELurl values in a CELX script.

Marco

Re: Converting a cel:URL position into a celx command

Posted: 03.02.2010, 22:52
by Chuft-Captain
t00fri wrote:sure enough my above reply was NOT meant to be an apology! ;-)
sure enough, I knew that. :lol:

t00fri wrote:... I was actually quite convinced that a pure Lua solution was possible and thus preferred.
I was less convinced, though hopeful, that a pure Lua solution was possible.
Anyway, it looks like Vincent's on the case now, so a solution is sure to follow. :)

CC

Re: Converting a cel:URL position into a celx command

Posted: 05.02.2010, 01:08
by fsgregs
Marco and Vincent:

Marco, thank you so much for the effort you made to write a celx script that would convert my cel:URL to go to the same spot. It works just fine if I click on it separately in 1.6.0 as a single script. Sadly, when I turn on the addon within the addons folder of Lua Edu tools, the script is called OK, but the viewer doesn't go anywhere. The viewer stay still. The commands to move the viewer to the new location simply don't work.

This is most confusing, because there is a script being used in Lua Edu Tools as an addon, that does work. It is a small script for the addon, "Large Scale Universe". When I turn on that addon from within Lua Edu Tools by toggling it on in the "Set Addon Visibility" box, the script immediately activates and the viewer is whisked to a position deep in space far beyond the Milky Way. Why the position commands in this celx script work in Lua Edu Tools, and your position commands don't work, is a mystery perhaps Vincent could figure out. Here is the brief script from the Large Scale Universe:

function mark_galaxies()
for dso in celestia:dsos() do
if dso:type() == "galaxy" then
dso:mark( "white", "disk", 1, 0.6 )
end
end
end

--celestia:unmarkall()
--celestia:setrenderflags { markers = true }
--mark_galaxies()

obs = celestia:getobserver()
mw = celestia:find("Milky Way")
celestia:select(mw)

mw_dist = obs:getposition():distanceto(mw:getposition()) / (3.08e19)
mw_d = 10
if mw_dist > 50 and mw_dist < 1e3 then
mw_d = 2
end

obs:gotodistance(mw, 5.8e3 * mw:radius() / (obs:getfov() / 0.4688), mw_d) --changed from 1.1e4 to 5.8e3 to get closer to main part of clusters
celestia:setrenderflags { nebulae = true } -- added to turn on nebula


Thanks to everyone. Unless there is a way around this, i will just have to remove that addon from Lua Tools until 1.6.1. There is no use having it if the viewer cannot go to the right position to view the Hubble classes.

FYI, this is the view the addon is supposed to give the user:
Hubble class.jpg

Re: Converting a cel:URL position into a celx command

Posted: 05.02.2010, 03:13
by Cham
Frank,

for the previous Hubble classification addon, I'm using the following script to place the user exactly where it should :

Code: Select all

-- Title: Activer/D?sactiver la classification galactique de Hubble

Populations = celestia:find("Populations")
MilkyWay = celestia:find("Milky Way")
E6 = celestia:find("E6")
Sa = celestia:find("Sa")
SBa = celestia:find("SBa")
obs = celestia:getobserver()

Hubble_t = {
      "Irr",
      "E0",
      "E2",
      "E4",
      "E6",
      "S0",
      "Sa",
      "Sb",
      "Sc",
      "SBa",
      "SBb",
      "SBc",

      "Irr_label",
      "E0_label",
      "E2_label",
      "E4_label",
      "E6_label",
      "S0_label",
      "Sa_label",
      "Sb_label",
      "Sc_label",
      "SBa_label",
      "SBb_label",
      "SBc_label",

      "Irr_frame",
      "E0_frame",
      "E2_frame",
      "E4_frame",
      "E6_frame",
      "S0_frame",
      "Sa_frame",
      "Sb_frame",
      "Sc_frame",
      "SBa_frame",
      "SBb_frame",
      "SBc_frame"
}

if not HubbleState then
   HubbleState = 1
else
   HubbleState = HubbleState + 1
   if HubbleState > 3 then
      HubbleState = 1
   end
end

if HubbleState == 1 then
   celestia:setrenderflags{nebulae = true}

   for k, object in pairs(Hubble_t) do
      hubble = celestia:find(object)
      hubble:setvisible(true)
   end

   celestia:select(MilkyWay)
   obs:gotolonglat(E6, math.rad(0), math.rad(0), 1.25E19, 0)
   wait(0)

   vertical = (Sa:getposition() - SBa:getposition()):normalize()
   obs:lookat(obs:getposition(), E6:getposition(), vertical)

   celestia:print(" Classification galactique de Hubble affich?e", 3)

elseif HubbleState == 2 then
   Populations:setvisible(true)

   celestia:print(" Statistiques affich?es pour un rayon de 100 millions d'ann?es-lumi?re.\n Nombre total de galaxies dans l'Univers de Celestia : 10 937.", 10)

elseif HubbleState == 3 then
   Populations:setvisible(false)
   celestia:select(MilkyWay)
   obs:follow(MilkyWay)
   obs:center(MilkyWay, 2)

   for k, object in pairs(Hubble_t) do
      hubble = celestia:find(object)
      hubble:setvisible(false)
   end

   celestia:print(" Classification de Hubble d?sactiv?e", 3)
end

Re: Converting a cel:URL position into a celx command

Posted: 05.02.2010, 04:56
by fsgregs
Cham:

Thanks for posting your goto script. Boy, this gets weirder and weirder. I inserted your script into the Lua Edu Tools addon, to replace the other one. It worked! When I activated the addon in Lua Edu Tools by checking the addon box in the "Set Addon Visibility" menu, the viewer actually did go out into space and get positioned in front of the hubble classes.

Unfortunately, the position one goes to ... is NOT the correct position. Rather, the Hubble classes are skewed at an angle, and they are backward (the viewer is behind them). Why running your script from inside Lua Edu Tools would bring me close to the correct place but put me in the wrong spot, is an absolute mystery.

here is the view when I click on your script directly:
h3.jpg


Here is the view when I activate the script from within Lua Edu Tools by checking the addon check box:
h2.jpg


Why this would occur is ... :?:

Frank