See site in english Voir le site en francais
Website skin:
home  download  forum  link  contact

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length

Author Topic: [help]splitage de mon code source[résolu]  (Read 3205 times)

0 Members and 1 Guest are viewing this topic.

Offline no matter

  • Legend
  • ******
  • Posts: 2826
  • Karma: 1
25 February 2007, 22:38:09
Etant donné que je suis un benet du C++, j'ai restreint mon code pour mon futur projet (avec Well) à un seul fichier
cpp.
Je souhaiterai faire dans les règles de l'art maintenant et splitter l'histoire en .h et .cpp.
Je sais que je peux mettre ma classe dans un fichier "xxxx.h" et rajouter aussi "#include xxxx.h" mais je sais pas trop
si je dois changer la syntaxe de certaines chose, rajouter d'autre trucs ni même ce que je peux mettre (en plus de la
vessel class) en tout dans un fichier .h.

Si quelqu'un veut bien éclairer ma lanterne je le remercie d'avance.

Le code en question (désolé c'est long):
Quote
// ==============================================================
//               LTV DLL
//               Vessel Class LTV
//   MANY THANKS TO:
//                 - Computerex
//                 - Korben62
//               - Dansteph
// ==============================================================

#define STRICT
#define ORBITER_MODULE

#include <orbitersdk.h>
#include <cstdio>
#include <cmath>
#include <string>
#include <stdio.h>
#include <OrbiterSoundSDK3.h>


// ==============================================================
// Some vessel parameters
// ==============================================================
const double PER_FUELMASS = 3000.0;
const double PER_ISP = 2e8;
const double H_ISP = 1e5;
const double PER_MAXRCSTH = 4e2;
const double PER_MAXHOVERTH = 4e4;
const double GEAR_OPERATING_SPEED = 0.20;


#define BACK 1
#define LOADBACK "Sound\\CTV-1\\ATVbackground.wav"

#define RED RGB(255, 0, 0)
#define YELLOW RGB(255, 255, 0)
#define WHITE RGB(255, 255, 255)
#define BLUE RGB(0, 0, 255)
#define GREY RGB(160, 160, 160)
#define BRIGHTERGREY RGB(200, 200, 200)
#define GAINSBORO RGB(220,220,220)
#define HUDGREEN RGB(189 ,183 ,107)
#define SLATGREY RGB(112 ,128 ,144)
#define CORNFLOWERBLUE RGB(100 ,149 ,237)
#define SKYBLUE RGB(135 ,206 ,235)
#define LIGHTSTEELBLUE RGB(176 ,196 ,222)
#define DARKTURQUISE RGB(0 ,206 ,209)
#define SEAGREEN RGB(46 ,139 ,87)
#define LIGHTSEAGREEN RGB(32 ,178 ,170)
#define HOTPINK RGB(255 ,105 ,180)
#define ORANGE RGB(255 ,69 ,0)
#define SEAGREEN2 RGB(84 ,255 ,159)



// 1. vertical lift component (wings and body)

void VLiftCoeff (double aoa, double M, double Re, double *cl, double *cm, double *cd)
{
   static const double step = RAD*15.0;
   static const double istep = 1.0/step;
   static const int nabsc = 25;
   static const double CL[nabsc] = {0.1, 0.17, 0.2, 0.2, 0.17, 0.1, 0, -0.11, -0.24, -0.38,  -0.5,  -0.5, -0.02,
0.6355,    0.63,   0.46, 0.28, 0.13, 0.0, -0.16, -0.26, -0.29, -0.24, -0.1, 0.1};
   static const double CM[nabsc] = {  0,    0,   0,   0,    0,   0, 0,     0,    0,0.002,0.004, 0.0025,0.0012,      0,-
0.0012,-0.0007,    0,    0,   0,     0,     0,     0,     0,    0,   0};
   // lift and moment coefficients from -180 to 180 in 15 degree steps.
   // This uses a documented lift slope of 0.0437/deg, everything else is rather ad-hoc

   aoa += PI;
   int idx = max (0, min (23, (int)(aoa*istep)));
   double d = aoa*istep - idx;
   *cl = CL[idx] + (CL[idx+1]-CL[idx])*d;
   *cm = CM[idx] + (CM[idx+1]-CM[idx])*d;
   *cd = 0.06 + oapiGetInducedDrag (*cl, 2.266, 0.6);
}

// 2. horizontal lift component (vertical stabiliser and body)

void HLiftCoeff (double beta, double M, double Re, double *cl, double *cm, double *cd)
{
   static const double step = RAD*22.5;
   static const double istep = 1.0/step;
   static const int nabsc = 17;
   static const double CL[nabsc] = {0, 0.2, 0.3, 0.2, 0, -0.2, -0.3, -0.2, 0, 0.2, 0.3, 0.2, 0, -0.2, -0.3, -0.2, 0};

   beta += PI;
   int idx = max (0, min (15, (int)(beta*istep)));
   double d = beta*istep - idx;
   *cl = CL[idx] + (CL[idx+1]-CL[idx])*d;
   *cm = 0.0;
   *cd = 0.02 + oapiGetInducedDrag (*cl, 1.5, 0.6);
}


// ==============================================================
// LTV class interface
// ==============================================================

bool GetTargetName(void *id, char *str, void *data);

enum Power{OFF,ON};

class LTV: public VESSEL2 {
public:
   LTV (OBJHANDLE hVessel, int flightmodel);
   void clbkSetClassCaps (FILEHANDLE cfg);
    void clbkPostCreation (void);
    void clbkPostStep (double simt, double simdt, double mjd);
    int  clbkConsumeBufferedKey (DWORD key, bool down, char *kstate);
   void clbkLoadStateEx (FILEHANDLE scn, void *vs);
   void clbkSaveState (FILEHANDLE scn);
    void SetHudColor(DWORD color){HUDCOLOR = color;}
   DWORD GetHudColor(){return HUDCOLOR;}
   void FlightComputer(void);
   int MyID;
   void DefineAnimations (void);
   enum GearStatus { GEAR_CLOSED, GEAR_OPEN, GEAR_CLOSING, GEAR_OPENING} gear_status ;
   void RevertGear (void);
   
private:
   void clbkDrawHUD(int iMode, const HUDPAINTSPEC* pHPS, HDC hdc);
    DWORD HUDCOLOR;
   THRUSTER_HANDLE th_hover, th_rcs[14], th_group[4];
   Power FlightComp;
   DWORD Cam;
   BEACONLIGHTSPEC beacon1;
   BEACONLIGHTSPEC beacon2;
   
   UINT anim_gear;
   double gear_state;
};

//======================================================
// LTV constructeur
//======================================================
LTV::LTV (OBJHANDLE hVessel, int flightmodel)
      : VESSEL2 (hVessel, flightmodel)
{
   SetHudColor(1);
    FlightComp = OFF;
   Cam = 1;
   gear_status = GEAR_CLOSED;
   gear_state = 0.0000;
}


void LTV::clbkPostCreation (void)
{
MyID=ConnectToOrbiterSoundDLL3(GetHandle());

RequestLoadVesselWave3(MyID,BACK,LOADBACK,INTERNAL_ONLY);

SoundOptionOnOff3(MyID,PLAYCOUNTDOWNWHENTAKEOFF,FALSE);
SoundOptionOnOff3(MyID,DISPLAYTIMER,FALSE);

if (Cam == 2)
{
   SetCameraDefaultDirection(_V(0,-1,0));
}
else
{
   SetCameraDefaultDirection(_V(0,0,0));
}
//initialisation des animations
SetAnimation (anim_gear, gear_state);
}

//======================================================
// Animations
//======================================================
void LTV::DefineAnimations (void)
{
   // ***** 1. Gear animation *****
   //P1=front P2=left P3=right P4=doorway

   static UINT P1grp[23] = {52,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,201,202,203};
   static MGROUP_ROTATE P1 (0, P1grp, 23, _V(0, -1.2, 1.7), _V(1,0,0), 25*RAD);
   static UINT P2grp[22] =
{140,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,195,196,197};
   static MGROUP_ROTATE P2 (0, P2grp, 22, _V(-1.79,-1.2,0), _V(0,0,1),(25*RAD));
   static UINT P3grp[22] = {80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101};
   static MGROUP_ROTATE P3 (0, P3grp, 22, _V(1.79,-1.2,0), _V(0,0,1),(-25*RAD));
   static UINT P4grp[41] =
{102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,1
28,129,130,131,132,133,134,135,136,137,138,139,198,199,200};
   static MGROUP_ROTATE P4 (0, P4grp, 41, _V(0,-1.2,-1.7), _V(1,0,0),(-25*RAD));

   anim_gear = CreateAnimation (0);
   AddAnimationComponent (anim_gear, 0, 1, &P1);
   AddAnimationComponent (anim_gear, 0.1, 0.9699, &P2);
   AddAnimationComponent (anim_gear, 0, 0.9899, &P3);
   AddAnimationComponent (anim_gear, 0.07, 0.9999, &P4);
}
//====================================================== ---------
void LTV::RevertGear (void)
{
   gear_status = ((gear_status == GEAR_CLOSED || gear_status == GEAR_CLOSING) ?
      GEAR_OPENING : GEAR_CLOSING);
}


// ======================================================
// Set the capabilities of LTV class
// ======================================================

void LTV::clbkSetClassCaps (FILEHANDLE cfg)
{
   SetSize (8);
   SetEmptyMass (4000);
   SetCameraOffset (_V(-0.4,2,1.4));
   SetCameraDefaultDirection(_V(0,0,0));
   SetCrossSections (_V(24.8,17.3,26.3));
   SetCW (0.3, 0.3, .3, .3);
   //SetDockParams(_V(0,3.37,0),_V(0,1,0),_V(0,0,-1)); moved to cfg to have a possibility of IDS Channel choice
   SetTouchdownPoints (_V(0,-4.2,1), _V(-1,-4.2,-1), _V(1,-4.2,-1));
   // inertia: not yet = 5.1 3.74 5.03   
   
   // propellant resources
   PROPELLANT_HANDLE hpr = CreatePropellantResource (PER_FUELMASS);

   // ***************** thruster definitions *******************
      PARTICLESTREAMSPEC exhaust_hover = {
      0, 2.0, 10, 200, 0.05, 0.05, 8, 1.0, PARTICLESTREAMSPEC::EMISSIVE,
      PARTICLESTREAMSPEC::LVL_SQRT, 0, 1,
      PARTICLESTREAMSPEC::ATM_PLOG, 1e-5, 0.1
   };
      PARTICLESTREAMSPEC contrail_hover = {
      0, 5.0, 8, 200, 0.15, 1.0, 5, 3.0, PARTICLESTREAMSPEC::DIFFUSE,
      PARTICLESTREAMSPEC::LVL_PSQRT, 0, 2,
      PARTICLESTREAMSPEC::ATM_PLOG, 1e-4, 1
   };
   
   th_hover = CreateThruster (_V(0,-1.5,0), _V(0,1,0), PER_MAXHOVERTH, hpr, H_ISP);
   CreateThrusterGroup (&th_hover, 1, THGROUP_HOVER);
   AddExhaust (th_hover, 5, 0.4, _V(0,-3.3,0), _V(0,-1,0));
   //AddExhaust (th_hover, 8, 1, _V(0,-1.5,-1), _V(0,-1,0));

   AddExhaustStream (th_hover, _V(0,-3, 1), &contrail_hover);
   //AddExhaustStream (th_hover, _V(0,-3,-1), &contrail_hover);
   //AddExhaustStream (th_hover, _V(0,-2, 1), &exhaust_hover);
   //AddExhaustStream (th_hover, _V(0,-2,-1), &exhaust_hover);
      
    th_rcs[ 0] = CreateThruster (_V( 1,0, 3), _V(0, 1,0), PER_MAXRCSTH, hpr, PER_ISP);
   th_rcs[ 1] = CreateThruster (_V( 1,0, 3), _V(0,-1,0), PER_MAXRCSTH, hpr, PER_ISP);
   th_rcs[ 2] = CreateThruster (_V(-1,0, 3), _V(0, 1,0), PER_MAXRCSTH, hpr, PER_ISP);
   th_rcs[ 3] = CreateThruster (_V(-1,0, 3), _V(0,-1,0), PER_MAXRCSTH, hpr, PER_ISP);
   th_rcs[ 4] = CreateThruster (_V( 1,0,-3), _V(0, 1,0), PER_MAXRCSTH, hpr, PER_ISP);
   th_rcs[ 5] = CreateThruster (_V( 1,0,-3), _V(0,-1,0), PER_MAXRCSTH, hpr, PER_ISP);
   th_rcs[ 6] = CreateThruster (_V(-1,0,-3), _V(0, 1,0), PER_MAXRCSTH, hpr, PER_ISP);
   th_rcs[ 7] = CreateThruster (_V(-1,0,-3), _V(0,-1,0), PER_MAXRCSTH, hpr, PER_ISP);
   th_rcs[ 8] = CreateThruster (_V( 1,0, 3), _V(-1,0,0), PER_MAXRCSTH, hpr, PER_ISP);
   th_rcs[ 9] = CreateThruster (_V(-1,0, 3), _V( 1,0,0), PER_MAXRCSTH, hpr, PER_ISP);
   th_rcs[10] = CreateThruster (_V( 1,0,-3), _V(-1,0,0), PER_MAXRCSTH, hpr, PER_ISP);
   th_rcs[11] = CreateThruster (_V(-1,0,-3), _V( 1,0,0), PER_MAXRCSTH, hpr, PER_ISP);
   th_rcs[12] = CreateThruster (_V( 0,0,-3), _V(0,0, 1), PER_MAXRCSTH, hpr, PER_ISP);
   th_rcs[13] = CreateThruster (_V( 0,0, 3), _V(0,0,-1), PER_MAXRCSTH, hpr, PER_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);

    // visual specs
   SetMeshVisibilityMode (AddMesh (oapiLoadMeshGlobal ("ARD-CTV\\LTV")), MESHVIS_EXTERNAL);

   static VECTOR3 beacon1pos = {1.8,2.74,0};
   static VECTOR3 beacon1col = {0.823529, 0.811765, 0.117647};
       beacon1.shape = (BEACONSHAPE_STAR);
      beacon1.pos = &beacon1pos;
      beacon1.col = &beacon1col;
      beacon1.size = (0.1);
      beacon1.falloff = (1);
      beacon1.period = (1);
      beacon1.duration = (0.4);
      beacon1.tofs = (2);
      beacon1.active = true;
      
      AddBeacon (&beacon1);
      
   static VECTOR3 beacon2pos = {-1.8,2.74,0};
   static VECTOR3 beacon2col = {0.1, 0.1, 0.8};
       beacon2.shape = (BEACONSHAPE_STAR);
      beacon2.pos = &beacon2pos;
      beacon2.col = &beacon2col;
      beacon2.size = (0.1);
      beacon2.falloff = (1);
      beacon2.period = (1);
      beacon2.duration = (0.3);
      beacon2.tofs = (1);
      beacon2.active = true;
      
      AddBeacon (&beacon2);
      DefineAnimations();

}

// ==============================================================
// API callback interface, animation graphic update
// ==============================================================

void LTV::clbkPostStep (double simt, double simdt, double mjd)
{
   
   PlayVesselWave3(MyID,BACK);

   if (FlightComp == ON)
   {
      FlightComputer();
   }
// animation train d'atterrissage
   if (gear_status >= GEAR_CLOSING) {
      double dg = simdt * GEAR_OPERATING_SPEED;
      if (gear_status == GEAR_CLOSING) {
         if (gear_state > 0.0) gear_state = max (0.0, gear_state-dg);
         else                  gear_status = GEAR_CLOSED;
      } else {
         if (gear_state < 1.0) gear_state = min (1.0, gear_state+dg);
         else                  gear_status = GEAR_OPEN;
      }
      SetAnimation (anim_gear, gear_state);
   }
      if (gear_status >= GEAR_CLOSING) {
      double dg = simdt * GEAR_OPERATING_SPEED;
      if (gear_status == GEAR_CLOSING) {
         if (gear_state > 0.0) gear_state = max (0.0, gear_state-dg);
         else                  gear_status = GEAR_CLOSED;
      } else {
         if (gear_state < 1.0) gear_state = min (1.0, gear_state+dg);
         else                  gear_status = GEAR_OPEN;
      }
      SetAnimation (anim_gear, gear_state);
   }

   
}


// ======================================================
// Keyboard interface handler (buffered key events)
// ======================================================
int LTV::clbkConsumeBufferedKey (DWORD key, bool down, char *kstate)
{
   if (!down) return 0; // only process keydown events
   
         switch (key)
      {
      case OAPI_KEY_G: // trains d'atterissage
         {
            if (GetAltitude() > 10)
            RevertGear();
         }
         return 1;           

      case OAPI_KEY_F11:
           {
              
              if (GetHudColor() == 19)
              {
                 SetHudColor(1);
              }
              else
              {
                 SetHudColor(GetHudColor()+1);
              }
              return true;
           }
        case OAPI_KEY_F12:
           {
            
              if (GetHudColor() == 1)
              {
                 SetHudColor(19);
              }
              else
              {
                 SetHudColor(GetHudColor()-1);
              }
              return true;
           }
       case OAPI_KEY_P:
           {
              if (FlightComp == OFF)
              {
                 FlightComp = ON;
              }
              else
              {
                 FlightComp = OFF;
                 ToggleNavmode(NAVMODE_HLEVEL);
              }
              return true;
           }
        case OAPI_KEY_C:
           {
              if (Cam == 1)
              {
                 SetCameraOffset (_V(0,-3.5,0.3));
                   SetCameraDefaultDirection(_V(0,-1,0));
                 Cam = 2;
              }
              else
              {
                 SetCameraOffset (_V(-0.4,2,1.4));
                   SetCameraDefaultDirection(_V(0,0,0));
                 Cam = 1;
              }
              return true;
           }
        case OAPI_KEY_K:
           {
              if (beacon1.active == true)
              {
                 beacon1.active = false;
              }
              else
              {
                 beacon1.active = true;
              }
              if (beacon2.active == true)
              {
                 beacon2.active = false;
              }
              else
              {
                 beacon2.active = true;
              }
              return true;
           }
             //SWITCH END//
        }
   return 0;         
}

void LTV::FlightComputer()
{
   if (oapiGetTimeAcceleration() > 100)
   {
      if (GetNavmodeState(NAVMODE_KILLROT))
      {
         ToggleNavmode(NAVMODE_KILLROT);
      }
      if (GetNavmodeState(NAVMODE_HLEVEL))
      {
         ToggleNavmode(NAVMODE_HLEVEL);
      }
      if (GetNavmodeState(NAVMODE_PROGRADE))
      {
         ToggleNavmode(NAVMODE_PROGRADE);
      }
      if (GetNavmodeState(NAVMODE_RETROGRADE))
      {
         ToggleNavmode(NAVMODE_RETROGRADE);
      }
      if (GetNavmodeState(NAVMODE_NORMAL))
      {
         ToggleNavmode(NAVMODE_NORMAL);
      }
      if (GetNavmodeState(NAVMODE_ANTINORMAL))
      {
         ToggleNavmode(NAVMODE_ANTINORMAL);
      }
   }

   
    double ALT = GetAltitude();

    if (ALT < 100)
    {
       if (!GetNavmodeState(NAVMODE_HLEVEL))
       {
          ToggleNavmode(NAVMODE_HLEVEL);
       }
    }
   
    double  STAT = GetNavmodeState(NAVMODE_HLEVEL);
   
    if (ALT < 4.3)
    {
          SetThrusterLevel(th_hover,0);
          if ( STAT = true)
       {DeactivateNavmode(NAVMODE_HLEVEL);}
       }
}
            
// ====================================================== --------
// Vessel initialisation
// ====================================================== --------
DLLCLBK VESSEL *ovcInit (OBJHANDLE hvessel, int flightmodel)
{
   return new LTV (hvessel, flightmodel);
}

// ====================================================== --------
// Vessel cleanup
// ====================================================== --------
DLLCLBK void ovcExit (VESSEL *vessel)
{
   if (vessel) delete (LTV*)vessel;
}

void LTV::clbkDrawHUD(int iMode, const HUDPAINTSPEC* pHPS, HDC hdc)
{
   VESSEL2::clbkDrawHUD(iMode, pHPS, hdc);
    char cbuf[255];
   char * BankSign = " ";
    char * TargetBankSign = " ";
   char * PitchRateSign = " ";
   char * TargetPitchRateSign = " ";
   char * BankRateSign = " ";
   char * TargetBankRateSign = " ";
   char * TargetPosSign = " ";
   

   double Heading; oapiGetFocusHeading(&Heading);
   VECTOR3 vec; GetHorizonAirspeedVector(vec);
   VECTOR3 attitudevector; GetAngularVel(attitudevector);
   double Pitch = GetPitch()*DEG,Bank = GetBank()*DEG;
   double Time = oapiGetSimMJD();
   ELEMENTS Element; GetElements(Element,Time);
   ORBITPARAM Elements; GetElements(NULL,Element,&Elements,Time,FRAME_ECL);

   OBJHANDLE RefPlanet = GetGravityRef();
   double RefPlanetRad = oapiGetSize(RefPlanet);
   
   
   VECTOR3 W,F,A;
    GetForceVector(F);
    GetWeightVector(W);
    A=(F-W)/GetMass();

   if (Bank < 0)
   {
      Bank *= -1;
      BankSign = "R";
   }
   else {BankSign = "L";}
   if (attitudevector.x < 0){PitchRateSign = "DN";}
   else{PitchRateSign = "UP";}
   if (attitudevector.z < 0){BankRateSign = "L";}
   else{BankRateSign = "R";}

DWORD HUD = GetHudColor();

   switch(iMode)
   {
      
        case HUD_SURFACE:
      {
               
         switch (HUD)
      {
      case (1):
         SetTextColor(hdc,RED);
         break;
      case (2):
         SetTextColor(hdc,YELLOW);
         break;
      case (3):
         SetTextColor(hdc,WHITE);
         break;
      case (4):
         SetTextColor(hdc,BLUE);
         break;
      case (5):
         SetTextColor(hdc,GREY);
         break;
      case (6):
         SetTextColor(hdc,BRIGHTERGREY);
         break;
      case (7):
         SetTextColor(hdc,GAINSBORO);
         break;
      case (8):
         SetTextColor(hdc,HUDGREEN);
         break;
      case (9):
         SetTextColor(hdc,SLATGREY);
         break;
      case (10):
         SetTextColor(hdc,CORNFLOWERBLUE);
         break;
      case (11):
         SetTextColor(hdc,SKYBLUE);
         break;
      case (12):
         SetTextColor(hdc,LIGHTSTEELBLUE);
         break;
      case (13):
         SetTextColor(hdc,DARKTURQUISE);
         break;
      case (14):
         SetTextColor(hdc,SEAGREEN);
         break;
      case (15):
         SetTextColor(hdc,LIGHTSEAGREEN);
         break;
      case (16):
         SetTextColor(hdc,HOTPINK);
         break;
      case (17):
         SetTextColor(hdc,ORANGE);
         break;
      case (18):
         SetTextColor(hdc,SEAGREEN2);
         break;

      }
         if (HUD != 19)
         {
         sprintf(cbuf,"Heading: %.2f",Heading*DEG);
         TextOut(hdc,10,240,cbuf,strlen(cbuf));
         sprintf(cbuf,"Airspeed: %.2f",GetAirspeed());
         TextOut(hdc,10,260,cbuf,strlen(cbuf));
         sprintf(cbuf,"V/s: %.2f",vec.y);
         TextOut(hdc,10,280,cbuf,strlen(cbuf));
         sprintf(cbuf,"Pitch Rate: %.2f%s",attitudevector.x*DEG,PitchRateSign);
         TextOut(hdc,10,300,cbuf,strlen(cbuf));
         sprintf(cbuf,"Bank Rate: %.2f%s",attitudevector.z*DEG,BankRateSign);
         TextOut(hdc,10,320,cbuf,strlen(cbuf));
         sprintf(cbuf,"Pitch: %.2f",Pitch);
         TextOut(hdc,10,340,cbuf,strlen(cbuf));
         sprintf(cbuf,"Bank: %.2f%s",Bank,BankSign);
         TextOut(hdc,10,360,cbuf,strlen(cbuf));
         sprintf(cbuf,"Speed: %.2f m/s",GetAirspeed());
         TextOut(hdc,10,380,cbuf,strlen(cbuf));
         sprintf(cbuf,"Accel: %.2fm/s/s",A.z);
         TextOut(hdc,10,400,cbuf,strlen(cbuf));
         sprintf(cbuf,"G Factor: %.2f",A.y/9.80665);
         TextOut(hdc,10,420,cbuf,strlen(cbuf));
          

         }


       }break;
       case HUD_DOCKING:
          {
                switch (HUD)
      {
      case (1):
         SetTextColor(hdc,RED);
         break;
      case (2):
         SetTextColor(hdc,YELLOW);
         break;
      case (3):
         SetTextColor(hdc,WHITE);
         break;
      case (4):
         SetTextColor(hdc,BLUE);
         break;
      case (5):
         SetTextColor(hdc,GREY);
         break;
      case (6):
         SetTextColor(hdc,BRIGHTERGREY);
         break;
      case (7):
         SetTextColor(hdc,GAINSBORO);
         break;
      case (8):
         SetTextColor(hdc,HUDGREEN);
         break;
      case (9):
         SetTextColor(hdc,SLATGREY);
         break;
      case (10):
         SetTextColor(hdc,CORNFLOWERBLUE);
         break;
      case (11):
         SetTextColor(hdc,SKYBLUE);
         break;
      case (12):
         SetTextColor(hdc,LIGHTSTEELBLUE);
         break;
      case (13):
         SetTextColor(hdc,DARKTURQUISE);
         break;
      case (14):
         SetTextColor(hdc,SEAGREEN);
         break;
      case (15):
         SetTextColor(hdc,LIGHTSEAGREEN);
         break;
      case (16):
         SetTextColor(hdc,HOTPINK);
         break;
      case (17):
         SetTextColor(hdc,ORANGE);
         break;
      case (18):
         SetTextColor(hdc,SEAGREEN2);
         break;

      }
             if (HUD != 19)
         {
         sprintf(cbuf,"Heading: %.2f",Heading*DEG);
         TextOut(hdc,10,240,cbuf,strlen(cbuf));
         sprintf(cbuf,"Speed: %.2f",GetAirspeed());
         TextOut(hdc,10,260,cbuf,strlen(cbuf));
         sprintf(cbuf,"V/s: %.2f",vec.y);
         TextOut(hdc,10,280,cbuf,strlen(cbuf));
         sprintf(cbuf,"Pitch Rate: %.2f%s",attitudevector.x*DEG,PitchRateSign);
         TextOut(hdc,10,300,cbuf,strlen(cbuf));
         sprintf(cbuf,"Bank Rate: %.2f%s",attitudevector.z*DEG,BankRateSign);
         TextOut(hdc,10,320,cbuf,strlen(cbuf));
         sprintf(cbuf,"Pitch: %.2f",Pitch);
         TextOut(hdc,10,340,cbuf,strlen(cbuf));
         sprintf(cbuf,"Bank: %.2f%s",Bank,BankSign);
         TextOut(hdc,10,360,cbuf,strlen(cbuf));
         sprintf(cbuf,"Speed: %.2f m/s",GetAirspeed());
         TextOut(hdc,10,380,cbuf,strlen(cbuf));
         sprintf(cbuf,"Accel: %.2fm/s/s",A.z);
         TextOut(hdc,10,400,cbuf,strlen(cbuf));
         sprintf(cbuf,"G Factor: %.2f",A.y/9.80665);
         TextOut(hdc,10,420,cbuf,strlen(cbuf));
          

         }

          }break;
          case HUD_ORBIT:
          {
                switch (HUD)
      {
      case (1):
         SetTextColor(hdc,RED);
         break;
      case (2):
         SetTextColor(hdc,YELLOW);
         break;
      case (3):
         SetTextColor(hdc,WHITE);
         break;
      case (4):
         SetTextColor(hdc,BLUE);
         break;
      case (5):
         SetTextColor(hdc,GREY);
         break;
      case (6):
         SetTextColor(hdc,BRIGHTERGREY);
         break;
      case (7):
         SetTextColor(hdc,GAINSBORO);
         break;
      case (8):
         SetTextColor(hdc,HUDGREEN);
         break;
      case (9):
         SetTextColor(hdc,SLATGREY);
         break;
      case (10):
         SetTextColor(hdc,CORNFLOWERBLUE);
         break;
      case (11):
         SetTextColor(hdc,SKYBLUE);
         break;
      case (12):
         SetTextColor(hdc,LIGHTSTEELBLUE);
         break;
      case (13):
         SetTextColor(hdc,DARKTURQUISE);
         break;
      case (14):
         SetTextColor(hdc,SEAGREEN);
         break;
      case (15):
         SetTextColor(hdc,LIGHTSEAGREEN);
         break;
      case (16):
         SetTextColor(hdc,HOTPINK);
         break;
      case (17):
         SetTextColor(hdc,ORANGE);
         break;
      case (18):
         SetTextColor(hdc,SEAGREEN2);
         break;

      }
             if (HUD != 19)
         {
            sprintf(cbuf,"ApT: %.2f h   %.2f min   %.2f
s",Elements.ApT/60/60,Elements.ApT/60,Elements.ApT);
            TextOut(hdc,10,200,cbuf,strlen(cbuf));
            sprintf(cbuf,"PeT: %.2f h   %.2f min   %.2f
s",Elements.PeT/60/60,Elements.PeT/60,Elements.PeT);
            TextOut(hdc,10,220,cbuf,strlen(cbuf));
            sprintf(cbuf,"ApD: %.2f",Elements.ApD);
                TextOut(hdc,10,240,cbuf,strlen(cbuf));
            sprintf(cbuf,"PeD: %2.f",Elements.PeD);
            TextOut(hdc,10,260,cbuf,strlen(cbuf));
            sprintf(cbuf,"EcA: %.2f",Elements.EcA);
            TextOut(hdc,10,280,cbuf,strlen(cbuf));
            sprintf(cbuf,"Lec: %.2f",Elements.Lec);
            TextOut(hdc,10,300,cbuf,strlen(cbuf));
            sprintf(cbuf,"MnA: %.2f",Elements.MnA);
            TextOut(hdc,10,320,cbuf,strlen(cbuf));
            sprintf(cbuf,"MnL: %.2f",Elements.MnL);
            TextOut(hdc,10,340,cbuf,strlen(cbuf));
            sprintf(cbuf,"SMI: %.2f",Elements.SMi);
            TextOut(hdc,10,360,cbuf,strlen(cbuf));
            sprintf(cbuf,"Orbital Period: %.2f",Elements.T);
            TextOut(hdc,10,380,cbuf,strlen(cbuf));
            sprintf(cbuf,"ECC: %.4f",Element.e);
            TextOut(hdc,10,400,cbuf,strlen(cbuf));
            sprintf(cbuf,"Inc: %.2f",Element.i);
            TextOut(hdc,10,420,cbuf,strlen(cbuf));
            sprintf(cbuf,"PeA: %.2fKm / %.2f miles",(Elements.PeD-RefPlanetRad)/1000,
(Elements.PeD-RefPlanetRad)/1000*0.621371192);
            TextOut(hdc,10,440,cbuf,strlen(cbuf));
            sprintf(cbuf,"ApA: %.2fKm / %.2f miles",(Elements.ApD-RefPlanetRad)/1000,
(Elements.ApD-RefPlanetRad)/1000*0.621371192);
            TextOut(hdc,10,460,cbuf,strlen(cbuf));
            


         }
          }break;
   }

   SetTextColor(hdc,BLUE);
   TextOut(hdc,475,40,"ESA-LTVsys revision4", 20);
    if (FlightComp == ON)
   {
      TextOut(hdc,500, 960, "ALUN-SPec", 9);
   }
   else
   {
      TextOut(hdc,500,960, "ASC/DESC-SPec", 13);
   }
   
   
}
// ==================================================
// Read state from scn
// ==================================================
void LTV::clbkLoadStateEx(FILEHANDLE scn, void*vs)
{
   char*line;

   while (oapiReadScenario_nextline(scn,line))
   {
      if (!strnicmp (line, "HUDCOLOR", 8))
      {
         sscanf (line+8, "%d",&HUDCOLOR);
      }
      if (!strnicmp (line, "GEAR", 4))
      {
         sscanf (line+4, "%d%lf", &gear_status, &gear_state);
      }
        if (!strnicmp (line, "FLIGHTCOMPUTER",14))
      {
         int i = 0;
         sscanf(line+14, "%d" ,&i);
         if (i == 0)
         {
            FlightComp = OFF;
         }
         else
         {
            FlightComp = ON;
         }
      }
      if (!strnicmp (line, " ",6))
      {
         Cam = 2;
         SetCameraDefaultDirection(_V(0,-1,0));
         SetCameraOffset (_V(0,-3.5,0.3));
      }
      if (!strnicmp (line, "BEACON",6))
      {
         beacon1.active = true;
      }
   
      else {
            ParseScenarioLineEx (line, vs);
         // unrecognised option - pass to Orbiter's generic parser
      }
   }
}
// ===============================================
// Save state to scn
// ===============================================
void LTV::clbkSaveState(FILEHANDLE scn)
{
   char cbuf[256];
   // Write default vessel parameters
   VESSEL2::clbkSaveState (scn);
   
   oapiWriteScenario_int(scn,"HUDCOLOR",HUDCOLOR);
 
   
   
   if (FlightComp == ON)
   {
       oapiWriteScenario_int (scn,"FLIGHTCOMPUTER",1);
   }

   if (Cam == 2)
   {
      oapiWriteScenario_string(scn,"CAMERA","");
   }
   if (beacon1.active == true)
   {
      oapiWriteScenario_string(scn,"BEACON","");
   }
   sprintf (cbuf, "%d %0.4f", gear_status, gear_state);
   oapiWriteScenario_string (scn, "GEAR", cbuf);
}


Ahhh, y a des smiley de partout ^^



Message modifié ( 26-02-2007 18:09 )

------------

no matter.

Offline tompouce

  • Legend
  • ******
  • Posts: 1214
  • Karma: 0
Reply #1 - 25 February 2007, 23:53:43
Moi si tu veux j'ai des alumettes pour ta lanterne :lol: désoler je ne connais rien au C++


___________________________________________________
electro ... orbiter... FAN



Offline Apofis

  • Sr. Member
  • ****
  • Posts: 349
  • Karma: 0
Reply #2 - 26 February 2007, 12:37:18
bon on va y aller tranquillou

le .h est comme une vitrine ou la liste que tu aurai collé sur ta boite a outil qui décris se que contient la boite. Tu y met
toutes tes variables globales(S'est mal a éviter s'est franchement mal vu ^^), tes constantes et 'entete de tes
méthodes(s'est  le therme pour les fonction d'une classe en c++) et celle de ta classe.

dans le .cpp en gros s'est se que contient ta vitrine ou ta boite a outil proprement dis. tu y as donc le code de tes méthodes.

exemple :

Quote

fichier toto.h

#include "orbitersdk.h" //pour avoir accés au sdk de orbiter

variable globale; //a éviter s'est plus propre de créer des variable a l'interieur de la classe elle même

const CONSTANTE_GLOBALE //on peu aussi avoir des constante globale

class toto : public VESSEL {

  const int NBRE_YEUX = 2; //constante propre de la classe toto

   bool heureux = true; //variable propre de la classe

   toto(OBJHANDLE hObj, int fmodel); //constructeur. doit etre obligatoirement ajoutée. cette méthode est abelée
automatiquement quand l'objet est crée
   ~toto(); //destructeur. po obligatoire mais fortement conseillé de déclarer surtout si tu fais des alocation de mémoire.
s'est oco que tu désaloue ta mémoire. est automatiquement appelé quand l'objet est détruit.

  void rendreMalheureux(void); //une méthode comme tant d'autre ^^

}; //ne po oublier le ; ou sa part en sucette :lol:

fichier toto.cpp

#include "toto.h" // on inclue toto.h pour avoir accés a l'en-tete

//on déclare le constructeur de cette maniere.
toto::toto(OBJHANDLE hObj, int fmodel) {

   heureux = true; //a chaque création d'un objet toto on dira que toto est heureux

}

//déclaration d'une méthode
void toto::rendreMalheureux(void){

   heureux = false;

}
 


comme tu as pu le remarqué j'ai écris toute mes constante en majuscule. en faite s'est uen convention d'écriture. comme sa tu
les repère tres vite et quand tu lis un code tu comprend plus facilement aussi.

voila si tu as des questions hesite po. Moi je te propose de tenter de séparer ton code et j'y jeterai volontier un coup
d'oeil apres. Rien de tel que d'essayer pour apprendre ;)



Message modifié ( 26-02-2007 12:39 )

"Oups c quoi se bruit" Fred Haise, apollo 13 :P

Offline no matter

  • Legend
  • ******
  • Posts: 2826
  • Karma: 1
Reply #3 - 26 February 2007, 14:21:47
Quote
bon on va y aller tranquillou
Entièrement d'accord!!
Merci pour ton aide, je vais essayer de m'y mettre doucement ;) . En effet, rien de tel pour apprendre que de s'y
mettre


------------

no matter.

Offline Apofis

  • Sr. Member
  • ****
  • Posts: 349
  • Karma: 0
Reply #4 - 26 February 2007, 14:23:22
Quote
no matter a écrit:
Quote
bon on va y aller tranquillou
Entièrement d'accord!!
Merci pour ton aide, je vais essayer de m'y mettre doucement ;) . En effet, rien de tel pour apprendre que de s'y
mettre


po de soucis et hesite po a demender si tu croche sur quelque chose


"Oups c quoi se bruit" Fred Haise, apollo 13 :P

Offline DanSteph

  • Administrator
  • Legend
  • *****
  • Posts: 15407
  • Karma: 256
  • Hein, quoi !?
    • FsPassengers
Reply #5 - 26 February 2007, 15:10:45
Désolé je fais doublont mais plus coté "pratique"

Dans ton cas tu prend tout ce qu'il y a avant les lignes:

" //======================================================
// LTV constructeur
//======================================================
"

Tu les coupes du cpp et tu les mets dans un fichier "h" exemple "ltv.h" que tu crée vide et inclu dans ton projet of
course.

Tout le reste tu le laisse dans le cpp que tu peut renommer "ltv.cpp" (si tu veux) Au début de ce fichier tu fait
un "#include "ltv.h" et c'est baché.

La ou ca devient réellement pratique (sinon c'est heuu baf ... juste plus joli) c'est quand tu te sert de ca pour
organiser tes fonctions entre different cpp... du coup tu n'a plus des listing de 3000 lignes ou tu t'emmerde a
rechercher une fonction mais plutôt different listing organisé a ton gout. un listing pour tout ce qui concerne
l'iitialisation, un autre pour la fonction "boucle principale" un autre pour load et save des scenarios etc etc...

navigation et lecture plus facile, projet mieux organisé= ecriture plus facile, moins de bug, bref, indispensable.

Dans ton cas on pourrait imaginer que tu va separer les fonctions de "save et load scenario" du listing principal.
Tu crée donc un "LoadSaveScenario.cpp" et tu coupe du listing principal de la ligne:

"// ==================================================
// Read state from scn
// =================================================="


Jusqu'a la fin et tu colle ces lignes dans ton nouveau cpp. Au debut tu "#include" ton fichier "ltv.h" et voila.
Les fonctions de "load save" sont dans un listing séparé, facile a retrouver et qui ne pollue pas d'autres listing.

Perso j'ai séparé l'initialisation dans un cpp (clbkSetClassCaps,DefineAnimations ,ovcexit, ovcinit etc etc) la fonctions
clavier dans un autre (clbkConsumeBufferedKey ),  boucle principale (clbkPostStep) etc etc

Ca donne ca pour le DGIV:




Si tu a des soucis, envoie moi le projet zippé en mail et je te le splitte.

En dernier je te suggere fortement de backuper tout ton folder qui contient le projet
si possible avec des backup incremental. Il arrive qu'on s'engage sur une voie boiteuse
et qu'on foute un projet en l'air (devoir refaire toute une partie est une bonne raison de laisser tomber)
Avec les backup incremental, facile de retrouver le projet a divers stades.

Exemple: tu zipe le folder et tu copie ce zip ailleurs , pour finir tu a des zip comme ca:

1_AvantIntegrationAnim.zip
2_AvantEssaiAnimation.zip
3_AnimOkOnCommenceLeComputer.zip

Pour fspassengers j'ai fini avec 400 sauvegardes, je ne l'ai jamais regretté.

A++

Dan



Message modifié ( 26-02-2007 15:17 )

« Last Edit: 26 February 2007, 17:21:03 by DanSteph »

Offline no matter

  • Legend
  • ******
  • Posts: 2826
  • Karma: 1
Reply #6 - 26 February 2007, 17:02:57
Il me vient tout de suite une question:
J'utilise Crimson Editor (malheureusement car je n'ai rien d'autre) pour compiler et je ne sais pas si je peux utiliser une structure avec plusieurs .cpp ?
Pour le reste, je pense avoir saisi le but et la méthode ;)

EDIT: je viens de splitter mon LTV.cpp vers LTV.cpp et LTV.h, çà compile OK ;)



Message modifié ( 26-02-2007 17:07 )

« Last Edit: 26 February 2007, 17:21:03 by no matter »
------------

no matter.

Offline Apofis

  • Sr. Member
  • ****
  • Posts: 349
  • Karma: 0
Reply #7 - 26 February 2007, 17:10:18
Quote
no matter a écrit:
Il me vient tout de suite une question:
J'utilise Crimson Editor (malheureusement car je n'ai rien d'autre) pour compiler et je ne sais pas si je peux utiliser une
structure avec plusieurs .cpp ?
Pour le reste, je pense avoir saisi le but et la méthode ;)

EDIT: je viens de splitter mon LTV.cpp vers LTV.cpp et LTV.h, çà compile OK ;)

tu peu télécharger VISUAL C++  version express il est gratuit et tu aura la platforme la plus utilisée et tu pourra avoir la
jolie liste de cpp comme dan ;)


« Last Edit: 26 February 2007, 17:21:03 by Apofis »
"Oups c quoi se bruit" Fred Haise, apollo 13 :P

Offline no matter

  • Legend
  • ******
  • Posts: 2826
  • Karma: 1
Reply #8 - 26 February 2007, 17:21:03
Oui, merci, j'étais justement en train de regarder la page de téléchargement chez microsoft. Je vois ce qu'il me reste à
faire! Je vais récupérer l'iso pour graver le cd (ahhh, 470Mo...>_<).


« Last Edit: 26 February 2007, 17:21:03 by no matter »
------------

no matter.