-- http://www.celestiaproject.net/forum/viewtopic.php?t=4903)

The code below was modified further by Don G., for clarification (mostly the variable names).

Toti, what is the purpose of computing a seemingly arbitrary number (6 in this case) and calling it rot_speed? What is "rot_speed"? ...

Code: Select all

` -- Complete one orbit (360 degrees):`

local rot_speed = 360 / orbitTime

The next line takes this seemingly arbitrary number, multiplies it by scriptTime and multiplies it by 5. What does "5" represent? Wouldn't we want to increase the longitude by a fixed value for each render pass?

Code: Select all

` -- This is the longitude we pass to the function. It's a function of`

-- time, like many parameter trajectories:

local longitude = rot_speed * scriptTime * 5

Earlier, orbitTime is defined so that an orbit is supposed to take 60 seconds...

Code: Select all

` -- Define an orbit to take 60 seconds:`

local orbitTime = 60

However, in 60 seconds, we orbit the Earth FIVE times, not just once.

So, I was wondering if you could clarify things a bit more?

Thank you Toti!

-Don G.

Code: Select all

`--******************************************************`

--

-- This script is a modification of Harald Schmidt's

-- "Around the Earth" script.

--

--******************************************************

--************************************************

-- UCS = Universal Coordinate System

--************************************************

-- This function puts the viewer at longitiude on myObject.

-- All is performed in UCS:

function around(myObject, longitude, distance, upvector)

-- These two equations look rather complicated, but they are only a 2-D

-- polar-cartesian conversion, that is, given a (radius, angle) = (r,

-- pos), convert it to (x, y) values. They are a "classic":

local x = distance * math.cos(math.rad(longitude))

local z = distance * math.sin(math.rad(longitude))

-- Keep the up pointing coordinate on the UCS "horizontal" plane:

local y = 0

-- Create a vector with the above coordinates. We create a vector because

-- they don't need to be that precise (they are pretty small coordinates,

-- with length = distance at most):

local offsetVector = celestia:newvector(x,y,z)

-- Obtain a vector that is the center of myObject in UCS. This is a

-- 'position' vector, so it is very precise. Why is this? Because UCS

-- places its center at about 200 AU from Sol. If we do not assure enough

-- precision, our centerBodyPosition would not be placed on myObject but

-- a few thousand km. from it.

local centerBodyPositionVector = myObject:getposition ()

-- Viewer's position: Let's go to the center of myObject and then go to

-- ourVector (that is what a vector addition does, really). This adds a

-- 'common vector' (offsetVector) to a 'position vector'

-- (centerBodyPositionVector), so the maximun precision is retained. We

-- want that, because we want to place the viewer exactly where it's

-- needed (and not a few thousand km. away).

local viewerPositionVector = centerBodyPositionVector + offsetVector

-- let's place the observer there:

local obs = celestia:getobserver()

obs:setposition (viewerPositionVector)

-- Look at earth centered with upvector as "ceiling". This is complex...

-- Close your hand. Extend your thumb. Then extend the first finger, and

-- point it to this -> x. (Keep the angle between both fingers fixed.)

-- This behaves like the viewer: your thumb is the 'up' axis. Your first

-- finger is the viewer's 'look_at' axis. When you point it to the 'x',

-- you are transforming the 'up' vector (your thumb moves with your hand),

-- but it doesn't matter, because you have already defined where it is in

-- relation with the rest of your hand. I believe that Celestia does this

-- same thing that you have done with your hand: First creates an

-- "abstract" viewer, then defines where is 'up' and last, moves/rotates

-- the viewer to point its "camera" to the selected body. The 'up' vector

-- signals the viewer's "ceiling" BEFORE Celestia rotates it in order to

-- look at some place.

obs:lookat (centerBodyPositionVector, upvector)

-- print the viewer's position (in UCS):

celestia:flash("Viewer pos.: " .. viewerPositionVector.x ..

" " .. viewerPositionVector.y ..

" " .. viewerPositionVector.z , 1)

-- return control to Celestia for a moment (to refresh screen, etc.):

wait(0.0)

end

--************************************************

-- Now call the function

--************************************************

-- Define which direction we should call 'up'. Since this is only a rough

-- direction, we can use a 'common vector'. We don't need precision here:

local upvector = celestia:newvector (0,1,0)

-- select body:

local myObject = celestia:find("Sol/Earth")

-- Define an orbit to take 60 seconds:

local orbitTime = 60

-- Complete one orbit (360 degrees):

local rot_speed = 360 / orbitTime

-- Fix the viewer's distance to the body's center:

local distance = 0.005

-- loop for the time specified in orbitTime:

local scriptTime = 0

while scriptTime < orbitTime do

scriptTime = celestia:getscripttime()

-- This is the longitude we pass to the function. It's a function of

-- time, like many parameter trajectories:

local longitude = rot_speed * scriptTime * 5

-- Call the function:

around(myObject, longitude, distance, upvector)

end