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

< Celestia < Celx Scripting < CELX Lua Methods

goto

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

Moves the camera to the currently selected object, taking <duration> seconds, stopping <radiusdistance> from the object (in units of object’s radius + 1), using the <upframestring> Coordinate System, and defining the <upvector> axis that points up.

Arguments:

time <duration>
The number of seconds to take going to the object. Default is 1.0 second.
distance <radiusdistance>
Describes how far away from the object you want to be positioned, in units of the object's radius, plus 1. Default is 5.0.
Special <radiusdistance> values are:
  • 0 (zero) is the center of the object. In version 1.3.1, using this value causes the program to incorrectly recognize further positioning values, so do not use zero.
  • 1 is the surface of the object. Traveling to the exact surface level of an object may cause some graphics cards to display random polygons on the display screen, so it is best to use a value slightly above the surface.
upframe <upframestring>
Sets the specified Coordinate System. Default is "observer". The <upframestring> must have one of the following values:
  • chase
  • ecliptical
  • equatorial
  • geographic
  • lock
  • observer
  • universal
up <upvector>
Defines which axis points up, X [1 0 0], Y [0 1 0] or Z [0 0 1]. Default is [0 1 0].


CELX equivalent-1:

Based on the observer:gotodistance() method.


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> )

Summarized:

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 equivalent-2:

Based on the observer:goto(table) method.

Using this method, many different types of gotos can be performed. The strength of this method is that the observer orientation can be programmed, so the axis that points up after the goto can also be determined.

This method uses positions to goto, instead of a distance from the object, so that needs some additional calculations. The parameters for the goto must be given in the table:


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)

Summarized:

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)

Example:
The following example selects Mars and takes five seconds to travel 10 times the radius of mars above the surface and Y-axis pointing up.

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 with observer:gotodistance() method:

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 with observer:goto(table) method:

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)


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.