Celestia/Celx Scripting/CELX Lua Methods/CEL command rotate
rotate
editrotate { duration <duration> rate <rate> axis <axisvector> }
Rotates the camera using the currently defined Coordinate System during <duration> seconds. You must first use the select command to select an object, and optionally use the setframe command to set Coordinate System, if it is not currently defined.
The rotate command must be followed by a wait command with a <duration> equal to or greater than that of the rotate command.
Arguments:
- duration <duration>
- The length of time, in seconds, to execute the rotate command. Default is 1.0 second.
- rate <rate>
- Speed at which to rotate the camera. Default is 0.0.
Positive and negative values are used to indicate the direction of rotation. - axis <axisvector>
- Defines which axis [ <x> <y> <z> ] to rotate around. No default.
Set the <x> , <y> or <z> value to 1 for yes, 0 for no. You may also specify multiple axes.
CELX equivalent-1:
Based on the observer:rotate() method.
This equivalent rotates the observer during about <duration> seconds over exactly <duration> * <rate> degrees.
- Find and select an object with name <string> to select and store in "objectname".
objectname = celestia:find( <string> ) celestia:select(objectname)
- Initialize "duration" of the rotation in seconds.
duration = <duration>
- Calculate "rotationangle" as the product of "duration" * <rate> in units of degrees. <rate> is the rotation velocity in degrees per second. The "rotationangle" must be converted to radians by multiplying with math.pi (= 3.14159265) and divide by 180. The Lua math.rad(rotationangle) function can also be used for this.
rotationangle = math.rad(duration * <rate> )
- Create the axis vector [ <x> <y> <z> ] for the rotation and store in "axis_vector".
axis_vector = celestia:newvector( <x> , <y> , <z> )
- Get observer instance of the active view and store in "obs".
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
Summarized:
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
Summarized as a function:
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 equivalent-2:
Based on the observer:rotate() method.
This equivalent rotates the observer during exactly <duration> seconds over about <duration> * <rate> degrees.
- Find and select an object with name <string> to select and store in "objectname".
objectname = celestia:find( <string> ) celestia:select(objectname)
- Initialize "duration" of the rotation in seconds.
duration = <duration>
- Calculate "rotationangle" as the product of "duration" * <rate> in units of degrees. <rate> is the rotation velocity in degrees per second. The "rotationangle" must be converted to radians by multiplying with math.pi (= 3.14159265) and divide by 180. The Lua math.rad(rotationangle) function can also be used for this.
rotationangle = math.rad(duration * <rate> )
- Create the axis vector [ <x> <y> <z> ] for the rotation and store in "axis_vector".
axis_vector = celestia:newvector( <x> , <y> , <z> )
- Get observer instance of the active view and store in "obs".
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
Summarized:
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
Summarized as a function:
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)
Example:
The following example selects, follows and centers Earth (so the coordinate system of the frame of reference is set to ecliptic), then rotates the camera to the right (positive rate value) along the Z axis of the currently selected object for 5 seconds.
CEL:
select { object "Sol/Earth" } follow { } center { } wait { duration 1 } rotate { duration 5 rate 10 axis [0 0 1] } wait { duration 5 }
CELX with the observer:rotate() method, exact angle:
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
CELX with the observer:rotate() method in a function, exact angle:
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)
CELX with the observer:rotate() method, exact time:
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
CELX with the observer:rotate() method in a function, exact time:
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)