A small CELX function library

All about writing scripts for Celestia in Lua and the .cel system
Topic author
maxim
Posts: 1036
Joined: 13.11.2003
With us: 21 years
Location: N?rnberg, Germany

A small CELX function library

Post #1by maxim » 18.04.2005, 12:46

Here are some wrapper functions for providing CEL functionality which doesn't exists in CELX.
Nothing special, but you may add this to your personal CELX function library, and use it as convenient replacement functions when converting CEL-scripts to CELX scripts.

Code: Select all

--*---------------------------------------------*----------
--* CELX replacement for CEL 'orbit()' function *----------
--*---------------------------------------------*----------
function orbit(axis,rate,duration)
  script = celestia:createcelscript(string.format("{ orbit {axis %s rate %1.1f duration %1.1f} }",axis,rate,duration))
  while script:tick(0.001) do
    wait (0)
  end
end 


Code: Select all

--*-----------------------------------------------*----------
--* CELX replacement for CEL 'gotoloc()' function *----------
--*-----------------------------------------------*----------
function gotoloc(x,y,z,xrot,yrot,zrot,time)
  script = celestia:createcelscript(string.format("{ gotoloc {time %1.1f position [%i %i %i] xrot %i yrot %i zrot %i} }",time,x,y,z,xrot,yrot,zrot))
  while script:tick(0.001) do
    wait (0)
  end
end 


Some more for your CELX function library:

Code: Select all

--*--------------------------------------------------------------------------------*--
--* 'dimUpDown()' let's you increase or decrease the actual ambient light setting, *--
--* so that you can easily show features that are hidden in (planetary) shadows.   *--
--*                                                                                *--
--* start   The dimming start value. Normaly that should be retrieved via          *--
--*         celestia:getambient() before. Possible values are between 0 and 1      *--
--*                                                                                *--
--* stop    The dimming end value. Should be greater than 'start' for dimming      *--
--*         up and less than 'start' for dimming down. Possible values are         *--
--*         between 0 and 1                                                        *--
--*                                                                                *--
--* step    The increase/decrease amount of ambient light in each iterating step.  *--
--*         Should be positive for dimming up and negative for dimming down.       *--
--*         '0.02' is a good mean value.                                           *--
--*                                                                                *--
--* time    The waiting time between each iteration step. Greater values make      *--
--*         dimming slower. Smaller values make dimming faster. '0.01' is a good   *--
--*         mean value                                                             *--
--*--------------------------------------------------------------------------------*--

function dimUpDown(start, stop, step, time)
  for i = start,stop,step do
    celestia:setambient (i)
    wait (time)
  end
  wait (0.4)
end 

maxim
Last edited by maxim on 20.04.2005, 12:17, edited 1 time in total.

symaski62
Posts: 610
Joined: 01.05.2004
Age: 41
With us: 20 years 6 months
Location: france, divion

Post #2by symaski62 » 18.04.2005, 23:55

Code: Select all

--*---------------------------------------------*----------
--* CELX replacement for CEL 'orbit()' function *----------
--*---------------------------------------------*----------
function orbit(axis,rate,duration)
  script = celestia:createcelscript(string.format("{ orbit {axis %s rate %1.1f duration %1.1f} }",axis,rate,duration))
  while script:tick(0.001) do
    wait (0)
  end
end 


error '{' ?!? :oops:
windows 10 directX 12 version
celestia 1.7.0 64 bits
with a general handicap of 80% and it makes much d' efforts for the community and s' expimer, thank you d' to be understanding.

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

Post #3by maxim » 20.04.2005, 12:18

I renamed the topic because this is gonna be a bit more general.
More content to follow...

maxim

cpotting
Posts: 164
Joined: 18.03.2004
Age: 63
With us: 20 years 8 months
Location: Victoria, BC Canada

Post #4by cpotting » 20.07.2005, 13:22

I created this function just recently. It is like your dimUpDown, except that it handles the ambient light level, the visible magnitude and the field of view simultaneously. It can easily be exanded to handle any other scalar setting as well, though I haven't run across the need to do so yet (e.g. minorbitsize, minfeaturesize, etc).

Code: Select all

--[[ Smoothly changes the values for the current observer's field of view, the ambient light level and/or the faintest
     visible star magnitude over a period of time.
     new_values may include the items: fov, ambient, magnitude
     duration is in seconds and defaults to 2 ]]
function smooth_change(new_values, duration)
   local init_code = "obs=celestia:getobserver();"
   if duration == nil then
      init_code = init_code .. "duration = 2;"
   else
      init_code = init_code .. "duration = " .. duration .. ";"
   end
   init_code = init_code .. "end_time=celestia:getscripttime() + duration;"
   local change_code = "percent = 1;" ..
                       "while percent > 0 do\n" ..
                          "percent=math.max((end_time - celestia:getscripttime()) / duration, 0);"
   local final_code = "wait(0.0);" ..
                      "end;"
   local changes = false
   if new_values.fov ~= nil and math.rad(new_values.fov) ~= celestia:getobserver():getfov() then
      init_code = init_code .. "delta_fov = math.rad(" .. new_values.fov .. ") - obs:getfov();"
      change_code = change_code .. "obs:setfov(math.rad(" .. new_values.fov .. ") - delta_fov * percent);"
      changes = true
   end
   if new_values.magnitude ~= nil and new_values.magnitude ~= celestia:getfaintestvisible() then
      init_code = init_code .. "delta_mag = " .. new_values.magnitude .. " - celestia:getfaintestvisible();"
      change_code = change_code .. "celestia:setfaintestvisible(" .. new_values.magnitude .. " - delta_mag * percent);"
      changes = true
   end
   if new_values.ambient ~= nil and new_values.ambient ~= celestia:getambient() then
      init_code = init_code .. "delta_ambient = " .. new_values.ambient .. " - celestia:getambient();"
      change_code = change_code .. "celestia:setambient(" .. new_values.ambient .. " - delta_ambient * percent);"
      changes = true
   end
   if changes then
      assert(loadstring(init_code .. change_code .. final_code))()
   end
end
-- example:
smooth_change({ fov=24, magnitude=8, duration=5 })


Let me know what you think of it.
Clive Pottinger
Victoria, BC Canada


Return to “Scripting”