So I want to have a beacon that I can turn on/off and then move along the Y axis with a key. For 2010
I can get the beacon to turn/off with a key. But even though the Yvalue changes the beacon doesn't move up/down
I can get the beacon to turn/off with a key. But even though the Yvalue changes the beacon doesn't move up/down
Code:
#define ORBITER_MODULE
#include "orbitersdk.h"
#include "BEACON1.h"
VISHANDLE MainExternalMeshVisual = 0;
// Constructor
BEACON1::BEACON1 (OBJHANDLE hObj, int fmodel)
: VESSEL2 (hObj, fmodel)
{
BEACONON = 0;
SWITCHON = 0;
yvalue = 0;
beaconmove = 0;
}
//
void BEACON1::clbkSetClassCaps (FILEHANDLE cfg)
//void BEACON1::SetTransporter()
{
// physical specs
SetSize (1);
SetEmptyMass (25);
SetClipRadius(0.1);
SetTouchdownPoints (_V(0,0,8.7), _V(-5.45,0,-9.6), _V(5.45,0,-9.6));;
static VECTOR3 beaconpos[1] = {{0, 2, 0} };
static VECTOR3 beaconcol[1] = {{ 0, 0, 0 } };//black
for (int i = 0; i < 1; i++) {
beacon[i].shape = BEACONSHAPE_STAR;
beacon[i].pos = beaconpos + i;
beacon[i].col = beaconcol + i;
beacon[i].size = 0.3;
beacon[i].falloff = 0.3;
beacon[i].period = 0.8;
beacon[i].duration = 1;
beacon[i].tofs = (6 - i)*0.2;
beacon[i].active = false;
AddBeacon(beacon + i);
}
}
void BEACON1::clbkPreStep(double simt, double simdt, double mjd)
{
VECTOR3 new_beacon_pos = _V(0, yvalue, 0);
beaconpos[0] = new_beacon_pos;
sprintf(oapiDebugString(), "yvalue %2.2f,beacon %2.2f", yvalue, beaconpos[0].y);
}
void BEACON1::clbkPostStep(double simt, double simdt, double mjd)
{
if (beaconmove == 1){
yvalue = yvalue + .1;
beaconmove = 0;
}
if (beaconmove == 2){
yvalue = yvalue - .1;
if (yvalue < 0)yvalue = 0;
beaconmove = 0;
}
if (SWITCHON == 1)beacon[0].active = true;//turns beacon on
if (SWITCHON == 0)beacon[0].active = false;//turns beacon off
}
DLLCLBK VESSEL *ovcInit (OBJHANDLE hvessel, int flightmodel)
{
return new BEACON1 (hvessel, flightmodel);
}
DLLCLBK void ovcExit (VESSEL *vessel)
{
if (vessel) delete (BEACON1*)vessel;
}
// --------------------------------------------------------------
// Keyboard interface handler (buffered key events)
// --------------------------------------------------------------
int BEACON1::clbkConsumeBufferedKey(DWORD key, bool down, char *kstate)
{
// only process keydown events
if (!down)
return 0;
if (key == OAPI_KEY_1)
{// hatch
// beacon[0].active = true;
beaconmove = 1;
return 1;
}
if (key == OAPI_KEY_2)
{// hatch
// beacon[0].active = true;
beaconmove = 2;
return 1;
}
if(key==OAPI_KEY_J)
{// hatch
// beacon[0].active = true;
SWITCHON = 1;
return 1;
}
if(key==OAPI_KEY_K)
{// hatch
// beacon[0].active = false;
SWITCHON = 0;
return 1;
}
return 0;
}
// ====================================================================
// clbkVisualCreated used to display UMMU initialisation message
// because oapiDebugString() doesn't work in clbkSetClassCap
// ====================================================================
void BEACON1::clbkVisualCreated (VISHANDLE vis, int refcount)
{
MainExternalMeshVisual = GetMesh(vis,0);
}
// ==============================================================
// Visual destroyed
// ==============================================================
void BEACON1::clbkVisualDestroyed (VISHANDLE vis, int refcount)
{
MainExternalMeshVisual = 0;
}
void BEACON1::clbkSaveState(FILEHANDLE scn)
{
char cbuf[256];
sprintf(cbuf, "%d", SWITCHON);
oapiWriteScenario_string(scn, "SWITCHON", cbuf);
sprintf(cbuf, "%lf", yvalue);
oapiWriteScenario_string(scn, "YVALUE", cbuf);
SaveDefaultState(scn);
}
void BEACON1::clbkLoadStateEx(FILEHANDLE scn, void *status)
{
char *line;
while (oapiReadScenario_nextline(scn, line))
{
if (!_strnicmp(line, "YVALUE", 6)) {
sscanf(line + 6, "%lf", &yvalue);
}
if (!_strnicmp(line, "SWITCHON", 8)) {
sscanf(line + 8, "%D", &SWITCHON);
}
ParseScenarioLineEx(line, status);
}
}