Planets Planet Module Source Code!!!

Apokliptico

New member
Joined
Feb 11, 2009
Messages
31
Reaction score
0
Points
0
Location
Behind The firewall
Hi everyone!!! Well, i've finnaly finished my mars.dll module, that features a complex human friendly atmosphere. I couldn't have done it without the help from many users in this forum, so I decided to post the source code, so if anyone wants to create a new planet, or modify an existing one, it won't be such a tedious work.

Code:
#define ORBITER_MODULE
#include "OrbiterAPI.h"
#include "CelbodyAPI.h"
#pragma comment(lib, "Orbitersdk.lib")
#pragma comment(lib, "orbiter.lib")

class MyPlanet: public CELBODY {
public:
MyPlanet();
void clbkInit (FILEHANDLE cfg);
virtual bool clbkAtmParam (double alt, ATMPARAM *prm);
};

MyPlanet::MyPlanet():CELBODY()
{
// add constructor code here
}
bool MyPlanet::clbkAtmParam (double alt, ATMPARAM *prm)
{
    if(alt < 340000.0)
    {
        if(alt < 40000.0) prm->T = 292 - (70 / 40000.0 * alt);
        else if(alt < 80000.0) prm->T = 222 + (20 / 40000.0 * (alt - 40000));
        else if(alt < 120000.0) prm->T = 242 - (50 / 40000.0 * (alt - 80000));
        else if(alt < 200000.0) prm->T = 192 - (20 / 80000.0 * (alt - 120000));
        else if(alt < 300000.0) prm->T = 172 - (140 / 100000.0 * (alt - 200000));
        else prm->T = 32 - (31 / 40000.0 * (alt - 300000));
        prm->p = 85390 * exp((-3.7279 * 28.9644 * alt) / (8314.32 * prm->T));
        prm->rho = (1.293 / 85390) * prm->p;
        return true;
    }
    else return false;

}

void MyPlanet::clbkInit (FILEHANDLE cfg)
{
// read parameters from config file (e.g. tolerance limits, etc)
// perform any required initialisation (e.g. read perturbation terms from data files)
}

DLLCLBK void InitModule (HINSTANCE hModule)
{
// module initialisation
}

DLLCLBK void ExitModule (HINSTANCE hModule)
{
// module cleanup
}

DLLCLBK CELBODY *InitInstance (OBJHANDLE hBody)
{
// instance initialisation
return new MyPlanet;
}

DLLCLBK void ExitInstance (CELBODY *body)
{
// instance cleanup
delete (MyPlanet*)body;
}

Notice that I haven't made the complex ephemeris calculations, so I especified them in the .cfg file.

Thanks to everyone!
APOKLIPTICO
 

kwan3217

Addon Developer
Addon Developer
Donator
Joined
Apr 29, 2008
Messages
115
Reaction score
0
Points
16
Location
Geosynchronous Orbit
Cool! I've been interested in doing this for several other planets, and couldn't figure out how to do it without messing up the ephemeris. Can you please post your config file(s) that you changed that goes with this?
 

tblaxland

O-F Administrator
Administrator
Addon Developer
Webmaster
Joined
Jan 1, 2008
Messages
7,320
Reaction score
25
Points
113
Location
Sydney, Australia
Cool! I've been interested in doing this for several other planets, and couldn't figure out how to do it without messing up the ephemeris. Can you please post your config file(s) that you changed that goes with this?
Putting the elements in the config file will result in inaccurate ephemeris (but perhaps not by enough for you to care?). See my post here for more info:
http://www.orbiter-forum.com/showthread.php?t=6863#17
 

Apokliptico

New member
Joined
Feb 11, 2009
Messages
31
Reaction score
0
Points
0
Location
Behind The firewall
Sure! but my ephemeris are not that accurate, I've extracted them from the NASA's page...

So, here it is:
Code:
; === Configuration file for planet Mars ===
Name = Mars
Module = Mars
EllipticOrbit = TRUE
HasElements = TRUE

; === Planetary Mean Orbits ===
Epoch =  2000
SemiMajorAxis =  227936637228.13035621
Eccentricity =     0.09341233
Inclination =  1.85061
LongAscNode =      49.57854
LongPerihelion =  336.04084
MeanLongitude =  355.45332

; === Physical Parameters ===
Mass = 6.418542e+23
Size = 3.38992e6                   ; mean radius
JCoeff = 0.001964                  ; J2 coefficient for gravitational potential
AlbedoRGB = 1.0 0.7 0.3

; === Rotation Elements ===
SidRotPeriod = 88642.6632          ; 24.622962 hours
SidRotOffset = -0.757              ; by Chode - determined from the sun rise and
                                   ; set times for Spirit and Opportunity
Obliquity = 0.4663                 ; obliquity of ecliptic (26.72°)
LAN = 4.5865                       ; longitude of solar transit (262.78°)

; === Atmospheric Parameters ===
AtmPressure0 = 85390          ; pressure at zero altitude [Pa]
AtmDensity0 = 1.293             ; density at zero altitude [kg/m^3]
AtmGasConstant = 256.91        ; specific gas constant [J/(K kg)]
AtmGamma = 1.4              ; specific heat ratio c_p/c_v
AtmAltLimit = 340e3            ; cutoff altitude
AtmColor0 = 0.51 0.40 0.28
AtmHazeColor = 0.35 0.35 0.4
AtmHazeDensity = 1.5

; === Cloud parameters ===
CloudAlt = 7e3                 ; altitude of cloud layer
CloudRotPeriod = 1e6
CloudShadowDepth = 0.3
CloudMicrotextureAlt = 35e3 250e3

; === Visualisation Parameters ===
MaxPatchResolution = 9        ; surface texture resolution limit (1-10)
MinCloudResolution = 1         ; cloud layer from this resolution
MaxCloudResolution = 8         ; highest cloud resolution level
SpecularRipple = TRUE          ; enable specular water microtexture
Oh! And i've also installed Green Mars, but it installs its own .cfg file (pointless becouse it doesn't include a mars.dll which makes the atm pressure changes in the .cfg file ignored.) But if the creator of Green Mars sees this, be free to include a mars.dll in your package!

APOKLIPTICO

PD: I don't know if the orbital parameters are OK, so be free of correcting them!

PD2: If someone is brave enough to mess with the VSOP87 module, please post your code...
 

tblaxland

O-F Administrator
Administrator
Addon Developer
Webmaster
Joined
Jan 1, 2008
Messages
7,320
Reaction score
25
Points
113
Location
Sydney, Australia
PD2: If someone is brave enough to mess with the VSOP87 module, please post your code...
You made me curious so I just had a look at the exports of VSOP87.dll and Mars.dll. VSOP87.dll exports a class called VSOPOBJ which, judging by the name of its member functions, is derived from the CELBODY class. It looks like the planet modules, eg Mars.dll, derives a class from VSOPOBJ and exports it so Orbiter can communicate with it via the CELBODY member functions. How VSOPOBJ is initialised so that it knows to return the correct values, for Mars instead of Saturn say, is unclear but may possibly be revealed through disassembly, which I won't attempt right now.
 

Schimz

New member
Joined
Apr 9, 2008
Messages
99
Reaction score
0
Points
0
Wow, yes, this can be for my Green Mars !
Does it solve the haze bug ?
:cheers:
 

Apokliptico

New member
Joined
Feb 11, 2009
Messages
31
Reaction score
0
Points
0
Location
Behind The firewall
Haze Bug?? I don't know XD, i copied many of the values from earth, and some from the mars2060 cfg file. The sky looks just beautiful...
 

Schimz

New member
Joined
Apr 9, 2008
Messages
99
Reaction score
0
Points
0
Haze Bug?? I don't know XD, i copied many of the values from earth, and some from the mars2060 cfg file. The sky looks just beautiful...
When I've upped density, the haze disappeared (no sky, just the stars).
 

cjp

Addon Developer
Addon Developer
Donator
Joined
Feb 7, 2008
Messages
856
Reaction score
0
Points
0
Location
West coast of Eurasia
Would it be possible to dynamically load the old Mars module from the new one, using some windows system calls? Then you could have something like:

Code:
class MyNewMars : public CELBODY
{
    CELBODY *oldMars;

    int clbkEphemeris(double mjd, int req, double *ret)
        {return oldMars->clbkEphemeris(mjd, req, ret);}
}
Of course, the oldMars pointer needs to be initialized. I suggest:

  • during module initialization, open the old Mars DLL, and store a handle to it in a global variable
  • in the MyNewMars constructor, get the InitInstance function from the old Mars DLL, and call it to get the oldMars pointer.
 
Last edited:

cjp

Addon Developer
Addon Developer
Donator
Joined
Feb 7, 2008
Messages
856
Reaction score
0
Points
0
Location
West coast of Eurasia
But, why do that??
Then, your ephemeris are exactly the same as for the old Mars module. Which is a lot more accurate than simply using orbital elements in the .cfg file.

This way, you can use the more accurate ephemeris model from Orbiter together with your own atmospheric model.
 

T.Neo

SA 2010 Soccermaniac
Addon Developer
Joined
Jun 22, 2008
Messages
6,368
Reaction score
0
Points
0
Look, I'm not saying this is stupid or anything, and I want to thank Apokliptico for this source code, but why not just delete the module and define everything in the .cfg? That's what I would have done.
 
Last edited:

cjp

Addon Developer
Addon Developer
Donator
Joined
Feb 7, 2008
Messages
856
Reaction score
0
Points
0
Location
West coast of Eurasia
Look, I'm not saying this is stupid or anything, and I want to thank Apocalipto for this source code, but why not just delete the module and define everything in the .cfg? That's what I would have done.

From API_Guide.pdf:
Planet modules have one additional function: They can be used to define some atmospheric parameters, such as temperature, pressure and density as a function of altitude. Additional functions may be added to the planet module interface in the future.
Whenever you need something that's more complicated than possible through the .cfg file, you need to make a DLL file.
 

T.Neo

SA 2010 Soccermaniac
Addon Developer
Joined
Jun 22, 2008
Messages
6,368
Reaction score
0
Points
0
Whenever you need something that's more complicated than possible through the .cfg file, you need to make a DLL file.

I'm not THAT stupid. :p

I see now. The atmosphere can be implemented in a more complicated fashion in the DLL module.
 
Last edited:

Apokliptico

New member
Joined
Feb 11, 2009
Messages
31
Reaction score
0
Points
0
Location
Behind The firewall
My atmospheric model includes a temperature factor.

Also, the code'll be available for anyone who wants to do a planet module, since no one has posted an example code, well, I'm "no one".

For example, the creator of the Green Mars addon, never had the chance to include a complex atmosphere in his addon. Now, he can, and it also fixes that "haze bug" btw...

APOKLIPTICO
 

tblaxland

O-F Administrator
Administrator
Addon Developer
Webmaster
Joined
Jan 1, 2008
Messages
7,320
Reaction score
25
Points
113
Location
Sydney, Australia
Would it be possible to dynamically load the old Mars module from the new one, using some windows system calls? Then you could have something like:
Very good idea :speakcool:
 
Top