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

From Wikibooks, open books for an open world
Jump to navigation Jump to search

goto[edit | edit source]

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.


  • Find and select the target object with name <string> to go to and store in "objectname".
objectname = celestia:find( <string> )
celestia:select(objectname)
  • Get observer instance of the active view instance and set the coordinate system of the frame of reference to <upframestring>.
obs = celestia:getobserver()
frame = celestia:newframe( <upframestring>, objectname)
obs:setframe(frame)
  • Determine radius of "objectname" and store in "radius".
radius = objectname:radius()
  • Determine <distance> as: <radiusdistance> * "radius" of "objectname".
distance = <radiusdistance> * radius
  • Define a vector object, to determine which axis points up.
upaxis = celestia:newvector( <upvector> )
  • Goto determined <distance> of "objectname" in <duration> seconds with <upvector> pointing up.
    • <distance> is the distance from the center of target where to stop in km.
      • If no <distance> is given, the default distance = 20000 km.
      • If <distance> is smaller than the radius of the object, the goto will end within the object !!!
      • To obtain the radius of an object in km, you can use the object:radius() method.
    • <duration> is the number of seconds the goto should take.
      • If no <duration> is given, the default time = 5.0 seconds !!!
      • If no <upvector> = upaxis is given, the default is (0,1,0) --> Y-axis.
obs:gotodistance(objectname, distance, <duration>, upaxis )
  • Wait <duration> seconds.
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:

    • parameters.duration: duration (number)
    • parameters.from: source position
    • parameters.to: target position
    • parameters.initialOrientation: source orientation
    • parameters.finalOrientation: target orientation
    • parameters.startInterpolation:
    • parameters.endInterpolation:
    • parameters.accelTime:


  • Find and select the target object with name <string> to go to and store in "objectname".
objectname = celestia:find( <string> )
celestia:select(objectname)
  • Get observer instance of the active view instance and set the coordinate system of the frame of reference to <upframestring>.
obs = celestia:getobserver()
frame = celestia:newframe( <upframestring>, objectname)
obs:setframe(frame)
  • Determine radius of “objectname” and store in “radius”.
radius = objectname:radius()
  • Determine distance in km to goto as: <radiusdistance> * "radius" and store in "distance".
distance = <radiusdistance> * radius
  • Convert the determined "distance" to "objectname" into positions as follows:
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
  • The target observer orientation must point from the target position “topos” towards "objectname" with <upvector> as up vector:
upvec = celestia:newvector( <upvector> )
torot = topos:orientationto(objectpos, upvec)
  • Define and initialize the parameter table as follows:
    • Determine the number of seconds the goto should take.
    • Obtain the current position of the observer.
    • New position object = topos (result of 2 steps back).
    • Obtain the current orientation of the observer.
    • New observer orientation = torot (result of previous step).
    • Start adjusting the observer orientation after 20 percent of the time to goto.
    • End adjusting the observer orientation after 80 percent of the time to goto.
    • Spend 10% of the time for accelerating and decelerating
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
  • Goto target position with target orientation in <duration> seconds.
obs:goto(parameters)
  • Wait <duration> seconds.
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