Programming Question getting started with C++

Go to the example projects in the orbiter SDK and try to get them to compile and appear in the orbiter launchpad. Then modify them until they turn into your own addon and start coding from there.

I created an [ame="http://www.orbithangar.com/searchid.php?ID=4159"]MFD project wizard[/ame] that was handy for creating new addons for Orbiter 2006 but I haven't had time (or interest) to update it to work on Orbiter '10.
 
Watch this video:

Edit: Nevermind. Slow by about 18 hours.
 
now i have internet back, i can show you guys what i see:

heres the CPP i wrote for my LBS:
Code:
#define STRICT
#define ORBITER_MODULE

#include "orbitersdk.h"


class LBS: public VESSEL2 {
public:
LBS (OBJHANDLE hVessel, int flightmodel)
: VESSEL2 (hVessel, flightmodel) {}
void clbkSetClassCaps (FILEHANDLE cfg);

void LBS::clbkSetClassCaps (FILEHANDLE cfg)
{
SetSize (10);
SetEmptyMass (5000);
SetCW (0.09, 1.0, 1.8, 1.8);
SetWingAspect (0);
SetWingEffectiveness (0);
SetCrossSections (_V(81.55,81.56,26.20));
SetRotDrag (_V(0.6,0.6,0.35));
SetPMI (_V(15.43,15.43,4.86));
SetTrimScale (0.05);
SetCameraOffset (_V(0,0.0,0.0))
SetTouchdownPoints (_V(0,-2.9,-5), _V(0,-2.9,0), _V(0,-2.9,5));

//Animation
enum anim_status { CLOSED, OPEN, CLOSING, OPENING }
void LBS::DefineAnimations()
{
	static UINT ret1 = {Retainer1}
	static UNIT ret2 = {Retainer2}
	static UNIT ret3 = {Retainer3}
	static UNIT nose = {NoseCone}

	static MGROUP_ROTATE nose {
		0,
		nose, 1
		_V(0,2.9,6.7),
		_V(1,0,0),
		(float)(-120*RAD)
	}
	static MGROUP_ROTATE ret1 {
		0,
		ret1, 1
		_V(2.8,0,4.08)
		_V(0,1,0),
		(float)(80*RAD)
	}
	static MGROUP_ROTATE ret2 {
		0,
		ret2, 1
		_V(0,-2.8,4.23)
		_V(1,0,0),
		(float)(80*RAD)
	}
	static MGROUP_ROTATE ret3 {
		0,
		ret3, 1
		_V(-2.8,0,4.08)
		_V(0,1,0),
		(float)(-80*RAD)
	}

	anim = CreateAnimation (0)
	AddAnimationComponent (anim, 0, 1, &nose);
	AddAnimationComponent (anim, 0.1, 0.9, &ret1);
	AddAnimationComponent (anim, 0.1, 0.9, &ret2);
	AddAnimationComponent (anim, 0.1, 0.9, &ret3);

void LBS::Timestep (double simt)
{
	if (anim_status == CLOSING || ganim_status == OPENING) {
		double da = oapiGetSimStep() * anim_speed;
		if (anim_status == CLOSING) {
			if (anim_proc > 0.0)
				anim_proc = max (0.0, anim_proc-da);
			else
				anim_status = CLOSED;
		} else { // door opening
			if (anim_proc < 1.0)
				anim_proc = min (1.0, anim_proc+da);
			else
				anim_status = OPEN;
		}
		SetAnimation (anim, anim_proc);
	}
}



const double FUELMASS = 29000;
const double ISP = 7e3;
const double MAXMAINTH = 1001000;
const double MAXRCSTH = 1e5;

PROPELLANT_HANDLE tank;
tank = CreatePropellantResource (FUELMASS);

THRUSTER_HANDLE th_main, th_rcs[14], th_group[4];

th_main = CreateThruster (_V(0,0,-7.6), _V(0,0,1), MAXMAINTH, tank,ISP);
CreateThrusterGroup (&th_main, 1, THGROUP_MAIN);
AddExhaust (th_main, 8, 1, _V(0,0,-7.6), _V(0,0,-1));
th_rcs[ 0] = CreateThruster (_V( 1,0, 3), _V(0,1,0), MAXRCSTH, tank , ISP);
th_rcs[ 1] = CreateThruster (_V( 1,0, 3), _V(0,-1,0), MAXRCSTH, tank, ISP);
th_rcs[ 2] = CreateThruster (_V(-1,0, 3), _V(0,1,0), MAXRCSTH,tank, ISP);
th_rcs[ 3] = CreateThruster (_V(-1,0, 3), _V(0,-1,0), MAXRCSTH, tank, ISP);
th_rcs[ 4] = CreateThruster (_V( 1,0,-3), _V(0,1,0), MAXRCSTH, tank, ISP);
th_rcs[ 5] = CreateThruster (_V( 1,0,-3), _V(0,-1,0), MAXRCSTH, tank, ISP);
th_rcs[ 6] = CreateThruster (_V(-1,0,-3), _V(0,1,0), MAXRCSTH, tank, ISP);
th_rcs[ 7] = CreateThruster (_V(-1,0,-3), _V(0,-1,0), MAXRCSTH,tank , ISP);
th_rcs[ 8] = CreateThruster (_V( 1,0, 3), _V(-1,0,0), MAXRCSTH, tank, ISP);
th_rcs[ 9] = CreateThruster (_V(-1,0, 3), _V(1,0,0), MAXRCSTH, tank, ISP);
th_rcs[10] = CreateThruster (_V( 1,0,-3), _V(-1,0,0), MAXRCSTH, tank, ISP);
th_rcs[11] = CreateThruster (_V(-1,0,-3), _V(1,0,0), MAXRCSTH, tank, ISP);
th_rcs[12] = CreateThruster (_V( 0,0,-3), _V(0,0,1), MAXRCSTH, tank, ISP);
th_rcs[13] = CreateThruster (_V( 0,0, 3), _V(0,0,-1), MAXRCSTH, tank, ISP);

th_group[0] = th_rcs[0];
th_group[1] = th_rcs[2];
th_group[2] = th_rcs[5];
th_group[3] = th_rcs[7];
CreateThrusterGroup (th_group, 4, THGROUP_ATT_PITCHUP);

th_group[0] = th_rcs[1];
th_group[1] = th_rcs[3];
th_group[2] = th_rcs[4];
th_group[3] = th_rcs[6];
CreateThrusterGroup (th_group, 4, THGROUP_ATT_PITCHDOWN);

th_group[0] = th_rcs[0];
th_group[1] = th_rcs[4];
th_group[2] = th_rcs[3];
th_group[3] = th_rcs[7];
CreateThrusterGroup (th_group, 4, THGROUP_ATT_BANKLEFT);

th_group[0] = th_rcs[1];
th_group[1] = th_rcs[5];
th_group[2] = th_rcs[2];
th_group[3] = th_rcs[6];
CreateThrusterGroup (th_group, 4, THGROUP_ATT_BANKRIGHT);

th_group[0] = th_rcs[0];
th_group[1] = th_rcs[4];
th_group[2] = th_rcs[2];
th_group[3] = th_rcs[6];
CreateThrusterGroup (th_group, 4, THGROUP_ATT_UP);

th_group[0] = th_rcs[1];
th_group[1] = th_rcs[5];
th_group[2] = th_rcs[3];
th_group[3] = th_rcs[7];
CreateThrusterGroup (th_group, 4, THGROUP_ATT_DOWN);

th_group[0] = th_rcs[8];
th_group[1] = th_rcs[11];
CreateThrusterGroup (th_group, 2, THGROUP_ATT_YAWLEFT);

th_group[0] = th_rcs[9];
th_group[1] = th_rcs[10];
CreateThrusterGroup (th_group, 2, THGROUP_ATT_YAWRIGHT);

th_group[0] = th_rcs[8];
th_group[1] = th_rcs[10];
CreateThrusterGroup (th_group, 2, THGROUP_ATT_LEFT);

th_group[0] = th_rcs[9];
th_group[1] = th_rcs[11];
CreateThrusterGroup (th_group, 2, THGROUP_ATT_RIGHT);

CreateThrusterGroup (th_rcs+12, 1, THGROUP_ATT_FORWARD);
CreateThrusterGroup (th_rcs+13, 1, THGROUP_ATT_BACK);

AddMesh ("LBS");
}

DLLCLBK VESSEL *ovcInit (OBJHANDLE hvessel, int flightmodel)
{
return new LBS (hvessel, flightmodel);
}

DLLCLBK void ovcExit (VESSEL *vessel)
{
if (vessel) delete (LBS*)vessel;
}

and heres the error i get when i try to build it
Code:
1>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\Microsoft.CppBuild.targets(990,5): warning MSB8012: TargetPath(C:\Users\Ryan\documents\orbiter models\LBS\Release\LBS.dll) does not match the Linker's OutputFile property value (C:\Users\Ryan\My Documents\Orbiter2010\Modules\LBS.dll). This may cause your project to build incorrectly. To correct this, please make sure that $(OutDir), $(TargetName) and $(TargetExt) property values match the value specified in %(Link.OutputFile).
1>LINK : warning LNK4001: no object files specified; libraries used
1>LINK : error LNK2001: unresolved external symbol __DllMainCRTStartup@12
1>C:\Users\Ryan\My Documents\Orbiter2010\Modules\LBS.dll : fatal error LNK1120: 1 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

can anyone help me? i hope to get some custom DLLs sorted so i can move on to more advanced stuff (putting UMMU and UGCO into it)

thanks guys!

---------- Post added at 04:28 PM ---------- Previous post was at 04:14 PM ----------

in fact, im going to downgrade to MSVC++ 2008 so im on the same level as the video posted above, its downloading now, then i can hopefully get going
 
The errors you have are linker errors (LNK...). It means the linker is not correctly configured, that some libraries are missing, or that there is a conflict between libraries.
 
You never declared some stuff in your vessel class as well. Go look at your include and lib directories to make sure you chose the correct path for them. Copy them in fact and post them here so I can see what they generally look like. By the way, I see you are using Vessel2?
 
I'm going to assume "TimeStep" and "DefineAnimations".
 
ok, new error:
Code:
1>Compiling...
1>cl : Command line error D8016 : '/MT' and '/clr' command-line options are incompatible
1>Build log was saved at "file://c:\Users\Ryan\Documents\Orbiter2010\Orbitersdk\samples\LBS\Debug\BuildLog.htm"
1>LBS - 1 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

whats gone wrong?
 
You meant to DEBUG it right? I need to see what you changed because a small change can amount to a large problem.
 
i changed a hell of a lot:

i moved from 2010 to 2008 and followed the video tutorial exactly, except changing "testProject" to "LBS"
 
It shouldn't make too big a difference. Well, do you have Orbiter.lib in your source files? What about the directories? Can you paste them here?
 
ok, new error:
Code:
1>Compiling...
1>cl : Command line error D8016 : '/MT' and '/clr' command-line options are incompatible
1>Build log was saved at "file://c:\Users\Ryan\Documents\Orbiter2010\Orbitersdk\samples\LBS\Debug\BuildLog.htm"
1>LBS - 1 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

whats gone wrong?
In Project Properties, "Configuration Properties -> General -> Common Language Runtime Support" select "No Common Language Runtime Support".


I'm in the middle of creating an article about using VC++ 2010 and Orbiter SDK property sheets for creating new projects. I think it will be completed by this weekend, as I need to make yet a few GIF animations, due to the fact that there are too many screenshots for a single post. There will be no need to configure all the options or add libraries to source files when you use those property sheets.
 
Do you manage to recompile the ShuttlePB sample without changing nothing ? If yes, you're on the good way.
 
Didn't want to start a new thread, so here goes...

Writing code is turning out easier than I thought, it's trying to put it in a project that's giving me all the grief...

Using VC++ 2010, I can't open after converting any of Orbitersdk's samples to the new version (and thus cannot compile) with the following error:

Code:
C:\Users\Scott\Desktop\Fi\Orbitersdk\samples\ShuttlePB\ShuttlePB.vcxproj : error  : The project file could not be loaded. Root element is missing.  C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\Microsoft.CppBuild.targets

How can I repair my MSBuild installation? This is all very confusing for such a bumpkin as myself.

EDIT: It's also noteworthy that I can't create new projects or convert any samples. The one I tried to open was converted last autumn when the program still worked for me. I wrote the code in question in Notepad++ instead.

---------- Post added at 11:01 PM ---------- Previous post was at 06:49 PM ----------

Nevermind, problem solved by reinstalling .NET 4.0. :facepalm:
 
Last edited:
The project is refusing to build with these errors:

Code:
1>LSS.obj : error LNK2001: unresolved external symbol "public: __thiscall LSS::~LSS(void)" (??1LSS@@QAE@XZ)
1>LSS.obj : error LNK2001: unresolved external symbol "public: __thiscall LSS::LSS(void *,int)" (??0LSS@@QAE@PAXH@Z)

Class interface (I assume it's relevant):

Code:
class LSS: public VESSEL3 {
public:
    LSS (OBJHANDLE hVessel, int flightmodel);
    ~LSS ();
    void clbkSetClassCaps (FILEHANDLE cfg);
};
 
The project is refusing to build with these errors:

Code:
1>LSS.obj : error LNK2001: unresolved external symbol "public: __thiscall LSS::~LSS(void)" (??1LSS@@QAE@XZ)
1>LSS.obj : error LNK2001: unresolved external symbol "public: __thiscall LSS::LSS(void *,int)" (??0LSS@@QAE@PAXH@Z)
Did you define in your code the LSS::LSS and LSS::~LSS functions?

Like for example:
Code:
LSS::LSS (OBJHANDLE hVessel, int flightmodel) : VESSEL3 (hVessel, flightmodel) {
}

LSS::~LSS () {
}
 
I was wondering, too... Can you post the whole project ?
 
The project so far:
Code:
//First test version...none of these unnecessary constants later
#define STRICT
#define ORBITER_MODULE

#include "orbitersdk.h"

const double LSS_SIZE       = 18;
const VECTOR3 LSS_CS        = {122.1,122.1,71};
const VECTOR3 LSS_PMI       = {10,10,5};
const VECTOR3 LSS_RD        = {0.5,0.5,0.5};
const double LSS_EMPTYMASS  = 3084.4;
const double LSS_FUELMASS   = 27000.5;
const double LSS_ISP        = 4560.1;
const VECTOR3 LSS_TDP [3]   = {{0,-3.098563,5.306288},{-2.865911,-3.098563,-5.235881},{2.865911,-3.098563,-5.235881}};

const double LSS_MAXMAINTH  = 25000;
const double LSS_MAXRETROTH = 25000;
const double LSS_MAXHOVERTH = 260000;
const double LSS_MAXRCSTH   = 8000;

const VECTOR3 LSS_DOCK_POS  = {0,0,9.408442};
const VECTOR3 LSS_DOCK_DIR  = {0,0,1};
const VECTOR3 LSS_DOCK_ROT  = {0,1,0};

class LSS: public VESSEL3 {
public:
	LSS (OBJHANDLE hVessel, int flightmodel);
	~LSS ();
	void clbkSetClassCaps (FILEHANDLE cf
 
Last edited:
The project so far:
To be honest, I don't really know if what I have defines what you posted. Still just learning the basics here. :facepalm:

You need to also implement the function LSS::LSS(OBJHANDLE, int) and maybe LSS::~LSS().

The first one is called a constructor and is responsible for creating the vessel if you call "new LSS(OBJHANDLE, int)". In that, you need to do first a reference to the constructor of the superclass (VESSEL3) because it does not have a default constructor (without parameters, VESSEL3::VESSEL3() ).

The second one (~LSS()) is called a destructor. It is implicitly called automatically if your object is destroyed, for example by delete. You use this for cleaning up and freeing all memory that you allocated in your vessel. if you have no such thing, or automatic behavior, like the destructors of objects that you used inside your class is doing all fine, you may not define a destructor, because it would be empty anyway.

So you need to write there at least:

LSS::LSS(OBJHANDLE hVessel, int iFlightModel) : VESSEL3(hVessel, iFlightModel) {}

In the constructor, you should ALWAYS initialize (=give variables initial values) all your object variables, because otherwise they are undefined. A pointer could for example be filled with garbage, but not be zero, when you expected it to. Uninitialized variables are in my observation, the most common error source in Orbiter modules.

You can initialize things by two ways: Either by assignments ("x = 0;") or in the initialization list in the beginning, the part that follows after the ":" (LSS(...) : VESSEL3(...), x(0)"

You can not yet call most orbiter functions there, for example for creating thrusters at such, which is why you need to delay this to clbkSetClassCaps. But you can set the thruster handles to NULL and be on the safe side.
 
Last edited:
Try to add orb's lines that way :

Code:
...
class LSS: public VESSEL3 {
public:
	LSS (OBJHANDLE hVessel, int flightmodel);
	~LSS ();
	void clbkSetClassCaps (FILEHANDLE cfg);
};


[B]LSS::LSS (OBJHANDLE hVessel, int flightmodel) : VESSEL3 (hVessel, flightmodel) {
}

LSS::~LSS () {
}[/B]

void LSS::clbkSetClassCaps (FILEHANDLE cfg)
{
...

It's a tricky part, it took me forever to figure how it works...

Edit : ninja'ed by Urumpwe :ninja:
 
Back
Top