Page 1 of 1

Some basic script questions

Posted: 23.10.2005, 18:53
by Malenfant
I've been playing around with some of the scripts from the Celestia wikibook ( http://en.wikibooks.org/wiki/Simple_CELX_Scripting ) and have come up with this to get the distance between Cassini and the observer:

Code: Select all

camera = celestia:getobserver()
cassini = celestia:find("Cassini") -- finds object named Cassini
cameraPosition = camera:getposition() -- gets position of observer
cassiniPosition = cassini:getposition() -- gets position of Cassini
distance = cassiniPosition:distanceto(cameraPosition) -- gets distance from  position of Cassini to that of observer
celestia:flash("Current distance to Cassini is "..distance.. " km")


To test it out, I selected Cassini and went to it (actually I set a distance of 1 km so I could verify the distance easily), so it's centred on the screen. When I run the code however, Cassini disappears - it seems that the direction the camera is facing suddenly changes for no apparent reason when I run the script (the distance stays the same so I know the camera isn't actually moving in space), and it doesn't seem to be looking at the same point each time. In fact this viewpoint shift happens whenever I run the script, regardless of what I'm looking at at the time.

Anyone know what's going on? How do I keep the view centred on whatever I'm looking at?

Also, I thought the default measurement for Celestia was the somewhat arcane "microlightyear"? If so, why does this script give results in kilometres? (not that I'm complaining, I prefer km by far. Just wondering what's going on).

Posted: 23.10.2005, 22:49
by Malenfant

Code: Select all

camera = celestia:getobserver()
cassini = celestia:find("Cassini") -- finds object named Cassini
camera:center(cassini,1)
cameraPosition = camera:getposition() -- gets position of observer
cassiniPosition = cassini:getposition() -- gets position of Cassini
distance = cassiniPosition:distanceto(cameraPosition) -- gets distance from  position of Cassini to that of observer
celestia:flash("Current distance to Cassini is "..distance.. " km")
wait(2)


OK, so this centres the view apparently. But I notice that everytime I run the script, the view centres - even when it's already centred on Cassini. It's like the viewpoint shifts to offcentre at the start, before centring itself. How can I stop this happening?

Posted: 24.10.2005, 01:38
by BrainDead
Malenfant wrote:OK, so this centres the view apparently. But I notice that everytime I run the script, the view centres - even when it's already centred on Cassini. It's like the viewpoint shifts to offcentre at the start, before centring itself. How can I stop this happening?

Don't know if it's related or not, but I had the same kind of opening view
problems when I ran my first test script. Seems that the offsets were
caused by the way in which I executed the scripts. (Double-clicking on the
file name in the open dialog.)

By the way, thanks for this example code. I've played with it a bit and
added my version of it to the discussion page on the Wikibook site.

Thanks.

Posted: 24.10.2005, 03:22
by Malenfant
BrainDead wrote:Don't know if it's related or not, but I had the same kind of opening view problems when I ran my first test script. Seems that the offsets were caused by the way in which I executed the scripts. (Double-clicking on the file name in the open dialog.)


How else would you open a script from within Celestia? I thought that was the only way you could run a script in Celestia - is there another way? (and how did you get round this problem that you had?).

EDIT: I notice in the wikibook discussion you say "Mystery explained... Open Scripts dialog and I double-clicked on the celx script in order to open it. If I simply use the dialogs provided by Celestia to open the script, the movement does not occur. Thanks."

What "dialogs provided by Celestia" are you talking about? All that's obvious to me is the Open Scripts dialog.

Posted: 24.10.2005, 04:40
by cpotting
Malenfant wrote:What "dialogs provided by Celestia" are you talking about? All that's obvious to me is the Open Scripts dialog.


Ahhh, I duplicated the problem. It only happens when you do the following:
1) select File -> Open Script from the Celestia menu
2) navigate the windows dialogue to the desired directory
3) double-click on the file name.

The other ways to open a script that do not cause this
a1) select File -> Open Script from the Celestia menu
a2) navigate the windows dialogue to the desired directory
a3) single-click on the file name and either press ENTER or click on the Open button

b1) open Windows Explorer
b2) navigate to the desired directory
b3) double click on the script or
right-click and select open or
single click on the script and press ENTER

Posted: 24.10.2005, 06:47
by Malenfant
Huh. How bizarre - yeah, it works fine if I just open the file by pressing enter instead of doubleclicking it in the Open Script menu.

What could cause such odd behaviour?!

Posted: 24.10.2005, 07:36
by Vincent
Hi,

I think I found the trick...

When you double-click on your celx file in the Celestia script browser, you change the camera view as if you had directly double-clicked on another object in the celestia main window. Try to double-click on a star : Celestia change the view to center the object you have selected...

You can also try to move the Celestia script browser to center of the screen, then double-click on your celx file. You will be able to see Cassini because you didn't change the camera view (too much).

@+
Vincent

Posted: 24.10.2005, 10:22
by BrainDead
I think that Clive and Vincent have hit the Nail on the Head! here.

Isn't it interesting that such a trivial matter causes sooo much confusion
though.

Thanks guys.

Re: Some basic script questions

Posted: 24.10.2005, 11:13
by cpotting
Malenfant wrote:I thought the default measurement for Celestia was the somewhat arcane "microlightyear"? If so, why does this script give results in kilometres? (not that I'm complaining, I prefer km by far. Just wondering what's going on).


You are right. For most of the methods, distances are given in microlightyears - a nice compromise unit for dealing with interplanetary and interstellar distances.

But it seems that, for some cases at any rate, the authors realised that a more appropriate unit would be the kilometre. So radius(), gotodistance(), distanceto() and some others return kilometres.

You just have to check the documentation to make sure you're getting the right units. It has caught me more than once.

Re: Some basic script questions

Posted: 24.10.2005, 20:26
by Malenfant
cpotting wrote:You are right. For most of the methods, distances are given in microlightyears - a nice compromise unit for dealing with interplanetary and interstellar distances.


What's wrong with just sticking to AU as the default measurement though (just calculating it now, a microlightyear is about 0.063 AU, or just under 10 million km? What possible use is that for anything? Seems like a comprimise that is beneficial for nobody)

Re: Some basic script questions

Posted: 25.10.2005, 12:42
by cpotting
Malenfant wrote:What's wrong with just sticking to AU as the default measurement though (just calculating it now, a microlightyear is about 0.063 AU, or just under 10 million km? What possible use is that for anything? Seems like a comprimise that is beneficial for nobody)


Well, you would really have to talk to Chris about that. But remember 99.99% of what Celestia deals with are stars. Distances to stars are measured in light-years, so it would be a logical first-choice. However, trying to measure interplanetary distances in lightyears would be a major pain - so the uLy (mico-lightyear) seems a good compromise. It gives reasonable values for interplanetary distances and can be easily converted to/from light-years.

Choosing the au as a base unit would make interplanetary distances easy to work with, but it doesn't convert well to light-years (read it doesn't convert well to 99.99% of what Celestia works with).

I can't say for sure if that is why uLy was chosen, but it seems logical to me.