跳轉到內容

Celestia/Celx 指令碼/CELX Lua 方法/Celx 觀察者

來自華夏公益教科書,開放的書籍,面向開放的世界

Celx 指令碼: 觀察者

[編輯 | 編輯原始碼]

觀察者

[編輯 | 編輯原始碼]

觀察者物件用於訪問特定於檢視的屬性,例如檢視器位置、檢視器方向、參考系和跟蹤狀態。可以使用 goto 命令或直接設定屬性來操作檢視器位置和方向。

在 CELX 指令碼中,可以使用觀察者方法作用於觀察者物件,方法是在觀察者物件和觀察者方法之間用分號隔開。

以下方法可用於獲取觀察者物件

備註

  1. 由於檢視(以及觀察者)可以由使用者建立和銷燬,因此 Lua 中的觀察者物件可能變得無效。訪問無效觀察者物件會導致錯誤。
  2. 為了方便處理觀察者物件,您可以使用 “==“ 將它們與其他觀察者物件進行比較,這對於其他 celx 物件來說是不可靠的。

本章列出了所有可用的觀察者方法,這些方法可用於 “觀察者” 物件。

observer:goto(object/position:target [, number:duration, number:start_interpolation, number:end_interpolation])

跳轉到一個物件或位置,類似於在鍵盤上按 [G] 鍵。

引數

target
要跳轉到的 “物件” 物件或 “位置” 物件。
duration [可選]
跳轉所需的時間(以秒為單位)。預設值為 5 秒。
start_interpolation [可選]
跳轉過程中,觀察者應從初始方向開始轉向最終方向的時間點(以 0 到 1 之間的百分數表示)。預設值為 0.25。
  • 如果 start_interpolation 小於 0 或大於 1,則會調整為預設值。
end_interpolation [可選]
跳轉過程中,觀察者應從初始方向結束轉向最終方向的時間點(以 0 到 1 之間的百分數表示)。預設值為 0.75。
  • 如果 end_interpolation 小於 0 或大於 1,則會調整為預設值。

備註

  1. 此命令立即返回,因此您可能希望在繼續指令碼之前wait(number:duration) 秒。
  2. 當指定一個 “物件” 物件進行跳轉時,最終方向將指向 “物件” 物件。
  3. 當指定一個位置物件進行跳轉時,最終方向將與初始方向相同。
  4. 跳轉到 object:getposition() 方法返回的位置與跳轉到物件不同。這是因為返回的位置指的是物件的中心,因此您將跳轉到該物件的中心。
  5. 給定的位置應相對於通用參考系。因此,根據所使用的參考系,您必須先將位置轉換為 “Universal”,然後才能在 goto 中使用它。
  6. Celestia 中的位置分量 (X,Y,Z) 以光年百萬分之一儲存。因此,如果您定義了自己的公里或英里位置,則必須將這些位置進行轉換。因此,您可以使用一個常量,該常量必須首先在您的指令碼中初始化
    • 從公里到光年百萬分之一,使用常量 uly_to_km = 9460730.4725808。
    • 從英里到光年百萬分之一,使用常量 uly_to_mls = 5912956.5453630。
  7. 接下來,您可以將公里或英里轉換為光年百萬分之一,如下所示
    • millionths_of_a_light_year = number:km / uly_to_km
    • millionths_of_a_light_year = number:miles / uly_to_mls

示例 1
跳轉到指定物件。

mars = celestia:find("Sol/Mars")
celestia:select(mars)
obs = celestia:getobserver()
obs:goto(mars, 5.0)
celestia:print("We're on our way to Mars." , 5.0, -1, -1, 2, 4)
wait(5.0)

示例 2
跳轉到指定位置,即地球和月球之間的一半。執行此示例後,按 [Shift + *] 鍵,以驗證月球在觀察者後視鏡中的位置。

obs = celestia:getobserver()
-- Set frame of reference to "universal".
obs:setframe(celestia:newframe( "universal"))
-- Find the actual position of the Earth.
earth = celestia:find("Sol/Earth")
earthpos = earth:getposition()
-- Find the actual position of the Moon.
moon = celestia:find("Sol/Earth/Moon")
moonpos = moon:getposition()
-- Calculate new position halfway Earth - Moon.
newpos = earthpos + 0.5 * (moonpos - earthpos)
obs:goto(newpos, 3.0)
celestia:print("We're are going halfway Earth - Moon." , 5.0, -1, -1, 2, 4)
wait(3.0)
-- Follow and center Earth
obs:follow(earth)
obs:center(earth)
wait(2.0)


返回到觀察者 方法索引。


goto (表)

[編輯 | 編輯原始碼]

1.3.2 observer:goto(table:parameters)

從具有初始方向的初始位置跳轉到具有最終方向的最終位置。

使用此方法,可以執行許多不同型別的跳轉。

引數

parameters
跳轉的引數必須在表中給出。有效的表鍵是
  • duration
    跳轉所需的時間(以秒為單位)。預設值為 5 秒。
  • from
    跳轉開始的初始源位置。必須是 “位置” 物件。
  • to
    跳轉結束的最終目標位置。必須是 “位置” 物件。
  • initialOrientation
    觀察者的初始源方向。必須是 “旋轉” 物件。
  • finalOrientation
    觀察者的最終目標方向。必須是 “旋轉” 物件。
  • startInterpolation
    跳轉過程中,觀察者應從初始方向開始轉向最終方向的時間點(以 0 到 1 之間的百分數表示)。預設值為 0.25。
  • endInterpolation
    跳轉過程中,觀察者應從初始方向結束轉向最終方向的時間點(以 0 到 1 之間的百分數表示)。預設值為 0.75。
  • accelTime
    指示在前往目標過程中,用於從初始位置加速和減速的時間比例(以 0 到 1 之間的百分比表示)。它還表示用於朝最終位置減速的時間。前往目標過程中的剩餘時間用於勻速行駛。預設值為 0.25,最小值為 0.01,最大值為 0.5。
注意:請注意輸入錯誤和 Celestia 對鍵的區分大小寫。無法識別的鍵或型別錯誤的值將被直接忽略。

備註

  1. 此命令立即返回,因此您可能希望在繼續指令碼之前wait(number:duration) 秒。
  2. 如果想要從當前位置,以當前觀察者的方向開始前往目標,可以使用 observer:getposition()observer:getorientation() 方法分別獲取當前位置和方向。
  3. 給定的位置應相對於通用參考系。因此,根據所使用的參考系,您必須先將位置轉換為 “Universal”,然後才能在 goto 中使用它。
  4. Celestia 中的位置分量 (X,Y,Z) 以光年百萬分之一儲存。因此,如果您定義了自己的公里或英里位置,則必須將這些位置進行轉換。因此,您可以使用一個常量,該常量必須首先在您的指令碼中初始化
    • 從公里到光年百萬分之一,使用常量 uly_to_km = 9460730.4725808。
    • 從英里到光年百萬分之一,使用常量 uly_to_mls = 5912956.5453630。
  5. 接下來,您可以將公里或英里轉換為光年百萬分之一,如下所示
    • millionths_of_a_light_year = number:km / uly_to_km
    • millionths_of_a_light_year = number:miles / uly_to_mls

示例
從火星中心出發,前往“宇宙”座標系中 X 方向 20,000 公里的位置。

uly_to_km = 9460730.4725808
-- Set frame of reference to "universal"
obs = celestia:getobserver()
obs:setframe(celestia:newframe("universal"))
-- Find and select Mars
mars = celestia:find("Sol/Mars")
celestia:select(mars)
-- Obtain the actual position of Mars
now = celestia:gettime()
posmars = mars:getposition(now)
-- Define table and initialize table
parameters = { }
-- Number of seconds the goto should take
parameters.duration = 5.0
-- Obtain current observer position
parameters.from = obs:getposition()
-- Determine position to goto
parameters.to = celestia:newposition((posmars.x + (20000/uly_to_km)), posmars.y, posmars.z )
-- obtain current observer orientation
parameters.initialOrientation = obs:getorientation()
-- Determine observer orientation from position to goto, towards the position of Mars
parameters.finalOrientation = parameters.to:orientationto(posmars,celestia:newvector(0,1,0))
-- Start adjusting the observer orientation from the beginning of the goto
parameters.startInterpolation = 0.0
-- End adjusting the observer orientation at the end of the goto
parameters.endInterpolation = 1.0
-- Use 10% of the time to accelerate and 10% of the time to decelarate 
parameters.accelTime = 0.1
-- Perform the goto
obs:goto(parameters)
-- Finally follow Mars and wait until the goto has finished
obs:follow(mars)
wait(parameters.duration )


返回到觀察者 方法索引。


gotolonglat

[edit | edit source]

1.3.2 observer:gotolonglat(object:target [, number:longitude, number:latitude, number:distance, number:duration, vector:up-axis])

在指定時間內,前往目標物件表面經緯度座標上方的位置,並指定距離和向上方向的軸。

引數

target
前往的目標物件。必須是“object”型別的物件。
longitude [可選]
目標物件表面經度座標(以弧度表示)。預設值為 0。
西半球的經度為負數,東半球的經度為正數(不需要加“+”號)。
latitude [可選]
目標物件表面緯度座標(以弧度表示)。預設值為 0。
南半球的緯度為負數,北半球的緯度為正數(不需要加“+”號)。
distance [可選]
距目標物件中心的距離(以公里表示)。預設值為目標物件半徑的 5 倍。
特殊的距離值:
  • 0(零):前往目標物件中心。
  • 目標物件的半徑(公里):前往目標物件表面。
duration [可選]
跳轉所需的時間(以秒為單位)。預設值為 5 秒。
up-axis [可選]
定義向上方向的軸。必須是“vector”型別的物件。
  • celestia:newvector(1,0,0) --> X 軸
  • celestia:newvector(0,1,0) --> Y 軸是預設值
  • celestia:newvector(0,0,1) --> Z 軸

備註

  1. 經度和緯度以弧度(0 到 2*π)表示,不是度數(0 到 360)。180 度(半個圓周)等於 π 弧度 = 3.14159265 弧度 = math.pi 弧度(Lua)。可以使用以下方法將度數轉換為弧度,反之亦然:
    • radians = math.rad( number:degrees ) = ( number:degrees / 180 * math.pi) = ( number:degrees / 180 * 3.14159265).
    • degrees = math.deg( number:radians ) = ( number:radians * 180 / math.pi) = ( number:radians * 180 / 3.14159265).
  2. 可以使用 object:radius() 方法獲取目標物件的半徑(公里)。如果以公里表示的距離小於目標物件的半徑(公里),則前往目標過程將在目標物件內部結束。
  3. 此命令立即返回,因此您可能想要在指令碼中繼續執行之前,先使用 wait(number:duration) 方法等待指定時間(秒)。

示例
此示例選擇地球,並將攝像機定位在距離地球表面 12,000 公里的美國華盛頓州西雅圖上空。

earth = celestia:find("Sol/Earth")
celestia:select(earth)
obs = celestia:getobserver()
obs:synchronous(earth)
earthdistance = 12000 + earth:radius()
longitude = math.rad(-122.0)
latitude = math.rad(47.0)
obs:gotolonglat(earth, longitude, latitude, earthdistance, 5.0)
celestia:print("Traveling to Seattle, Washington, USA.", 5.0, -1, -1, 2, 4)
wait(5.0)
celestia:print("Hovering over Seattle, Washington, USA.", 5.0, -1, -1, 2, 4)
wait(5.0)


返回到觀察者 方法索引。


gotolocation

[edit | edit source]

observer:gotolocation(position:target [, number:duration])

在指定時間內,前往目標位置。

引數

target
前往的目標位置,在觀察者的當前參考系中。必須是“position”型別的物件。
duration [可選]
跳轉所需的時間(以秒為單位)。預設值為 5 秒。

備註

  1. 此命令立即返回,因此您可能想要在指令碼中繼續執行之前,先使用 wait(number:duration) 方法等待指定時間(秒)。
  2. 在此 observer:gotolocation() 方法中,位置是相對於此觀察者的當前參考系而言的,而 observer:goto()observer:goto(table) 方法使用的是宇宙參考系!
  3. Celestia 中的位置分量 (X,Y,Z) 以光年百萬分之一儲存。因此,如果您定義了自己的公里或英里位置,則必須將這些位置進行轉換。因此,您可以使用一個常量,該常量必須首先在您的指令碼中初始化
    • 從公里到光年百萬分之一,使用常量 uly_to_km = 9460730.4725808。
    • 從英里到光年百萬分之一,使用常量 uly_to_mls = 5912956.5453630。
  4. 接下來,您可以將公里或英里轉換為光年百萬分之一,如下所示
    • millionths_of_a_light_year = number:km / uly_to_km
    • millionths_of_a_light_year = number:miles / uly_to_mls

示例
前往位置:距地球中心 X = +7000 公里,Y = +9000 公里,Z = +11000 公里。

obs = celestia:getobserver()
-- Select and follow Earth (so the coordinate system
-- of the frame of reference is set to "ecliptic").
earth = celestia:find("Sol/Earth")
celestia:select(earth)
obs:follow(earth)
-- Convert km to millionths of a light year, using "uly_to_km".
uly_to_km = 9460730.4725808
newpos = celestia:newposition(7000/uly_to_km, 9000/uly_to_km, 11000/uly_to_km)
-- Goto target position.
obs:gotolocation(newpos, 5.0 )
wait(5.0)
-- You are at the right position now, but probably Earth is 
-- not visible yet. Center Earth to be sure to see our planet. 
obs:center(earth, 1.0)
wait(1.0)


返回到觀察者 方法索引。


gotodistance

[edit | edit source]

1.3.2 observer:gotodistance(object:target [, number:distance, number:duration, vector:up-axis])

在指定時間內,前往目標物件的指定距離,並指定向上方向的軸。

引數

target
前往的目標物件。必須是“object”型別的物件。
distance [可選]
距目標物件中心的距離(公里),表示停止的位置。預設值為 20000 公里。
duration [可選]
跳轉所需的時間(以秒為單位)。預設值為 5 秒。
up-axis [可選]
定義向上方向的軸。必須是“vector”型別的物件。
  • celestia:newvector(1,0,0) --> X 軸
  • celestia:newvector(0,1,0) --> Y 軸是預設值
  • celestia:newvector(0,0,1) --> Z 軸

備註

  1. 可以使用 object:radius() 方法獲取目標物件的半徑(公里)。如果以公里表示的距離小於目標物件的半徑(公里),則前往目標過程將在目標物件內部結束。
  2. 此命令立即返回,因此您可能想要在指令碼中繼續執行之前,先使用 wait(number:duration) 方法等待指定時間(秒)。

示例
選擇太陽,前往太陽,然後選擇地球,前往地球。接著,花費 3.0 秒,將您的顯示距離調整為距地球表面 90,000 公里。

sun = celestia:find("Sol")
celestia:select(sun)
obs = celestia:getobserver()
obs:goto(sun, 3.0)
wait(4.0)
earth = celestia:find("Sol/Earth")
celestia:select(earth)
obs:goto(earth, 3.0)
wait(4.0)
obs:gotodistance(earth, 90000+earth:radius(), 3.0)
wait(3.0)


返回到觀察者 方法索引。


gotosurface

[edit | edit source]

1.3.2 observer:gotosurface(object:target [, number:duration])

前往指定物件表面,並看向地平線。類似於按下鍵盤上的 [Ctrl+G] 鍵。

引數

target
要降落的物件。必須是“object”型別的物件。
duration [可選]
跳轉所需的時間(以秒為單位)。預設值為 5 秒。

備註

  1. 著陸位置將對應於您在前往目標開始之前懸停的物體表面經緯度座標。
  2. 前往目標完成後,您所看到的的地平線將對應於您在前往目標開始之前,螢幕上指向的方向(該方向即物體向上方向)。
  3. 此命令立即返回,因此您可能想要在指令碼中繼續執行之前,先使用 wait(number:duration) 方法等待指定時間(秒)。

示例
前往火星表面。

obs = celestia:getobserver()
planet = celestia:find("Sol/Mars")
celestia:select(planet)
obs:goto(planet, 3.0)
wait(4.0)
obs:gotosurface(planet, 3.0)
wait(3.0)


返回到觀察者 方法索引。


center

[edit | edit source]

observer:center(object:target [, number:duration])

旋轉觀察者的視角,使目標物件位於螢幕中心。類似於按下鍵盤上的 [c] 鍵。

引數

target
要位於螢幕中心的物體。必須是“object”型別的物件。
duration [可選]
居中的持續時間(秒)。預設值為 5 秒。

示例: 首先將土星置於螢幕中心,然後直線前往該行星。

obs = celestia:getobserver()
planet = celestia:find("Sol/Saturn")
obs:center(planet, 3.0)
wait(3.0)
obs:goto(planet, 3.0)
wait(3.0)


返回到觀察者 方法索引。


centerorbit

[edit | edit source]

1.3.2 observer:centerorbit(object:target [, number:duration])

圍繞當前參考系中用作參考的物體進行軌道運動,使目標在指定時間內位於中心。這類似於按下鍵盤上的 [Shift+C] 鍵。

引數

target
要位於中心的物體。必須是“object”型別的物件。
duration [可選]
居中的持續時間(秒)。預設值為 5 秒。

備註

  1. 如果您在螢幕上有一個原始物體,然後使用 observer:center() 方法將新物體置於中心,您可能會失去對原始物體的視野,因為觀察者會旋轉以使新物體位於中心。使用此 observer:centerorbit() 方法,可以在不失去對原始物體的視野的情況下,使觀察者旋轉以使目標物體位於中心,原始物體用作當前參考系中的參考物體。
  2. 如果當前參考系中用作參考的物體仍然位於螢幕中心,使用此方法可能會導致目標物體(完全或部分)消失在參考物體後面。
  3. 如果當前參考系中用作參考的物體與目標物體相同,但位於螢幕中心,使用此方法的結果將只是圍繞該物體進行軌道運動(持續指定時間),其中觀察者的方向相對於該物體保持不變。
  4. 如果目標物體已經位於螢幕中心,使用此方法將不會發生任何情況。
  5. 如果當前參考系為“宇宙”,使用此方法將不會發生任何情況。

示例

-- Goto and follow the Moon at specified distance
moon = celestia:find("Sol/Earth/Moon")
moonradius = moon:radius()
obs = celestia:getobserver()
obs:gotodistance(moon, 17500+moonradius, 3.0)
obs:follow(moon)
wait(3.0)
-- Rotate the observer a bit, so the Moon is not centered anymore
duration = 1.0
rotsteps = 25 * duration
rot = celestia:newrotation(celestia:newvector(0,1,0), math.rad(10)/rotsteps)
rotsteptime = duration/rotsteps
for i = 1, rotsteps do
   obs:rotate(rot)
   wait(rotsteptime)
end
-- Find and select Earth and center Earth on the screen, with the Moon still visible
earth = celestia:find("Sol/Earth")
celestia:select(earth)
obs:centerorbit(earth, 4.0)
wait(4.0)


返回到觀察者 方法索引。


travelling

[edit | edit source]

boolean observer:travelling()

返回一個布林值,指示當前是否正在進行前往目標或居中操作。

  • true 表示當前正在進行前往目標或居中操作
  • false 表示當前沒有進行前往目標或居中操作

備註

  1. 此方法可以與 observer:cancelgoto() 方法結合使用,該方法可以停止當前正在進行的任何前往目標或居中操作。
  2. 可以在 Lua 的“while”迴圈中使用此方法,以防止在仍有前往目標或居中操作正在進行的情況下繼續執行其他方法。

示例
在 10 秒內前往月球,並在到達後顯示閃爍的訊息。

moon = celestia:find("Sol/Earth/Moon")
obs = celestia:getobserver()
obs:goto(moon, 10.0)
actual_travel = obs:travelling()
while actual_travel do
   actual_travel = obs:travelling()
   wait(0.0)
end
celestia:flash("Arrived at the Moon", 5.0)
wait(5.0)


返回到觀察者 方法索引。


cancelgoto

[編輯 | 編輯原始碼]

1.3.2 observer:cancelgoto()

停止任何正在進行的 goto 或 center 命令。

備註

  1. 與 CEL: CANCEL { } 命令不同,該命令也會取消任何 goto,此方法不會對當前參考系和物件跟蹤生效。要完全模擬 CEL: CANCEL { } 命令,你還需要使用 observer:track(nil) 方法和 celestia:newframe("universal") 以及 observer:setframe() 方法。

示例
在 20 秒內前往月球,但在 5 秒後取消該 goto 命令。

moon = celestia:find("Sol/Earth/Moon")
obs = celestia:getobserver()
obs:goto(moon, 20.0)
wait(5.0)
actual_travel = obs:travelling()
if actual_travel then
   obs:cancelgoto()
   celestia:flash("GOTO aborted.",5.0)
   wait(5.0)
end


返回到觀察者 方法索引。


observer:follow(object:target)

對目標物件啟用跟隨模式。

跟隨與將參考系設定為 "ecliptical" 並將目標作為參考物件相同。

引數

target
要跟隨的物件。必須是 "object" 物件。

備註

  1. 隨著物件在太空中移動,觀察者也會隨之移動。物件可以在其軸上旋轉,這意味著經度將不斷變化。觀察者將保持與物件相同的距離和緯度。
  2. X 軸指向遠離太陽,朝向儒略 2000.0 春分點。Y 軸垂直於黃道,正 Y 指向北。Z 軸完成右手座標系。

示例
選擇火星,啟用跟隨模式,然後前往火星。

mars = celestia:find("Sol/Mars")
celestia:select(mars)
obs = celestia:getobserver()
obs:follow(mars)
obs:goto(mars, 2.0)
wait(2.0)


返回到觀察者 方法索引。


observer:synchronous(object:target)

對目標物件啟用同步模式。

同步模式與將參考系設定為 "planetographic"(也稱為 "geographic"),並將目標作為參考物件相同。

引數

target
要與之同步的物件。必須是 "object" 物件。

備註

  1. 觀察者保持在參考物件上方的靜止或地球同步軌道上。當物件在其軸上旋轉時,觀察者將保持與物件相同的距離、經度和緯度,就好像它與物件相連一樣。
  2. Celestia 座標系的原點是參考物件的中心。
  3. 在地理座標系中,座標軸隨著所選物件一起旋轉。Y 軸是旋轉軸,逆時針方向,因此對於順行旋轉體(如地球)它指向北,對於逆行旋轉體(如金星)它指向南。X 軸從物件的中心指向其零經度子午線與赤道的交點。Z 軸(與 XY 平面成直角)完成右手座標系。

示例
選擇地球並激活同步模式。

earth = celestia:find("Sol/Earth")
celestia:select(earth)
obs = celestia:getobserver()
obs:synchronous(earth)


返回到觀察者 方法索引。


observer:chase(object:target)

對目標物件啟用追逐模式。

追逐模式與將參考系設定為 "chase" 並將目標作為參考物件相同。

引數

target
要追逐的物件。必須是 "object" 物件。

備註

  1. 在追逐模式下,觀察者的位置相對於目標運動方向保持固定,觀察者的方向相對於目標運動方向保持不變。
  2. Celestia 座標系的原點是參考物件的中心。
  3. 此座標系類似於 "lock",不同的是,Z 軸指向相對於目標物件父體(行星的太陽,衛星的行星)的運動方向。

示例
選擇月球,啟用追逐模式,然後前往月球。

moon = celestia:find("Sol/Earth/Moon")
celestia:select(moon)
obs = celestia:getobserver()
obs:chase(moon)
obs:goto(moon, 2.0)
wait(2.0)


返回到觀察者 方法索引。


observer:lock(object:target)

啟用從當前參考物件到目標物件的軸的鎖定模式。

鎖定模式與將參考系設定為 "lock",並將目標作為目標物件和當前參考物件相同。

引數

target
要與當前參考物件鎖定的物件。必須是 "object" 物件。

備註

  1. 在鎖定模式下,觀察者的位置相對於參考物件和目標物件之間的直線保持固定。當目標物件相對於參考物件移動(相對而言)時,觀察者也會隨之移動。觀察者到參考物件的距離保持不變,觀察者到目標物件的距離可能會變化。
  2. Celestia 座標系的原點是參考物件的中心。
  3. Z 軸從參考物件指向目標物件。Y 軸位於由 Z 軸和參考物件旋轉軸定義的平面上,與 Z 軸成直角。X 軸完成右手座標系。
  4. 僅在啟用鎖定模式之前選擇一個物件,不會使該物件成為參考物件。要使一個物件成為參考物件,請先使用 observer:follow()observer:synchronous()observer:chase() 方法,然後再啟用鎖定模式。
  5. 如果參考物件與目標物件相同,則在太陽系中,中央恆星將被設定為參考物件。
  6. 如果太陽系中的中央恆星既是參考物件又是目標物件,則使用此 observer:lock() 方法將沒有任何效果。
  7. 如果在使用此 observer:lock() 方法之前激活了 "universal" 參考系(因此沒有可用的參考物件),則使用此方法將沒有任何效果。

示例
相對於地球保持位置,並使月球和地球之間的直線在視野中保持固定。(請注意,由於月球軌道偏心率,相對於月球的位置將會變化)。

-- Goto and follow the Moon at specified distance
moon = celestia:find("Sol/Earth/Moon")
moonradius = moon:radius()
obs = celestia:getobserver()
obs:gotodistance(moon, 45000+moonradius, 3.0)
obs:follow(moon)
wait(3.0)
-- Rotate the observer a bit, so the Moon is not centered anymore
duration = 1.0
rotsteps = 25 * duration
rot = celestia:newrotation(celestia:newvector(0,1,0), math.rad(10)/rotsteps)
rotsteptime = duration/rotsteps
for i = 1, rotsteps do
   obs:rotate(rot)
   wait(rotsteptime)
end
-- Find and select Earth and center Earth on the screen, with the Moon still visible
earth = celestia:find("Sol/Earth")
celestia:select(earth)
obs:centerorbit(earth, 4.0)
wait(4.0)
-- Make Earth the current reference object
obs:follow(earth)
-- Both Moon and Earth are in view now.
-- Activate lock mode and accelerate time.
obs:lock(moon)
celestia:settimescale(21600)


返回到觀察者 方法索引。


observer:track(object:target)

對物件設定跟蹤,即始終保持目標物件在它在太空中移動時保持在螢幕中央。

引數

target
要跟蹤的物件。必須是 "object" 物件。

備註

  1. 即使選擇了另一個物件,跟蹤也會保留在物件上。在你試圖檢視另一個物件之前,你必須取消對第一個物件的跟蹤。
  2. 要停止跟蹤物件,請使用 observer:track(nil)

示例
釋放對任何當前選定物件的控制,然後選擇地球並前往地球並跟蹤它。地球將以它在太空中實際移動的速度開始遠離你,但 Celestia 會跟蹤地球,使其保持在顯示器中央。時間將加速 1000 倍。

obs = celestia:getobserver()
obs:cancelgoto()
obs:track(nil)
obs:setframe(celestia:newframe("universal"))
earth = celestia:find("Sol/Earth")
celestia:select(earth)
distance = 7 * earth:radius()
obs:gotodistance(earth, distance, 3.0 )
wait (5.0)
obs:track(earth)
celestia:settimescale(1000)


返回到觀察者 方法索引。


獲取位置

[編輯 | 編輯原始碼]

position observer:getposition()

返回此觀察者在通用座標系中的當前位置,作為 "position" 物件。

備註

  1. Celestia 中的位置分量 (X,Y,Z) 以光年百萬分之一儲存。因此,如果您定義了自己的公里或英里位置,則必須將這些位置進行轉換。因此,您可以使用一個常量,該常量必須首先在您的指令碼中初始化
    • 從公里到光年百萬分之一,使用常量 uly_to_km = 9460730.4725808。
    • 從英里到光年百萬分之一,使用常量 uly_to_mls = 5912956.5453630。
  2. 接下來,您可以將公里或英里轉換為光年百萬分之一,如下所示
    • millionths_of_a_light_year = number:km / uly_to_km
    • millionths_of_a_light_year = number:miles / uly_to_mls
  3. CELX "position" 物件包含太空中一個點的精確座標。位置相對於座標系,可能需要在進一步使用之前轉換為或從通用座標系轉換。
  4. 可以在 CELX "position" 物件上使用 position 方法。"Position" 物件也可以在其他方法中使用,這些方法需要 "position" 物件作為引數。

示例

obs = celestia:getobserver()
actual_obspos = obs:getposition()
celestia:print("Actual observer position:\nX = " .. actual_obspos.x .. 
               "\nY = " .. actual_obspos.y .. "\nZ = " ..  actual_obspos.z, 15, -1, -1, 1, 6)
wait(15.0)


返回到觀察者 方法索引。


設定位置

[編輯 | 編輯原始碼]

observer:setposition(position:pos)

設定此觀察者的新位置。

引數

pos
此觀察者在通用座標系中的新位置。必須是 "position" 物件。

備註

  1. Celestia 中的位置分量 (X,Y,Z) 以光年百萬分之一儲存。因此,如果您定義了自己的公里或英里位置,則必須將這些位置進行轉換。因此,您可以使用一個常量,該常量必須首先在您的指令碼中初始化
    • 從公里到光年百萬分之一,使用常量 uly_to_km = 9460730.4725808。
    • 從英里到光年百萬分之一,使用常量 uly_to_mls = 5912956.5453630。
  2. 接下來,您可以將公里或英里轉換為光年百萬分之一,如下所示
    • millionths_of_a_light_year = number:km / uly_to_km
    • millionths_of_a_light_year = number:miles / uly_to_mls

示例
設定新的觀察者位置,位於地球和月球之間的一半位置。執行此示例後,按 [Shift + *] 鍵,以驗證月球在觀察者後視鏡中的位置。

obs = celestia:getobserver()
-- Set frame of reference to "universal".
obs:setframe(celestia:newframe( "universal"))
-- Find the actual position of the Earth.
earth = celestia:find("Sol/Earth")
earthpos = earth:getposition()
-- Find the actual position of the Moon.
moonpos = celestia:find("Sol/Earth/Moon"):getposition()
-- Calculate new position halfway Earth - Moon.
newpos = earthpos + 0.5 * (moonpos - earthpos)
-- Set new observer position and follow/center Earth
obs:setposition(newpos)
obs:follow(earth)
obs:center(earth, 0.0)
wait(0.0)


返回到觀察者 方法索引。


獲取方向

[編輯 | 編輯原始碼]

rotation observer:getorientation()

返回此觀察者的當前方向,作為 "rotation" 物件。

備註

  1. CELX "rotation" 物件在內部是一個四元數,它是數學上描述三維旋轉的一種可能性(即它可以轉換為旋轉矩陣)。旋轉也可以用來描述物體的方向或觀察者的方向(即觀察者看向哪裡,以及“向上”在哪裡)。
  2. 可以在 CELX "rotation" 物件上使用 rotation 方法。"Rotation" 物件也可以在其他方法中使用,這些方法需要 "rotation" 物件作為引數。

示例

obs = celestia:getobserver()
actual_obsrot = obs:getorientation()


返回到觀察者 方法索引。


設定方向

[編輯 | 編輯原始碼]

observer:setorientation(rotation:rot)

設定此觀察者的新方向。

引數

rot
此觀察者的新方向。必須是 "rotation" 物件。

示例
將新的觀察者位置設定為地球和月球的中點,然後將觀察者的方向交替指向地球和月球。

obs = celestia:getobserver()
-- Set frame of reference to "universal".
obs:setframe(celestia:newframe("universal"))
-- Find the actual position of the Earth.
earth = celestia:find("Sol/Earth")
earthpos = earth:getposition()
-- Find the actual position of the Moon.
moonpos = celestia:find("Sol/Earth/Moon"):getposition()
-- Calculate new position halfway Earth - Moon.
newpos = earthpos + 0.5 * (moonpos - earthpos)
obs:setposition(newpos)
-- Follow Earth
obs:follow(earth)
-- Observer orientation to look from newpos towards Earth.
rot1 = newpos:orientationto(earthpos, celestia:newvector(0,1,0))
-- Observer orientation to look from newpos towards the Moon.
rot2 = newpos:orientationto(moonpos, celestia:newvector(0,1,0))
-- Alternately switch the observer orientation.
for i = 1, 5 do
   obs:setorientation(rot1)
   wait(1.0)
   obs:setorientation(rot2)
   wait(1.0)
end


返回到觀察者 方法索引。


旋轉

[edit | edit source]

observer:rotate(rotation:rot)

根據給定的旋轉,旋轉觀察者。

引數

rot
要用於當前觀察者方向的旋轉。必須是“rotation”物件。

備註

  1. 此方法立即設定新的觀察者方向。為了更接近模擬 CEL: ROTATE 命令,並讓觀察者在一段時間內旋轉,可以在 Lua “for” 或 “while” 控制結構中使用此 observer:rotate() 方法將旋轉角度分解成多個較小的旋轉角度,然後快速依次處理這些角度(請參閱下一條註釋)。
  2. 在 Lua “for” 控制結構中使用此 observer:rotate() 方法時(請參閱示例-1),旋轉週期將比 number:duration 秒多出一小段時間(取決於您的計算機速度),但沿指定軸的總旋轉角度將完全正確。這是因為在生成的迴圈中,執行命令也會佔用一些額外的計算機時間。對於速度較慢的計算機,您可以減少每秒的步數,但這也會導致場景變得更加卡頓。
  3. 也可以在 Lua “while” 控制結構中使用此 observer:rotate() 方法(請參閱示例-2)。在這種情況下,旋轉週期可以精確地設定為 number:duration 秒,但沿指定軸的總旋轉角度將不會完全正確。同樣取決於您的計算機速度,您需要對 “while” 控制結構中每個序列的步長或等待時間進行猜測,才能儘可能接近目標總旋轉角度。

示例 1
選擇、跟蹤並居中地球,然後將觀察者在大約 5 秒內沿地球的 Z 軸向右旋轉精確 90 度。

-- Find, select, follow and center Earth first.
earth = celestia:find("Sol/Earth")
celestia:select(earth)
obs = celestia:getobserver()
obs:follow(earth)
obs:center(earth, 1.0)
wait(1.0)
-- Rotate the observer during about 5 seconds over exactly 90 degrees along the Z axis
duration = 5.0
axis_vector = celestia:newvector(0,0,1)
rotationangle = math.rad(90)
obs = celestia:getobserver()
-- Split up the rotation in 50 steps per second.
-- The factor 0.75 is an estimate and may depend on the speed of your computer.
rotsteps = 50 * duration
rotsteptime = 0.75*duration/rotsteps
-- Create new rotation object of split up rotation angle over the specified axis.
rot = celestia:newrotation(axis_vector, rotationangle/rotsteps)
-- Actually execute the rotation.
for i = 1, rotsteps do
   obs:rotate(rot)
   wait(rotsteptime)
end

示例 2
選擇、跟蹤並居中地球,然後將觀察者在精確 5 秒內沿地球的 Z 軸向右旋轉大約 90 度。

-- Find, select, follow and center Earth first.
earth = celestia:find("Sol/Earth")
celestia:select(earth)
obs = celestia:getobserver()
obs:follow(earth)
obs:center(earth, 1.0)
wait(1.0)
-- Rotate the observer during exactly 5 seconds over about 90 degrees along the Z axis
duration = 5.0
axis_vector = celestia:newvector(0,0,1)
rotationangle = math.rad(90)
obs = celestia:getobserver()
-- Split up the rotation in 50 steps per second.
-- The factor 0.75 is an estimate and may depend on the speed of your computer.
rotsteps = 50 * duration
rotsteptime = 0.75*duration/rotsteps
-- Create new rotation object of split up rotation angle over the specified axis.
rot = celestia:newrotation(axis_vector, rotationangle / rotsteps)
-- Get the elapsed time in seconds since the script has been started and store in "t0". 
t0= celestia:getscripttime()
-- Actually execute the rotation.
while celestia:getscripttime() <= t0 + duration do
   obs:rotate(rot)
   wait(rotsteptime)
end


返回到觀察者 方法索引。


lookat

[edit | edit source]

observer:lookat([position:from,] position:to, vector:up)

根據規範設定觀察者的方向,以從 position:from 處看向 position:to,並讓 vector:up 指向上方。

引數

from [可選]
看向位置 to 的點。必須是“position”物件。
如果未提供,則使用當前位置。
to
從位置 from 處看向的點。必須是“position”物件。
up
指向當前檢視中 up 方向的向量。必須是“vector”物件。
不能與 from --> to 的軸平行。

備註

  1. 將觀察者的方向設定為從 position:from 處看向 position:to 並不意味著觀察者也位於 position:from 處。此方法僅設定觀察者方向,而不設定觀察者位置。

示例
轉到地球將在 1 天內到達的空間位置。從該位置看向地球,並觀察地球如何向你靠近(時間加速 3600 倍)。及時躲開…

-- Find and select Earth
earth = celestia:find("Sol/Earth")
celestia:select(earth)
obs = celestia:getobserver()
-- Set frame of reference to "universal".
obs:setframe(celestia:newframe("universal"))
-- Determine the new observer position and the position of Earth
now = celestia:gettime()
newpos = earth:getposition(now+1)
posearth = earth:getposition(now)
obs:goto(newpos,0.0)
wait(0.0)
-- Look at Earth and see how it comes towards you
upvec = celestia:newvector(0,1,0)
obs:lookat(newpos, posearth, upvec)
celestia:settimescale(3600)


返回到觀察者 方法索引。


gettime

[edit | edit source]

number observer:gettime()

將此觀察者的時間作為 TDB(質心動力時間)儒略日返回。

舊版本的 Celestia 使用 UTC(協調世界時)來計算時間和位置。
從版本 1.5.0 開始,雖然 Celestia 仍然在螢幕上顯示 UTC,
但它在內部使用 TDB 時間刻度來執行其他所有操作,因此對於 CELX 指令碼來說, !!!

備註

  1. 此方法不同於 celestia:gettime() 方法,因為在多檢視場景中,模擬時間在可用觀察者之間可能會有所不同。此方法返回活動檢視觀察者的時間。有關不同檢視(觀察者)之間時間同步的更多資訊,請檢視 1.6.1 celestia:synchronizetime()1.6.1 celestia:istimesynchronized() 方法。
  2. TDB 時間刻度與更熟悉的 UTC 略有不同。透過使用 TDB,Celestia 可以更準確地放置物體。截至 2008 年 1 月 1 日,兩者之間的差異約為 65 秒。有關更多資訊,請參閱 Celestia/Time_Scales
  3. 要進行 UTC 和 TDB 時間之間的轉換,您可以使用 1.5.0 celestia:utctotdb()1.5.0 celestia:tdbtoutc() 方法。
  4. 要進行普通日曆日期和儒略日之間的轉換,您可以使用 celestia:tojulianday()celestia:fromjulianday() 方法。

示例
獲取活動檢視觀察者的 TDB 時間,並將其轉換為 UTC 日曆日期/時間。可以透過將 print 語句的結果與螢幕右上角顯示的 UTC 日期/時間進行比較來檢查這一點。

celestia:settimescale(0)
obs = celestia:getobserver()
actual_observer_tdbtime = obs:gettime()
ut = celestia:tdbtoutc(actual_observer_tdbtime)
celestia:print("Date/time: " .. ut.year .. " " .. ut.month .. " " .. ut.day .. " "
                .. ut.hour .. " " .. ut.minute .. " " .. ut.seconds, 10.0, -1, -1, 2, 4) 
wait(10.0)


返回到觀察者 方法索引。


getspeed

[edit | edit source]

1.3.2 number observer:getspeed()

將此觀察者的當前速度以百萬分之一光年/秒的形式返回一個數字。

備註

  1. 可以使用 observer:setspeed() 方法設定此觀察者的速度。
  2. 當您想要將獲得的速度轉換為 km/s 或 miles/s 時,可以使用一個常量,該常量必須首先在您的指令碼中進行初始化
    • 從百萬分之一光年轉換為 km,使用常量 uly_to_km = 9460730.4725808。
    • 從百萬分之一光年轉換為 miles,使用常量 uly_to_mls = 5912956.5453630。
  3. 接下來,您可以將百萬分之一光年轉換為 km 或 miles,如下所示
    • km/s = number:millionths_of_a_light_year/s * uly_to_km
    • miles/s = number:millionths_of_a_light_year/s * uly_to_mls

示例
獲取此觀察者的實際速度。要檢查此示例的工作原理,您首先可以多次按下鍵盤上的 [A] 鍵,將觀察者的速度設定為特定值,該值將在螢幕左下角顯示(如果未顯示,請按下鍵盤上的 [V] 鍵)。

uly_to_km = 9460730.4725808
obs = celestia:getobserver()
actual_obsspeed = obs:getspeed() * uly_to_km
celestia:print("Actual observer speed: " .. actual_obsspeed .. " km/s.", 10.0, -1, -1, 2, 4)
wait(10.0)


返回到觀察者 方法索引。


setspeed

[edit | edit source]

1.3.2 observer:setspeed(number:speed)

設定此觀察者的速度。

引數

speed
此觀察者的速度,以百萬分之一光年/秒為單位。必須是數字。

備註

  1. 可以使用 observer:getspeed() 方法獲取此觀察者的實際速度。
  2. 當您擁有以 km/s 或 miles/s 為單位定義的速度時,您需要將此速度轉換為百萬分之一光年/秒。為此,您可以使用一個常量,該常量必須首先在您的指令碼中進行初始化
    • 從 km/s 轉換為百萬分之一光年/s,使用常量 uly_to_km = 9460730.4725808。
    • 從 miles/s 轉換為百萬分之一光年/s,使用常量 uly_to_mls = 5912956.5453630。
  3. 接下來,您可以將 km/s 或 miles/s 轉換為百萬分之一光年/s,如下所示
    • millionths_of_a_light_year/s = number:km/s / uly_to_km
    • millionths_of_a_light_year/s= number:miles/s / uly_to_mls

示例
將此觀察者的速度設定為 150 km/s。觀察者的速度將在螢幕左下角顯示(如果未顯示,請按下鍵盤上的 [V] 鍵)。

uly_to_km = 9460730.4725808
obs = celestia:getobserver()
obs:setspeed(150/uly_to_km)


返回到觀察者 方法索引。


getsurface

[edit | edit source]

string observer:getsurface()

返回一個字串,描述當前使用的表面。這可能是“知識的極限”,或者可能是備用表面的名稱。

備註

  1. 當使用“正常”表面時,將返回空字串 ""。

示例

obs = celestia:getobserver()
actual_surface = obs:getsurface()
celestia:print("Actual surface: " .. actual_surface, 10.0, -1, -1, 2, 4)
wait(10.0)


返回到觀察者 方法索引。


setsurface

[edit | edit source]

observer:setsurface(string:name)

為與指定表面名稱相關的物體設定此觀察者要顯示的備用表面紋理。

引數

name
要使用的表面的名稱。必須是字串。
名稱必須與solarsys.ssc 檔案的AltSurface條目中定義的備用表面名稱一致。它不是紋理檔案本身的名稱。
注意: 當必須設定 'Normal' 表面時,請使用空字串 ""。

備註

  1. 例如,如果您想為地球建立一個名為 "Earth-2" 的備用表面紋理,並且它的相關紋理檔名是 earth2.jpg,您將在 ' "Earth" "Sol" ' 條目的結束大括號之後,將以下條目新增到 solarsys.ssc 檔案中。"Earth-2" 在下面的程式碼中是在 observer:setsurface() 方法中指定的表面名稱。
AltSurface "Earth-2" "Sol/Earth"
{
  Texture "earth2.jpg"
}

示例

-- Set surface to 'limit of knowledge'
celestia:getobserver():setsurface("limit of knowledge")
-- Set surface to 'Normal'
celestia:getobserver():setsurface("")
-- Set surface to 'Earth-2' according the code in 'Notes'.
celestia:getobserver():setsurface("Earth-2")


返回到觀察者 方法索引。


getlocationflags

[edit | edit source]

1.3.2 表格 observer:getlocationflags()

返回一個包含所有已知位置標誌的表格(參見observer:setlocationflags() 方法)作為鍵,以及一個布林值作為值,指示特定位置標誌是啟用還是停用。

備註

  1. 此方法特別有用,可以在指令碼開始時儲存所有位置標誌,以便使用 celestia_cleanup_callback() 函式在指令碼結束或指令碼終止時重置這些值。

示例

obs = celestia:getobserver()
actual_locationflags = obs:getlocationflags()


返回到觀察者 方法索引。


setlocationflags

[edit | edit source]

1.3.2 observer:setlocationflags(table:locationflags)

使用 celestia:setlabelflags()celestia:showlabel() 方法開啟位置時,啟用或停用特定位置型別的標記。

引數

locationflags
一個包含位置標誌作為鍵,以及每個鍵的布林值作為值的表格。每個位置標誌必須是以下之一:
  • city
  • observatory
  • landingsite
  • crater
  • vallis
  • mons
  • planum
  • chasma
  • patera
  • mare
  • rupes
  • tessera
  • regio
  • chaos
  • terra
  • volcano
  • astrum
  • corona
  • dorsum
  • fossa
  • catena
  • mensa
  • rima
  • undae
  • tholus
  • reticulum
  • planitia
  • linea
  • fluctus
  • farrum
  • insula
  • other

備註

  1. 可以使用 observer:getlocationflags() 方法獲取特定位置型別標記的當前設定。
  2. 可以使用 celestia:setminfeaturesize() 方法設定要標記的位置的最小尺寸。
  3. Celestia Motherlode 上,您可以找到並下載 Bob Hegwood 為太陽系行星製作的不同巡迴指令碼。當您在計算機上安裝並執行這些指令碼時,您將瞭解有關特定位置型別的含義的更多資訊。

示例
啟用所有位置型別的標記。

-- create and initialize table
table = {}
table.city = true
table.observatory = true
table.landingsite = true
table.crater = true
table.vallis = true
table.mons = true
table.planum = true
table.chasma = true
table.patera = true
table.mare = true
table.rupes = true
table.tessera = true
table.regio = true
table.chaos = true
table.terra = true
table.astrum = true
table.corona = true
table.dorsum = true
table.fossa = true
table.catena = true
table.mensa = true
table.rima = true
table.undae = true
table.reticulum = true
table.planitia = true
table.linea = true
table.fluctus = true
table.farrum = true
table.other = true
obs = celestia:getobserver()
obs:setlocationflags(table)
celestia:setlabelflags{locations = true}

或更短

-- note the curly braces
obs = celestia:getobserver()
obs:setlocationflags{city = true, observatory = true, landingsite = true, crater = true,
                     vallis = true, mons = true, planum = true, chasma = true, patera = true,
                     mare = true, rupes = true, tessera = true, regio = true, chaos = true,
                     terra = true, astrum = true, corona = true, dorsum = true, fossa = true,
                     catena = true, mensa = true, rima = true, undae = true, reticulum = true,
                     planitia = true, linea = true, fluctus = true, farrum = true, other = true}
celestia:setlabelflags{locations = true}

或更短

obs = celestia:getobserver()
table = obs:getlocationflags()
for key, value in pairs(table) do 
   table[key] = true 
end
obs:setlocationflags(table)
celestia:setlabelflags{locations = true}


返回到觀察者 方法索引。


getfov

[edit | edit source]

數字 observer:getfov()

以弧度為單位返回此觀察者的當前視野 (FOV) 值。

備註

  1. Celestia 以畫素為單位相對於顯示視窗的大小計算 FOV 值,但也可以使用 observer:setfov() 方法設定。
  2. FOV 值以度數°分'秒" 的格式顯示在螢幕右下角。(如果未顯示任何值,請按鍵盤上的 [V] 鍵)。
  3. CELX 中的角度以弧度而不是度數定義。180 度(半圓)等於 π 弧度 = 3.14159265 弧度 = math.pi 弧度 (LUA)。您可以按照以下步驟將度數轉換為弧度,反之亦然。
    • radians = math.rad( number:degrees ) = ( number:degrees / 180 * math.pi) = ( number:degrees / 180 * 3.14159265).
    • degrees = math.deg( number:radians ) = ( number:radians * 180 / math.pi) = ( number:radians * 180 / 3.14159265).
  4. 請注意,螢幕上顯示的分鐘部分和部分是從 0 到 100,而是從 0 到 60。
    要從度數°分'秒" 轉換為弧度,您首先需要將分鐘和秒轉換為十進位制度數,反之亦然。

示例
獲取並列印實際的 FOV 值,以度數°分'秒" 為單位。將其與螢幕右下角的 FOV 值進行比較。

obs = celestia:getobserver()
actual_fov = obs:getfov()
degrees = math.deg(actual_fov)
-- Determine whole number of degrees
degrees_d = math.floor(degrees)
-- Determine whole number of minutes
degrees = (degrees - degrees_d) * 60
degrees_m = math.floor(degrees)
-- Determine number of seconds
degrees_s = (degrees - degrees_m) * 60
celestia:print("Actual FOV value is: " .. degrees_d .. " degrees " ..
                degrees_m .. " minutes " .. degrees_s .. " seconds.", 10.0, -1, -1, 2, 4)
wait(10.0)


返回到觀察者 方法索引。


setfov

[edit | edit source]

observer:setfov(數字:fov)

以弧度為單位設定此觀察者的視野 (FOV) 值。

引數

fov
以弧度為單位的新 FOV 值。必須是數字。

備註

  1. Celestia 以畫素為單位相對於顯示視窗的大小計算 FOV 值。可以使用 observer:getfov() 方法獲取此觀察者的當前 FOV 值。
  2. FOV 值以度數°分'秒" 的格式顯示在螢幕右下角。(如果未顯示任何值,請按鍵盤上的 [V] 鍵)。
  3. CELX 中的角度以弧度而不是度數定義。180 度(半圓)等於 π 弧度 = 3.14159265 弧度 = math.pi 弧度 (LUA)。您可以按照以下步驟將度數轉換為弧度,反之亦然。
    • radians = math.rad( number:degrees ) = ( number:degrees / 180 * math.pi) = ( number:degrees / 180 * 3.14159265).
    • degrees = math.deg( number:radians ) = ( number:radians * 180 / math.pi) = ( number:radians * 180 / 3.14159265).
  4. 請注意,螢幕上顯示的分鐘部分和部分是從 0 到 100,而是從 0 到 60。
    要從度數°分'秒" 轉換為弧度,您首先需要將分鐘和秒轉換為十進位制度數,反之亦然。

示例
將此觀察者的新 FOV 值設定為 25°45'15"。

degrees_d = 25
degrees_m = 45
degrees_s = 15
-- Convert number of seconds to decimal minutes
degrees = degrees_s / 60
-- Convert number of minutes to decimal degrees
degrees = (degrees_m + degrees) / 60
degrees = degrees_d + degrees
radians = math.rad(degrees)
obs = celestia:getobserver()
obs:setfov(radians)


返回到觀察者 方法索引。


getframe

[edit | edit source]

框架 observer:getframe()

在 CELX "框架" 物件中返回此觀察者的參考框架。

備註

  1. 可以使用 observer:setframe() 方法設定此觀察者的新參考框架。
  2. CELX 參考 "框架" 是一個原點和一組軸,定義了用於天體軌跡和方向的座標系。原點是目錄檔案中定義的另一個天體。有多種方法可以設定座標系軸。
  3. 可以使用 框架 方法在 CELX "框架" 物件上。本節還提供了有關使用參考框架的更多資訊。"框架" 物件也可以在其他方法中使用,這些方法需要 "框架" 物件作為引數。

示例

obs = celestia:getobserver()
actual_frame = obs:getframe()


返回到觀察者 方法索引。


setframe

[edit | edit source]

observer:setframe(框架:f)

設定此觀察者的新參考框架。

引數

f
此觀察者的新參考框架。必須是 "框架" 物件。

備註

  1. 可以使用 observer:getframe() 方法獲取此觀察者的當前參考框架。
  2. 可以使用 celestia:newframe() 方法建立一個新的參考框架作為 "框架" 物件。

示例 1
告訴 Celestia 將活動座標系設定為 UNIVERSAL

frame = celestia:newframe("universal")
obs = celestia:getobserver()
obs:setframe(frame)

示例 2
以下示例選擇月球,然後將活動座標系設定為 CHASE 並前往月球。

moon = celestia:find("Sol/Earth/Moon")
celestia:select(moon)
frame = celestia:newframe("chase", moon)
obs = celestia:getobserver()
obs:setframe(frame)
obs:goto(moon, 2.0)
wait(2.0)

示例-3
告訴 Celestia 將活動座標系設定為鎖定地球和太陽。此示例將保持您相對於地球中心的方位,並在時間推移時將太陽 (Sol) 和地球保持在視野中。在執行此示例之前,請確保地球和太陽都在觀察者的視野中。

earth = celestia:find("Sol/Earth")
celestia:select(earth)
sun = celestia:find("Sol")
frame = celestia:newframe("lock", earth, sun)
obs = celestia:getobserver()
obs:setframe(frame)
celestia:settimescale(50000)


返回到觀察者 方法索引。


splitview

[edit | edit source]

1.3.2 observer:splitview(字串:splitdirection [, 數字:splitpos])

拆分此觀察者的檢視。

引數

splitdirection
用於確定螢幕必須沿哪個方向拆分的字串。必須是
  • "H" 表示水平拆分。
  • "V" 表示垂直拆分。
splitpos [可選]
以 0(左/下)到 1(右/上)之間的百分比數字表示在何處拆分活動檢視。預設值為 0.5(在中間)。
  • 如果 splitpos 小於 0.1,則 splitpos 將調整為 0.1。
  • 如果 splitpos 大於 0.9,則 splitpos 將調整為 0.9。

備註

  1. 在使用此 observer:splitview() 方法之後,可以使用 celestia:getobservers() 方法獲取每個檢視的 "觀察者" 物件。

示例
將實際檢視在中間垂直拆分。左側轉到金星,右側轉到火星,並在 10 秒後再次恢復單檢視。

obs = celestia:getobserver()
obs:splitview("V", 0.5)
observers = celestia:getobservers()
venus = celestia:find("Sol/Venus")
observers[1]:gotodistance(venus, 50000)
mars = celestia:find("Sol/Mars")
observers[2]:gotodistance(mars, 30000)
wait(10.0)
obs:singleview()


返回到觀察者 方法索引。


deleteview

[edit | edit source]

1.3.2 observer:deleteview()

刪除此觀察者的檢視。

在使用此方法後,觀察者將變得無效。

備註

  1. 只有在至少存在一個 Mulitiview 時,使用此方法才有意義。此方法對單檢視觀察者沒有影響。

示例
將實際檢視在中間垂直拆分。左側轉到金星,右側轉到火星,並在 10 秒後刪除金星上的檢視。

obs = celestia:getobserver()
obs:splitview("V", 0.5)
observers = celestia:getobservers()
venus = celestia:find("Sol/Venus")
observers[1]:gotodistance(venus, 50000)
mars = celestia:find("Sol/Mars")
observers[2]:gotodistance(mars, 30000)
wait(10.0)
observers[1]:deleteview()


返回到觀察者 方法索引。


singleview

[edit | edit source]

1.3.2 observer:singleview()

使此觀察者的檢視成為唯一的檢視。

所有其他觀察者檢視將被刪除,並立即變得無效。

備註

  1. 此方法在 celestia_cleanup_callback() 函式中也很有用,因此單檢視將始終在指令碼結束或指令碼終止時恢復。

示例
建立 4 個觀察者的多檢視,並在幾秒鐘後,將第 4 個觀察者設為唯一的檢視。

obs = celestia:getobserver()
obs:splitview("V", 0.5)
observers = celestia:getobservers()
observers[1]:splitview("H", 0.5)
observers[2]:splitview("H", 0.5)
observers = celestia:getobservers()
mercury = celestia:find("Sol/Mercury")
observers[1]:gotodistance(mercury, 20000)
venus = celestia:find("Sol/Venus")
observers[2]:gotodistance(venus, 50000)
mars = celestia:find("Sol/Mars")
observers[3]:gotodistance(mars, 30000)
io = celestia:find("Sol/Jupiter/Io")
observers[4]:gotodistance(io, 15000)
celestia:print("Which view does not belong in this scene?", 10.0, -1, -1, 2, 4)
wait(10.0)
observers[4]:singleview()
celestia:print("This view, because Io is a moon of\n" ..
               "Jupiter, instead of a planet.", 10.0, -1, -1, 2, 4)
wait(10.0)


返回到觀察者 方法索引。


isvalid

[edit | edit source]

1.3.2 布林值 observer:isvalid()

返回一個布林值,指示觀察者是否仍然有效。

  • 如果此觀察者仍然有效,則為 true。
  • 如果此觀察者不再有效,則為 false。

示例
建立多檢視,然後刪除一些檢視,並確定哪些觀察者仍然有效。

obs = celestia:getobserver()
obs:splitview("V", 0.5)
observers = celestia:getobservers()
observers[1]:splitview("H", 0.5)
observers[2]:splitview("H", 0.5)
observers = celestia:getobservers()
mercury = celestia:find("Sol/Mercury")
observers[3]:gotodistance(mercury, 20000)
venus = celestia:find("Sol/Venus")
observers[1]:gotodistance(venus, 50000)
earth = celestia:find("Sol/Earth")
observers[4]:gotodistance(earth, 50000)
mars = celestia:find("Sol/Mars")
observers[2]:gotodistance(mars, 30000)
celestia:print("The 4 inner planets of our Solar System.", 10.0, -1, -1, 2, 4)
wait(10.0)
observers[4]:singleview()
celestia:print("Back to our own planet", 3.0, -1, -1, 2, 4)
wait(3.0)
valid = { }
for key, value in pairs(observers) do 
   valid[key] = observers[key]:isvalid() 
   if valid[key] then
      celestia:print("Observer " .. key .. " is valid.", 3.0, -1, -1, 2, 4)
   else
      celestia:print("Observer " .. key .. " is NOT valid.", 3.0, -1, -1, 2, 4)
   end
   wait(3.5)
end


返回到觀察者 方法索引。


gettrackedobject

[編輯 | 編輯原始碼]

1.5.0 object observer:gettrackedobject()

返回當前在 CELX “object” 物件中跟蹤的物件。

備註

  1. 如果當前沒有跟蹤任何物件,則返回一個空物件。空物件與 nil 不同!
  2. CELX “object” 物件可以引用一個天體,例如行星或恆星,但它也可以是一個位置或航天器。
  3. 可以使用object 方法處理 CELX “object” 物件。“Object” 物件也可以用在其他方法中,這些方法需要一個“object” 物件作為引數。

示例
顯示此觀察者當前跟蹤的物件名稱。可以透過按鍵盤上的 [Esc] 鍵終止示例。
在執行此示例時,您可以選擇不同的物件並按鍵盤上的 [T] 鍵來跟蹤或停止跟蹤該物件。

while true do
   obs = celestia:getobserver()
   tracked_obj = obs:gettrackedobject()
   tracked_obj_name = tracked_obj:name()
   if tracked_obj_name == "?" then
      celestia:print("No object currently tracked")
   else
      celestia:print("Tracking "..tracked_obj_name)
   end
   wait(0)
end


返回到觀察者 方法索引。


makeactiveview

[編輯 | 編輯原始碼]

1.6.0 observer:makeactiveview()

使此觀察者的檢視成為當前活動檢視。

示例
建立多檢視後,確定哪個觀察者是活動檢視併為該觀察者恢復單檢視。

obs = celestia:getobserver()
obs:splitview("V", 0.5)
observers = celestia:getobservers()
venus = celestia:find("Sol/Venus")
observers[1]:gotodistance(venus, 50000)
mars = celestia:find("Sol/Mars")
observers[2]:gotodistance(mars, 30000)
wait(10.0)
observers[1]:makeactiveview()
obs = celestia:getobserver()
obs:singleview()


返回到觀察者 方法索引。


1.6.1 observer:orbit(rotation:rot)

根據給定的旋轉使觀察者圍繞當前參考物件旋轉。

引數

rot
此觀察者用於軌道的旋轉。必須是一個“rotation”物件。

備註

  1. 此方法會立即設定新的觀察者位置和方向。為了更好地模擬 CEL: ORBIT 命令,並讓觀察者在一段時間內圍繞某個軌道旋轉,可以透過將旋轉角度分成多個更小的旋轉角度來實現。這些較小的旋轉角度可以快速地依次處理。使用此 observer:orbit() 方法,透過 Lua “for” 或 “while” 控制結構(參見下一部分)。
  2. 當在 Lua “for” 控制結構中使用此 observer:orbit() 方法時(參見示例 1),軌道週期將比 number:duration 秒多出一小部分(取決於計算機的速度),但繞指定軸旋轉的總角度將是完全正確的。這是因為在生成的迴圈中,執行命令也會消耗一些額外的計算機時間。如果計算機速度較慢,可以減少每秒的步數,但這也可能意味著場景變得更加卡頓。
  3. 也可以在 Lua “while” 控制結構中使用此 observer:orbit() 方法(參見示例 2)。在這種情況下,軌道週期可以精確地設定為 number:duration 秒,但繞指定軸旋轉的總角度將不完全正確。同樣,根據計算機的速度,您需要估計“while” 控制結構中每個序列的步長角度或等待時間,以便儘可能接近目標軌道角度。
  4. 對於沒有參考物件存在的通用參考系,即使選中了物件,使用此 observer:orbit() 方法也不會導致觀察者繞某個軌道旋轉!

示例 1
選擇、跟蹤並以地球為中心,然後使觀察者在大約 10 秒內圍繞地球的 Y 軸旋轉精確地 360 度。

-- Find, select, follow and center Earth first.
earth = celestia:find("Sol/Earth")
celestia:select(earth)
obs = celestia:getobserver()
obs:follow(earth)
obs:center(earth, 1.0)
wait(1.0)
-- Orbit during about 10 seconds over 360 degrees, around the Y axis
duration = 10.0
orbitangle = math.rad(360.0)
axis_vector = celestia:newvector(0,1,0)
-- Split up the orbit in 30 steps per second and determine the orbit steptime for each single step.
-- The factor 0.75 is an estimate and may depend on the speed of your computer.
orbitsteps = 30 * duration
orbitsteptime = 0.75*duration/orbitsteps
-- Create new rotation object of split up orbit angle around the specified axis.
rot = celestia:newrotation(axis_vector, orbitangle/orbitsteps)
-- Actually execute the orbit.
for i = 1, orbitsteps do
   obs:orbit(rot)
   wait(orbitsteptime)
end

示例 2
選擇、跟蹤並以地球為中心,然後使觀察者在精確地 10 秒內圍繞地球的 Y 軸旋轉大約 360 度。

-- Find, select, follow and center Earth first.
earth = celestia:find("Sol/Earth")
celestia:select(earth)
obs = celestia:getobserver()
obs:follow(earth)
obs:center(earth, 1.0)
wait(1.0)
-- Orbit during 10 seconds over about 360 degrees, around the Y axis
duration = 10.0
orbitangle = math.rad(360.0)
axis_vector = celestia:newvector(0, 1, 0)
-- Split up the orbit in 30 steps per second and determine the orbit steptime for each single step.
-- The factor 0.75 is an estimate and may depend on the speed of your computer.
orbitsteps = 30 * duration
orbitsteptime = 0.75*duration/orbitsteps
-- Create new rotation object of split up orbit angle around the specified axis.
rot = celestia:newrotation(axis_vector, orbitangle/orbitsteps)
-- Get the elapsed time in seconds since the script has been started and store in "t0". 
t0 = celestia:getscripttime()
-- Actually execute the orbit
while celestia:getscripttime() <= t0 + duration do
   obs:orbit(rot)
   wait(orbitsteptime)
end


返回到觀察者 方法索引。


華夏公益教科書