Page 1 of 1

'Basic' Solar system simulation.

Posted: 21.03.2006, 13:13
by Despina
Apologies if this is the wrong section to post in, but I thought people working on Celestia development would be the most qualified to answer my question :)

I'm working on a semi-educational game written in C++, which includes a solar system (Sun, planets, moons, and a few minor objects like comets) representation that can be sped up and slowed down. Whilst it doesn't need to be too accurate, I would like to at least put some effort into making this as accurate as possible rather than 'faking it'.

I suppose my ideal situation would be to find a function that returns position/orientation of a body, given some setup data and a time. I realise that this is a very complicated issue, but I'm actually having trouble finding any offline example code to get started with. There's lots of online examples though.

If anyone could point me at either the relevant place in Celestia, or another place that would help get me started - or even some tips on how to approach this, I'd greatly appreciate it - I've been looking on and off for a few days now but haven't really found anything simple enough to gets started with. If I do get up and running, I think I'll have to write a good tutorial up!

Posted: 26.03.2006, 05:18
by scratt
Hi there Despina,

I can sympathise with where you are at right now. Once you delve into Celestia you will find it's very logical, for such a complicated program. Don't be afraid to search through the code, or experiement either..

I would recommend that you look at this thread about how the coordinate systems work in Celestia first...

http://www.celestiaproject.net/forum/viewtopic.php?t=8662

Then you want to start looking in Body.cpp and the Body Class for routines like getLocalToHeliocentric and so on...

Most 'Bodies' return their position and other data based on simply a time variable, which is the simulation time.

Let me know if that gets you started and if you need any more help..

Posted: 26.03.2006, 11:04
by selden
The problem of determining the location and velocity of a body travelling along an ellipse is not an easy one to solve from first principles. It's often called Kepler's Equation.

Fortunately, however, it's an "already solved problem" :)

Some codes are available at http://www.cococubed.com/code_pages/codes.shtml
e.g. Fortran sorce code is at
http://www.cococubed.com/codes/ephem/fxt_routines.f

A site with an interactive page that produces some related results is at http://janus.astro.umd.edu/

Posted: 27.03.2006, 22:37
by Despina
Thanks both for the replies, just reading through it all more is a lot of help - I've started to realise how little I know about astronomical terminology!

I've actually gotten something up and running with libnova which is very good, but now that I know what I'm looking for, I think the celestia body code is going to be easier to use. So, once I've tidied things up a bit more I'm going to start looking at using that.

Now I'm getting somewhere, it's really fun! I might spin this off into a separate project of my own now. The main thing I've found helpful (as a teaching tool) is averaging out the radii of the bodies, and scaling down their oribits so everything fits on screen. Obviously, not a feature you'd want in Celestia ;) but it's a great way to illustrate some facts about the solar system. It ends up similar to those java solar system apps you get embedded in web pages, but much nicer looking!

-thanks again, hopefully I'll be able to get much further with it over the coming months and can post a link!

Posted: 27.03.2006, 22:55
by selden
Making a scaled down system in Celestia isn't so strange, and already has been done. Unfortunately, the Web site is unreachable where the Orrery Addon used to be. You might try sending a Private Message to its author, Andrea. He might be able to help. I've seen him post to the Forum recently.

Posted: 27.03.2006, 23:26
by Despina
selden wrote:Making a scaled down system in Celestia isn't so strange, and already has been done.


Ahh, I though it would be against the ethos of celestia which seems to strive for accuracy, but I suppose it makes perfect sense as an addon.

Found the orrery addon at the celestia motherlode:

http://www.celestiamotherlode.net/catal ... tor_id=120


-thanks!

Posted: 28.03.2006, 03:19
by scratt
Cool! I did not know about that addon... That's going to be handy for me..

Thanks.

selecting a body

Posted: 13.04.2006, 23:36
by tec
Hi Despina,
I wrote some code in at the top of pickPlanet() that print out many of the body attributes that the user picks with their left mouse button. You can do the same if you add this code to the top of your pickPlanet in universe.cpp. Make sure your debuggin flag is displaying all levels of prints so the DPRINTF will work.

Tim Curry


if (pickInfo.closestBody != NULL)
{
// Retain that body
Body* closestBody = pickInfo.closestBody;
DPRINTF(1, " pick::star model = %d, when=%lf\n", star->getModel(), when );
DPRINTF(1, " pick::model %d\n", closestBody->getModel() );
DPRINTF(1, " pick::radius %d\n", closestBody->getRadius() );
DPRINTF(1, " pick::bounding radius %d\n", closestBody->getBoundingRadius() );
DPRINTF(1, " pick::mass %d\n", closestBody->getMass() );

DPRINTF(1, " pick::name %s\n", closestBody->getName().c_str() );
DPRINTF(1, " pick::HelPos %f %f %f Kmeters\n",
closestBody->getHeliocentricPosition(when) );
DPRINTF(1, " pick::Direction %f %f %f \n", direction.x, direction.y, direction.z );

if( closestBody->getOrbit() != NULL )
{
Point3d pos = closestBody->getOrbit()->positionAtTime( when );
DPRINTF(1, " pick::orbit relative to earth %f %f %f km\n", pos.x, pos.y, pos.z );
}
Point3d pos = closestBody->getHeliocentricPosition(when);
Vec3f vpos;
vpos.x = (float)pos.x;
vpos.y = (float)pos.y;
vpos.z = (float)pos.z;
DPRINTF(1, " pick::HelPos from Cartesian to Planetocentric %f %f %f\n",
closestBody->cartesianToPlanetocentric( vpos ) );

DPRINTF(1, " pick::HelPos in Planetocentric %f %f %f light years\n",
closestBody->getEclipticalToEquatorial(when) );
//DPRINTF(1, " pick::Location Name %s\n", closestBody->findLocation("ISS")->getName().c_str() );
DPRINTF(1, " pick::Orientx %f %f %f %f\n",
closestBody->getOrientation().w,
closestBody->getOrientation().x,
closestBody->getOrientation().y,
closestBody->getOrientation().z);
DPRINTF(1, " pick::Star Pos %f %f %f\n",
starPos.x,starPos.y,starPos.z);
DPRINTF(1, " pick::Origin Pos %f %f %f\n",
origin.x,origin.y,origin.z);