Page 1 of 1

Frames of Reference in V1.3.2

Posted: 26.12.2004, 20:33
by cpotting
HI all,

I am still slogging away at frames of reference. I have further modified my script as shown below, but I am still having problems. Any help would be appreciated.

a) I still do not see any difference between the "observer" frame of reference and the "ecliptic" frame of reference. They still appear to be identically declared, positioned and oriented.

b) I used the information in Don Goyette's "Celestia .CEL Scripting Guide" and Harold Schmidt's "FramesOfReference_v1.0.celx" script, which both helped my understanding along a fair bit. I tried to use the knowledge gleaned to create my own script. However, my script does not show the "lock" frame of reference correctly. Once it is chosen, "lock" should cause the views to rotate around the Earth keeping the Earth and the ISS in the same relative positions. It does not do this, and I can't see why not.

Here is my new script:

Code: Select all

-- vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv KEYBOARD RELATED FUNCTIONS AND VARIABLES vvvvvvvvvvvvvvvvvvvvvvvvvvv
input_buffer = {} -- FIFO buffer filled by celestia_keyboard_callback(), extracted by get_key()
special_keys = {} -- holds the list of keys that will be allowed.

-- Callback for keyboard.  Places acceptable keystrokes into a keyboard buffer
function celestia_keyboard_callback(input)
   -- catch letter/number regular keys
   if special_keys[input] == true then
      table.insert(input_buffer, input)
      return true   -- tell Celestia not to process this key
   -- catch special keys
   elseif special_keys[string.byte(input)] == true then
      table.insert(input_buffer, string.byte(input))
      return true   -- tell Celestia not to process this key
   end
   return false  -- we did not want to intercept this key - tell Celestia to process it.
end

-- Pop the oldest keystroke out of the keyboard buffer
function get_key()
   local key = input_buffer[1]
   if key ~= nil then
      table.remove(input_buffer, 1)
   end
   return key
end
-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ KEYBOARD RELATED FUNCTIONS AND VARIABLES ^^^^^^^^^^^^^^^^^^^^^^^^^^^
-- constants
KM_PER_MLY   = 9466411.842
EARTH = celestia:find("Sol/Earth")
IIS = celestia:find("Sol/Earth/IIS")
ABOVE = celestia:newposition(0, 1, 0)
CENTRE = celestia:newposition(0, 0, 0)
special_keys = { u=true, e=true, q=true, p=true, o=true, l=true, c=true, x=true }
-- set up the screens
obs = celestia:getobserver()
obs:singleview()
obs:splitview("h")
obs:splitview("v")
obs:track(nil)
celestia:settimescale(1000)
-- set up the locations where we will position each observer
obsvrs = celestia:getobservers()
obsvr_positions = { celestia:newposition(300000 / KM_PER_MLY, 000000 / KM_PER_MLY, 000000 / KM_PER_MLY),
                    celestia:newposition(000001 / KM_PER_MLY, 300000 / KM_PER_MLY, 000000 / KM_PER_MLY),
                    celestia:newposition(000000 / KM_PER_MLY, 000000 / KM_PER_MLY, 300000 / KM_PER_MLY)
                  }
celestia:requestkeyboard(true)
celestia:settimescale(1000)
frame_name = ""
key = "e"
while key ~= "x" do
   if key == "u" then
      frame_name = "universal"
      useframe = celestia:newframe("universal")
   elseif key == "q" then
      frame_name = "equatorial"
      useframe = celestia:newframe("equatorial", EARTH)
   elseif key == "e" then
      frame_name = "ecliptic"
      useframe = celestia:newframe("ecliptic", EARTH)
   elseif key == "p" then
      frame_name = "planetographic"
      useframe = celestia:newframe("planetographic", EARTH)
   elseif key == "o" then
      frame_name = "observer"
      useframe = celestia:newframe("observer", EARTH)
   elseif key == "l" then
      frame_name = "lock"
      useframe = celestia:newframe("lock", EARTH, IIS)
   elseif key == "c" then
      frame_name = "chase"
      useframe = celestia:newframe("chase", EARTH)
   end
   if key ~= nil and key ~= "x" then
      -- the user selected a frame, so set each observer to use the new frame
      for x = 1, 3 do
         obsvrs[x]:setframe(useframe)
      end
      -- determine the up vector for the frame by subtracting the origin of the frame's axes (converted to universal
      -- coordinates) from a positive position on the Y axis (converted to universal coordinates)
      up = useframe:from(ABOVE) - useframe:from(CENTRE)
   end
   for x = 1, 3 do
      -- for each observer, determine where the origin of the axes is; position the observer at the appropriate point
      -- along one of the axes; have the observer look at the origin.
      central = useframe:from(CENTRE)
      obsvrs[x]:setposition(obsvrs[x]:getframe():from(obsvr_positions[x]))
      obsvrs[x]:lookat(central, up)
   end
   celestia:flash("current frame: " .. frame_name, 1)
   wait(0.0)
   key = get_key()
end

To use it, simply start it and select a frame of reference using the keys
u - for universal
e - for ecliptic
q - for equatorial
p - for planetographic
o - for observer
l - for lock
c - for chase

The upper view shows the view looking "down" along the Y axis, while the lower views are from the X and Z axes. "x" ends the script.

Can anyone see what I am doing wrong?

Thanks.

Re: Frames of Reference in V1.3.2

Posted: 27.12.2004, 21:58
by cpotting
cpotting wrote:b) ... However, my script does not show the "lock" frame of reference correctly. Once it is chosen, "lock" should cause the views to rotate around the Earth keeping the Earth and the ISS in the same relative positions. It does not do this, and I can't see why not.


Umm... never mind problem b)... I found my mistake:

Code: Select all

IIS = celestia:find("Sol/Earth/IIS")

Appearently they named the thing the "International Space Station", not the "Incredibly Interesting Satelllite". Who knew? :oops:.