Yes. But without the {} brackets.
void WORMHOLE::clbkPostStep(double simt, double simdt, double mjd)
{
for (UINT i = 0; i < oapiGetVesselCount(); i++)
{
OBJHANDLE hvessel = oapiGetVesselByIndex(i);
if (hvessel != GetHandle())
{
VECTOR3 vesselpos = _V(0, 0, 0);
VECTOR3 gatepos = _V(0, 0, 0);
VECTOR3 relpos = _V(0, 0, 0);
oapiGetGlobalPos(hvessel, &vesselpos);
oapiGetGlobalPos(GetHandle(), &gatepos);
relpos = vesselpos - gatepos;
double distance = length(relpos);
// if (distance < triggerdistance) jump = true;
if ((distance < triggerdistance) && (jump == true))
{
VESSELSTATUS2 vs_vessel, vs_other_gate;
memset(&vs_vessel, 0, sizeof(vs_vessel));
memset(&vs_other_gate, 0, sizeof(vs_other_gate));
vs_vessel.version = 2;
vs_other_gate.version = 2;
VESSEL *v;
v = oapiGetVesselInterface(hvessel);
v->GetStatusEx(&vs_vessel);
OBJHANDLE h_other_gate;
char myname[16];
char GateA[16];
sprintf(myname, GetName());
sprintf(GateA, "Gate_A");
if (strcmp(myname, GateA) == 0)
{
h_other_gate = oapiGetVesselByName("Gate_B");
}
else{
h_other_gate = oapiGetVesselByName("Gate_A");
}
VESSEL *v_other_gate;
v_other_gate = oapiGetVesselInterface(h_other_gate);
v_other_gate->GetStatusEx(&vs_other_gate);
vs_vessel.rbody = vs_other_gate.rbody;
vs_vessel.rpos = vs_other_gate.rpos;
vs_vessel.vrot = vs_other_gate.vrot;
vs_vessel.arot = vs_other_gate.arot;
VECTOR3 outvel = _V(rvel.x, rvel.y, rvel.z);
VECTOR3 rofs;
GlobalRot(outvel, rofs);
vs_vessel.rvel.x = vs_other_gate.rvel.x + rofs.x;
vs_vessel.rvel.y = vs_other_gate.rvel.y + rofs.y;
vs_vessel.rvel.z = vs_other_gate.rvel.z + rofs.z;
jump = false;
v->DefSetStateEx(&vs_vessel);
}
}
}
So not sure what I would need to set trigger distance as?
Thanks. I don't understand why it says another orbiter is running when I exit? and try to run it.
void WORMHOLE::clbkPostStep(double simt, double simdt, double mjd)
{
for (UINT i = 0; i < oapiGetVesselCount(); i++)
{
OBJHANDLE hvessel = oapiGetVesselByIndex(i);
if (hvessel != GetHandle())
{
VECTOR3 vesselpos = _V(0, 0, 0);
VECTOR3 gatepos = _V(0, 0, 0);
VECTOR3 relpos = _V(0, 0, 0);
oapiGetGlobalPos(hvessel, &vesselpos);
oapiGetGlobalPos(GetHandle(), &gatepos);
relpos = vesselpos - gatepos;
double triggerdistance = 200;
double distance = length(relpos);
// if (distance < triggerdistance) jump = true;
if ((distance < triggerdistance) && (jump == true))
{
VESSELSTATUS2 vs_vessel, vs_other_gate;
memset(&vs_vessel, 0, sizeof(vs_vessel));
memset(&vs_other_gate, 0, sizeof(vs_other_gate));
vs_vessel.version = 2;
vs_other_gate.version = 2;
VESSEL *v;
v = oapiGetVesselInterface(hvessel);
v->GetStatusEx(&vs_vessel);
OBJHANDLE h_other_gate;
char myname[16];
char GateA[16];
sprintf(myname, GetName());
sprintf(GateA, "Gate_A");
if (strcmp(myname, GateA) == 0)
{
h_other_gate = oapiGetVesselByName("Gate_B");
}
else{
h_other_gate = oapiGetVesselByName("Gate_A");
}
VESSEL *v_other_gate;
v_other_gate = oapiGetVesselInterface(h_other_gate);
v_other_gate->GetStatusEx(&vs_other_gate);
vs_vessel.rbody = vs_other_gate.rbody;
vs_vessel.rpos = vs_other_gate.rpos;
vs_vessel.vrot = vs_other_gate.vrot;
vs_vessel.arot = vs_other_gate.arot;
VECTOR3 outvel = _V(rvel.x, rvel.y, rvel.z);
VECTOR3 rofs;
GlobalRot(outvel, rofs);
vs_vessel.rvel.x = vs_other_gate.rvel.x + rofs.x;
vs_vessel.rvel.y = vs_other_gate.rvel.y + rofs.y;
vs_vessel.rvel.z = vs_other_gate.rvel.z + rofs.z;
jump = false;
v->DefSetStateEx(&vs_vessel);
}
}
}
You could be align in the z axis. and 200 meters away. or be 200 meters above the gate's center, right.
bool jump;
WORMHOLE::WORMHOLE (OBJHANDLE hObj, int fmodel)
: VESSEL2 (hObj, fmodel)
{
rpos = _V(0, 0, 0);
rvel = _V(0, 0, 0);
jump = false;
}
o that as you go thru the gateway z center point but could be 200 meters high/low left right. But the z distance would be 0. I may be thinking in too simple of terms
So in the debugger should I be able to see Distance, triggerdistance
It say Jump is true. when I have it declared false. but that may be wrong?
oapiGetGlobalPos(hvessel, &vesselpos);
oapiGetGlobalPos(GetHandle(), &gatepos);
relpos = vesselpos - gatepos;
VECTOR3 gaterelative_pos = _V(0, 0, 0);
oapiGlobalToLocal(GetHandle(), &relpos, &gaterelative_pos);
and z =0
void WORMHOLE::clbkPostStep(double simt, double simdt, double mjd)
{
for (UINT i = 0; i < oapiGetVesselCount(); i++)
{
OBJHANDLE hvessel = oapiGetVesselByIndex(i);
if (hvessel != GetHandle())
{
VECTOR3 vesselpos = _V(0, 0, 0);
VECTOR3 gatepos = _V(0, 0, 0);
VECTOR3 relpos = _V(0, 0, 0);
oapiGetGlobalPos(hvessel, &vesselpos);
oapiGetGlobalPos(GetHandle(), &gatepos);
relpos = vesselpos - gatepos;
double triggerdistance = 200;
VECTOR3 gaterelative_pos = _V(0, 0, 0);
oapiGlobalToLocal(GetHandle(), &relpos, &gaterelative_pos);
if ((gaterelative_pos.x<-500) || (gaterelative_pos.x>500) || (gaterelative_pos.y<-500) || (gaterelative_pos.y>500) || (gaterelative_pos.x<-10) || (gaterelative_pos.x>10)) jump = true;
//double distance = length(relpos);
// if (distance < triggerdistance) jump = true;
if (jump == true)
{
VESSELSTATUS2 vs_vessel, vs_other_gate;
memset(&vs_vessel, 0, sizeof(vs_vessel));
memset(&vs_other_gate, 0, sizeof(vs_other_gate));
vs_vessel.version = 2;
vs_other_gate.version = 2;
VESSEL *v;
v = oapiGetVesselInterface(hvessel);
v->GetStatusEx(&vs_vessel);
OBJHANDLE h_other_gate;
char myname[16];
char GateA[16];
sprintf(myname, GetName());
sprintf(GateA, "Gate_A");
if (strcmp(myname, GateA) == 0)
{
h_other_gate = oapiGetVesselByName("Gate_B");
}
else{
h_other_gate = oapiGetVesselByName("Gate_A");
}
VESSEL *v_other_gate;
v_other_gate = oapiGetVesselInterface(h_other_gate);
v_other_gate->GetStatusEx(&vs_other_gate);
vs_vessel.rbody = vs_other_gate.rbody;
vs_vessel.rpos = vs_other_gate.rpos;
vs_vessel.vrot = vs_other_gate.vrot;
vs_vessel.arot = vs_other_gate.arot;
VECTOR3 outvel = _V(rvel.x, rvel.y, rvel.z);
VECTOR3 rofs;
GlobalRot(outvel, rofs);
vs_vessel.rvel.x = vs_other_gate.rvel.x + rofs.x;
vs_vessel.rvel.y = vs_other_gate.rvel.y + rofs.y;
vs_vessel.rvel.z = vs_other_gate.rvel.z + rofs.z;
jump = false;
v->DefSetStateEx(&vs_vessel);
}
}
}
Not sure where the jump = true should be?
void WORMHOLE::clbkPostStep(double simt, double simdt, double mjd)
{
for (UINT i = 0; i < oapiGetVesselCount(); i++)
{
OBJHANDLE hvessel = oapiGetVesselByIndex(i);
if (hvessel != GetHandle())
{
VECTOR3 vesselpos = _V(0, 0, 0);
VECTOR3 gatepos = _V(0, 0, 0);
VECTOR3 relpos = _V(0, 0, 0);
oapiGetGlobalPos(hvessel, &vesselpos);
oapiGetGlobalPos(GetHandle(), &gatepos);
relpos = vesselpos - gatepos;
double triggerdistance = 200;
VECTOR3 gaterelative_pos = _V(0, 0, 0);
oapiGlobalToLocal(GetHandle(), &relpos, &gaterelative_pos);
// if ((gaterelative_pos.x<-500) || (gaterelative_pos.x>500) || (gaterelative_pos.y<-500) || (gaterelative_pos.y>500) || (gaterelative_pos.x<-10) || (gaterelative_pos.x>10)) jump = true;
//double distance = length(relpos);
// if (distance < triggerdistance) jump = true;
if ((gaterelative_pos.x<-500) || (gaterelative_pos.x>500) || (gaterelative_pos.y<-500) || (gaterelative_pos.y>500) || (gaterelative_pos.x<-10) || (gaterelative_pos.x>10)&& (jump == true))//ship is near gate and key pressed
{
VESSELSTATUS2 vs_vessel, vs_other_gate;
memset(&vs_vessel, 0, sizeof(vs_vessel));
memset(&vs_other_gate, 0, sizeof(vs_other_gate));
vs_vessel.version = 2;
vs_other_gate.version = 2;
VESSEL *v;
v = oapiGetVesselInterface(hvessel);
v->GetStatusEx(&vs_vessel);
OBJHANDLE h_other_gate;
char myname[16];
char GateA[16];
sprintf(myname, GetName());
sprintf(GateA, "Gate_A");
if (strcmp(myname, GateA) == 0)
{
h_other_gate = oapiGetVesselByName("Gate_B");
}
else{
h_other_gate = oapiGetVesselByName("Gate_A");
}
VESSEL *v_other_gate;
v_other_gate = oapiGetVesselInterface(h_other_gate);
v_other_gate->GetStatusEx(&vs_other_gate);
vs_vessel.rbody = vs_other_gate.rbody;
vs_vessel.rpos = vs_other_gate.rpos;
vs_vessel.vrot = vs_other_gate.vrot;
vs_vessel.arot = vs_other_gate.arot;
VECTOR3 outvel = _V(rvel.x, rvel.y, rvel.z);
VECTOR3 rofs;
GlobalRot(outvel, rofs);
vs_vessel.rvel.x = vs_other_gate.rvel.x + rofs.x;
vs_vessel.rvel.y = vs_other_gate.rvel.y + rofs.y;
vs_vessel.rvel.z = vs_other_gate.rvel.z + rofs.z;
jump = false;
v->DefSetStateEx(&vs_vessel);
}
}
}
}
DLLCLBK VESSEL *ovcInit (OBJHANDLE hvessel, int flightmodel)
{
return new WORMHOLE (hvessel, flightmodel);
}
DLLCLBK void ovcExit(VESSEL *vessel)
{
if (vessel) delete (WORMHOLE*)vessel;
}
// --------------------------------------------------------------
// Keyboard interface handler (buffered key events)
// --------------------------------------------------------------
int WORMHOLE::clbkConsumeBufferedKey(DWORD key, bool down, char *kstate)
{
// only process keydown events
if (!down)
return 0;
if (key == OAPI_KEY_K) // ATTACH
{
jump=true;
return 1;
}
So I ran it once exited closed the launchpad and tried to run debugger it said another orbiter was running.
When I start the scn the DG is not at Gate A. But when the scn starts the dg and Gate A share the same location..
dg:Deltaglider
STATUS Orbiting Earth
RPOS 1617828.44 -0.02 6818375.98
Gate_A:WORMHOLE
STATUS Orbiting Earth
RPOS 1482737.05 -0.02 6849462.07
BEGIN_SHIPS
Gate_A:WORMHOLE
STATUS Orbiting Earth
RPOS 1617828.80 -0.02 6818817.38
RVEL -7337.975 -0.000 1741.006
AROT 0.00 -0.00 0.00
AFCMODE 7
NAVFREQ 0 0
XPDR 0
END
Gate_B:WORMHOLE
STATUS Orbiting Moon
RPOS 1565655.91 1471150.43 168845.54
RVEL 905.646 900.312 32.534
AROT 0.00 -0.00 0.00
AFCMODE 7
NAVFREQ 0 0
XPDR 0
END
dg:Deltaglider
STATUS Orbiting Earth
RPOS 1617828.44 -0.02 6818375.98
RVEL -7337.989 -0.000 1734.809
AROT 0.00 -0.00 0.00
RCSMODE 0
AFCMODE 7
PRPLEVEL 0:0.985416 1:0.993757
NAVFREQ 0 0 0 0
XPDR 0
AAP 0:0 0:0 0:0
END
END_SHIPS
Gate_A:WORMHOLE
STATUS Orbiting Earth
RPOS 1482737.05 -0.02 6849462.07
RVEL -7370.953 -0.000 1595.629
AROT 0.00 -0.00 0.00
AFCMODE 7
NAVFREQ 0 0
XPDR 0
END
Gate_B:WORMHOLE
STATUS Orbiting Moon
RPOS 1582162.46 1487566.71 169429.21
RVEL 891.710 887.213 31.037
AROT 0.00 -0.00 0.00
AFCMODE 7
NAVFREQ 0 0
XPDR 0
END
dg:Deltaglider
STATUS Orbiting Earth
RPOS 1482737.05 -0.02 6849462.07
RVEL -7370.953 -0.000 1595.629
AROT 0.00 -0.00 0.00
RCSMODE 0
AFCMODE 7
PRPLEVEL 0:0.982191 1:0.993757
NAVFREQ 0 0 0 0
XPDR 0
AAP 0:0 0:0 0:0
END