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!!]Animation en C++[résolu]  (Read 3133 times)

0 Members and 1 Guest are viewing this topic.

Offline no matter

  • Legend
  • ******
  • Posts: 2826
  • Karma: 1
19 February 2007, 19:36:22
Que dire de plus, sinon que mes animations ne fonctionnent toujours pas!
Il y a sans doute quelquechose que je n'ai toujours pas compris mais je ne vois pas vraiment quoi.

Je me suis inspiré (ou plutôt j'ai copié! :siffle: ) du code source du XB982 de Korben pour les anims mais bien que
l'état del'animation soit bien écrit et sans doute lu dans le fichier .scn, l'animation en elle-même ne donne aucun autre
résultat, les groupes ne bougent pas.

Voici l'intégralité du code source (désolé c'est long):
du reste pas de fichier .h, tout est dans le cpp (c'est la première fois que je travaille ainsi et c'est peut-être une
mauvaise idée, je n'en sais rien...)
Quote

#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.25,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[22] =
{240,239,238,115,114,113,112,111,110,109,108,107,106,105,104,103,102,101,100,99,98,97};
   static MGROUP_ROTATE P1 (0, P1grp, 22, _V(0, -1.2, 1.7), _V(1,0,0), 50*RAD);
   //static UINT P2grp[0] = {27,28,35,36,37,38};
   //static MGROUP_ROTATE P2 (0, P2grp, 6, _V(0,0,0), _V(0,0,1), (float)(175.5*RAD));
   //static UINT P3grp[0] = {29,30};
   //static MGROUP_ROTATE P3 (0, P3grp, 2, _V(0,0,0), _V(0,0,1), (float)(35.5*RAD));
   //static UINT P4grp[0] = {27,28};
   //static MGROUP_ROTATE P4 (0, P4grp, 2,   _V(0,0,0), _V(1,0,0), (float)(-35.5*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.25,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));
   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.411765, 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);

}

// ==============================================================
// 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) pour plus tard...
            RevertGear();
         }
         return 1;      // pas sûr du 1, true? çà ne change rien quant au résultat     

      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.25,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);
}


Je suis ouvert à toute critique, correction ou indication, merci d'avance ;)



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

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

no matter.

Offline laserpithium

  • Legend
  • ******
  • Posts: 1473
  • Karma: 0
Reply #1 - 19 February 2007, 19:46:29
Pas le temps ce soir, mais je me penche demain sur ton problème sans faute.



La sagesse me cours après, mais je suis plus rapide
Si Dieu existe, butons-le !

Offline no matter

  • Legend
  • ******
  • Posts: 2826
  • Karma: 1
Reply #2 - 19 February 2007, 19:55:52
Merci ;)


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

no matter.

Offline Apofis

  • Sr. Member
  • ****
  • Posts: 349
  • Karma: 0
Reply #3 - 20 February 2007, 01:36:58
Quote
no matter a écrit:

du reste pas de fichier .h, tout est dans le cpp (c'est la première fois que je travaille ainsi et c'est peut-être une
mauvaise idée, je n'en sais rien...)


effectivement pour etre dans la règle de l'art il te faudrai un .h. On va dire que s'est plus propre et surtout plus lisible
apres (une fois que tu as bien oublié quoi est ou dans ton code) pour des éventuelles release.

une derniere chose hesite po a commenter plus ton code tu verra sa rend toujours service ^^( un commentaire c apres les // ou
tu as aussit les 2 balises : ouverture /* et fermeture */. en principe tu utilise la premiere facon si tu as juste une ligne
de commentaire et la 2ème pour de long commentaitre type entete de ton code)

maintenant pour ton soucis j'ai fais 4 jours de carnaval la suis po trop en état mais si laser trouve po j'y jeterai un oeil
a tete reposée ^^


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

Offline DanSteph

  • Administrator
  • Legend
  • *****
  • Posts: 15407
  • Karma: 256
  • Hein, quoi !?
    • FsPassengers
Reply #4 - 20 February 2007, 11:53:16
Premiere chose que je vois, ta fonction "DefineAnimations" n'est appellée a aucun moment du code,elle est
declarée
dans la classe mais jamais appellée donc jamais executée.

Ecrit a la fin de la fonction "clbkSetClassCaps" après "AddBeacon (&beacon2);"

comme cela:

   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();



Je rappelle en passant qu'on peut tout a fait executer le code de son vessel en mode debug
donc pas a pas, en mettant un breakpoint (f9) sur une ligne tu aurais vu que le code n'était
pas appellé. C'est assez peut connu vu qu'on crée une dll et pas un exe mais bougrement utile
voir indispensable quand le code devient toufu.

Si tu a besoin d'aide n'hésite pas... pour spliter ton projet en h et divers cpp par exemple...
tu m'envoie en mail et je te retourne le tout bien organisé. (un truc simple comme ca je
peut le faire rapidement)

Dan



Message modifié ( 20-02-2007 14:47 )


Offline MartySpaceLines

  • Legend
  • ******
  • Posts: 1096
  • Karma: 0
Reply #5 - 20 February 2007, 13:12:40
Quote
Apofis a écrit:
j'ai fais 4 jours de carnaval

lequel?


@++

MSL  


Offline no matter

  • Legend
  • ******
  • Posts: 2826
  • Karma: 1
Reply #6 - 20 February 2007, 15:12:24
Bien, merci pour tout les conseils et merci Dan pour le DefineAnimation() (au fait, comment vas ta jambe?)

Quote
Si tu a besoin d'aide n'hésite pas... pour spliter ton projet en h et divers cpp par exemple...
tu m'envoie en mail et je te retourne le tout bien organisé. (un truc simple comme ca je
peut le faire rapidement)
C'est pas tombé dans l'oreille d'un sourd ;) mais je préfère pas trop te harceler en ce moment!
Pour les breakpoint,

Je dois bien avouer que pour passer du simple "Hello world" à une dll pour Orbiter, il y a quand même un sacré pas à
franchir :)


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

no matter.

Offline no matter

  • Legend
  • ******
  • Posts: 2826
  • Karma: 1
Reply #7 - 20 February 2007, 15:26:34
Oh mon dieu!!! Çà MARCHE!!! Rahh, tu as quand même un sacré coup d'oeil Dan!


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

no matter.

Offline laserpithium

  • Legend
  • ******
  • Posts: 1473
  • Karma: 0
Reply #8 - 20 February 2007, 16:08:04
Bon, il semble donc que j'arrive après la bataille.
Content que ça marche !

Dan, tu peux expliquer comment tu fais pour mettre des breakpoints dans le code (je veux dire à pars "appuyer sur F9"), et en
particulier comment tu passes le breakpoint lors de l'éxécution ?

Si seulement j'avais su que l'on pouvait mettre des breakpoints dans une DLL !!!



La sagesse me cours après, mais je suis plus rapide
Si Dieu existe, butons-le !

Offline DanSteph

  • Administrator
  • Legend
  • *****
  • Posts: 15407
  • Karma: 256
  • Hein, quoi !?
    • FsPassengers
Reply #9 - 20 February 2007, 18:00:24
C'est peut connu mais indispensable pour de grand projet ou se sortir facilement
des problèmes de code.

Avec Vs2005:

Project->Properties (alt-f7)
Debugging

Et tu rentre l'executable qui va faire tourner ta dll (orbiter.exe)
et le chemin



Une fois fait il suffit de lancer avec F5 après avoir placé des breakpoint
ca va lancer Orbiter, tu choisi le scenario comme d'hab et hop ca s'arrette
la ou tu a mis les breakpoints tu peut faire tourner pas a pas (f10/f11) et
voir toutes les valeurs des variables.

Tu peut aussi mettre des breakpoint conditionel etc etc...

Ca marche avec tout y compris par exemple Flight sim et une dll addon
hyper utile donc.

Of course faut compiler en debug avec database... c'est standard ca
de toute facon pour le debug.

EDIT:

un exemple, un breakpoint/execution dans la fonction "LoadSavescenario.cpp"
apres lancement orbiter s'arette sur la ligne du breakpoint

ATTENTION ORBITER TOUJOURS EN MODE FENETRE SINON IL
RESTE EN PLEIN ECRAN AU BREAK (et hop redemaragge du pc, aucun moyen d'en sortir
(enfin si mais c'est pas garanti, alt-tab pour focuser sur VS05 et F5 pour
continuer l'execution mais du coup ca a servi a rien)




En faisant F10 on execute chaque ligne (sans rentrer dans les sous fonction, on peut executer
les sous fonction avec F11) En bas on vois les variable locale ou auto (contextuelle), on peut
aussi en ajouter dans "watch" comme par exemple des globales. A noter qu'on peut modifier
les variables en double cliquant a droite sur la valeurs.
En faisant "+" sur les typedef (ex: SYS) on peut voir toutes les variables contenue dans ce type.
En faisant F5 on relance l'execution normale et hop Orbiter s'execute de nouveau normalement
jusqu'au prochain breakpoint.

Quand on veut aller plus loins comme par exemple hacker un truc (dans le bon sens du terme "rajouter des fonctionnalité" "obtenir plus que permis") on peut faire un watch de la mémoire, afficher le code ASM la on rentre dans le core de la prog avec hexa, assembleur etc etc. Ca c'est surtout utile pour des SDK très limitée comme FS, avec orbiter pas besoin la SDK est :top: .

Dan



Message modifié ( 20-02-2007 18:38 )


Offline DanSteph

  • Administrator
  • Legend
  • *****
  • Posts: 15407
  • Karma: 256
  • Hein, quoi !?
    • FsPassengers
Reply #10 - 20 February 2007, 18:04:32
Quote
no matter a écrit:
Je dois bien avouer que pour passer du simple "Hello world" à une dll pour Orbiter, il y a quand même un
sacré pas à franchir :)


Vu le boulot fait sur vos addons avec well ca va venir vite à mon avis,
le bon plis c'est de faire et de savoir ou chercher les infos...
Finalement la prog c'est que de gros fichier config ;) (oui bon)

A la clé contrôle total de vos addons avec des possibilités pratiquement infinie

Hésite pas a poser toutes les questions que tu veux dans le forum
sur la prog, même si elles te semblent idiote, ca me fait toujours plaisir d'aider.
Dan



Message modifié ( 20-02-2007 18:39 )


Offline Apofis

  • Sr. Member
  • ****
  • Posts: 349
  • Karma: 0
Reply #11 - 20 February 2007, 18:38:41
Quote
MartySpaceLines a écrit:
Quote
Apofis a écrit:
j'ai fais 4 jours de carnaval

lequel?


Monthey biensur!!! le meilleur carna du monde entier (enfin c chez moi quoi :) ) :lol:

et samedi j'etais à Sion. sympas mais trop grand 32 guggen sa fais trop a mon gouts

enfin vivement l'année prochaine :friend::friend::friend::friend:


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

Offline brainstorm

  • Legend
  • ******
  • Posts: 2694
  • Karma: 0
Reply #12 - 20 February 2007, 22:30:11
Super le coup des breakpoints ! ;) Je me doutais que c'était faisable, mais aucune idée sur la façon de faire ... ;)


« Last Edit: 20 February 2007, 22:30:11 by brainstorm »