Celestia/Celx 指令碼/CELX Lua 方法/CEL 命令 rotate
外觀
rotate { duration <duration> rate <rate> axis <axisvector> }
在 <duration> 秒內使用當前定義的座標系旋轉攝像機。您必須首先使用 select 命令選擇一個物體,並且可以根據需要使用 setframe 命令設定座標系,如果它當前沒有定義。
rotate 命令後面必須跟著一個 wait 命令,其 <duration> 等於或大於 rotate 命令的 <duration>。
引數
- duration <duration>
- 執行 rotate 命令的時間長度,以秒為單位。預設值為 1.0 秒。
- rate <rate>
- 旋轉攝像機的速度。預設值為 0.0。
正值和負值用於指示旋轉方向。 - axis <axisvector>
- 定義要繞其旋轉的軸 [ <x> <y> <z> ]。沒有預設值。
將 <x> 、 <y> 或 <z> 值設定為 1 表示 是,設定為 0 表示 否。您也可以指定多個軸。
CELX 等效項-1
基於 observer:rotate() 方法。
此等效項在 大約 <duration> 秒內旋轉觀察者,旋轉角度為 正好 <duration> * <rate> 度。
- 查詢並選擇名稱為 <string> 的物體以選擇並存儲在 "objectname" 中。
objectname = celestia:find( <string> ) celestia:select(objectname)
- 初始化旋轉的 "duration",以秒為單位。
duration = <duration>
- 計算 "rotationangle",它是 "duration" * <rate> 的乘積,單位為度。<rate> 是每秒的旋轉速度,單位為度。必須將 "rotationangle" 轉換為弧度,方法是乘以 math.pi (= 3.14159265) 併除以 180。Lua 的 math.rad(rotationangle) 函式也可以用於此目的。
rotationangle = math.rad(duration * <rate> )
- 為旋轉建立軸向量 [ <x> <y> <z> ] 並存儲在 "axis_vector" 中。
axis_vector = celestia:newvector( <x> , <y> , <z> )
- 獲取活動檢視的觀察者例項並存儲在 "obs" 中。
obs = celestia:getobserver()
- 將旋轉分成每秒 50 步。
因子 0.75 是一個估計值,可能取決於計算機的速度。
rotsteps = 50 * duration rotsteptime = 0.75*duration/rotsteps
- 建立一個新的旋轉物體,該物體在指定軸上進行分割後的旋轉角度。
rot = celestia:newrotation(axis_vector, rotationangle/rotsteps)
- 實際執行旋轉。
for i = 1, rotsteps do obs:rotate(rot) wait(rotsteptime) end
總結
objectname = celestia:find( <string> ) celestia:select(objectname) duration = <duration> rotationangle = math.rad(duration * <rate> ) axis_vector = celestia:newvector( <x> , <y> , <z> ) obs = celestia:getobserver() rotsteps = 50 * duration rotsteptime = 0.75*duration/rotsteps rot = celestia:newrotation(axis_vector, rotationangle/rotsteps) for i = 1, rotsteps do obs:rotate(rot) wait(rotsteptime) end
作為函式總結
function rotate_obs_angle(rottime, rotangle, rotaxis)
-- Rottime is the duration of the rotation in seconds
-- Rotangle is the angle to rotate the observer view in radians
-- Rotaxis is the axis vector (x,y,z) for the rotation
local obs = celestia:getobserver()
local rotsteps = 50 * rottime
local rotsteptime = 0.75*rottime/rotsteps
local rot = celestia:newrotation(rotaxis, rotangle/rotsteps)
for i = 1, rotsteps do
obs:rotate(rot)
wait(rotsteptime)
end
end
objectname = celestia:find( <string> )
celestia:select(objectname)
duration = <duration>
rotationangle = math.rad(duration * <rate> )
axis_vector = celestia:newvector( <x> , <y> , <z> )
rotate_obs_angle(duration, rotationangle, axis_vector)
CELX 等效項-2
基於 observer:rotate() 方法。
此等效項在 正好 <duration> 秒內旋轉觀察者,旋轉角度為 大約 <duration> * <rate> 度。
- 查詢並選擇名稱為 <string> 的物體以選擇並存儲在 "objectname" 中。
objectname = celestia:find( <string> ) celestia:select(objectname)
- 初始化旋轉的 "duration",以秒為單位。
duration = <duration>
- 計算 "rotationangle",它是 "duration" * <rate> 的乘積,單位為度。<rate> 是每秒的旋轉速度,單位為度。必須將 "rotationangle" 轉換為弧度,方法是乘以 math.pi (= 3.14159265) 併除以 180。Lua 的 math.rad(rotationangle) 函式也可以用於此目的。
rotationangle = math.rad(duration * <rate> )
- 為旋轉建立軸向量 [ <x> <y> <z> ] 並存儲在 "axis_vector" 中。
axis_vector = celestia:newvector( <x> , <y> , <z> )
- 獲取活動檢視的觀察者例項並存儲在 "obs" 中。
obs = celestia:getobserver()
- 將旋轉分成每秒 50 步。
因子 0.75 是一個估計值,可能取決於計算機的速度。
rotsteps = 50 * duration rotsteptime = 0.75*duration/rotsteps
- 建立一個新的旋轉物體,該物體在指定軸上進行分割後的旋轉角度。
rot = celestia:newrotation(axis_vector, rotationangle/rotsteps)
- 獲取指令碼啟動後經過的秒數,並存儲在 "t0" 中。
t0= celestia:getscripttime()
- 實際執行旋轉。
while celestia:getscripttime() <= t0 + duration do obs:rotate(rot) wait(rotsteptime) end
總結
objectname = celestia:find( <string> ) celestia:select(objectname) duration = <duration> rotationangle = math.rad(duration * <rate> ) axis_vector = celestia:newvector( <x> , <y> , <z> ) obs = celestia:getobserver() rotsteps = 50 * duration rotsteptime = 0.75*duration/rotsteps rot = celestia:newrotation(axis_vector, rotationangle/rotsteps) t0= celestia:getscripttime() while celestia:getscripttime() <= t0 + duration do obs:rotate(rot) wait(rotsteptime) end
作為函式總結
function rotate_obs_time(rottime, rotangle, rotaxis)
-- Rottime is the duration of the rotation in seconds
-- Rotangle is the angle to rotate the observer view in radians
-- Rotaxis is the axis vector (x,y,z) for the rotation
local obs = celestia:getobserver()
local rotsteps = 50 * rottime
local rotsteptime = 0.75*rottime/rotsteps
local rot = celestia:newrotation(rotaxis, rotangle/rotsteps)
local t0= celestia:getscripttime()
while celestia:getscripttime() <= t0 + duration do
obs:rotate(rot)
wait(rotsteptime)
end
end
objectname = celestia:find( <string> )
celestia:select(objectname)
duration = <duration>
rotationangle = math.rad(duration * <rate> )
axis_vector = celestia:newvector( <x> , <y> , <z> )
rotate_obs_time(duration, rotationangle, axis_vector)
示例
以下示例選擇、跟蹤並居中地球(因此參考系的座標系設定為黃道),然後將攝像機沿當前選定物體的 Z 軸向右(正速率值)旋轉 5 秒。
CEL
select { object "Sol/Earth" }
follow { }
center { }
wait { duration 1 }
rotate { duration 5 rate 10 axis [0 0 1] }
wait { duration 5 }
使用 observer:rotate() 方法的 CELX,精確角度
earth = celestia:find("Sol/Earth")
celestia:select(earth)
obs = celestia:getobserver()
obs:follow(earth)
obs:center(earth, 1.0)
wait(1.0)
duration = 5.0
rotation_angle = math.rad(duration * 10)
axis_vector = celestia:newvector(0,0,1)
rotsteps = 50 * duration
rotsteptime = 0.75*duration/rotsteps
rot = celestia:newrotation(axis_vector, rotation_angle/rotsteps)
for i = 1, rotsteps do
obs:rotate(rot)
wait(rotsteptime)
end
使用 observer:rotate() 方法的 CELX,在函式中,精確角度
function rotate_obs_angle(rottime, rotangle, rotaxis)
-- Rottime is the duration of the rotation in seconds
-- Rotangle is the angle to rotate the observer view in radians
-- Rotaxis is the axis vector (x,y,z) for the rotation
local obs = celestia:getobserver()
local rotsteps = 50 * rottime
local rotsteptime = 0.75*rottime/rotsteps
local rot = celestia:newrotation(rotaxis, rotangle/rotsteps)
for i = 1, rotsteps do
obs:rotate(rot)
wait(rotsteptime)
end
end
earth = celestia:find("Sol/Earth")
celestia:select(earth)
obs = celestia:getobserver()
obs:follow(earth)
obs:center(earth, 1.0)
wait(1.0)
duration = 5.0
rotation_angle = math.rad(duration * 10)
axis_vector = celestia:newvector(0,0,1)
rotate_obs_angle(duration, rotation_angle, axis_vector)
使用 observer:rotate() 方法的 CELX,精確時間
earth = celestia:find("Sol/Earth")
celestia:select(earth)
obs = celestia:getobserver()
obs:follow(earth)
obs:center(earth, 1.0)
wait(1.0)
duration = 5.0
rotation_angle = math.rad(duration * 10)
axis_vector = celestia:newvector(0,0,1)
rotsteps = 50 * duration
rot = celestia:newrotation(axis_vector, rotation_angle/rotsteps)
rotsteptime = duration/rotsteps
t0= celestia:getscripttime()
while celestia:getscripttime() <= t0 + duration do
obs:rotate(rot)
wait(rotsteptime)
end
使用 observer:rotate() 方法的 CELX,在函式中,精確時間
function rotate_obs_time(rottime, rotangle, rotaxis)
-- Rottime is the duration of the rotation in seconds
-- Rotangle is the angle to rotate the observer view in radians
-- Rotaxis is the axis vector (x,y,z) for the rotation
local obs = celestia:getobserver()
local rotsteps = 50 * rottime
local rotsteptime = 0.75*rottime/rotsteps
local rot = celestia:newrotation(rotaxis, rotangle/rotsteps)
local t0= celestia:getscripttime()
while celestia:getscripttime() <= t0 + duration do
obs:rotate(rot)
wait(rotsteptime)
end
end
earth = celestia:find("Sol/Earth")
celestia:select(earth)
obs = celestia:getobserver()
obs:follow(earth)
obs:center(earth, 1.0)
wait(1.0)
duration = 5.0
rotation_angle = math.rad(duration * 10)
axis_vector = celestia:newvector(0,0,1)
rotate_obs_time(duration, rotation_angle, axis_vector)