Question sun.dll -- Is there a way to make a new sun/star?

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
10,583
Reaction score
4,414
Points
203
Location
Dallas, TX
I think the answer is NO. But is there a way to make a new sun/star? So you can have 2 stars/sun.

This is for Orbiter2010?
 
You mean a binary? In principle it should be possible, although I've never tried it.
Almost certainly only one of them will act as a light emitter.

The real problem is the computation of the planet orbits. Any series expansion solution will be very expensive w.r.t. the number of terms you need (in particular if they orbit in the stars' near field), and it will only be valid for a short period of time, so you may need to patch several solutions together (making sure that the transitions of the state vectors are continuous across the patches).

You could do the planet ephemerides by numerical propagation, but that has itself plenty of problems (stability, propagation to arbitrary simulation start time, etc.)
 
We've been working on creating the look (if not the physics) of the Gargantua-Pantagruel system. We're using add-ons from Anroalh12 https://www.orbithangar.com/searchid.php?ID=6745 for the Interstellar system and olrik jhor https://www.orbithangar.com/search_quick.php?text=Gargantua&submit.x=15&submit.y=11 for the Gargantua texture. Anroalh12 has set up the system well but the only way to achieve the appearance of Gargantua is to replace the star texture (star.dds) with the Gargantua texture. Unfortunately, this makes all the primary planetary system stars in your Orbiter installation appear as Gargantua.

A solution would be to make an alternate Sun.dll (SunG.dll) to place in Modules/Celbody. The SunG.dll would call for the Gargantua star texture (renamed starG.dds) whenever Interstellar is the selected scenario environment. Finally, the Gargantua.cfg would change from this:
Code:
; === Configuration file for star by Anroalh12 ===
Name = Gargantua
Module = Sun
ErrorLimit = 1e-6
SamplingInterval = 1497        ; interpolation sampling interval [s]
                               ; (interpolation error ~1m)
Mass = 1.9889194444e+30
Size = 5.0232e7     ; mean radius

to this:
Code:
; === Configuration file for star by Anroalh12 ===
Name = Gargantua
Module = [COLOR="Red"]SunG[/COLOR]
ErrorLimit = 1e-6
SamplingInterval = 1497        ; interpolation sampling interval [s]
                               ; (interpolation error ~1m)
Mass = 1.9889194444e+30
Size = 5.0232e7     ; mean radius

This should leave any other primary planetary system star unchanged. Our problem is that neither Gattispilot nor I know how to code the SunG.dll. Any help or suggestions greatly appreciated!
 
The real problem is the computation of the planet orbits. Any series expansion solution will be very expensive w.r.t. the number of terms you need (in particular if they orbit in the stars' near field), and it will only be valid for a short period of time, so you may need to patch several solutions together (making sure that the transitions of the state vectors are continuous across the patches).

I suspect you're being overly negative here. As so often, it's a question of scope. Doing a stability analysis for planetary orbits for a binary on a timescale of a million to 100 million years is a hard task. But it didn't seem to me that this is what Orbiter is about.

Simulating planet orbits in a binary on a timescale of <10.000 years such that you can do spaceflight between the various bodies of the system on the other hand doesn't strike me as too complicated - I've done Brian Aldiss' Helliconia system (planet orbiting star in about a year, both together orbiting giant star with a period of ~1000 years on an eccentric orbit) in a straightforward multi-body gravity solver I've coded (including GR corrections), and this works just fine over these timescale - with a minute of computation, you can fill your tables for the next few thousand years if you want to pre-compute, and running at real time is going to be even easier if you so desire.
 
Well what Ben is suggesting is to recode the sun.dll and just switch mesh/texture. But simce one can do open a .dll to get the code. Not sure how to do that
 
But simce one can do open a .dll to get the code. Not sure how to do that

You basically can't - a DLL is compiled binary code and its internals are for all practical purposes not accessible to the rest of the world (aka c'losed format') - you have to ask nicely whoever has the source code (aka 'open format') used to create the DLL to let you have it - which he may or may not do - then you can change it and re-compile it to get a new DLL.
 
I knew that. But I guess Martin has the code has I needed see it in the samples folder

---------- Post added at 01:35 PM ---------- Previous post was at 07:25 AM ----------
kXKieXZ.jpg


So looking at the APIguide. I get this how to buidl a sun, asteroid, moon,...

So My code is this:
MyPlanet.cpp
Code:
#define ORBITER_MODULE
#include "MyPlanet.h"

MyPlanet::MyPlanet(OBJHANDLE hObj) : CELBODY2(hObj)
{
	// add constructor code here
}
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)
}
bool MyPlanet::bEphemeris() const
{
	return true;
	// class supports ephemeris calculation
}
int clbkEphemeris(double mjd, int req, double *ret)
{
	// return planet position and velocity for Modified Julian date mjd in ret
}
int clbkFastEphemeris(double simt, int req, double *ret)
{
	// return interpolated planet position and velocity for simulation time simt in ret
}
DLLCKBK CELBODY *InitInstance(OBJHANDLE hBody)
{
	// instance initialisation
	return new MyPlanet;
}
DLLCLBK void ExitInstance(CELBODY *body)
{
	// instance cleanup
	delete (MyPlanet*)body;
}
DLLCLBK void InitModule(HINSTANCE hModule)
{
	// module initialisation
}
DLLCLBK void ExitModule(HINSTANCE hModule)
{
	// module cleanup
}
and MyPlanet.h
Code:
#include "OrbiterAPI.h"
#include "CelbodyAPI.h"
class DLLEXPORT MyPlanet : public CELBODY2 {
public:
	MyPlanet(OBJHANDLE hObj);
	void clbkInit(FILEHANDLE cfg);
	int clbkEphemeris(double mjd, int req, double *ret);
	int clbkFastEphemeris(double simt, int req, double *ret);
};

But I get 1 errors:


Error 1 error C2509: 'bEphemeris' : member function not declared in 'MyPlanet'

4 IntelliSense: inherited member is not allowed c:\orbiter100830\Orbitersdk\samples\NEWSUN\MyPlanet.CPP 13 16 MyPlanet
5 IntelliSense: identifier "DLLCKBK" is undefined c:\orbiter100830\Orbitersdk\samples\NEWSUN\MyPlanet.CPP 26 1 MyPlanet
6 IntelliSense: expected a ';' c:\orbiter100830\Orbitersdk\samples\NEWSUN\MyPlanet.CPP 26 17 MyPlanet
C:\orbiter100830\Orbitersdk\samples\NEWSUN\MyPlanet.CPP 14 1 MyPlanet
 
Last edited:
Error 1 error C2509: 'bEphemeris' : member function not declared in 'MyPlanet'
This means exactly what it says: you haven't declared the bEphemeris function in the header file.
 
Thanks. But it is declared in CelbodyAPI.h
Even if I add CelbodyAPI.h into my project I get those errors.
not sure about this line:
Add orbiter.lib and orbitersdk.lib
as additional dependencies.
 
Thanks. But it is declared in CelbodyAPI.h
Even if I add CelbodyAPI.h into my project I get those errors.
not sure about this line:
Add orbiter.lib and orbitersdk.lib
as additional dependencies.

You need to add those libraries to your project, just like you add them to any Orbiter project.

About the declaration, the function probably is declared in the class you are deriving (CELBODY2), but if you are implementing that function, you need to declare it. :shrug:
 
So this is how I get it set up. Following the set up in the api guide.
qLmX5l4.jpg


4 IntelliSense: inherited member is not allowed c:\orbiter100830\Orbitersdk\samples\NEWSUN\MyPlanet.CPP 13 16 MyPlanet
 
So this is how I get it set up. Following the set up in the api guide.
qLmX5l4.jpg


4 IntelliSense: inherited member is not allowed c:\orbiter100830\Orbitersdk\samples\NEWSUN\MyPlanet.CPP 13 16 MyPlanet

You need to declare
Code:
void bEphemeris() const;
in your header, and need to add
Code:
MyPlanet::
to clbkEphemeris and clbkFastEphemeris in the source file.
 
Last edited:
Thanks. In the h:
Code:
#include "OrbiterAPI.h"
#include "CelbodyAPI.h"
class DLLEXPORT MyPlanet : public CELBODY2 {
public:
	MyPlanet(OBJHANDLE hObj);
	void clbkInit(FILEHANDLE cfg);
	MyPlanet::int clbkEphemeris(double mjd, int req, double *ret);
	MyPlanet::int clbkFastEphemeris(double simt, int req, double *ret);


	
	void bEphemeris() const;
};

Still errors. I guess somewhere I need to id the mesh to use?
 
:facepalm:
I'm sorry to ask, but do you know the basics of classes in c++? :uhh:
First, you must declare, in the header file, every function your class implements.
Second, in the source file, every function your class implements must have the class name as prefix, and that is separated from the function name by "::".
 
Some have questioned that too.

But I am following the example in the api guide:

2.2.1 First steps
Create a new DLL project for your planet module, e.g. in Orbitersdk\samples\MyPlanet. Set
up all the usual include and library paths for Orbiter plugins. Add orbiter.lib and orbitersdk.lib
as additional dependencies.

step 2:
We now need to the class interface for the new planet module by deriving a custom class
from CELBODY2. Create a new header file in your project, e.g. MyPlanet.h, and add the
following:
#include "OrbiterAPI.h"
#include "CelbodyAPI.h"
class DLLEXPORT MyPlanet: public CELBODY2 {
public:
MyPlanet (OBJHANDLE hObj);
void clbkInit (FILEHANDLE cfg);
int clbkEphemeris (double mjd, int req, double *ret);
int clbkFastEphemeris (double simt, int req, double *ret);
};

step 3:
To implement the methods in our MyPlanet class, create a source file in your project, e.g.
MyPlanet.cpp. Add the following lines:
#define ORBITER_MODULE
#include "MyPlanet.h"
MyPlanet::MyPlanet (OBJHANDLE hObj): CELBODY2 (hObj)
{
// add constructor code here
}
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)
}
bool MyPlanet::bEphemeris() const
{
return true;
// class supports ephemeris calculation
}
int clbkEphemeris (double mjd, int req, double *ret)
{
// return planet position and velocity for Modified Julian date mjd in ret
}
int clbkFastEphemeris (double simt, int req, double *ret)
{
// return interpolated planet position and velocity for simulation time simt in ret
}
last step:
2.2.3 The API interface
Next, we need to define the API interface that will allow Orbiter to load an instance of the
celestial body interface. This is done by implementing the InitInstance and ExitInstance
functions in MyPlanet.cpp:
DLLCKBK CELBODY *InitInstance (OBJHANDLE hBody)
{
// instance initialisation
return new MyPlanet;
}
DLLCLBK void ExitInstance (CELBODY *body)
{
// instance cleanup
delete (MyPlanet*)body;
}
ORBITER Programmer’s Guide (c) 2001-2009 Martin Schweiger 40
InitInstance and ExitInstance are called by Orbiter each time an instance of the planet is
loaded or discarded. There are also functions InitModule and ExitModule, which are called
only once per simulation run, and can be used to initialise and clean up global resources:
DLLCLBK void InitModule (HINSTANCE hModule)
{
// module initialisation
}
DLLCLBK void ExitModule (HINSTANCE hModule)
{
// module cleanup
}

---------- Post added at 07:34 AM ---------- Previous post was at 05:19 AM ----------

So updated my cpp and h:
Code:
#define ORBITER_MODULE
#include "MyPlanet.h"

MyPlanet::MyPlanet(OBJHANDLE hObj) : CELBODY2(hObj)
{
	// add constructor code here
}
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)
}
bool MyPlanet::bEphemeris() const
{
	return true;
	// class supports ephemeris calculation
}
int clbkEphemeris(double mjd, int req, double *ret)
{
	// return planet position and velocity for Modified Julian date mjd in ret
}
int clbkFastEphemeris(double simt, int req, double *ret)
{
	// return interpolated planet position and velocity for simulation time simt in ret
}
DLLCKBK CELBODY *InitInstance(OBJHANDLE hBody)
{
	// instance initialisation
	return new MyPlanet;
}
DLLCLBK void ExitInstance(CELBODY *body)
{
	// instance cleanup
	delete (MyPlanet*)body;
}
DLLCLBK void InitModule(HINSTANCE hModule)
{
	// module initialisation
}
DLLCLBK void ExitModule(HINSTANCE hModule)
{
	// module cleanup
}

Code:
#include "OrbiterAPI.h"
#include "CelbodyAPI.h"
class DLLEXPORT MyPlanet : public CELBODY2 {
public:
	MyPlanet(OBJHANDLE hObj);
	void clbkInit(FILEHANDLE cfg);
	int clbkEphemeris(double mjd, int req, double *ret);
	int clbkFastEphemeris(double simt, int req, double *ret);


	
	bool bEphemeris() const;
};

new errors:
Error 3 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int C:\orbiter100830\Orbitersdk\samples\NEWSUN\MyPlanet.CPP 25 1 MyPlanet
Error 4 error C2512: 'MyPlanet' : no appropriate default constructor available C:\orbiter100830\Orbitersdk\samples\NEWSUN\MyPlanet.CPP 28 1 MyPlanet
Error 2 error C2146: syntax error : missing ';' before identifier 'CELBODY' C:\orbiter100830\Orbitersdk\samples\NEWSUN\MyPlanet.CPP 25 1 MyPlanet




So how do you tell it which mesh,....
 
Code:
#define ORBITER_MODULE
#include "MyPlanet.h"

MyPlanet::MyPlanet(OBJHANDLE hObj) : CELBODY2(hObj)
{
	// add constructor code here
}
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)
}
bool MyPlanet::bEphemeris() const
{
	return true;
	// class supports ephemeris calculation
}
int [COLOR="red"]MyPlanet::[/COLOR]clbkEphemeris(double mjd, int req, double *ret)
{
	// return planet position and velocity for Modified Julian date mjd in ret
}
int [COLOR="Red"]MyPlanet::[/COLOR]clbkFastEphemeris(double simt, int req, double *ret)
{
	// return interpolated planet position and velocity for simulation time simt in ret
	[COLOR="red"]return 0;// or whatever should it be[/COLOR]
}
DLLCKBK CELBODY *InitInstance(OBJHANDLE hBody)
{
	// instance initialisation
	return new MyPlanet;
}
DLLCLBK void ExitInstance(CELBODY *body)
{
	// instance cleanup
	delete (MyPlanet*)body;
}
DLLCLBK void InitModule(HINSTANCE hModule)
{
	// module initialisation
}
DLLCLBK void ExitModule(HINSTANCE hModule)
{
	// module cleanup
}
 
Thanks. So my cpp:
Code:
#define ORBITER_MODULE
#include "MyPlanet.h"

MyPlanet::MyPlanet(OBJHANDLE hObj) : CELBODY2(hObj)
{
	// add constructor code here
}
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)
}
bool MyPlanet::bEphemeris() const
{
	return true;
	// class supports ephemeris calculation
}
int MyPlanet::clbkEphemeris(double mjd, int req, double *ret)
{
	// return planet position and velocity for Modified Julian date mjd in ret
}
int MyPlanet::clbkFastEphemeris(double simt, int req, double *ret)
{
	// return interpolated planet position and velocity for simulation time simt in ret
	return 0;// or whatever should it be
}
DLLCKBK CELBODY *InitInstance(OBJHANDLE hBody)
{
	// instance initialisation
	return new MyPlanet;
}
DLLCLBK void ExitInstance(CELBODY *body)
{
	// instance cleanup
	delete (MyPlanet*)body;
}
DLLCLBK void InitModule(HINSTANCE hModule)
{
	// module initialisation
}
DLLCLBK void ExitModule(HINSTANCE hModule)
{
	// module cleanup
}

now I get:
5 IntelliSense: identifier "DLLCKBK" is undefined c:\orbiter100830\Orbitersdk\samples\NEWSUN\MyPlanet.CPP 27 1 MyPlanet
7 IntelliSense: expected a declaration c:\orbiter100830\Orbitersdk\samples\NEWSUN\MyPlanet.CPP 44 1 MyPlanet
6 IntelliSense: expected a ';' c:\orbiter100830\Orbitersdk\samples\NEWSUN\MyPlanet.CPP 27 17 MyPlanet
 
Try DLLCLBK instead of DLLCKBK.
 
Code:
DLLCLBK CELBODY *InitInstance(OBJHANDLE hBody)
{
	// instance initialisation
	return new MyPlanet;
}

errors:
3 IntelliSense: no default constructor exists for class "MyPlanet" c:\orbiter100830\Orbitersdk\samples\NEWSUN\MyPlanet.CPP 32 13 MyPlanet
Error 2 error C2512: 'MyPlanet' : no appropriate default constructor available C:\orbiter100830\Orbitersdk\samples\NEWSUN\MyPlanet.CPP 30 1 MyPlanet


not sure what goes here:

Code:
MyPlanet::MyPlanet(OBJHANDLE hObj) : CELBODY2(hObj)
{
	

// add constructor code here
}
 
Back
Top