Request Gateway transport system

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,736
Reaction score
2,707
Points
203
Location
Dallas, TX
Thanks. I have this:
Code:
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);
			}


		}
	}

Ok So our gateway mesh is about 500 meters in a diameter. So I assume the distance id measured center to center. So not sure what I would need to set trigger distance as?
 

jedidia

shoemaker without legs
Addon Developer
Joined
Mar 19, 2008
Messages
10,883
Reaction score
2,135
Points
203
Location
between the planets
So not sure what I would need to set trigger distance as?

Can't help you with that, as I don't know your meshes and your requirements. Just pick something you think works well for a start and refine it later.
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,736
Reaction score
2,707
Points
203
Location
Dallas, TX
Thanks. I don't understand why it says another orbiter is running when I exit? and try to run it.
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,736
Reaction score
2,707
Points
203
Location
Dallas, TX
yes. I ran it in debug and exit debug. Then ran it to test. Then exit and shut the launchpad down.
But now it seems to be working.

Code:
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);
			}


		}
	}

I put triggerdistance in the if statement. When in debug it was showing someother number.
So in the debugger I noticed that I can see Distance, and now triggerdistance.



So for the distance. The mesh is 500 meters in diameter. So the idea is to drive the ship thru the center of the mesh. But since the distance is a measure from center to center. You could be align in the z axis. and 200 meters away. or be 200 meters above the gate's center, right.
 

jedidia

shoemaker without legs
Addon Developer
Joined
Mar 19, 2008
Messages
10,883
Reaction score
2,135
Points
203
Location
between the planets
You could be align in the z axis. and 200 meters away. or be 200 meters above the gate's center, right.

All of which would result in the same distance. I don't think I understand the question.
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,736
Reaction score
2,707
Points
203
Location
Dallas, TX
I thought so. Is there are way to check the x,y, z differences.

So 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?

h:
Code:
bool jump;
cpp:
Code:
WORMHOLE::WORMHOLE (OBJHANDLE hObj, int fmodel)
: VESSEL2 (hObj, fmodel)

{
	
	rpos = _V(0, 0, 0);
	rvel = _V(0, 0, 0);
	
	jump = false;
}
 

jedidia

shoemaker without legs
Addon Developer
Joined
Mar 19, 2008
Messages
10,883
Reaction score
2,135
Points
203
Location
between the planets
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

I see. That's going to get a bit more complicated, as that means calculating the position of the vessel in the gate's local coordinate system. It's a while ago since I did that. It's not that difficult, but nothing I can pull out of my sleeve without having the API docs handy, so it'll have to wait until the evening (UTC+2).

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?

Where did you put your breakpoint?
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,736
Reaction score
2,707
Points
203
Location
Dallas, TX
Thanks. Here is the breakpoints:
aIb7siO.jpg
 

jedidia

shoemaker without legs
Addon Developer
Joined
Mar 19, 2008
Messages
10,883
Reaction score
2,135
Points
203
Location
between the planets
Well, you're only setting jump back to false if the vessel is in jumping distance (i.e. the jump was executed).

So if you trigger the condition that sets jump to true, but the vessel is not within distance, jump will stay true until any vessel is close enough to jump. So it's well possible that it would show up as true at this point.
It would be prudent to put jump = false right before the end of clbkPostStep. It would be even more prudent to move if (jump == true) to the beginning of clbkPostStep and only execute the entire code if that is actually the case, to avoid spending unnecessary resources.

---------- Post added at 06:39 PM ---------- Previous post was at 12:52 PM ----------

Right, about distance in local coordinates. Looks like a pretty easy solution, thanks to orbiters excellent transformation api.

Here's what you have so far:

Code:
oapiGetGlobalPos(hvessel, &vesselpos);
oapiGetGlobalPos(GetHandle(), &gatepos);
relpos = vesselpos - gatepos;

This gives you the relative position of the vessel to the gate in global coordinates. Since it is usually not the case that the gate is aligned exactly with the global coordinate system, this doesn't tell you whether the vessel is left, above or in front of the gate. For that, we have to transform these coordinates to the gates local coordinate system, which, as mentioned, is made easy by orbiter:

Code:
VECTOR3 gaterelative_pos = _V(0, 0, 0);
oapiGlobalToLocal(GetHandle(), &relpos, &gaterelative_pos);

There. gaterelative_pos should now contain the coordinates of the vessel relative to the gates position and alignment (i.e. z+ is front, y+ is above, x+ is right... I think. Orbiter is left-handed, which tends to confuse me, but I'm pretty sure I got it right).
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,736
Reaction score
2,707
Points
203
Location
Dallas, TX
So all this should be in the not handle part

So if we want the ship to go thru the gate when the rel position is rel x<500 or rel x>-500 and Rel y >500 and y rel<500 and z =0. So anywhere with in a 100 meter x, y cylinder it would trigger it.
 

jedidia

shoemaker without legs
Addon Developer
Joined
Mar 19, 2008
Messages
10,883
Reaction score
2,135
Points
203
Location
between the planets

I really wouldn't. The chances that z is going to hit exactly zero are astronomical. You could floor it, which should work at reasonable velocities and low time acceleration. Or you could define a range of maybe +- 10 meters or so.
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,736
Reaction score
2,707
Points
203
Location
Dallas, TX
Thanks. I have this. Not sure where the jump = true should be?
Code:
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);
			}


		}
	}

This puts the dg where gate A. I am sure if has to be that how jump is defined
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,736
Reaction score
2,707
Points
203
Location
Dallas, TX
For right now i want the user to open the gate using the key K . So do nothing if Jump=false when K is pressed then check to see if close or not.

I think later i think something like gate is open always. See if you are close if close then jump and close gate and start timer. Move out of range of the gate. When the timer ends the gate opens again

---------- Post added 10-04-17 at 04:41 AM ---------- Previous post was 10-03-17 at 04:49 PM ----------

So this is what I have:
Code:
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;
	}

I ran it once :
scn:
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
but the dg is placed where Gate A didn't press K
scn:
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

So I ran it once exited closed the launchpad and tried to run debugger it said another orbiter was running.
 

jedidia

shoemaker without legs
Addon Developer
Joined
Mar 19, 2008
Messages
10,883
Reaction score
2,135
Points
203
Location
between the planets
So I ran it once exited closed the launchpad and tried to run debugger it said another orbiter was running.

No idea what that's about honestly. Anyways, did it work?
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,736
Reaction score
2,707
Points
203
Location
Dallas, TX
No. For some reason. 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.. I didn't press K to set Jump= true.
 

jedidia

shoemaker without legs
Addon Developer
Joined
Mar 19, 2008
Messages
10,883
Reaction score
2,135
Points
203
Location
between the planets
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..

I am confused. Are they in the same location, or aren't they? both at once can't be true.
In any case, if the scenario above is what you're using, the DG seems to be over 100,000 meters away from Gate A in the x axis alone:

Code:
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
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,736
Reaction score
2,707
Points
203
Location
Dallas, TX
Sorry for confusion
So if I open the scn in notepad:
Code:
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

So this is the scn before I run it.

then I open orbiter and run the scn. I exit and the dg is placed with the GAte A. I can thrust the DG and the Gate A follows.
saved state:
Code:
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

So as I see it jump is always true and it is with in the rel distance x, y, z
 
Top