One button for showing constellation scheme and name

The place to discuss creating, porting and modifying Celestia's source code.
Topic author
Imy
Posts: 109
Joined: 13.10.2006
With us: 18 years 1 month

One button for showing constellation scheme and name

Post #1by Imy » 05.01.2008, 09:47

Hello,

Would not be interesting having cycle buttons for showing constellation schemes and constellation names?
For instance, I press a first time '/' button from keyboard, and then constellation schemes become visible, I press a second time and then is added the names of these constellations, a third press for showing only names and the last one to hide names and schemes of constellation, and you restart...
It would be quicker than always playing with panels. It may free also some letters for other functions. What do you think about that?

Thanks in advance.

ElChristou
Developer
Posts: 3776
Joined: 04.02.2005
With us: 19 years 9 months

Post #2by ElChristou » 05.01.2008, 10:13

Not a bad idea...
Image

ANDREA
Posts: 1543
Joined: 01.06.2002
With us: 22 years 5 months
Location: Rome, ITALY

Post #3by ANDREA » 05.01.2008, 11:05

I agree absolutely, it's a good idea.
Bye

Andrea :D
"Something is always better than nothing!"
HP Omen 15-DC1040nl- Intel® Core i7 9750H, 2.6/4.5 GHz- 1TB PCIe NVMe M.2 SSD+ 1TB SATA 6 SSD- 32GB SDRAM DDR4 2666 MHz- Nvidia GeForce GTX 1660 Ti 6 GB-WIN 11 PRO

Topic author
Imy
Posts: 109
Joined: 13.10.2006
With us: 18 years 1 month

Post #4by Imy » 07.01.2008, 15:39

I post a piece of script to test yourself how cycle commands could be. This is about only constellations. Pay attention, it seems (i don't know why :roll: ) that keypresses callback function doesn't allow to continue to use normal keymap...

Code: Select all

CommandCycleIndexConst=0
-- Callback for keypresses (name is hardcoded in celestia)
function celestia_keyboard_callback(str)


--About constellations
   if str == "\047" then
   
      CommandCycleIndexConst=CommandCycleIndexConst+1
   
   
      if CommandCycleIndexConst>4 then
      CommandCycleIndexConst=1
   end
 
      if CommandCycleIndexConst==1 then
         celestia:show("constellations")
         celestia:hidelabel("constellations")
      elseif CommandCycleIndexConst==2 then
      celestia:show("constellations")
         celestia:showlabel("constellations")
      elseif CommandCycleIndexConst==3 then
      celestia:hide("constellations")
         celestia:showlabel("constellations")
      elseif CommandCycleIndexConst==4 then
      celestia:hide("constellations")
         celestia:hidelabel("constellations")
      end
  return true
end

-- enable keyboard-callback:
celestia:requestkeyboard(true)
celestia:flash("Command cycle example start")

-- and do nothing...
while true do
  wait(0)
end



I've tried to extend the principle for showing names and orbits of different objects as planets (p button), moons (m), asteroids(a), spacecraft(s). I'm quite a beginner in celestia scripting and this next piece of script doesn't run totally (specially for orbits :x ) :

Code: Select all

CommandCycleIndexConst=0
CommandCycleIndexPlanet=0
CommandCycleIndexAster=0
CommandCycleIndexMoon=0
CommandCycleIndexSpc=0
-- Callback for keypresses (name is hardcoded in celestia)
function celestia_keyboard_callback(str)


--About constellations
   if str == "\047" then
   
      CommandCycleIndexConst=CommandCycleIndexConst+1
   
   
      if CommandCycleIndexConst>4 then
      CommandCycleIndexConst=1
   end
 
      if CommandCycleIndexConst==1 then
         celestia:show("constellations")
         celestia:hidelabel("constellations")
      elseif CommandCycleIndexConst==2 then
      celestia:show("constellations")
         celestia:showlabel("constellations")
      elseif CommandCycleIndexConst==3 then
      celestia:hide("constellations")
         celestia:showlabel("constellations")
      elseif CommandCycleIndexConst==4 then
      celestia:hide("constellations")
         celestia:hidelabel("constellations")
      end

--About planets   
   elseif str == "\112" then
   
      CommandCycleIndexPlanet=CommandCycleIndexPlanet+1
   
   
      if CommandCycleIndexPlanet>4 then
      CommandCycleIndexPlanet=1
   end
 
      if CommandCycleIndexPlanet==1 then
         celestia:setorbitflags {planet=true}
         celestia:hidelabel("planets")
      elseif CommandCycleIndexPlanet==2 then
      celestia:setorbitflags {planet=true}
         celestia:showlabel("planets")
      elseif CommandCycleIndexPlanet==3 then
      celestia:setorbitflags {planet=false}
         celestia:showlabel("planets")
      elseif CommandCycleIndexPlanet==4 then
      celestia:setorbitflags {planet=false}
         celestia:hidelabel("planets")
      end
   
--About asteroids   
   elseif str == "\97" then
   
      CommandCycleIndexAster=CommandCycleIndexAster+1
   
   
      if CommandCycleIndexAster>4 then
      CommandCycleIndexAster=1
   end
 
      if CommandCycleIndexAster==1 then
         celestia:setorbitflags {Asteroids=true}
         celestia:hidelabel("asteroids")
      elseif CommandCycleIndexAster==2 then
      celestia:setorbitflags {Asteroid=true}
         celestia:showlabel("asteroids")
      elseif CommandCycleIndexAster==3 then
      celestia:setorbitflags {Asteroid=false}
         celestia:showlabel("asteroids")
      elseif CommandCycleIndexAster==4 then
      celestia:setorbitflags {Asteroid=false}
         celestia:hidelabel("asteroids")
      end

--About moons
elseif str == "\109" then
   
      CommandCycleIndexMoon=CommandCycleIndexMoon+1
   
   
      if CommandCycleIndexMoon>4 then
      CommandCycleIndexMoon=1
   end
 
      if CommandCycleIndexMoon==1 then
         celestia:setorbitflags {Moon=true}
         celestia:hidelabel("Moons")
      elseif CommandCycleIndexMoon==2 then
      celestia:setorbitflags {Moon=true}
         celestia:showlabel("Moons")
      elseif CommandCycleIndexMoon==3 then
      celestia:setorbitflags {Moon=false}
         celestia:showlabel("Moons")
      elseif CommandCycleIndexMoon==4 then
      celestia:setorbitflags {Moon=false}
         celestia:hidelabel("Moons")
      end


--About spacecrafts
elseif str == "\115" then
   
      CommandCycleIndexSpc=CommandCycleIndexSpc+1
   
   
      if CommandCycleIndexSpc>4 then
      CommandCycleIndexSpc=1
   end
 
      if CommandCycleIndexSpc==1 then
         celestia:setorbitflags {Spacecraft=true}
         celestia:hidelabel("spacecrafts")
      elseif CommandCycleIndexSpc==2 then
      celestia:setorbitflags {Spacecraft=true}
         celestia:showlabel("spacecrafts")
      elseif CommandCycleIndexSpc==3 then
      celestia:setorbitflags {Spacecraft=false}
         celestia:showlabel("spacecrafts")
      elseif CommandCycleIndexSpc==4 then
      celestia:setorbitflags {Spacecraft=false}
         celestia:hidelabel("spacecrafts")
      end

   
 
 
  end 
  return true
end

-- enable keyboard-callback:
celestia:requestkeyboard(true)
celestia:flash("Command cycle example start")

-- and do nothing...
while true do
  wait(0)
end

Topic author
Imy
Posts: 109
Joined: 13.10.2006
With us: 18 years 1 month

Post #5by Imy » 10.01.2008, 08:58

I don't why setorbitflags don't show orbits altough I turn the value on true?

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

Post #6by Vincent » 10.01.2008, 11:52

Imy wrote:I don't why setorbitflags don't show orbits altough I turn the value on true?

Have you also set orbits renderflag to true ?

Code: Select all

celestia:setrenderflags { orbits = true }
@+
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

Topic author
Imy
Posts: 109
Joined: 13.10.2006
With us: 18 years 1 month

Post #7by Imy » 11.01.2008, 10:33

Exact : if you add this line in keypresses callback orbits appear for asteroids but problems still exist for planets... I have no more moon or spacecraft labels anymore!
What does mean exactly setrenderflags and setorbitflag? What is the difference please?

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

Post #8by Vincent » 11.01.2008, 11:44

Imy wrote:What does mean exactly setrenderflags and setorbitflag? What is the difference please?

You may want to have a look at Harald Schmidt celx page:
http://celestia.h-schmidt.net/celx-summary-latest.html
@+
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

Topic author
Imy
Posts: 109
Joined: 13.10.2006
With us: 18 years 1 month

Post #9by Imy » 11.01.2008, 13:36

Thanks for the link. Setrenderflag allows orbits and setorbitflag selects objects whose orbit is wanted to be shown, doesn't it?

But this doesn't explain why i can show asteroid orbits im my last script and planet orbits are still hidden...

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

Post #10by Vincent » 11.01.2008, 16:41

Imy wrote:Thanks for the link. Setrenderflag allows orbits and setorbitflag selects objects whose orbit is wanted to be shown, doesn't it?
Yep, that's it.

Imy wrote:But this doesn't explain why i can show asteroid orbits im my last script and planet orbits are still hidden...

Object class names in get/setorbitlflags methods must be capitalized.
So the issue should be fixed by replacing (in the 'Planets' block):

Code: Select all

if CommandCycleIndexPlanet==1 then
         celestia:setorbitflags {planet=true}

with

Code: Select all

if CommandCycleIndexPlanet==1 then
         celestia:setorbitflags {Planet=true}
@+
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

Topic author
Imy
Posts: 109
Joined: 13.10.2006
With us: 18 years 1 month

Post #11by Imy » 14.01.2008, 08:40

Hummm... I capitalized words in setorbitflags function and I don't in showlabel and hidelabel function. It runs better surely. However, I still have troubles!
When I use setorbitflags for planet, it seems that selected orbit is still visible although I've decided to hide them...
In Spacecraft Hidelabel and Showlabel function I have had to write in singular spacecraft word although for the others (like planet or moon) plural form run correctly.
I've still problems with spacecraft. All is hidden at the beginning of the script except spacecraft labels, why?

I post a second version of the script where all seems to be good except for spacecraft. I initialise in hidding objects at the beginning:

Code: Select all


celestia:setrenderflags {orbits =false, labels=false, constellations=false}

CommandCycleIndexConst=0
CommandCycleIndexPlanet=0
CommandCycleIndexAster=0
CommandCycleIndexMoon=0
CommandCycleIndexSpc=0
-- Callback for keypresses (name is hardcoded in celestia)
function celestia_keyboard_callback(str)

celestia:setrenderflags {orbits =true, labels=true}

--About constellations
   if str == "\047" then
   
      CommandCycleIndexConst=CommandCycleIndexConst+1
   
   
      if CommandCycleIndexConst>4 then
      CommandCycleIndexConst=1
   end
 
      if CommandCycleIndexConst==1 then
         celestia:show("constellations")
         celestia:hidelabel("constellations")
      elseif CommandCycleIndexConst==2 then
      celestia:show("constellations")
         celestia:showlabel("constellations")
      elseif CommandCycleIndexConst==3 then
      celestia:hide("constellations")
         celestia:showlabel("constellations")
      elseif CommandCycleIndexConst==4 then
      celestia:hide("constellations")
         celestia:hidelabel("constellations")
      end

--About planets   
   elseif str == "\112" then
   
      CommandCycleIndexPlanet=CommandCycleIndexPlanet+1
   
   
      if CommandCycleIndexPlanet>4 then
      CommandCycleIndexPlanet=1
   end
 
      if CommandCycleIndexPlanet==1 then
         celestia:setorbitflags {Planet=true}
         celestia:hidelabel("planets")
      elseif CommandCycleIndexPlanet==2 then
      celestia:setorbitflags {Planet=true}
         celestia:showlabel("planets")
      elseif CommandCycleIndexPlanet==3 then
      celestia:setorbitflags {Planet=false}
         celestia:showlabel("planets")
      elseif CommandCycleIndexPlanet==4 then
      celestia:setorbitflags {Planet=false}
         celestia:hidelabel("planets")
      end
   
--About asteroids   
   elseif str == "\97" then
   
      CommandCycleIndexAster=CommandCycleIndexAster+1
   
   
      if CommandCycleIndexAster>4 then
      CommandCycleIndexAster=1
   end
 
      if CommandCycleIndexAster==1 then
         celestia:setorbitflags {Asteroid=true}
         celestia:hidelabel("asteroids")
      elseif CommandCycleIndexAster==2 then
      celestia:setorbitflags {Asteroid=true}
         celestia:showlabel("asteroids")
      elseif CommandCycleIndexAster==3 then
      celestia:setorbitflags {Asteroid=false}
         celestia:showlabel("asteroids")
      elseif CommandCycleIndexAster==4 then
      celestia:setorbitflags {Asteroid=false}
         celestia:hidelabel("asteroids")
      end

--About moons
elseif str == "\109" then
   
      CommandCycleIndexMoon=CommandCycleIndexMoon+1
   
   
      if CommandCycleIndexMoon>4 then
      CommandCycleIndexMoon=1
   end
 
      if CommandCycleIndexMoon==1 then
         celestia:setorbitflags {Moon=true}
         celestia:hidelabel("moons")
      elseif CommandCycleIndexMoon==2 then
      celestia:setorbitflags {Moon=true}
         celestia:showlabel("moons")
      elseif CommandCycleIndexMoon==3 then
      celestia:setorbitflags {Moon=false}
         celestia:showlabel("moons")
      elseif CommandCycleIndexMoon==4 then
      celestia:setorbitflags {Moon=false}
         celestia:hidelabel("moons")
      end


--About spacecrafts
elseif str == "\115" then
   
      CommandCycleIndexSpc=CommandCycleIndexSpc+1
   
   
      if CommandCycleIndexSpc>4 then
      CommandCycleIndexSpc=1
   end
 
      if CommandCycleIndexSpc==1 then
         celestia:setorbitflags {Spacecraft=true}
         celestia:hidelabel("spacecraft")
      elseif CommandCycleIndexSpc==2 then
      celestia:setorbitflags {Spacecraft=true}
         celestia:showlabel("spacecraft")
      elseif CommandCycleIndexSpc==3 then
      celestia:setorbitflags {Spacecraft=false}
         celestia:showlabel("spacecraft")
      elseif CommandCycleIndexSpc==4 then
      celestia:setorbitflags {Spacecraft=false}
         celestia:hidelabel("spacecraft")
      end

   
 
 
  end 
  return true
end

-- enable keyboard-callback:
celestia:requestkeyboard(true)
celestia:flash("Command cycle example start")

-- and do nothing...
while true do
  wait(0)
end
[/code]

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

Post #12by Vincent » 14.01.2008, 11:57

Imy wrote:When I use setorbitflags for planet, it seems that selected orbit is still visible although I've decided to hide them...
This is the expected behaviour. The current selection's orbit is always displayed unless you disable orbits rendeflag.

Imy wrote:In Spacecraft Hidelabel and Showlabel function I have had to write in singular spacecraft word although for the others (like planet or moon) plural form run correctly.
This is because the plural for 'spacecraft' is... 'spacecraft'.

Imy wrote:I've still problems with spacecraft. All is hidden at the beginning of the script except spacecraft labels, why?

I think that this is simply because you have spacecraft labels enabled before running the script. Your script works fine for me.
@+
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

Topic author
Imy
Posts: 109
Joined: 13.10.2006
With us: 18 years 1 month

Post #13by Imy » 15.01.2008, 10:32

Thanks. Finally Shall I change all setorbitflags by setrenderflag about orbit? Is not easier?

This is because the plural for 'spacecraft' is... 'spacecraft'.
I didn't search in this way why spacecraft option didn't run as they would... :?

Imy wrote:
I've still problems with spacecraft. All is hidden at the beginning of the script except spacecraft labels, why?

I think that this is simply because you have spacecraft labels enabled before running the script. Your script works fine for me.


But I ask to hide all labels at the beginning of the script. Spacecraft labels are included also, aren't they?

I'm beginning to wonder if it would not be interesting to use a special shift button too. When you've selected Earth, if you play with P button in my script, well all orbits disapear ; but if you press SHIFT + P, only Earth orbit would be hidden. This could be useful to select orbits, to show for example, only mercury and earth orbit to compare them... or to show only spacecraft orbiting around earth...
But Celestia can do that? First how to say SHIFT+P? And Above all, can we show orbits for one object and not for a class of object?

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

Post #14by Vincent » 15.01.2008, 12:18

Imy wrote:But I ask to hide all labels at the beginning of the script. Spacecraft labels are included also, aren't they?
'labels' is not a valid renderflag. You must disable all labels using celestia:setlabelflags.
You can also write your own function that enable/disable all labels:

Code: Select all

setLabelRenderflag = function (b)
  t = celestia:getlabelflags()
  for class, flag in pairs(t) do
    t[class] = b
    celestia:setlabelflags(t)
  end
end

Then, just call:

Code: Select all

setLabelRenderflag(true)
or

Code: Select all

setLabelRenderflag(false)


Imy wrote:First how to say SHIFT+P?

Code: Select all

if str == "P"


Imy wrote:And Above all, can we show orbits for one object and not for a class of object?

No, this is not possible, yet.
@+
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

Topic author
Imy
Posts: 109
Joined: 13.10.2006
With us: 18 years 1 month

Post #15by Imy » 16.01.2008, 12:38

'labels' is not a valid renderflag
What does that mean exactly? Is a bugged function?

Imy wrote:
And Above all, can we show orbits for one object and not for a class of object?

No, this is not possible, yet.


So my selective option will be for a next time ...

Why keypress callback function doesn't continue to use the basic keymap? When I execute my script, enter or g buttons don't run although I haven't used them in the function.

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

Post #16by Vincent » 23.01.2008, 14:21

Imy wrote:
'labels' is not a valid renderflag
What does that mean exactly? Is a bugged function?
It's not a bug. The labels renderflag doesn't exist. Each label must be turned on/off separately with the 'setlabelflags' method.

Imy wrote:Why keypress callback function doesn't continue to use the basic keymap? When I execute my script, enter or g buttons don't run although I haven't used them in the function.

Just tell your celestia_keyboard_callback function to return false instead of true.

One small suggestion: you should add comments to precise to which char corresponds each ASCII code you're using in your script. Not everybody knows that '\047' corresponds to '/', '\112' to 'p', etc.
@+
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

Topic author
Imy
Posts: 109
Joined: 13.10.2006
With us: 18 years 1 month

Post #17by Imy » 25.01.2008, 09:55

if CommandCycleIndexMoon==1 then
celestia:setorbitflags {Moon=true}
celestia:hidelabel("Moons")
elseif CommandCycleIndexMoon==2 then
celestia:setorbitflags {Moon=true}
celestia:showlabel("Moons")
elseif CommandCycleIndexMoon==3 then
celestia:setorbitflags {Moon=false}
celestia:showlabel("Moons")
elseif CommandCycleIndexMoon==4 then
celestia:setorbitflags {Moon=false}
celestia:hidelabel("Moons")
end


I was improving code in including a more general function and I found that my variable CommandCycleIndexMoon (and probably others) hasn't done what I ordered : when the variable is 1 then, 2 is done, when it is 2 this is 1, 3 for 4 and 4 for 3:evil: :roll: !! What's the problem? From me or a subtility from celestia scripting?

Avatar
selden
Developer
Posts: 10192
Joined: 04.09.2002
With us: 22 years 2 months
Location: NY, USA

Post #18by selden » 25.01.2008, 11:21

You need to replace the braces {} by parentheses ().

Lua uses parentheses () to delimit function arguments.

Braces {} delimit tables.
Selden

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

Post #19by Vincent » 25.01.2008, 17:45

The problem is not related to the use of braces; braces must be used here since orbitflags are defined as a table; as for parentheses, they would be superfluous here.

The problem is that since we told the callback function to return false, the 'M' key is still toggling the Moons labels. So, you can solve this issue by adding a return true at the end of the 'm' char test (and also at the end of all char tests) to block the default 'M' key function:

Code: Select all

--About moons
elseif str == "\109" then

    CommandCycleIndexMoon=CommandCycleIndexMoon+1

    if CommandCycleIndexMoon>4 then
      CommandCycleIndexMoon=1
    end

    if CommandCycleIndexMoon==1 then
      celestia:setorbitflags {Moon=true}
      celestia:hidelabel("moons")
    elseif CommandCycleIndexMoon==2 then
      celestia:setorbitflags {Moon=true}
      celestia:showlabel("moons")
    elseif CommandCycleIndexMoon==3 then
      celestia:setorbitflags {Moon=false}
      celestia:showlabel("moons")
    elseif CommandCycleIndexMoon==4 then
       celestia:setorbitflags {Moon=false}
       celestia:hidelabel("moons")
    end

    return true

--About spacecrafts
elseif str == "\115" then
@+
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

Topic author
Imy
Posts: 109
Joined: 13.10.2006
With us: 18 years 1 month

Post #20by Imy » 26.01.2008, 11:13

I've still problems please:? :

-How to desactivate keypress callback when enter panel is shown (where you tape your destination)

-What about setlabelflags? I've changed hidelabel and showlabel functions with setlabelflags as suggested so that I can use table instead of strings in its parameters. But when I've written celestia:setlabelflags {Planet=true}, well nothing, no planet labels although these ones can be shown with classic showlabel...

-I'm often coding with VB language: in this you have lcase/ucase function, i suppose these kind of functions exists also in Lua. These functions change case of a string : you have "HeLLo", and then this string with lcase become "hello". What is the equivalent in lua language please?


Return to “Development”