Dear all,

I am looking into having celestia display a satellite whose orbit and attitude are provided in real time over a network socket.

The easiest way would be to read the socket from a scriptedOrbit lua script. But this implies that the simulation time updating would be dependent on how frequently the orbit function is called. Also this implies that in a call to orbit the time argument is ignored and the state returned by orbit always corresponds to a later time with respect to the one returned by the previous call, whereas one could request orbit at time t and t+dt in any order to compute the velocity.

To avoid these problems, it would be better to have the socket be read from a lua hook that is run in the main Celestia loop.


The lua hook would reads from a TCP socket in non blocking mode the following information :
- current simulation time
- current simulation rate
- number of spacecraft
- spacecraft 1 ID
- epoch for spacecraft 1 state
- position vector spacecraft 1
- velocity vector spacecraft 1
- attitude quaternion spacecraft 1
- angular velocity vector spacecraft 1
....
....
- spacecraft n ID
- epoch for spacecraft n state
- position vector spacecraft n
- velocity vector spacecraft n
- attitude quaternion spacecraft n
- angular velocity vector spacecraft n

Each time such a block of data is received:
- the actual simulation time would be compared to the one received on the socket and if they differ by more than some epsilon, the simulation time would be reset.
- the simulation rate is set
- the data (epoch and states) for each spacecraft is stored in some global variables.


The scripted orbit called with argument t would then return (position vector spacecraft at epoch)+(velocity vector spacecraft at epoch)*(t-epoch)
(we could also imagine a higher order scheme where acceleration or other extrapolation/interpolation parameters are passed via the socket)
Similarly the scripted attitude would return the quaternion at epoch rotated after dt=(t-epoch) at provided angular velocity.

This scheme requires that the lua hook and the scriptedOrbit, scriptedOrientation share some variables.

Unfortunately I have not found a nice way to do this yet without changing the Celestia source code:
http://www.shatters.net/forum/viewtopic.php?f=9&t=16873

Therefore I am thinking of adding a new celx command to store variables in a dictionary and retrieve them. This dictionary implemented in C++ in celestia would then be used to share variables across all scripts.

What do you think?
Is this the right approach?
Do you have a better idea on how to do this?

Kind regards,