// ==============================================================
// Part of the ORBITER SDK
// Copyright (C) 2002-2004 Martin Schweiger
// All rights reserved
//
// ==============================================================
#define STRICT
#define ORBITER_MODULE
#include "orbitersdk.h"
#include "DRAGONFLYTITAN.h"
#include <math.h>
#include <stdio.h>
#include <vector>
VISHANDLE MainExternalMeshVisual = 0;
DRAGONFLYTITAN::DRAGONFLYTITAN(OBJHANDLE hObj, int fmodel) : VESSEL3(hObj, fmodel) {
DefineAnimations();
Height_From_Ground = 0;
}
void DRAGONFLYTITAN::clbkPreStep(double simt, double simdt, double mjd) {
}
void DRAGONFLYTITAN::clbkSetClassCaps(FILEHANDLE cfg) {
// physical specs
SetSize(6.08);
SetEmptyMass(MASS);
SetCW(0.9, 0.9, 2, 1.4);
SetWingAspect(0.1);
SetWingEffectiveness(0.1);
SetCrossSections(_V(232.84, 1220.32, 166.36));
SetRotDrag(_V(0.1, 0.1, 0.1));
if (GetFlightModel() >= 1) {
SetPitchMomentScale(1e-4);
SetBankMomentScale(1e-4);
}
SetPMI(_V(163.54, 208.04, 76.03));
SetTrimScale(0.05);
SetCameraOffset(_V(0, 1, 3.121));
double ro = Passo;
TOUCHDOWNVTX td[4];
double x_target = -0.5;
double stiffness = (-1)*(MASS*9.80655) / (3 * x_target);
double damping = 0.9*(2 * sqrt(MASS*stiffness));
for (int i = 0; i<4; i++)
{
td[i].damping = damping;
td[i].mu = 3;
td[i].mu_lng = 3;
td[i].stiffness = stiffness;
}
td[0].pos.x = cos(30 * RAD)*ro;
td[0].pos.y = -Height_From_Ground;
td[0].pos.z = -sin(30 * RAD)*ro;
td[1].pos.x = 0;
td[1].pos.y = -Height_From_Ground;
td[1].pos.z = 1 * ro;
td[2].pos.x = -cos(30 * RAD)*ro;
td[2].pos.y = -Height_From_Ground;
td[2].pos.z = -sin(30 * RAD)*ro;
td[3].pos.x = 0;
td[3].pos.y = 15 * ro;
td[3].pos.z = 0;
SetTouchdownPoints(td, 4);
SetMeshVisibilityMode(AddMesh(oapiLoadMeshGlobal("DRAGONFLYTITAN1")), MESHVIS_ALWAYS); //Main ship mesh
ph_main = CreatePropellantResource(FUELMASS);
th_hover[0] = CreateThruster(_V(5, 0, 5), _V(0, 1, 0), 10 / 4, ph_main, RCS_ISP);
th_hover[1] = CreateThruster(_V(-5, 0, 5), _V(0, 1, 0), 10 / 4, ph_main, RCS_ISP);
th_hover[2] = CreateThruster(_V(5, 0, -5), _V(0, 1, 0), 10 / 4, ph_main, RCS_ISP);
th_hover[3] = CreateThruster(_V(-5, 0, -5), _V(0, 1, 0), 10 / 4, ph_main, RCS_ISP);
thg_hover = CreateThrusterGroup(th_hover, 4, THGROUP_HOVER);
}
void DRAGONFLYTITAN::clbkPostStep(double simt, double simdt, double mjd) {
}
DLLCLBK VESSEL *ovcInit(OBJHANDLE hvessel, int flightmodel) {
return new DRAGONFLYTITAN(hvessel, flightmodel);
}
DLLCLBK void ovcExit(VESSEL *vessel) {
if (vessel) delete (DRAGONFLYTITAN*)vessel;
}
// --------------------------------------------------------------
// Keyboard interface handDRAGONFLYTITAN (buffered key events)
// --------------------------------------------------------------
int DRAGONFLYTITAN::clbkConsumeBufferedKey(DWORD key, bool down, char *kstate) {
// only process keydown events
if (!down) return 0;
return 0;
}
void DRAGONFLYTITAN::DefineAnimations(void) {
}
void DRAGONFLYTITAN::clbkVisualCreated(VISHANDLE vis, int refcount) {
MainExternalMeshVisual = GetMesh(vis, 0);
// We warn the user, in the case UMmu isn't installed it's a good idea to send a "oapiDebugString"
// Orbiter message, otherwise your addon will not be fully operational and user may not notice.
// (nobody read doc, you may be the only one, if you read this send me a postcard ;)
}
// ==============================================================
// Visual destroyed
// ==============================================================
void DRAGONFLYTITAN::clbkVisualDestroyed(VISHANDLE vis, int refcount) {
MainExternalMeshVisual = 0;
}
// ========================================================================
// clbkLoadState function of Orbiter - Save scenario when user exit Orbiter
// ========================================================================
void DRAGONFLYTITAN::clbkSaveState(FILEHANDLE scn) {
char cbuf[256];
VESSEL2::clbkSaveState(scn);
}
// ========================================================================
// clbkLoadStateEx function of Orbiter - Load Orbiter scenario
// ========================================================================
void DRAGONFLYTITAN::clbkLoadStateEx(FILEHANDLE scn, void *status) {
float wheelrot = 0.0;
char *line;
while (oapiReadScenario_nextline(scn, line)) {
{
ParseScenarioLineEx(line, status);
// unrecognised option - pass to Orbiter's generic parser
}
}
}
void DRAGONFLYTITAN::clbkFocusChanged(bool getfocus, OBJHANDLE hNewVessel, OBJHANDLE hOldVessel) {
// erase message if we focus to another vessel
if (!getfocus) strcpy(oapiDebugString(), "");
}