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: [Question C++] créer des animations pour un vaisseau  (Read 4184 times)

0 Members and 1 Guest are viewing this topic.

Offline ea76620

  • Sr. Member
  • ****
  • Posts: 393
  • Country: France fr
  • Karma: 15
06 December 2011, 00:48:51
Bonjour,

Je me suis lancé dans la création d'un module de station spatiale (compatible UMMU donc forcément en créant un module en c++).

J'ai réussis à m'en sortir avec les moteurs et les docks mais je n'ai pas réussis à faire des animations (pour les panneaux solaire).
J'ai regarder dans la doc d'orbiter, les exemples de projet et également sur google mais je n'ai pas compris grand chose à ce sujet.

Donc la question est: comment je dois faire ceci?

Merci d'avance

Au revoir



Message modifié ( 06-12-2011 00:52 )


Offline Bibi Uncle

  • Legend
  • ******
  • Posts: 2264
  • Country: Canada ca
  • Karma: 17
Reply #1 - 06 December 2011, 02:08:25
Premièrement, le group que tu souhaites animer doit être séparé dans ton fichier MSH. Ensuite dans le constructeur du vaisseau, tu dois définir les animations (tu peux créer une fonction pour ça).

Pour définir les animations, tu doit créer une animation. Pour ça, utilise la fonction CreateAnimation. Passe-lui 0.0 comme paramètre. Dans cette animation, tu peux avoir plusieurs sous-animation. Par exemple, l'ouverture d'une soute pourrait avoir 2 panneaux à animer. Les sous-animations sont créer avec les classes MGROUP_ROTATE, MGROUP_TANSLATE et MGROUP_SCALE, qui représente une rotation, une translation et un agrandissement respectivement.

Prenons l'exemple d'une rotation. Le code ressembleras à ceci :
Code: [Select]
void Vessel::Vessel()
{
anim_gear = CreateAnimation (0.0); // création de l'animation

static UINT groups[4] = {5,6,10,11}; // groupes participants
static MGROUP_ROTATE nosewheel (
0, // index du mesh
groups, 4, // groupes participants et leur nombre
_V(0,-1.0,8.5), // centre de rotation
_V(1,0,0), // axe de rotation
(float)(0.5*PI) // portée de la rotation
);
AddAnimationComponent (
anim_gear // l'identificateur d'animation
0, // début de la sous-animation dans l'animation principale
1, // fin de la sous-animation
&nosewheel); // classe de sous-animation
}
Ensuite, durant chaque frame, tu dois mettre à jour tes animations. Pour ça, tu calcules où devrait se trouver l'animation (0 est le début, 1 est la fin), et tu devras appeler la fonction SetAnimation en lui spécifiant l'animation et le point où elle est rendue.

En général, durant le callback de chaque frame, tu prends le temps écoulé, tu le multiplie avec ta vitesse d'animation et tu l'additionne avec la position précédente. Comme ça, l'animation est fluide. Tu peux soustraire si tu veux faire l'animation inverse. Attention ! La variable que tu envoies à SetAnimation ne doit pas être inférieure à 0 ou supérieure à 1. Quand tu additionnes ou soustrait, fais une condition du genre :
Code: [Select]
if(gear_proc < 0.0)
{
gear_proc = 0.0;
}
et une autre pour tester la supériorité à 1.

Si une partie a besoin d'éclaircissement, n'hésite pas ! ;)



Message modifié ( 06-12-2011 02:08 )

Émile

Pluton, Saturne et Jupiter
Entendez-vous monter vers vous le chant de la Terre?

- Luc Plamondon

Offline ea76620

  • Sr. Member
  • ****
  • Posts: 393
  • Country: France fr
  • Karma: 15
Reply #2 - 06 December 2011, 07:46:11
Bonjour,

Quote
Premièrement, le group que tu souhaites animer doit être séparé dans ton fichier MSH.


C'est à dire que je doit faire plusieurs MSH?

J'ai commencer à mettre ça mais j'ai plusieurs truc qui sont soulignés (je les ,ai soulignés en noir):

Code: [Select]
[u]void[/u] SD_st_module_1::[u]SD_st_module_1[/u]()
{
[u]anim_gear[/u] = CreateAnimation (0.0); // création de l'animation

static UINT groups[4] = {5,6,10,11}; // groupes participants
static MGROUP_ROTATE nosewheel (
0, // index du mesh
groups, 4, // groupes participants et leur nombre
_V(0,-1.0,8.5), // centre de rotation
_V(1,0,0), // axe de rotation
(float)(0.5*PI) // portée de la rotation
);
AddAnimationComponent (
anim_gear // l'identificateur d'animation
0, // début de la sous-animation dans l'animation principale
1, // fin de la sous-animation
&nosewheel); // classe de sous-animation
}

[u]if[/u](gear_proc <; 0.0)
{
gear_proc = 0.0;
}

if(gear_proc <; 1.0)
{
gear_proc = 1.0;
}



et voici la liste des erreur:

Quote
1>------ Début de la génération : Projet : Sandersmodule1, Configuration : Release Win32 ------
1>  Sandersmodule1.cpp
1>Sandersmodule1.cpp(343): error C2533: 'SD_st_module_1::{ctor}' : type de retour non autorisé pour les constructeurs
1>Sandersmodule1.cpp(343): error C2511: 'SD_st_module_1::SD_st_module_1(void)' : impossible de trouver la fonction membre surchargée dans 'SD_st_module_1'
1>          Sandersmodule1.cpp(69) : voir la déclaration de 'SD_st_module_1'
1>Sandersmodule1.cpp(361): error C2059: erreur de syntaxe : 'if'
1>Sandersmodule1.cpp(361): error C2143: erreur de syntaxe : absence de ')' avant ';'
1>Sandersmodule1.cpp(361): error C2059: erreur de syntaxe : 'constant'
1>Sandersmodule1.cpp(361): error C2059: erreur de syntaxe : ')'
1>Sandersmodule1.cpp(362): error C2143: erreur de syntaxe : absence de ';' avant '{'
1>Sandersmodule1.cpp(362): error C2447: '{' : en-tête de fonction manquant (liste formelle à l'ancien format ?)
1>Sandersmodule1.cpp(366): error C2059: erreur de syntaxe : 'if'
1>Sandersmodule1.cpp(366): error C2143: erreur de syntaxe : absence de ')' avant ';'
1>Sandersmodule1.cpp(366): error C2059: erreur de syntaxe : 'constant'
1>Sandersmodule1.cpp(366): error C2059: erreur de syntaxe : ')'
1>Sandersmodule1.cpp(367): error C2143: erreur de syntaxe : absence de ';' avant '{'
1>Sandersmodule1.cpp(367): error C2447: '{' : en-tête de fonction manquant (liste formelle à l'ancien format ?)
1>Sandersmodule1.cpp(372): error C2059: erreur de syntaxe : 'for'
1>Sandersmodule1.cpp(372): error C2143: erreur de syntaxe : absence de ')' avant ';'
1>Sandersmodule1.cpp(372): error C2143: erreur de syntaxe : absence de ';' avant '<'
1>Sandersmodule1.cpp(372): error C4430: spécificateur de type manquant - int est pris en compte par défaut. Remarque : C++ ne prend pas en charge int par défaut
1>Sandersmodule1.cpp(372): error C2086: 'int anim_gear' : redéfinition
1>          Sandersmodule1.cpp(371) : voir la déclaration de 'anim_gear'
1>Sandersmodule1.cpp(372): error C2143: erreur de syntaxe : absence de ';' avant '++'
1>Sandersmodule1.cpp(372): error C4430: spécificateur de type manquant - int est pris en compte par défaut. Remarque : C++ ne prend pas en charge int par défaut
1>Sandersmodule1.cpp(372): error C2086: 'int anim_gear' : redéfinition
1>          Sandersmodule1.cpp(371) : voir la déclaration de 'anim_gear'
1>Sandersmodule1.cpp(372): error C2059: erreur de syntaxe : ')'
1>Sandersmodule1.cpp(382): error C2143: erreur de syntaxe : absence de ';' avant '{'
1>Sandersmodule1.cpp(382): error C2447: '{' : en-tête de fonction manquant (liste formelle à l'ancien format ?)
========== Génération : 0 a réussi, 1 a échoué, 0 mis à jour, 0 a été ignoré ==========


Il y a donc un truc qu'il faut faire et que je n'ai pas fait mais je ne vois pas quoi.


Je débute en c++ depuis 2 jours et je ne sais pas comment déclarer une fonction.


Merci d'avance

Au revoir



Message modifié ( 06-12-2011 20:06 )


Offline ea76620

  • Sr. Member
  • ****
  • Posts: 393
  • Country: France fr
  • Karma: 15
Reply #3 - 07 December 2011, 01:20:22
Bonjour,

J'ai peut être trouver de l'inspiration dans les samples de l'HST d'orbiter pour l'instant j'ai réussis à ce qu'il n'y ai pas de trait rouge.

je verrai la suite demain (enfin cette après midi vu l'heure :) :) :) ).

Au revoir



Message modifié ( 07-12-2011 01:24 )


Offline ea76620

  • Sr. Member
  • ****
  • Posts: 393
  • Country: France fr
  • Karma: 15
Reply #4 - 07 December 2011, 22:04:15
Bonjour,

Avec l'aide des source du HST (Hubble Space Telescope) j'ai réussis à définir des animations mais y a un gros problème:

la partie principale du vaisseau bouge en même temps que un de mes panneaux solaires

j'ai regarder dans le paramétrage des animations et je ne vois pas ce que ça pourrait être...

J'ai testé divers paramètre aucun changement (mis à part que une fois ça a fait une translation du corps du vaisseau avec ce même panneau).


Si quelqu'un pourrait m'apporter de l'aide ça m'arrangerait.

Edit: j'ai une info supplémentaire sur le problème:

J'ai essayer en mettant d'autre numéros de groupe quelconque pour les animations ceux ci bien sur tournait mais la parti qui tourne avec l'un des panneaux solaire aussi.


Merci d'avance

Au revoir



Message modifié ( 07-12-2011 22:47 )


Offline jacquesmomo

  • Le budget !!!
  • Legend
  • ******
  • Posts: 7408
  • Country: France fr
  • Karma: 598
  • Plus on rate, plus on a de chances de réussir !..
Reply #5 - 07 December 2011, 22:32:49
Quote
ea76620 a écrit:
C'est à dire que je doit faire plusieurs MSH?
Non, mais dans le fichier.msh les formes 3D sont dans des groupes.

Edite un fichier.msh avec bloc note et tu comprendras...

En tout cas je te souhaite bon courage, car ce qu'explique Bibi Uncle c'est surement du basique...
donc faut passer du temps! (pour moi, c'est pas encore le jour... on verra dans l'avenir peut-être)


Mes add-ons sont là !

Offline Bibi Uncle

  • Legend
  • ******
  • Posts: 2264
  • Country: Canada ca
  • Karma: 17
Reply #6 - 07 December 2011, 22:53:05
C'est bien que tu ais réussi à progresser comment ça tout seul. Ça l'habitue à regarder des exemples des autres.

Pour le corps qui bouge en même temps, peut-être le panneau solaire est dans le même groupe que le corps ?


Émile

Pluton, Saturne et Jupiter
Entendez-vous monter vers vous le chant de la Terre?

- Luc Plamondon

Offline ea76620

  • Sr. Member
  • ****
  • Posts: 393
  • Country: France fr
  • Karma: 15
Reply #7 - 07 December 2011, 22:58:18
Le problème en image:







ça fait bizarre quand même :)

Si vous voulez voir le fichier source n’hésitez pas à demander



Message modifié ( 07-12-2011 23:00 )


Offline ea76620

  • Sr. Member
  • ****
  • Posts: 393
  • Country: France fr
  • Karma: 15
Reply #8 - 07 December 2011, 23:07:23
Quote
Bibi Uncle a écrit:
C'est bien que tu ais réussi à progresser comment ça tout seul. Ça l'habitue à regarder des exemples des autres.

Pour le corps qui bouge en même temps, peut-être le panneau solaire est dans le même groupe que le corps ?


Les groupes je doit les définir avec le logiciel 3D (anim8tor) ? ou dans le .msh (la je ne sais pas faire)?

ça me semble bizarre car j'avais essayer de mettre d'autre groupes à la place des panneaux (je voulait justement vérifier si le le corps n'était pas "lier" avec l'un d'eux) et il bougeait quand même.

Je vais quand même refaire les groupes dans anim8tor on ne sais jamais

Merci d'avoir répondu



Message modifié ( 07-12-2011 23:09 )


Offline DanSteph

  • Administrator
  • Legend
  • *****
  • Posts: 15407
  • Karma: 256
  • Hein, quoi !?
    • FsPassengers
Reply #9 - 07 December 2011, 23:11:46
C'est vachement bien de t'être dépatouillé tout seul, 90% des gens abandonnent déjà avant ce stade :badsmile:

Le problème peut avoir plusieurs sources, peux-tu poster le code ? (Mais plus vraisemblablement pas le bon numéro de groupe de mesh)

Un truc à savoir quand même : j'utilise perso un utilitaire 3dmax qui m'exporte aussi un fichier C++ de définition de groupe.
Comme les animations sont reconnues par numéro de groupe (place dans le mesh) un petit édit du mesh et hop ! Toutes tes anims sont nazes (genre ton image) et tu te retape tout les no à la main. Avec l'utilitaire un petit F5 pour recompiler et c'est bon.

Si tu compte pas toucher le mesh c'est pas grave mais si tu bosse dessus il te faut un tel utilitaire.

A++

Dan



Message modifié ( 07-12-2011 23:15 )


Offline ea76620

  • Sr. Member
  • ****
  • Posts: 393
  • Country: France fr
  • Karma: 15
Reply #10 - 07 December 2011, 23:27:35
Voila les codes:


SDmodule1.cpp:

Quote
// ==============================================================
//                    ORBITER MODULE: HST
//                  Part of the ORBITER SDK
//          Copyright (C) 2001-2007 Martin Schweiger
//                   All rights reserved
//
// HST.cpp
// HST basic specs and animations
//
// HST mesh and textures by David Sundstrom
// ==============================================================


#define ORBITER_MODULE

#include "SDmodule1.h"
#include

// ==============================================================
// HST class implementation
// ==============================================================


// --------------------------------------------------------------
// Constructor
// --------------------------------------------------------------

SDmodule1::SDmodule1 (OBJHANDLE hObj, int fmodel)
: VESSEL2 (hObj, fmodel)
{
   ant_proc = 0.0;
   ant_status = DOOR_CLOSED;
   hatch_proc = 0.0;
   hatch_status = DOOR_CLOSED;
   array_proc = 1.0;
   array_status = DOOR_OPEN;
   DefineAnimations ();
}

// --------------------------------------------------------------
// Define animation sequences for moving parts
// --------------------------------------------------------------

void SDmodule1::DefineAnimations (void)
{
   // 1. Hi-gain antenna
   //static UINT HiGainAnt1Grp[2] = {1,3};
   //static MGROUP_ROTATE HiGainAnt1 (0, HiGainAnt1Grp, 2, _V(0.002579,1.993670,0.238158), _V(-1,0,0), (float)(PI*0.51));
   //static UINT HiGainAnt2Grp[2] = {0,2};
   //static MGROUP_ROTATE HiGainAnt2 (0, HiGainAnt2Grp, 2, _V(0.002740,-2.013091,0.238118), _V(1,0,0), (float)(PI*0.51));
   //anim_ant = CreateAnimation (0.0196);
   //AddAnimationComponent (anim_ant, 0, 0.5, &HiGainAnt1);
   //AddAnimationComponent (anim_ant, 0, 1,   &HiGainAnt2);

   // 2. Main telescope hatch
   //static UINT HatchGrp[1] = {86};
   //static MGROUP_ROTATE Hatch (0, HatchGrp, 1, _V(0.089688,1.456229,7.526453), _V(-1,0,0), (float)(RAD*113));
   //anim_hatch = CreateAnimation (0);
   //AddAnimationComponent (anim_hatch, 0, 1, &Hatch);

   // 3. Solar arrays - folding

   anim_array = CreateAnimation (2);
   static UINT ArrayLFoldGrp[1] = {4};
   static UINT ArrayRFoldGrp[2] = {3};
   static MGROUP_ROTATE ArrayLFold1 (0, ArrayLFoldGrp, 1, _V(-1.75,0, 2), _V(0, 1,0), (float)(-PI*0.5));
   AddAnimationComponent (anim_array, 0.6, 1, &ArrayLFold1);
   static MGROUP_ROTATE ArrayRFold2 (0, ArrayRFoldGrp, 2, _V( 1.75,0, 2), _V(0, 1,0), (float)(PI*0.5));
   AddAnimationComponent (anim_array, 0.6, 1, &ArrayRFold2);
   //static MGROUP_SCALE  ArrayLFold3 (0, ArrayLFoldGrp, 4, _V(0,0.053583,1.429349), _V(1,1,4));
   //AddAnimationComponent (anim_array, 0.6, 1,   &ArrayLFold3);
   //static MGROUP_ROTATE ArrayRFold1 (0, ArrayRFoldGrp, 5, _V( 1.9, 0.053583,1.429349), _V(0, 1,0), (float)(PI*0.5));
   //AddAnimationComponent (anim_array, 0,   0.4, &ArrayRFold1);
   //static MGROUP_ROTATE ArrayRFold2 (0, ArrayRFoldGrp, 5, _V(0,0.053583,1.429349), _V(-1,0,0), (float)(PI*0.5));
   //AddAnimationComponent (anim_array, 0.4, 0.6, &ArrayRFold2);
   //static MGROUP_SCALE  ArrayRFold3 (0, ArrayRFoldGrp, 4, _V(0,0.053583,1.429349), _V(1,1,4));
   //AddAnimationComponent (anim_array, 0.6, 1,   &ArrayRFold3);

}

//void SDmodule1::ActivateAntenna (DoorStatus action)
//{
//   ant_status = action;
//}

//void SDmodule1::RevertAntenna (void)
//{
//   ActivateAntenna ((ant_status == DOOR_CLOSED || ant_status == DOOR_CLOSING) ?
//      DOOR_OPENING : DOOR_CLOSING);
//}

//void SDmodule1::ActivateHatch (DoorStatus action)
//{
//   hatch_status = action;
//}

//void SDmodule1::RevertHatch (void)
//{
//   ActivateHatch ((hatch_status == DOOR_CLOSED || hatch_status == DOOR_CLOSING) ?
//      DOOR_OPENING : DOOR_CLOSING);
//}

void SDmodule1::ActivateArray (DoorStatus action)
{
   array_status = action;
}

void SDmodule1::RevertArray (void)
{
   ActivateArray ((array_status == DOOR_CLOSED || array_status == DOOR_CLOSING) ?
      DOOR_OPENING : DOOR_CLOSING);
}

// ==============================================================
// Overloaded callback functions
// ==============================================================

// --------------------------------------------------------------
// Set vessel class parameters
// --------------------------------------------------------------

void SDmodule1::clbkSetClassCaps (FILEHANDLE cfg)
{
   THRUSTER_HANDLE th_main[2], th_hover, th_rcs[14], th_group[4];

   SetSize (PB_SIZE);
   SetEmptyMass (PB_EMPTYMASS);
   SetPMI (PB_PMI);
   SetCrossSections (PB_CS);
   SetRotDrag (PB_RD);

   // docking port definitions
   SetDockParams (PB_DOCK_POS, PB_DOCK_DIR, PB_DOCK_ROT);

   // propellant resources
   PROPELLANT_HANDLE hpr = CreatePropellantResource (PB_FUELMASS);

   // main engine
   th_main[0] = CreateThruster (_V(-1.38,0,-2.15), _V(0,0,1), PB_MAXMAINTH, hpr, PB_ISP);
   th_main[1] = CreateThruster (_V(1.38,0,-2.15), _V(0,0,1), PB_MAXMAINTH, hpr, PB_ISP);
   th_group[0] = th_main[0];
   th_group[1] = th_main[1];
   CreateThrusterGroup (th_main, 2, THGROUP_MAIN);
   AddExhaust (th_main[0], 1, 0.15, _V(-1.38,0,-2.15), _V(0,0,-1));
   AddExhaust (th_main[1], 1, 0.15, _V(1.38,0,-2.15), _V(0,0,-1));

   PARTICLESTREAMSPEC contrail_main = {
      0, 5.0, 16, 200, 0.15, 1.0, 5, 3.0, PARTICLESTREAMSPEC::DIFFUSE,
      PARTICLESTREAMSPEC::LVL_PSQRT, 0, 2,
      PARTICLESTREAMSPEC::ATM_PLOG, 1e-4, 1
   };
   PARTICLESTREAMSPEC exhaust_main = {
      0, 2.0, 20, 200, 0.05, 0.1, 8, 1.0, PARTICLESTREAMSPEC::EMISSIVE,
      PARTICLESTREAMSPEC::LVL_SQRT, 0, 1,
      PARTICLESTREAMSPEC::ATM_PLOG, 1e-5, 0.1
   };
   AddExhaustStream (th_main, _V(0,0.3,-10), &contrail_main);
   AddExhaustStream (th_main, _V(0,0.3,-5), &exhaust_main);

   // hover engine
   th_hover = CreateThruster (_V(0,-1.5,0), _V(0,1,0), PB_MAXHOVERTH, hpr, PB_ISP);
   CreateThrusterGroup (&th_hover, 1, THGROUP_HOVER);
   //AddExhaust (th_hover, 8, 1, _V(0,-1.5,1), _V(0,-1,0));
   //AddExhaust (th_hover, 8, 1, _V(0,-1.5,-1), _V(0,-1,0));


   //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
   //};
   //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
   //};

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

   // RCS engines

   th_rcs[ 0] = CreateThruster (_V(-0.850, 1.15,-2), _V(0,-1,0), PB_MAXRCSTH, hpr, PB_ISP);
   th_rcs[ 1] = CreateThruster (_V(-0.850, 1.15, 2), _V(0,-1,0), PB_MAXRCSTH, hpr, PB_ISP);
   th_rcs[ 2] = CreateThruster (_V( 0.850, 1.15,-2), _V(0,-1,0), PB_MAXRCSTH, hpr, PB_ISP);
   th_rcs[ 3] = CreateThruster (_V( 0.850, 1.15, 2), _V(0,-1,0), PB_MAXRCSTH, hpr, PB_ISP);
   th_rcs[ 4] = CreateThruster (_V(-0.850,-1.15,-2), _V(0, 1,0), PB_MAXRCSTH, hpr, PB_ISP);
   th_rcs[ 5] = CreateThruster (_V(-0.850,-1.15, 2), _V(0, 1,0), PB_MAXRCSTH, hpr, PB_ISP);
   th_rcs[ 6] = CreateThruster (_V( 0.850,-1.15,-2), _V(0, 1,0), PB_MAXRCSTH, hpr, PB_ISP);
   th_rcs[ 7] = CreateThruster (_V( 0.850,-1.15, 2), _V(0, 1,0), PB_MAXRCSTH, hpr, PB_ISP);
   th_rcs[ 8] = CreateThruster (_V(-0.850, 1, 2.15), _V(0,0,-1), PB_MAXRCSTH, hpr, PB_ISP);
   th_rcs[ 9] = CreateThruster (_V( 0.850,-1, 2.15), _V(0,0,-1), PB_MAXRCSTH, hpr, PB_ISP);
   th_rcs[10] = CreateThruster (_V(-1, 1, 2), _V( 1,0,0), PB_MAXRCSTH, hpr, PB_ISP);
   th_rcs[11] = CreateThruster (_V( 1, 1, 2), _V(-1,0,0), PB_MAXRCSTH, hpr, PB_ISP);
   th_rcs[12] = CreateThruster (_V(-1,-1,-2), _V( 1,0,0), PB_MAXRCSTH, hpr, PB_ISP);
   th_rcs[13] = CreateThruster (_V( 1,-1,-2), _V(-1,0,0), PB_MAXRCSTH, hpr, PB_ISP);
   th_rcs[14] = CreateThruster (_V(0,0,-3.15), _V(0,0, 1), PB_MAXRCSTH, hpr, PB_ISP);

   AddExhaust (th_rcs[ 0], 0.4, 0.2, _V(-0.850, 1.15,-2), _V(0,-1,0));
   AddExhaust (th_rcs[ 1], 0.4, 0.2, _V(-0.850, 1.15, 2), _V(0,-1,0));
   AddExhaust (th_rcs[ 2], 0.4, 0.2, _V( 0.850, 1.15,-2), _V(0,-1,0));
   AddExhaust (th_rcs[ 3], 0.4, 0.2, _V( 0.850, 1.15, 2), _V(0,-1,0));
   AddExhaust (th_rcs[ 4], 0.4, 0.2, _V(-0.850,-1.15,-2), _V(0, 1,0));
   AddExhaust (th_rcs[ 5], 0.4, 0.2, _V(-0.850,-1.15, 2), _V(0, 1,0));
   AddExhaust (th_rcs[ 6], 0.4, 0.2, _V( 0.850,-1.15,-2), _V(0, 1,0));
   AddExhaust (th_rcs[ 7], 0.4, 0.2, _V( 0.850,-1.15, 2), _V(0, 1,0));
   AddExhaust (th_rcs[ 8], 0.4, 0.2, _V(-0.850, 1, 2.15), _V(0,0,-1));
   AddExhaust (th_rcs[ 8], 0.4, 0.2, _V( 0.850,-1, 2.15), _V(0,0,-1));
   AddExhaust (th_rcs[10], 0.4, 0.2, _V(-1, 1, 2), _V(-1,0,0));
   AddExhaust (th_rcs[10], 0.4, 0.2, _V(-1,-1, 2), _V(-1,0,0));
   AddExhaust (th_rcs[11], 0.4, 0.2, _V( 1, 1, 2), _V( 1,0,0));
   AddExhaust (th_rcs[11], 0.4, 0.2, _V( 1,-1, 2), _V( 1,0,0));
   AddExhaust (th_rcs[12], 0.4, 0.2, _V(-1,-1,-2), _V(-1,0,0));
   AddExhaust (th_rcs[12], 0.4, 0.2, _V(-1, 1,-2), _V(-1,0,0));
   AddExhaust (th_rcs[13], 0.4, 0.2, _V( 1,-1,-2), _V( 1,0,0));
   AddExhaust (th_rcs[13], 0.4, 0.2, _V( 1, 1,-2), _V( 1,0,0));
   AddExhaust (th_rcs[ 8], 0.4, 0.2, _V( 0.850, 1, 2.15), _V(0,0,-1));
   AddExhaust (th_rcs[ 8], 0.4, 0.2, _V(-0.850,-1, 2.15), _V(0,0,-1));
   AddExhaust (th_rcs[14], 0.4, 0.2, _V(-0.850, 1,-2.15), _V(0,0, 1));
   AddExhaust (th_rcs[14], 0.4, 0.2, _V( 0.850, 1,-2.15), _V(0,0, 1));
   AddExhaust (th_rcs[14], 0.4, 0.2, _V(-0.850,-1,-2.15), _V(0,0, 1));
   AddExhaust (th_rcs[14], 0.4, 0.2, _V( 0.850,-1,-2.15), _V(0,0, 1));

   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[1];
   th_group[2] = th_rcs[6];
   th_group[3] = th_rcs[7];
   CreateThrusterGroup (th_group, 4, THGROUP_ATT_BANKLEFT);

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

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

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

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

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

   th_group[0] = th_rcs[11];
   th_group[1] = th_rcs[13];
   CreateThrusterGroup (th_group, 2, THGROUP_ATT_LEFT);

   th_group[0] = th_rcs[10];
   th_group[1] = th_rcs[12];
   CreateThrusterGroup (th_group, 2, THGROUP_ATT_RIGHT);

   th_group[0] = th_rcs[14];
   CreateThrusterGroup (th_group, 1, THGROUP_ATT_FORWARD);

   th_group[0] = th_rcs[8];
   CreateThrusterGroup (th_group, 1, THGROUP_ATT_BACK);

   // camera parameters
   SetCameraOffset (_V(0,0,0));

   // associate a mesh for the visual
   AddMesh ("SD_st_module_1");
}

// --------------------------------------------------------------
// Read status from scenario file
// --------------------------------------------------------------

void SDmodule1::clbkLoadStateEx (FILEHANDLE scn, void *vs)
{
   char *line;

   while (oapiReadScenario_nextline (scn, line)) {
      if (!_strnicmp (line, "ANT", 3)) {
         //sscanf (line+3, "%d%lf", &ant_status, &ant_proc);
      //} else if (!_strnicmp (line, "HATCH", 5)) {
         //sscanf (line+5, "%d%lf", &hatch_status, &hatch_proc);
      //} else if (!_strnicmp (line, "FOLD", 4)) {
         sscanf (line+5, "%d%lf", &array_status, &array_proc);
      } else {
         ParseScenarioLineEx (line, vs);
      }
   }

   //SetAnimation (anim_ant, ant_proc);
   //SetAnimation (anim_hatch, hatch_proc);

   SetAnimation (anim_array, array_proc);
}

// --------------------------------------------------------------
// Save status to scenario file
// --------------------------------------------------------------

void SDmodule1::clbkSaveState (FILEHANDLE scn)
{
   char cbuf[256];
   SaveDefaultState (scn);
   sprintf (cbuf, "%d %0.4f", ant_status, ant_proc);
   oapiWriteScenario_string (scn, "ANT", cbuf);
   sprintf (cbuf, "%d %0.4f", hatch_status, hatch_proc);
   oapiWriteScenario_string (scn, "HATCH", cbuf);
   sprintf (cbuf, "%d %0.4f", array_status, array_proc);
   oapiWriteScenario_string (scn, "FOLD", cbuf);
}

// --------------------------------------------------------------
// Frame update
// --------------------------------------------------------------

void SDmodule1::clbkPostStep (double simt, double simdt, double mjd)
{
   // Animate hi-gain antenna
   //if (ant_status >= DOOR_CLOSING) {
   //   double da = simdt * ANTENNA_OPERATING_SPEED;
   //   if (ant_status == DOOR_CLOSING) {
   //      if (ant_proc > 0.0) ant_proc = max (0.0, ant_proc-da);
   //      else                ant_status = DOOR_CLOSED;
   //   } else {
   //      if (ant_proc < 1.0) ant_proc = min (1.0, ant_proc+da);
   //      else                ant_status = DOOR_OPEN;
   //   }
   //   SetAnimation (anim_ant, ant_proc);
   //}

   // Animate main telescope hatch
   //if (hatch_status >= DOOR_CLOSING) {
   //   double da = simdt * HATCH_OPERATING_SPEED;
   //   if (hatch_status == DOOR_CLOSING) {
   //      if (hatch_proc > 0.0) hatch_proc = max (0.0, hatch_proc-da);
   //      else                  hatch_status = DOOR_CLOSED;
   //   } else {
   //      if (hatch_proc < 1.0) hatch_proc = min (1.0, hatch_proc+da);
   //      else                  hatch_status = DOOR_OPEN;
   //   }
   //   SetAnimation (anim_hatch, hatch_proc);
   //}

   // Animate solar arrays

   if (array_status >= DOOR_CLOSING) {
      double da = simdt * ARRAY_OPERATING_SPEED;
      if (array_status == DOOR_CLOSING) {
         if (array_proc > 0.0) array_proc = max (0.0, array_proc-da);
         else                  array_status = DOOR_CLOSED;
      } else {
         if (array_proc < 1.0) array_proc = min (1.0, array_proc+da);
         else                  array_status = DOOR_OPEN;
      }
      SetAnimation (anim_array, array_proc);
   }
}

// --------------------------------------------------------------
// Keyboard interface handler (buffered key events)
// --------------------------------------------------------------

int SDmodule1::clbkConsumeBufferedKey (DWORD key, bool down, char *kstate)
{
   if (!down) return 0; // only process keydown events

   if (KEYMOD_CONTROL (kstate)) {

      switch (key) {
      //case OAPI_KEY_1: // deploy/retract antenna
      //   RevertAntenna();
      //   return 1;
      //case OAPI_KEY_2: // open/close hatch
      //   RevertHatch();
      //   return 1;

      case OAPI_KEY_1: // open/fold solar arrays
         RevertArray();
         return 1;
      }
   }
   return 0;
}

// --------------------------------------------------------------
// Respond to generic messages
// --------------------------------------------------------------

int SDmodule1::clbkGeneric (int msgid, int prm, void *context)
{
   switch (msgid) {
   case VMSG_LUAINTERPRETER:
      return Lua_InitInterpreter (context);
   case VMSG_LUAINSTANCE:
      return Lua_InitInstance (context);
   }
   return 0;
}

// ==============================================================
// API callback interface
// ==============================================================

// --------------------------------------------------------------
// Vessel initialisation
// --------------------------------------------------------------

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

// --------------------------------------------------------------
// Vessel cleanup
// --------------------------------------------------------------

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


SDmodule1.h

Quote
// ==============================================================
//                 ORBITER MODULE: Atlantis
//                  Part of the ORBITER SDK
//          Copyright (C) 2001-2004 Martin Schweiger
//                   All rights reserved
//
// HST.h
// HST basic specs and animations
//
// HST mesh and textures by David Sundstrom
// ==============================================================


#ifndef __SDmodule1_H
#define __SDmodule1_H

#define STRICT
#include "orbitersdk.h"

// ==============================================================
// Some parameters and capabilities
// ==============================================================

//const double ANTENNA_OPERATING_SPEED = 0.025;
//const double HATCH_OPERATING_SPEED = 0.022;

const double ARRAY_OPERATING_SPEED = 0.02;

const double  PB_SIZE       = 3.15;             // mean radius [m]
const VECTOR3 PB_CS         = {5.23,15.25,16.78}; // x,y,z cross sections [m^2]
const VECTOR3 PB_PMI        = {0.80,3.11,3.18};// principal moments of inertia (mass-normalised) [m^2]
const VECTOR3 PB_RD         = {0.025,0.025,0.02};//{0.05,0.1,0.05};  // rotation drag coefficients
const double  PB_EMPTYMASS  = 1500.0;           // empty vessel mass [kg]
const double  PB_FUELMASS   = 1000.0;           // max fuel mass [kg]
const double  PB_ISP        = 1e4;             // fuel-specific impulse [m/s]

const double  PB_MAXMAINTH  = 1e4;            
const double  PB_MAXHOVERTH = 0.0;
const double  PB_MAXRCSTH   = 0.5e2;

const VECTOR3 PB_DOCK_POS   = {0,0,-3.15};      // docking port location [m]
const VECTOR3 PB_DOCK_DIR   = {0,0,-1};         // docking port approach direction
const VECTOR3 PB_DOCK_ROT   = {0,1,0};        // docking port alignment direction

// ==============================================================
// HST class interface
// ==============================================================


class SDmodule1: public VESSEL2 {
public:
   enum DoorStatus { DOOR_CLOSED, DOOR_OPEN, DOOR_CLOSING, DOOR_OPENING } ant_status, hatch_status, array_status;
   SDmodule1 (OBJHANDLE hObj, int fmodel);
   void DefineAnimations (void);
   //void ActivateAntenna (DoorStatus action);
   //void RevertAntenna (void);
   //void ActivateHatch (DoorStatus action);
   //void RevertHatch (void);

   void ActivateArray (DoorStatus action);
   void RevertArray (void);

   // Overloaded callback functions
   void clbkSetClassCaps (FILEHANDLE cfg);
   void clbkLoadStateEx (FILEHANDLE scn, void *vs);
   void clbkSaveState (FILEHANDLE scn);
   void clbkPostStep (double simt, double simdt, double mjd);
   int  clbkConsumeBufferedKey (DWORD key, bool down, char *kstate);
   int  clbkGeneric (int msgid, int prm, void *context);

private:
   UINT anim_ant, anim_hatch, anim_array;
   double ant_proc, hatch_proc, array_proc;

   // script interface-related methods, implemented in HST_Lua.cpp
   int Lua_InitInterpreter (void *context);
   int Lua_InitInstance (void *context);
};

#endif // !__HST_H


SDbase_Lua.cpp

Quote
// ==============================================================
//                    ORBITER MODULE: HST
//                  Part of the ORBITER SDK
//          Copyright (C) 2001-2007 Martin Schweiger
//                   All rights reserved
//
// HST_Lua.cpp
// Script extensions to HST module
// ==============================================================


#include "SDmodule1.h"

#ifdef SCRIPTSUPPORT

extern "C" {
#include
#include
#include
}

// ==========================================================================
// API function prototypes


SDmodule1 *lua_toSDmodule1 (lua_State *L, int idx = 1);
//int hstAntenna (lua_State *L);
//int hstHatch (lua_State *L);

int hstArray (lua_State *L);

// ==========================================================================
// API initialisation


int SDmodule1::Lua_InitInterpreter(void *context)
{
   lua_State *L = (lua_State*)context;

   // add interpreter initialisation here

   return 0;
}

int SDmodule1::Lua_InitInstance(void *context)
{
   lua_State *L = (lua_State*)context;

   // check if interpreter has DG table loaded already
   luaL_getmetatable (L, "VESSEL.SDmodule1");

   if (lua_isnil (L, -1)) { // register new functions
      lua_pop (L, 1);
      static const struct luaL_reg hstLib[] = {
         //{"antenna", hstAntenna},
         //{"hatch", hstHatch},
         {"array", hstArray},
         {NULL, NULL}
      };

      // create metatable for vessel userdata
      luaL_newmetatable (L, "SDmodule1.vtable");

      // create a table for the overloaded methods
      luaL_openlib (L, "SDmodule1.method", hstLib, 0);

      // create metatable for accessing inherited methods from VESSEL
      luaL_newmetatable (L, "SDmodule1.base");
      lua_pushstring (L, "__index");
      luaL_getmetatable (L, "VESSEL.vtable");
      lua_settable (L, -3);

      // set HST.base as metatable for HST.method
      lua_setmetatable (L, -2);

      // point vessel userdata to HST.method
      lua_pushstring (L, "__index");
      lua_pushvalue (L, -2);
      lua_settable (L, -4);

      // pop HST.method from the stack
      lua_pop (L, 1);
   }

   lua_setmetatable (L, -2);

   return 0;
}

// ==========================================================================
// Script API functions


SDmodule1 *lua_toSDmodule1 (lua_State *L, int idx)
{
   VESSEL **pv = (VESSEL**)lua_touserdata (L, idx);
   SDmodule1 *hst = (SDmodule1*)*pv;
   return hst;
}

static SDmodule1::DoorStatus HSTaction[2] = {
   SDmodule1::DOOR_CLOSING,
   SDmodule1::DOOR_OPENING
};

//static int hstAntenna (lua_State *L)
//{
//   SDmodule1 *hst = lua_toSDmodule1 (L, 1);
//   int action = lua_tointeger (L, 2);
//   if (hst && action >= 0 && action < 2)
//      hst->ActivateAntenna (HSTaction[action]);
//   return 0;
//}

//static int hstHatch (lua_State *L)
//{
//   SDmodule1 *hst = lua_toSDmodule1 (L, 1);
//   int action = lua_tointeger (L, 2);
//   if (hst && action >= 0 && action < 2)
//      hst->ActivateHatch (HSTaction[action]);
//   return 0;
//}

static int hstArray (lua_State *L)
{
   SDmodule1 *hst = lua_toSDmodule1 (L, 1);
   int action = lua_tointeger (L, 2);
   if (hst && action >= 0 && action < 2)
      hst->ActivateArray (HSTaction[action]);
   return 0;
}

// ==========================================================================

#else // skip script support: dummy stubs

int SDmodule1::Lua_InitInterpreter(void *context)
{
   return 0;
}

int SDmodule1::LuaInitInstance (void *context)
{
   return 0;
}

#endif // SCRIPTSUPPORT


Le code est basé sur celui du HST


Quote
j'utilise perso un utilitaire 3dmax qui m'exporte aussi un fichier C++ de définition de groupe.

J'ai gmax mais pas 3DS mais quel est le nom de cet utilitaire?



Message modifié ( 07-12-2011 23:39 )


Offline jacquesmomo

  • Le budget !!!
  • Legend
  • ******
  • Posts: 7408
  • Country: France fr
  • Karma: 598
  • Plus on rate, plus on a de chances de réussir !..
Reply #11 - 07 December 2011, 23:31:02
Quote
DanSteph a écrit:
C'est vachement bien de t'être dépatouillé tout seul, 90% des gens abandonnent déjà avant ce stade :badsmile:
C'est mon avis :)

Quand je serai à la retraite, je pense que je te soliciterai... ;)
mais c'est pas encore....


Mes add-ons sont là !

Offline Bibi Uncle

  • Legend
  • ******
  • Posts: 2264
  • Country: Canada ca
  • Karma: 17
Reply #12 - 08 December 2011, 00:39:34
Ton erreur est là :

static UINT ArrayLFoldGrp[1] = {4};
static UINT ArrayRFoldGrp[2] = {3};

ArrayRFoldGrp[2] signifie que tu crées un tableau de 2 UINT, mais tu n'initialises seulement un UINT. L'autre est automatique mis à zéro car ta DLL est en debug. Le groupe zéro doit être le groupe du corps du module.

Bref, remplace

static UINT ArrayRFoldGrp[2] = {3};

par

static UINT ArrayRFoldGrp[1] = {3};

et

static MGROUP_ROTATE ArrayRFold2 (0, ArrayRFoldGrp, 2, _V( 1.75,0, 2), _V(0, 1,0), (float)(PI*0.5));

par

static MGROUP_ROTATE ArrayRFold2 (0, ArrayRFoldGrp, 1, _V( 1.75,0, 2), _V(0, 1,0), (float)(PI*0.5));


Émile

Pluton, Saturne et Jupiter
Entendez-vous monter vers vous le chant de la Terre?

- Luc Plamondon

Offline ea76620

  • Sr. Member
  • ****
  • Posts: 393
  • Country: France fr
  • Karma: 15
Reply #13 - 08 December 2011, 06:58:29
Bonjour,

Merci pour la solution: c'était bien ça maintenant les panneaux bougent tout seul et le corps reste bien en place.


Bon c'est pas tout mais maintenant je vais m'occuper de la gestion des UMMU (allez dans combien de temps le prochain bug? :) )

Au revoir


Offline DanSteph

  • Administrator
  • Legend
  • *****
  • Posts: 15407
  • Karma: 256
  • Hein, quoi !?
    • FsPassengers
Reply #14 - 08 December 2011, 11:08:27
Quote
Bibi Uncle a écrit:
Ton erreur est là :

static UINT ArrayLFoldGrp[1] = {4};
static UINT ArrayRFoldGrp[2] = {3};

ArrayRFoldGrp[2] signifie que tu crées un tableau de 2 UINT, mais tu n'initialises seulement un UINT. L'autre est automatique mis à zéro car ta DLL est en debug. Le groupe zéro doit être le groupe du corps du module.

:applause: Je vois que tu t'y est sacrément mis au C++, chapeau.


Quote
ea76620 a écrit:
Bon c'est pas tout mais maintenant je vais m'occuper de la gestion des UMMU (allez dans combien de temps le prochain bug? :) )

J'expliquais dernièrement à un ami que faire un gros (moyen) projet c'est comme un crash d'avion qui durerait super longtemps : Tu vas régulièrement de merdes en merdes à t'arracher les cheveux. C'est là que l'expérience compte et que savoir fouiller, flairer, dénicher, googler devient une des compétences principale.

Accessoirement le mode débug est indispensable, en faisant tourner ton code pas a pas tu aurais éventuellement vu qu'une valeur était au fraise.

Mais ne t'inquiète pas les "pros" sont logés à la même enseigne, bug et rebug ;)

Dan


Offline Mars Bleu

  • Hero Member
  • *****
  • Posts: 638
  • Karma: 33
Reply #15 - 08 December 2011, 19:35:27
Je regarde tout ça avec grand intérêt, car je compte bien
me pencher sur des animations.

« Last Edit: 08 December 2011, 19:35:27 by Mars Bleu »