Programming Question getting started with C++

Grover

Saturn V Misfire
Addon Developer
Donator
Joined
Oct 3, 2010
Messages
1,466
Reaction score
0
Points
0
Location
Ascension Island
Ive decided recently that there are too many flaws in spacecraft3 to get to know it well, so im just going to go ahead and learn a little C++

This isnt another thread asking generally "how do i make a custom DLL ship", i already did my homework, though the tutorial i used was a little sketchy, so i just have a couple of questions:

1) when i download vc++ studio, i can choose 2008 or 2010, but which is best for coding for orbiter (is there any compatibility issue?)

2) (stupid question) is it a .cpp file that i put the coding into before compiling?

3) is there a tutorial which can explain how to add animations like gear and cargo bay doors?

4) finally is there a tutorial to explain creating a 2d VC?

Thanks to anyone who can help
 
1) Either or.
2) Yes. The .cpp has all the coding for the .dll. For now, a simple .dll woulsd only require a .cpp. A .h file is for a larger coding project to shorten it.
3) Unfortunately, no. The API and documentation does a pretty good job of explaining it.
4) I am not sure.
 
1) when i download vc++ studio, i can choose 2008 or 2010, but which is best for coding for orbiter (is there any compatibility issue?)

Better use the most recent version, there are no known problems so far.

2) (stupid question) is it a .cpp file that i put the coding into before compiling?

Well, better use .cpp and .h files. .h are header files which you include with "#include" and which contain declarations and sometimes also definitions. cpp files should mostly contain definitions. (Note that technically, there is no difference between .cpp and .h files. You can also include a .cpp file, if you want to, or write your code into .code files. It is just a convention to make development easier)

A single CPP file can include multiple headers and results in a single object file. Multiple object files are later linked together into your final orbiter module together with the libraries of Orbiter.

This separation into header and source files is pretty important for bigger add-on projects, while smaller ones can be done in a single cpp file. Having more CPP files means you can locate functions and definitions faster.

A single class can only be defined in a single header file (otherwise, you produce strange effects by having multiple declarations of a class in parallel), but you can use multiple cpp files for defining this class, eg, do the Lua interface of a vessel in a separate cpp file.

Well...how to explain this best...

In a header you describe the interfaces (for example variables and constants that are shared between multiple source files).
In a source file, you describe what is behind the interfaces (for example defining the properties of your vessel in clbkSetClassCaps).

3) is there a tutorial which can explain how to add animations like gear and cargo bay doors?

Not that I know, but you can see such stuff inside the samples of Orbiter.

4) finally is there a tutorial to explain creating a 2d VC?

Yes, martins blog here contains such tutorials.
 
Last edited:
3) is there a tutorial which can explain how to add animations like gear and cargo bay doors?

The "Hubble Telescope" sample is designed to demonstrate the animations ; probably the simplest sample to see them in action.

Good luck, C++ is the Way of the Probe ! :hailprobe:
 
Thanks guys, ill have a look at some samples when i get vsc++ tomorrow, and hopefully ill manage something. I aim to create an alternative to the arrow, similar build, but overcoming the UGCO cargo limit by not storing cargoes externally, but holding them in the vessels coding to save the problem with high poly counts by not actually loading meshes

Thanks guys!
 
Good luck, C++ is the Way of the Probe ! :hailprobe:

Actually the original Probe was a simple cfg file vessel. Then a spacecraft.dll (the original one, not spacecraf2 or 3) version came along. That version was finally turned into a custom dll vessel by Daver. Since then at least one replacement mesh has arrived. :lol:

Good luck Grover! I'll have to start down that road eventually.
 
Frankencoder from orbithangar, with a little spacecraft3 experience it made sense
 
Do you have a link? I tried searching for "frankencoder" but nothing came up
Edit: Nevermind, I got it, thanks
 
Last edited:
2) In fact, you can name the files like you want. Some persons use .hpp instead of .h because it defines a C++ class, not standard functions like in C. Others use .c and .h, just like in C. But you could name them .orbiter or .dichlorodiphenyltrichloroethane if you want (maybe Windows has a limit in file expansion lenght... :lol: ). However, the most common way is to define your class(es) in a .h file and your code in .cpp. However, you'll find pretty fast that your cpp file will became way too big. So, you'll separate it in different .cpp files.

For example, I always have a .h of my main class (the vessel). Then, I create a DLLCLBK.cpp in wich I have all the DLLCLBK and the constructor/destructor of my class. Then, I create another file named Callbacks.cpp in which I have all Orbiter's calbacks (clbkSetClassCaps, clbkLoadPanel2D, clbkSaveState, etc.). Finaly, I create other files with other functions (for example, Panel.cpp for all Panel related things, Autopilot.cpp for the autopilot, etc.).
 
If you don't already know, two tutorials which are often recommended are from cplusplus.com and cprogramming.com. They both have good tutorials and also C/C++ references.

For specific programming/compilation questions (and answers), google.com is your dearest friend :P, but I'd also recommend stackoverflow.com.

Good luck!
 
Stupid question i know, but how do i compile a .cpp file using msvc++? I cant find a "compile" button anywhere...
 
Stupid question i know, but how do i compile a .cpp file using msvc++? I cant find a "compile" button anywhere...

Try to "build" it. ;)

Also you never compile single cpp files with it, you need to put it into a project to tell VC++ how it should compile this.
 
I put it into a project and built it, but still no dll, what exactly do i do?

---------- Post added at 11:06 PM ---------- Previous post was at 10:59 PM ----------

Also, it says i cant debug because im missing an exe in the name of my project, whats going on?
 
I put it into a project and built it, but still no dll, what exactly do i do?

---------- Post added at 11:06 PM ---------- Previous post was at 10:59 PM ----------

Also, it says i cant debug because im missing an exe in the name of my project, whats going on?

Did you select to produce a DLL with as output? Check your settings.

DLLs can't be executed alone, you need to specify a executable (Exe) that uses this DLL for testing.
 
That's the video you need to see :


Configuring VC++ was a complete mystery for me, the enlightment came from this vid... I still watch it periodically, because I sometimes miss something.
 
I followed the video, but it was for an older msvs version and it wont work properly, is there a 2010 version walkthrough?
 
I followed the video, but it was for an older msvs version and it wont work properly, is there a 2010 version walkthrough?
It isn't that hard to set up the Visual Studio/C++ 2010 to compile Orbiter projects.

If you followed the above video tutorial, then IIRC you only additionally need to change the character set from Unicode to Multi-byte, and nothing more, if you don't want to use Orbiter 2010 property sheets.

If there are some other problems using that video tutorial, then I can make one, but not a video tutorial (I don't have and don't want to create an account at YouTube or other video uploading site), but rather using screenshots and description, step by step, with use of property sheets. Just wait for the weekend (tomorrow), and I'll start making one.
 
Back
Top