Got an Idea for a Celx Utility Script?

All about writing scripts for Celestia in Lua and the .cel system
Toti
Developer
Posts: 338
Joined: 10.02.2004
With us: 20 years 9 months

Post #21by Toti » 29.04.2004, 17:51

don wrote:Sounds pretty much like Harald's script, yes?
Very much like it, but more general (ie. other bodies as reference objects, screenshots (maybe AVIs?), etc.) But for practical reasons, orbital data access methods should be developed first...

don wrote:Not sure if this time is available, or if it can be calculated.

You need to compute the cosine of the angle between the (-1)*[planet's center_surface point] and the [sun's center_planet center] vectors. This will give you an estimation of the point's exposure to light.
You can then use this exposure to calculate the correct ambient light for the point.
Just an idea: use this modified version of the dot product angle formula (do the proper vector manipulation first (see above)):

Code: Select all

exposure   = [(u . v) / ( length(u) * length(v) ) + 1] / 2
where:
         u,v are vectors 
         . is the dot product

This will return you a value in the range [0(no light)..1(full light)]
But perhaps there is a more general approach for this.

Bye
Last edited by Toti on 29.04.2004, 18:43, edited 1 time in total.

Harry
Posts: 559
Joined: 05.09.2003
With us: 21 years 2 months
Location: Germany

Post #22by Harry » 29.04.2004, 18:19

Toti wrote:... so let's hope that a few methods for obtaining orbital mechanics data are developed.
Yes, I missed such a method back when I wrote the "timestep" script - I probably will simply add the data in a body's RotationElements-object to the data returned by object:getinfo().

don wrote:Not sure if this time is available, or if it can be calculated.
You need to calculate the angle between the (-1)*[planet's center_surface point] and the [sun's center_planet center] vectors. This will give you an estimation of the point's exposure to light. You can then use this exposure to calculate the correct ambient light for the point.

Right. But we still want the "actual local time", don't we? How about this:
- get vector from planet to sun (in UCS)
- create planetographic frame of reference for planet
- transform vector (i.e. as position) to planetographic frame
- set y-component of transformed vector to 0
- compute angle between x-axis(?) and transformed vector and compute a time from it (maybe simply divide by 24 and add offset to compensate for position of meridian)

Would this work, or did I overlook something?

Harald

Toti
Developer
Posts: 338
Joined: 10.02.2004
With us: 20 years 9 months

Post #23by Toti » 29.04.2004, 22:30

Harry wrote:I probably will simply add the data in a body's RotationElements-object to the data returned by object:getinfo().
This will be a very compact and intuitive way to solve it: no need to remember an extra method.

Harry wrote:Right. But we still want the "actual local time", don't we?

I think that for the need to compute "light exposure", the equation that I added above should be enough.
Anyway, a function to calculate local time IS necessary by itself, so let's go for it...
The idea is about the same: calculate the angle between the sun-pointing and the surface-pointing vector. But now you are not interested in the "real" angle, but in the equatorial-projected angle (because the local "real" time in all points along a planet's meridian is the same)
So first project the referred vectors (do Y=0 in planetographic frame), then compute the signed angle and multiply it by [daylength]/(2*pi). This will give you the time to midday, so add [daylength]/2 and you will get the "real" time for the surface point longitude.
Is this idea compatible with what you posted above?

Bye

Harry
Posts: 559
Joined: 05.09.2003
With us: 21 years 2 months
Location: Germany

Post #24by Harry » 29.04.2004, 23:42

Toti wrote:[...getinfo()...]
This will be a very compact and intuitive way to solve it: no need to remember an extra method.
But then you have to remember the name of one more member of the table which is returned by getinfo(). TANSTAAFL ;)

I think that for the need to compute "light exposure", the equation that I added above should be enough.
Sure, should be perfect.
[...] Is this idea compatible with what you posted above?

I hope so, but I've had to much of vectors and coordinate transformation to try 8) But as long as the planetographic frame does most of the job this shouldn't be to hard...

Harald

L2Cache
Posts: 25
Joined: 19.01.2004
With us: 20 years 10 months

Select a script with a mouse click

Post #25by L2Cache » 05.01.2005, 22:57

I need a script like the selectascript.celx where the user can select to run one of several scripts from a menu with a single mouse click. This would be useful for a kiosk where the user has only a single button trackball and no keyboard access.

maxim
Posts: 1036
Joined: 13.11.2003
With us: 21 years
Location: N?rnberg, Germany

Post #26by maxim » 05.01.2005, 23:43

What (and where) is 'selectascript.celx'???

maxim

L2Cache
Posts: 25
Joined: 19.01.2004
With us: 20 years 10 months

Post #27by L2Cache » 06.01.2005, 20:08

Sorry, the correct filname is: RunAScript_v1-1.celx.txt
It's on Don's Clestia Scripting page linked in previous posts above. It allows the user to run scripts from a menu using keyboard input.

I have a modified version working like a kiosk now that allows the user to run several scripts from a numbered menu. The plan is to alllow the kiosk user access to a few number keys only, unless a mouse click solution can be found.

L2Cache
Posts: 25
Joined: 19.01.2004
With us: 20 years 10 months

Post #28by L2Cache » 17.01.2005, 18:43

L2Cache wrote:Sorry, the correct filname is: RunAScript_v1-1.celx.txt
It's on Don's Clestia Scripting page linked in previous posts above. It allows the user to run scripts from a menu using keyboard input.

I have a modified version working like a kiosk now that allows the user to run several scripts from a numbered menu. The plan is to alllow the kiosk user access to a few number keys only, unless a mouse click solution can be found.


In doing the modified verrsion of the script, I noticed Celestia gives an error after a few seconds if keys other than 1, 2, or 9 are pressed. Adding three lines of code, as shown in the section below, solves the problem -- other keys are ignored and no error message is given.

Code: Select all

    if (rtnKeypress == "1") then
      filename = "script1.celx"

    elseif rtnKeypress == "2" then
      filename = "script2.celx"
   
    elseif rtnKeypress == "9" then
      filename = ""
     
    else -- Not a valid keypress, ignore it
      filename = ""
      rtnKeypress = ""  -- Clear the last keypress

    end

Vincent
Developer
Posts: 1356
Joined: 07.01.2005
With us: 19 years 10 months
Location: Nancy, France

RunAScript_v1-1.celx not working

Post #29by Vincent » 06.06.2005, 10:08

I downloaded the RunAScript_v1-1.celx file and modified the script1.celx to the filename I want to run, but nothing happens when I make a choice.

It's not a problem of key definition because when I add a print command to the loadfile command, the print command works correctly.

I'm running Celestia 1.4 pre6 with Windows XP. Does the loadfile function work with XP ? Do I need to install a Lua library first ?

This script can be fantasticly usefull and I'd really like to make it work...
@+
Vincent

Celestia Qt4 SVN / Celestia 1.6.1 + Lua Edu Tools v1.2
GeForce 8600 GT 1024MB / AMD Athlon 64 Dual Core / 4Go DDR2 / XP SP3

L2Cache
Posts: 25
Joined: 19.01.2004
With us: 20 years 10 months

Post #30by L2Cache » 06.06.2005, 16:42

Make sure you are pressing the number 1 on the main keyboard. The numeric kepad numbers don't work.
Here's what I'm using for script1.celx in my kiosk demo. I works with run a script on my win 98 system, celestia 1.3.2:

Code: Select all

        function CEL(source)
          local script = celestia:createcelscript(source)
          while script:tick() do
            wait(0)
          end
        end

        CEL([[
   {
   cancel { }
   wait {duration 2.0 }
   timerate { rate 1 }
   set {name "AmbientLightLevel" value 0.1}
   labels { clear "stars|galaxies|moons|planets|spacecraft" }   
   labels { clear "asteroids|constellations" }   
   renderflags { clear "galaxies|stars|planets|orbits|comettails|boundaries|markers" }
   renderflags { clear "eclipseshadows|pointstars|constellations" }
   set { name "FOV" value 21 }
   renderflags { set "cloudmaps|nightmaps|ringshadows|atmospheres" }
   renderflags { set "stars|planets" }

   print { text "And now, our Earth . . ." row -2 }
   select { object "Sol/Earth" }
   goto { time 15 distance 10 }
   wait { duration 15.0 }
   orbit { axis [ 0 1 0 ] rate 30 duration 20 }
   wait { duration 2.0 }
   goto { time 5 distance 1500 }
   wait { duration 5.0 }
   }
        ]])
 

Vincent
Developer
Posts: 1356
Joined: 07.01.2005
With us: 19 years 10 months
Location: Nancy, France

Post #31by Vincent » 06.06.2005, 17:35

L2Cache wrote:Make sure you are pressing the number 1 on the main keyboard. The numeric kepad numbers don't work.


Yes, I know that.

I think the problem comes from the loadfile function : I tried to add a print command to the loadfile command :

Code: Select all

...
if (rtnKeypress == "1") then
      celestia:print("TEST")
      filename = "solstice_hiver.celx"
...


When I press "1" on the main keyboard, the script correctly displays the text "TEST", but nothing else happens... That's why I'm sure the problem doesn't come from the keyboard but from the loadfile command...
@+
Vincent

Celestia Qt4 SVN / Celestia 1.6.1 + Lua Edu Tools v1.2
GeForce 8600 GT 1024MB / AMD Athlon 64 Dual Core / 4Go DDR2 / XP SP3

L2Cache
Posts: 25
Joined: 19.01.2004
With us: 20 years 10 months

Post #32by L2Cache » 06.06.2005, 19:29

If the original run a script works with the code I posted used as script1.celx on your system, then you could rename solstice_hiver.celx to script1.celx and run it with the original run a script. If it won't work then, it may be a problem with the code in solstice_hiver.celx.

Vincent
Developer
Posts: 1356
Joined: 07.01.2005
With us: 19 years 10 months
Location: Nancy, France

Post #33by Vincent » 06.06.2005, 19:44

L2Cache wrote:If the original run a script works with the code I posted used as script1.celx on your system, then you could rename solstice_hiver.celx to script1.celx and run it with the original run a script. If it won't work then, it may be a problem with the code in solstice_hiver.celx.


Sorry, I forgot to precise that run_a_script doesn't work with your script1.celx file. I also tried with a very simple script, but it doesn't work neither... Moreover, my solstice_hiver.celx script works very well when I load it from Celestia... That kills me :evil:
@+
Vincent

Celestia Qt4 SVN / Celestia 1.6.1 + Lua Edu Tools v1.2
GeForce 8600 GT 1024MB / AMD Athlon 64 Dual Core / 4Go DDR2 / XP SP3

L2Cache
Posts: 25
Joined: 19.01.2004
With us: 20 years 10 months

Post #34by L2Cache » 07.06.2005, 04:27

You could install celestia 1.3.2 in another folder like celestia2 and see if run a script will work with script1.celx in that celestia version, like it does on my system. If it does, the problem is with the later version of celestia.

Vincent
Developer
Posts: 1356
Joined: 07.01.2005
With us: 19 years 10 months
Location: Nancy, France

Post #35by Vincent » 07.06.2005, 06:28

That's what I did just after you told me you were running Celestia 1.3.2... And it didn't work.
@+
Vincent

Celestia Qt4 SVN / Celestia 1.6.1 + Lua Edu Tools v1.2
GeForce 8600 GT 1024MB / AMD Athlon 64 Dual Core / 4Go DDR2 / XP SP3

L2Cache
Posts: 25
Joined: 19.01.2004
With us: 20 years 10 months

Post #36by L2Cache » 07.06.2005, 18:03

If script1.celx runs on it's own ok, then it should run from run a script if they are in the same folder.

It works for me on three diferent systems running windows 98se and celestia 1.3.2. If you have access to a system running windows 98se, you could try the experiment there.

Vincent
Developer
Posts: 1356
Joined: 07.01.2005
With us: 19 years 10 months
Location: Nancy, France

Post #37by Vincent » 07.06.2005, 21:51

- Script1.celx runs on it's own...
- Run_a_script and script1.celx are in the same folder...
- I tried to run Run_a_script on my old Win 98 SE system, and it didn't work...

AAAARRRGH !

8O :lol: :? :( :cry: :evil: :twisted:
@+
Vincent

Celestia Qt4 SVN / Celestia 1.6.1 + Lua Edu Tools v1.2
GeForce 8600 GT 1024MB / AMD Athlon 64 Dual Core / 4Go DDR2 / XP SP3

L2Cache
Posts: 25
Joined: 19.01.2004
With us: 20 years 10 months

Post #38by L2Cache » 08.06.2005, 04:41

I'm out of ideas now, sorry.

Vincent
Developer
Posts: 1356
Joined: 07.01.2005
With us: 19 years 10 months
Location: Nancy, France

Post #39by Vincent » 08.06.2005, 21:41

As usual, you find the (trivial) solution of your problem(s) when you stop searching... :D
I went for a walk with my 2 year old son to visit the new Stanislas Place in Nancy when I got the solution :

Not only the 2 files have to be in the same folder, but you also have to specify the folder in which run_a_script.celx can find script1.celx.

- So the filename string is "script1.celx" ONLY if both files are in the main Celestia folder !
- But it is "scripts/script1.celx" (on windows) if both files are in a "scripts" folder of the main Celestia folder

Have a good night/evening/morning... :D

Thanks L2Cache ! :wink:
@+
Vincent

Celestia Qt4 SVN / Celestia 1.6.1 + Lua Edu Tools v1.2
GeForce 8600 GT 1024MB / AMD Athlon 64 Dual Core / 4Go DDR2 / XP SP3

L2Cache
Posts: 25
Joined: 19.01.2004
With us: 20 years 10 months

Post #40by L2Cache » 09.06.2005, 18:53

Thanks for the information. I've been running the files from the main Celestia folder, so I never encountered the problem.


Return to “Scripting”