Request Gateway transport system

So if I read the code the vessel must be be less than 10 and in front of and o rel velocity?

not 0 rel velocity, z component of relative velocity shall be less than 0 so the vessel is approaching and not going away. Check also if you have rotated properly the mesh, it should be around the z axis.

How are the Gates linked together?

I posted the code for it here:

http://www.orbiter-forum.com/showthread.php?p=554575&postcount=21
 
about the code I provided before, a check to exclude the "self transportation" of the gateway vessel must be added, since it's checking for all the vessels in the sim, it will check also for himself and its distance from himself will always be 0 and it will start to fly around in a loop until your pc melts down :lol:

---------- Post added at 17:07 ---------- Previous post was at 15:49 ----------

the quick and dirty example works with the following code (in pre or poststep of course), but it's still far to be perfect, it just could be a starting point

from now on have fun ;)

Code:
for (UINT i=0;i<oapiGetVesselCount();i++)
	{
		OBJHANDLE hvessel=oapiGetVesselByIndex(i);
		
		if(hvessel!=GetHandle())
		{
			VECTOR3 rpos,rvel;
			oapiGetRelativePos(hvessel,GetHandle(),&rpos);
			double distance=length(rpos);
			oapiGetRelativeVel(hvessel,GetHandle(),&rvel);
			
			if((distance<2)&&(rpos.z>0)&&(rvel.z<0))  
			{
			
			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;
			
			




			v->DefSetStateEx(&vs_vessel);
			}
		}
	}

So if i get this right, you would only be able to use 2 Gates at a time?
 
And can we make it either way coming and going into the gateway. So it is a 2 way gate?
 
The code is for a 2 ways single wormhole.

You can use that code to implement many other options, that was just a quick and dirty.
 
The code is for a 2 ways single wormhole.

You can use that code to implement many other options, that was just a quick and dirty.

would there be a way to make it like unlimited that you can select whatever wormhole u like?
 
would there be a way to make it like unlimited that you can select whatever wormhole u like?

There is, even if that's probably the most difficult option to add because it means to query the user for where he wants to go and it's not easy in orbiter, but it's only a matter of being creative... for example you can jump in a wormhole gate vessel and choose within it which other gate it will send the ships to. That can be done through hud text.

Or a dedicated MFD can be implemented, which will be then be available within the ships you want to send through the hole, so even better.
 
More questions.

So the gateway is 2 way right now, right?

So what determines when the ship enters the gateway and transported? I mean do the ship both need to be centered and 2 meters away from the center? How about speed?
 
gattisplot said:
So the gateway is 2 way right now, right?
fred18 said:
The code is for a 2 ways single wormhole.

gattisplot said:
So what determines when the ship enters the gateway and transported? I mean do the ship both need to be centered and 2 meters away from the center? How about speed?
Code:
if((distance<2)&&(rpos.z>0)&&(rvel.z<0))
 
Code:
if((distance<2)&&(rpos.z>0)&&(rvel.z<0))

So if the distance (center to Center) is less than 2 meters.

Relative velocity is less than 0 so speed is a factor, right?

rpos.z>0 You are going towards it, right?


So it is center of vessel of both vessels. Could we make the x and y larger?

So rather than a pinpoint you are aiming for a larger target?

---------- Post added at 02:13 PM ---------- Previous post was at 07:23 AM ----------

Endurance coming thru wormhole
Lz7zFqT.jpg


If I go thru and then reverse thruster I go thru?
k1cj1uF.jpg


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 rpos, rvel;
			oapiGetRelativePos(hvessel, GetHandle(), &rpos);
			double distance = length(rpos);
			oapiGetRelativeVel(hvessel, GetHandle(), &rvel);
			sprintf(oapiDebugString(), "distance %f rpos.z %f rvel.z %f", distance, rpos.z, rvel.z);
			if ((distance<20) && (rpos.z>0) && (rvel.z<0))
			{

				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;






				v->DefSetStateEx(&vs_vessel);
			}
		}
	}


}
 
Ok I have increased the distance to 2000. We have a sphere as a mesh that is 1000 diameter.

But Even though the Worm hole vessel z axis is opposite the approaching vessel. We have to go past the center and then back through?

So how do I make the target area larger?
 
Ok I have increased the distance to 2000. We have a sphere as a mesh that is 1000 diameter.

But Even though the Worm hole vessel z axis is opposite the approaching vessel. We have to go past the center and then back through?

So how do I make the target area larger?

Before we go on fixing code, do you understand what the expression "(rpos.z>0) && (rvel.z<0)" means?
 
Maybe? I see it as Relative position z vector greater than 0 So the vessel is in front of the gate?

And relative Velocity z vector is less than 0.
 
Maybe? I see it as Relative position z vector greater than 0 So the vessel is in front of the gate?

And relative Velocity z vector is less than 0.

Exactly not. remember relative coordinates are not local coordinates in orbiter. ;) Relative coordinates are like global coordinates in the orientation of the axes, but with a different origin. local coordinates are the vessel coordinates with Z+ being forward.

But otherwise, the behavior is correct. You are supposed to be travelling towards the gate in the Z-axis of the relative/global coordinate system of Orbiter from being in the positive Z-half of the coordinate system.

Now, how to fix it that the code is less surprising to you and other players?

One solution is the classic scalar product in linear algebra. Or dotp in Orbiter. if you take velocity and relative position in any coordinate system,

dotp(velocity, position) < 0

means that the vehicle is traveling coarsely towards the origin or gate (the range rate is negative).

If you have:

dotp(velocity, position)/(length(velocity)*length(position)) == -1

it flies perfectly straight towards the origin (gate).


Since we mentioned it:

dotp(velocity, position)/length(position)

gives you the range rate, the change in distance in that instance.

But since we want to avoid using too much FPU cycles, the first one should be perfectly fine for the task, together with the maximum distance from the center of the jump gate, if you want a worm hole kind of travel.
 
Thanks.

So if we get this:
Code:
VECTOR3 rpos, rvel;
			oapiGetRelativePos(hvessel, GetHandle(), &rpos);
			double distance = length(rpos);
			oapiGetRelativeVel(hvessel, GetHandle(), &rvel);

if dotp(&rvel, &rpos) < 0 so the vessel is travelling towards the center, right?
 
Thanks.

So if we get this:
Code:
VECTOR3 rpos, rvel;
            oapiGetRelativePos(hvessel, GetHandle(), &rpos);
            double distance = length(rpos);
            oapiGetRelativeVel(hvessel, GetHandle(), &rvel);
if dotp(&rvel, &rpos) < 0 so the vessel is travelling towards the center, right?

No, it is "dotp(rvel, rpos)" and yes, coarsely towards the center. dotp(rvel, rpos) = 0 would mean tangential travel. in this case, "dotp(rvel, rpos)/distance" is the range rate.

There are also other mathematical solutions possible, but dotp should become a name you should remember. It is really helpful mathematics.

And for being annoying: "&rvel" means "a pointer/reference to the variable rvel", for doing a classic "call by reference" (An other name you should better look up in a calm moment and learn, its useful). You need when you have a variable and need a pointer to it.
 
Last edited:
Ok So if dotp(rvel, rpos) = 0 we are travelling toward the center? So is x, y a factor. Can we make a larger target
 
Ok So if dotp(rvel, rpos) = 0 we are travelling toward the center? So is x, y a factor. Can we make a larger target

No, tangential means your velocity vector is perpendicular to the position vector.
 
So dotp(rvel, rpos) = 0 means travelling toward the center, right?

But we have to be perpendicular to the gate, right? So the x and Y difference would be 0
 
So dotp(rvel, rpos) = 0 means travelling toward the center, right?

But we have to be perpendicular to the gate, right? So the x and Y difference would be 0

Again. No. By repeating it, it does not get better.

dotp(A, B) = 0 means, A is 90° to B, which means perpendicular.

And why should you travel perpendicular to the gate? Its like crossing a like by walking parallel to it. It makes no sense.



Read here for the mathematical background:

https://en.wikipedia.org/wiki/Dot_product

What we are exploiting here can be visualized as such:

500px-Dot_Product.svg.png


But instead of normalizing the position vector for accurate results, we just want the sign to show the coarse trend. Does the velocity point towards or away from the gate?
 
Back
Top