Dany
Addon-Dev F.O.I.
- Joined
- Apr 7, 2011
- Messages
- 18
- Reaction score
- 0
- Points
- 0
I'm trying to program in C++ this "Stand", by inserting the option "SKIN".
I was able to implement it but I'm having trouble when closing:
Launchpad remains in memory, or it crashes if I add another similar vessel.
This is what I did:
File .Cpp
Code:
#define ORBITER_MODULE
#include "MyVessel.h"
//HINSTANCE g_hDLL;
// --------------------------------------------------------------
// Constructor
// --------------------------------------------------------------
MyVessel::MyVessel (OBJHANDLE hObj, int fmodel)
: VESSEL3 (hObj, fmodel)
{
int i, j;
visual = NULL;
exmesh = NULL;
skinpath[0] = '\0';
for (i = 0; i < 3; i++)
skin[i] = 0;
}
// --------------------------------------------------------------
// Destructor
// --------------------------------------------------------------
MyVessel::~MyVessel ()
{
int i, j;
for (i = 0; i < 3; i++)
if (skin[i]) oapiReleaseTexture (skin[i]);
}
//=========================================================
// Vessel Animations
//=========================================================
void MyVessel::DefineAnimations()
{
//ANIMATIONCOMPONENT_HANDLE parent;
//static UINT gear_groups[2] = {5,6};
//static MGROUP_ROTATE gear (
// 0,
// gear_groups,
// 2,
// _V(0,-1.0,8.5),
// _V(1,0,0),
// (float)(0.45*PI)
//);
//static UINT wheel_groups[2] = {10,11};
//wheel = new MGROUP_ROTATE (
// 0,
// wheel_groups,
// 2,
// _V(0,-1.0,6.5),
// _V(1,0,0),
// (float)(2*PI)
//);
//anim_gear = CreateAnimation (0.0);
//parent = AddAnimationComponent (anim_gear, 0, 1, &gear);
//anim_wheel = CreateAnimation (0.0);
//AddAnimationComponent (anim_wheel, 0, 1, wheel, parent);
}
// --------------------------------------------------------------
// Apply custom skin to the current mesh instance
// --------------------------------------------------------------
void MyVessel::ApplySkin ()
{
if (!exmesh) return;
if (skin[0]) oapiSetTexture (exmesh, 1, skin[0]);
}
//=========================================================
// Vessel Capabilities
//=========================================================
void MyVessel::clbkSetClassCaps (FILEHANDLE cfg)
{
int i;
// vessel caps definitions
SetTouchdownPoints (PB_TDP[0], PB_TDP[1], PB_TDP[2]);
SetMeshVisibilityMode (AddMesh (exmesh_tpl = oapiLoadMeshGlobal ("Stand")), MESHVIS_EXTERNAL);
}
//=========================================================
// Vessel Load and Save Parameters
//=========================================================
void MyVessel::clbkLoadStateEx (FILEHANDLE scn, void *vs)
{
char *line; while (oapiReadScenario_nextline (scn, line))
{
if (!strnicmp (line, "SKIN", 4))
{
sscanf (line+4, "%s", skinpath);
char fname[256];
strcpy (fname, "Stand\\Skins\\");
strcat (fname, skinpath);
int n = strlen(fname); fname[n++] = '\\';
strcpy (fname+n, "Stand.dds"); skin[0] = oapiLoadTexture (fname);
}
else
{
ParseScenarioLineEx (line, vs);
}
}
}
void MyVessel::clbkSaveState (FILEHANDLE scn)
{
char cbuf[256];
int i;
VESSEL3::clbkSaveState (scn);
if (skinpath[0])
oapiWriteScenario_string (scn, "SKIN", skinpath);
}
// --------------------------------------------------------------
// Create DG visual
// --------------------------------------------------------------
void MyVessel::clbkVisualCreated (VISHANDLE vis, int refcount)
{
visual = vis;
exmesh = GetDevMesh (vis, 0);
ApplySkin();
}
// --------------------------------------------------------------
// Destroy DG visual
// --------------------------------------------------------------
void MyVessel::clbkVisualDestroyed (VISHANDLE vis, int refcount)
{
visual = NULL;
exmesh = NULL;
}
//=========================================================
// Animation Template
//=========================================================
void MyVessel::Timestep (double simt)
{
//if (gear_status == CLOSING || gear_status == OPENING)
//{
// double da = oapiGetSimStep() * gear_speed;
// if (gear_status == CLOSING)
// {
// if (gear_proc > 0.0)
// gear_proc = max (0.0, gear_proc-da);
// else
// gear_status = CLOSED;
// }
// else
// {
// // door opening
// if (gear_proc < 1.0)
// gear_proc = min (1.0, gear_proc+da);
// else
// gear_status = OPEN;
// }
// SetAnimation (anim_gear, gear_proc);
//}
}
//=========================================================
// Load and Delete Module Stuff
//=========================================================
DLLCLBK void InitModule (HINSTANCE hModule)
{
//g_hDLL = hModule;
// perform global module initialisation here
}
DLLCLBK void ExitModule (HINSTANCE hModule)
{
// perform module cleanup here
}
//=========================================================
// Load and Delete Vessel Stuff
//=========================================================
DLLCLBK VESSEL *ovcInit (OBJHANDLE hvessel, int flightmodel)
{
return new MyVessel (hvessel, flightmodel);
}
DLLCLBK void ovcExit (VESSEL *vessel)
{
if (vessel)
delete (MyVessel*)vessel;
}
Code:
#pragma once
#include "Orbitersdk.h"
const VECTOR3 PB_TDP[3] = {{0,-48.6,20},{-20,-48.6,-20},{20,-48.6,-20}}; // touchdown points [m]
class MyVessel : public VESSEL3 {
public:
MyVessel (OBJHANDLE hObj, int fmodel);
~MyVessel ();
void DefineAnimations();
void clbkSetClassCaps (FILEHANDLE cfg);
void clbkLoadStateEx (FILEHANDLE scn, void *vs);
void clbkSaveState (FILEHANDLE scn);
void Timestep (double simt);
void clbkVisualCreated (VISHANDLE vis, int refcount);
void clbkVisualDestroyed (VISHANDLE vis, int refcount);
MESHHANDLE exmesh_tpl; // vessel mesh: global template
DEVMESHHANDLE exmesh; // vessel mesh: instance
private:
void ApplySkin(); // apply custom skin
VISHANDLE visual; // handle to DG visual representation
char skinpath[32]; // skin directory, if applicable
SURFHANDLE skin[1]; // custom skin textures, if applicable
};
Could some C++ expert help me understand if there is an error or something missing?
This is the second attempt to program in C++, the first one failed, have mercy.
Sorry for my english, Thank you.

