Celestia/Celx Scripting/CELX Lua Methods/CEL command rotate

< Celestia < Celx Scripting < CELX Lua Methods

rotate

rotate { 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.

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:

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.

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:

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)


Back to CEL command index

This article is issued from Wikibooks. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.