Request Gateway transport system

jedidia

shoemaker without legs
Addon Developer
Joined
Mar 19, 2008
Messages
10,883
Reaction score
2,135
Points
203
Location
between the planets
So as I see it jump is always true and it is with in the rel distance x, y, z

Yes it is. You should see why by looking at your code, especially the bits you added very recently ;)
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,736
Reaction score
2,707
Points
203
Location
Dallas, TX
I will. Thanks.

So what we want is jump is always false. It is turned true when K is pressed.

Then when the jump is made it is set false.

Should I be able to see the relpos x, y, z in the debugger?


I wonder if the if Jump = true shouldn't be at the first of this. So do nothing if jump= false but if jump =true then do the see if we are close and jump if we are. Then when the jump was made the jump=false now
 
Last edited:

jedidia

shoemaker without legs
Addon Developer
Joined
Mar 19, 2008
Messages
10,883
Reaction score
2,135
Points
203
Location
between the planets
Should I be able to see the relpos x, y, z in the debugger?

You should see all your declared locals in the debugger when triggering a breakpoint.

I wonder if the if Jump == true shouldn't be at the first of this.

It absolutely should. Looks like you start getting the hang of this :thumbup:
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,736
Reaction score
2,707
Points
203
Location
Dallas, TX
Code:
void WORMHOLE::clbkPostStep(double simt, double simdt, double mjd)
{
	for (UINT i = 0; i < oapiGetVesselCount(); i++)
	{
		OBJHANDLE hvessel = oapiGetVesselByIndex(i);

		if (jump == true){
		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.z<-10) || (gaterelative_pos.z>10)))//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);
			}


		}
	}

	}


}
So I ran the scn and focused on the Gate A pressed K now jump=true.
Look at the relgateposition:
+ gaterelative_pos {data=0x00aefb14 {0.00000000000000000, 0.00000000000000000, 0.00000000000000000} x=0.00000000000000000 ...} VECTOR3
i then moved the dg and focused back on the gateA then press k
- gaterelative_pos {data=0x00aefb14 {0.00000000000000000, 0.00000000000000000, 0.00000000000000000} x=0.00000000000000000 ...} VECTOR3

+ gatepos {data=0x00aefaf4 {3.7149167035010515e-242, 4.246296523661e-314#DEN, 2.2063606999321204e-305} x=3.7149167035010515e-242 ...} VECTOR3

- vesselpos {data=0x00aefb34 {0.00000000000000000, 0.00000000000000000, -8.9094030702417137e-103} x=0.00000000000000000 ...} VECTOR3



So because the rel position is 0,0,0 then 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
I don't understand what you're trying to say. I don't even see if it works or not in what you wrote.

If you're concerned about gaterelative_pos being 0, 0, 0, That is to be expected immediately after the jump.
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,736
Reaction score
2,707
Points
203
Location
Dallas, TX
Sorry.
using this scn:
BEGIN_SHIPS
Gate_A:WORMHOLE
STATUS Orbiting Earth
RPOS 1754494.29 -0.02 6784938.48
RVEL -7301.517 -0.000 1888.077
AROT 0.00 -0.00 0.00
AFCMODE 7
NAVFREQ 0 0
XPDR 0
END
Gate_B:WORMHOLE
STATUS Orbiting Moon
RPOS 1548612.64 1454214.93 168223.60
RVEL 920.129 913.916 34.101
AROT 0.00 -0.00 0.00
AFCMODE 7
NAVFREQ 0 0
XPDR 0
END
dg:Deltaglider
STATUS Orbiting Earth
RPOS 1754494.12 -0.02 6784562.71
RVEL -7301.525 -0.000 1880.458
AROT 0.00 -0.00 0.00
RCSMODE 2
AFCMODE 7
PRPLEVEL 0:0.985416 1:0.992303
NAVFREQ 0 0 0 0
XPDR 0
AAP 0:0 0:0 0:0
END
Did some more testing. When I press K focused on the Gate A the gate is open
So jump = true.
So I get these values at the break point:
Awqztfj.jpg

Code:
+		&relpos	0x00aefb58 {data=0x00aefb58 {-0.26056367321808022, 0.24045060385748118, -2.9722131190885874e-009} x=...}	VECTOR3 *

-		gaterelative_pos	{data=0x00aefb18 {0.00000000000000000, 0.00000000000000000, 1.7491605412344125e-239} x=0.00000000000000000 ...}	VECTOR3

I hit f5 still at the upper breakpoint but new gate relposition:
Code:
-		gaterelative_pos	{data=0x00aefb20 {0.00000000000000000, 1.7491605412344125e-239, 0.00000000000000000} x=0.00000000000000000 ...}	VECTOR3

the z info is now the x



Then I go to the next breakpoint. This is to see if the vessel is close enough. but now gaterelposition are all zeros?

mKunk9R.jpg


Code:
-		gaterelative_pos	{data=0x00aefb14 {0.00000000000000000, 0.00000000000000000, 0.00000000000000000} x=0.00000000000000000 ...}	VECTOR3

and since it goes pass that the dg isn't moved though jump = false. So I need to press K again
 
Last edited:

jedidia

shoemaker without legs
Addon Developer
Joined
Mar 19, 2008
Messages
10,883
Reaction score
2,135
Points
203
Location
between the planets
Then I go to the next breakpoint. This is to see if the vessel is close enough. but now gaterelposition are all zeros?

The probability of the position of the DG being exactly the same as the gate when it hasn't explicitly not been set is indeed very remote. Please initialise the variable with -1, -1, -1 instead of 0, 0, 0 and check the value again. If it still shows 0, 0, 0 then the result might be unexpected, but at least we know the variable was altered.
There's still the possibility that your debugger just doesn't show the right values because of some exotic compiler settings, though.

and since it goes pass that the dg isn't moved

Please ask yourself what you want to check for exactly, and then figure out what's wrong with that if-statement. Because it really couldn't be much wronger in any aspect.
Do some rubber duck debugging, it helps a lot, especially in situations like these.
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,736
Reaction score
2,707
Points
203
Location
Dallas, TX
Ok. I will try the inialization. I like the rubber duck concept

Code:
for (UINT i = 0; i < oapiGetVesselCount(); i++)
	{
		OBJHANDLE hvessel = oapiGetVesselByIndex(i);

		if (jump == true){
		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);

So this gets all the vessels handles
if "K" has been pressed then Jump is true else it is false
if Hveesel is NOT a gate
initialize vectors
then get global position on vessel and gate. relpos is the difference of the locations(vectors)
gaterelposition is the relative difference between gate and vessel


So if a dg is centered x, y, but located along the z axis 100 meters from the gate relposition would be 0,0,-100?
So if a dg is centered x, z, but located along the y axis 100 meters from the gate relposition would be 0,100,0? here a jump would be made
 
Last edited:

jedidia

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

if hvessel is NOT a gate

is actually "if hvessel is not THIS gate"

So far so good, but it's the next if statement where things get interesting ;)
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,736
Reaction score
2,707
Points
203
Location
Dallas, TX
Thanks.
Code:
			if (((gaterelative_pos.x<-500) || (gaterelative_pos.x>500) || (gaterelative_pos.y<-500) || (gaterelative_pos.y>500)) && ((gaterelative_pos.z<-10) || (gaterelative_pos.z>10)))//ship is near gate and key pressed
			{

So you get to this K is pressed jump is true we now have the positions and relative position, right. So is it in range?
so if gaterelposition.x is in between -500 and 500 or so if gaterelposition.y is in between -500 and 500 and gaterelposition.z is in between -10 and 10.
Then move the ship.
may rather than or they need to be AND like this:
so if gaterelposition.x is in between -500 and 500 AND if gaterelposition.y is in between -500 and 500 and gaterelposition.z is in between -10 and 10.
 

jedidia

shoemaker without legs
Addon Developer
Joined
Mar 19, 2008
Messages
10,883
Reaction score
2,135
Points
203
Location
between the planets
so if gaterelposition.x is in between -500 and 500 or so if gaterelposition.y is in between -500 and 500 and gaterelposition.z is in between -10 and 10.

That's not at all what it says in the code.
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,736
Reaction score
2,707
Points
203
Location
Dallas, TX
Code:
if (((gaterelative_pos.x<-500) || (gaterelative_pos.x>500) || (gaterelative_pos.y<-500) || (gaterelative_pos.y>500)) && ((gaterelative_pos.z<-10) || (gaterelative_pos.z>10)))//ship is near gate and key pressed
			{
if gaterelative_pos.x is less than -500 or gaterelative_pos.x>500 so if x value was -100, or 100
AND i need to change this:
if gaterelative_pos.y is less than -500 or gaterelative_pos.y>500 so if y value was -100, or 100
AND
if gaterelative_pos.z is less than -10 or gaterelative_pos.x>10 so if z value was -1, or 1. So if the x value , y value and z value are in range continue
 

jedidia

shoemaker without legs
Addon Developer
Joined
Mar 19, 2008
Messages
10,883
Reaction score
2,135
Points
203
Location
between the planets
This is what you want:
so if gaterelposition.x is in between -500 and 500

This is what you (correctly) interpreted your code to do:
if gaterelative_pos.x is less than -500 or gaterelative_pos.x>500

See the discrepancy between the two? ;)
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,736
Reaction score
2,707
Points
203
Location
Dallas, TX
So I want (-500>gaterelative_pos.x<500)

---------- Post added at 04:44 PM ---------- Previous post was at 12:33 PM ----------

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 (jump == true){
		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(-1, -1, -1);
			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 ((-500<gaterelative_pos.x>500) && (-500<gaterelative_pos.y>500) && (-10<gaterelative_pos.z>10))
So something is wrong. Now when I press K Jump =true. It should hit a break point. But it doesn't
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,736
Reaction score
2,707
Points
203
Location
Dallas, TX
Thanks 0
I get this :
WORMHOLE.CPP(103): warning C4804: '>' : unsafe use of type 'bool' in operation

Code:
void WORMHOLE::clbkPostStep(double simt, double simdt, double mjd)
{
	for (UINT i = 0; i < oapiGetVesselCount(); i++)
	{
		OBJHANDLE hvessel = oapiGetVesselByIndex(i);

		if (jump == true){
		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(-1, -1, -1);
			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 ((-500<gaterelative_pos.x>500) && (-500<gaterelative_pos.y>500) && (-10<gaterelative_pos.z>10))//ship is near gate and key pressed
what is odd It doesn't break when i am focused on the Gate A and press K
 

jedidia

shoemaker without legs
Addon Developer
Joined
Mar 19, 2008
Messages
10,883
Reaction score
2,135
Points
203
Location
between the planets
I get this :
WORMHOLE.CPP(103): warning C4804: '>' : unsafe use of type 'bool' in operation

Yes, that's because the syntax you're using shouldn't be used.

(a < b > c) is not the same as a < b && b > c. Instead, what it actually results in is (a < b) > c. In other words, you're comparing a result of type boolean to a numerical value, which is not a save thing to do. It also won't have the result you intended (but then, you don't get the result you intended because of the inverted comparators anyways)

You could of course have found that out yourself by just googling "unsafe use of type 'bool' in operation", as I did, because I didn't ever use this kind of syntax before, ergo never stumbled over the problem ;)

Seriously, I would be an awful developer without google and StackOverflow. Most people would be. Use it, and learn.
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,736
Reaction score
2,707
Points
203
Location
Dallas, TX
Thanks. I tried google and in stack over flow comparison c++
https://stackoverflow.com/questions/3830644/comparing-a-variable-to-a-range-of-values-in-c
Code:
if ((-500<gaterelative_pos.x) && (gaterelative_pos.x>500))
full if statement:
if (((-500<gaterelative_pos.x) && (gaterelative_pos.x>500)) && ((-500<gaterelative_pos.y) && (gaterelative_pos.y>500)) && ((-10<gaterelative_pos.z) && (gaterelative_pos.z>10)))

But not sure why it isn't breaking?

---------- Post added 10-06-17 at 05:07 AM ---------- Previous post was 10-05-17 at 06:12 PM ----------

At first I get this:
- gaterelative_pos {data=0x00aefb14 {0.00000000000000000, 0.00000000000000000, 0.00000000000000000} x=0.00000000000000000 ...} VECTOR3
continue:
- gaterelative_pos {data=0x00aefb14 {-2.2044093733256711e+285, 4.7535208471171000e+269, 1.5974607620371057e+234} x=-2.2044093733256711e+285 ...} VECTOR3
continue:
- gaterelative_pos {data=0x00aefb14 {-7.8158252101031936e+239, 4.7535208449831048e+269, -1.0394604954190492e+108} x=-7.8158252101031936e+239 ...} VECTOR3
continue:
- gaterelative_pos {data=0x00aefb14 {-1.9913653737407665e-059, 4.7535221060277448e+269, -1.8556644664300167e+205} x=-1.9913653737407665e-059 ...} VECTOR3
continue:
- gaterelative_pos {data=0x00aefb14 {-5.2047952780030685e-170, 4.7535221067852163e+269, -6.1829153407576083e+202} x=-5.2047952780030685e-170 ...} VECTOR3
I disable the breakpoint and now the DG is on the other side of the gate. no jump
 
Last edited:

Artlav

Aperiodic traveller
Addon Developer
Beta Tester
Joined
Jan 7, 2008
Messages
5,790
Reaction score
780
Points
203
Location
Earth
Website
orbides.org
Preferred Pronouns
she/her
Huh. I could have sworn i made a stargate add-on for Orbiter once.
However, all i can find is Warp Drive and Teleport Booth.
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,736
Reaction score
2,707
Points
203
Location
Dallas, TX
So not sure why it isn't jumping. The values look like they would fit the if statement.
 
Top