Difference between revisions of "Vessel code"

From OrbiterWiki
Jump to navigation Jump to search
 
Line 17: Line 17:
  
 
==Functions in your *.cpp file==
 
==Functions in your *.cpp file==
 +
The following text is a template for a *.cpp file. If you replace all the "Template" with your Vessel Class name (caution: use find and replace with case sensitive selected).
  
 
===Example Code===
 
===Example Code===

Revision as of 16:05, 25 July 2005

Introduction

--- THIS IS WORK IN PROGRESS ---

This is a quick guide to create your own vessel dll with VC++. It's not suited for newbees to c++. If you are new to orbiter, make a config based vessel first, or one based on vinkas spacecraft.dll or spacecraft2.dll. You will find here wich API functions are necessary to get a project running. This is basically just a very cut down version from one of the sample ships included in Orbiter SDK.

Adding sourcecode files to your project

After you have set up the compiler, it's time to start setting up the actual code.

Try to settle on a name for your vessel class first. Dont choose "testship" or "spacecraft". Try a unique name, like "ProtonLV", "HeavyCruiserHC" or whatever suits you. Save the project under that name and add the following two files (with your vessels name)

  • Source *.cpp file
  • Header *.h file

Example: "ProtonLV.cpp" and "ProtonLV.h"

Functions in your *.cpp file

The following text is a template for a *.cpp file. If you replace all the "Template" with your Vessel Class name (caution: use find and replace with case sensitive selected).

Example Code

  1. define ORBITER_MODULE
  1. include "Template.h"

void VLiftCoeff (double aoa, double M, double Re, double *cl, double *cm, double *cd) { }

void HLiftCoeff (double beta, double M, double Re, double *cl, double *cm, double *cd) { }

Template::Template (OBJHANDLE hObj, int fmodel)

VESSEL2 (hObj, fmodel)

{ }


Template::~Template () { }

void Template::clbkSetClassCaps (FILEHANDLE cfg) { }

void Template::clbkLoadStateEx (FILEHANDLE scn, void *vs) { }

void Template::clbkSaveState (FILEHANDLE scn) { }


void Template::clbkPreStep (double simt, double simdt, double mjd) { }

void Template::clbkPostStep (double simt, double simdt, double mjd) { }


int Template::clbkConsumeBufferedKey (DWORD key, bool down, char *kstate) { }


DLLCLBK void InitModule (HINSTANCE hModule) { }


DLLCLBK void ExitModule (HINSTANCE hModule) { }

DLLCLBK VESSEL *ovcInit (OBJHANDLE hvessel, int flightmodel) { }

DLLCLBK void ovcExit (VESSEL *vessel) { }

Functions in your *.h file

Example Code

  1. ifndef __TEMPLATE_H
  2. define __TEMPLATE_H
  1. define STRICT
  1. include "orbitersdk.h"

class Template: public VESSEL2 { public: Template (OBJHANDLE hObj, int fmodel); ~Template (); void clbkLoadStateEx (FILEHANDLE scn, void *vs); void clbkSaveState (FILEHANDLE scn); int clbkConsumeBufferedKey (DWORD key, bool down, char *kstate); void clbkSetClassCaps (FILEHANDLE cfg); void clbkPreStep (double simt, double simdt, double mjd); void clbkPostStep (double simt, double simdt, double mjd);

};


  1. endif