跳轉到內容

Celestia/Celx 指令碼/CELX Lua 方法/CEL 命令 goto

來自華夏公益教科書,自由的教科書

goto { time <duration> distance <radiusdistance> upframe <upframestring> up <upvector> }

將攝像機移動到當前選定的物件,花費 <duration> 秒,距離物件 <radiusdistance> 個單位的半徑加 1(以物件的半徑為單位),使用 <upframestring> 座標系,並將 <upvector> 軸定義為指向向上。

引數

time <duration>
移動到目標物件所花的時間(以秒為單位)。預設值為 1.0 秒。
distance <radiusdistance>
描述與物件之間的距離,以物件的半徑加 1 為單位。預設值為 5.0。
特殊 <radiusdistance> 值為
  • 0(零)是物件的中心。在 1.3.1 版本中,使用此值會導致程式錯誤地識別更遠的定位值,因此不要使用零。
  • 1 是物件的表面。移動到物件的精確表面水平可能會導致某些顯示卡在顯示屏上顯示隨機多邊形,因此最好使用略高於表面的值。
upframe <upframestring>
設定指定的座標系。預設值為“observer”。<upframestring> 必須具有以下值之一:
  • chase
  • ecliptical
  • equatorial
  • geographic
  • lock
  • observer
  • universal
up <upvector>
定義哪個軸指向向上,X [1 0 0],Y [0 1 0] 或 Z [0 0 1]。預設值為 [0 1 0]。


CELX 等效-1

基於 observer:gotodistance() 方法。


  • 找到並選擇名為 <string> 的目標物件以移動並存儲在“objectname”中。
objectname = celestia:find( <string> )
celestia:select(objectname)
  • 獲取活動檢視例項的觀察者例項,並將參考幀的座標系設定為 <upframestring>。
obs = celestia:getobserver()
frame = celestia:newframe( <upframestring>, objectname)
obs:setframe(frame)
  • 確定“objectname”的半徑並存儲在“radius”中。
radius = objectname:radius()
  • 確定 <distance> 為:<radiusdistance> * “objectname” 的“radius”。
distance = <radiusdistance> * radius
  • 定義一個向量物件,以確定哪個軸指向向上。
upaxis = celestia:newvector( <upvector> )
  • 以 <duration> 秒的速度移動到確定好的“objectname”的 <distance>,向上指向 <upvector>。
    • <distance> 是從目標中心到停止點的距離(以公里為單位)。
      • 如果沒有提供 <distance>,則預設距離 = 20000 公里。
      • 如果 <distance> 小於物件的半徑,則 goto 將在物件內結束 !!!
      • 要獲取物件的半徑(以公里為單位),可以使用 object:radius() 方法。
    • <duration> 是 goto 所需的時間(以秒為單位)。
      • 如果沒有提供 <duration>,則預設時間 = 5.0 秒 !!!
      • 如果沒有提供 <upvector> = upaxis,則預設值為 (0,1,0) --> Y 軸。
obs:gotodistance(objectname, distance, <duration>, upaxis )
  • 等待 <duration> 秒。
wait( <duration> )

總結

objectname = celestia:find( <string> )
celestia:select(objectname)
obs = celestia:getobserver()
frame = celestia:newframe( <upframestring>, objectname)
obs:setframe(frame)
radius = objectname:radius()
distance = <radiusdistance> * radius
upaxis = celestia:newvector( <upvector> )
obs:gotodistance(objectname, distance, <duration>, upaxis )
wait( <duration> )


CELX 等效-2

基於 observer:goto(table) 方法。

使用此方法,可以執行多種不同型別的 goto。此方法的優勢在於可以對觀察者方向進行程式設計,因此也可以確定 goto 後指向的軸。

此方法使用位置進行 goto,而不是物件的距離,因此需要一些額外的計算。goto 的引數必須在表中給出

    • parameters.duration: 持續時間(數字)
    • parameters.from: 源位置
    • parameters.to: 目標位置
    • parameters.initialOrientation: 源方向
    • parameters.finalOrientation: 目標方向
    • parameters.startInterpolation
    • parameters.endInterpolation
    • parameters.accelTime


  • 找到並選擇名為 <string> 的目標物件以移動並存儲在“objectname”中。
objectname = celestia:find( <string> )
celestia:select(objectname)
  • 獲取活動檢視例項的觀察者例項,並將參考幀的座標系設定為 <upframestring>。
obs = celestia:getobserver()
frame = celestia:newframe( <upframestring>, objectname)
obs:setframe(frame)
  • 確定“objectname”的半徑並存儲在“radius”中。
radius = objectname:radius()
  • 確定以公里為單位的 goto 距離,為:<radiusdistance> * “radius”,並將結果儲存在“distance”中。
distance = <radiusdistance> * radius
  • 將確定的“distance”轉換為“objectname”中的位置,如下所示
uly_to_km = 9460730.4725808
–- Determine and store the current observer position
frompos = obs:getposition()
–- Determine and store the current position of objectname
objectpos = objectname:getposition()
–- Determine the vector between the current observer
-- position and the current position of objectname
distancevec = frompos:vectorto(objectpos)
-– Determine the length of this vector in millionths of a light-year.
distancelength = distancevec:length()
–- Normalize this length to 1
normalvec = distancevec:normalize()
–- Distance to travel = (distancelength - distance /uly_to_km)
–- Direction to travel = normalvec
travelvec = (distancelength - distance /uly_to_km)*normalvec
-– Determine and store the position to goto
topos = frompos + travelvec
  • 目標觀察者方向必須從目標位置“topos”指向“objectname”,以 <upvector> 作為向上向量
upvec = celestia:newvector( <upvector> )
torot = topos:orientationto(objectpos, upvec)
  • 定義並初始化引數表,如下所示
    • 確定 goto 所需的時間(以秒為單位)。
    • 獲取觀察者的當前位置。
    • 新位置物件 = topos(結果來自之前的 2 個步驟)。
    • 獲取觀察者的當前方向。
    • 新的觀察者方向 = torot(結果來自之前的步驟)。
    • 在 goto 時間的 20% 後開始調整觀察者方向。
    • 在 goto 時間的 80% 後結束調整觀察者方向。
    • 將 10% 的時間用於加速和減速
parameters={}
parameters.duration = <duration>
parameters.from = obs:getposition()
parameters.to = topos
parameters.initialOrientation = obs:getorientation()
parameters.finalOrientation = torot
parameters.startInterpolation = 0.2
parameters.endInterpolation = 0.8
parameters. accelTime = 0.1
  • 以 <duration> 秒的速度移動到目標位置,目標方向為 <duration> 秒。
obs:goto(parameters)
  • 等待 <duration> 秒。
wait(parameters.duration)

總結

objectname = celestia:find( <string> )
celestia:select(objectname)
obs = celestia:getobserver()
frame = celestia:newframe( <upframestring>, objectname)
obs:setframe(frame)
radius = objectname:radius()
distance = <radiusdistance> * radius
uly_to_km = 9460730.4725808
–- Determine and store the current observer position
frompos = obs:getposition()
–- Determine and store the current position of objectname
objectpos = objectname:getposition()
–- Determine the vector between the current observer
-- position and the current position of objectname
distancevec = frompos:vectorto(objectpos)
-– Determine the length of this vector in millionths of a light-year.
distancelength = distancevec:length()
–- Normalize this length to 1
normalvec = distancevec:normalize()
–- Distance to travel = (distancelength - distance /uly_to_km)
–- Direction to travel = normalvec
travelvec = (distancelength - distance /uly_to_km)*normalvec
-– Determine and store the position to goto
topos = frompos + travelvec
upvec = celestia:newvector( <upvector> )
torot = topos:orientationto(objectpos, upvec)
parameters={}
parameters.duration = <duration>
parameters.from = obs:getposition()
parameters.to = topos
parameters.initialOrientation = obs:getorientation()
parameters.finalOrientation = torot
parameters.startInterpolation = 0.2
parameters.endInterpolation = 0.8
parameters. accelTime = 0.1
obs:goto(parameters)
wait(parameters.duration)

例子
以下示例選擇火星,並花費 5 秒的時間移動到火星表面以上 10 倍半徑的位置,Y 軸指向向上。

CEL

select { object "Mars" }
goto   { time 5.0 distance 11.0 upframe "ecliptic" up [0 1 0] }
print  { text "We're on our way to Mars." row -3 column 1 duration 5 }
wait   { duration 5 }

CELX-1,使用 observer:gotodistance() 方法

mars = celestia:find("Sol/Mars")
celestia:select(mars)
frame = celestia:newframe("ecliptic", mars)
obs = celestia:getobserver()
obs:setframe(frame)
marsradius = mars:radius()
marsdistance = 11 * marsradius
upaxis = celestia:newvector(0,1,0)
obs:gotodistance(mars, marsdistance, 5.0, upaxis)
celestia:print("We're on our way to Mars." , 5.0, -1, -1, 1, 3)
wait(5.0)

CELX-2,使用 observer:goto(table) 方法

mars = celestia:find("Sol/Mars")
celestia:select(mars)
frame = celestia:newframe("ecliptic", mars)
obs = celestia:getobserver()
obs:setframe(frame)
marsradius = mars:radius()
distance = 11 * marsradius
uly_to_km = 9460730.4725808
frompos = obs:getposition()
objectpos = mars:getposition()
distancevec = frompos:vectorto(objectpos)
distancelength = distancevec:length()
normalvec = distancevec:normalize()
travelvec = (distancelength - distance /uly_to_km)*normalvec
topos = frompos + travelvec
upvec = celestia:newvector(0,1,0)
torot = topos:orientationto(objectpos, upvec)
parameters={}
parameters.duration = 5.0
parameters.from = obs:getposition()
parameters.to = topos
parameters.initialOrientation = obs:getorientation()
parameters.finalOrientation = torot
parameters.startInterpolation = 0.2
parameters.endInterpolation = 0.8
parameters. accelTime = 0.1
obs:goto(parameters)
celestia:print("We're on our way to Mars." , 5.0, -1, -1, 1, 3)
wait(parameters.duration)


返回 CEL 命令索引

華夏公益教科書