Orbiter-Forum  

Go Back   Orbiter-Forum > Orbiter Addons > Addon Requests
Register Blogs Orbinauts List Social Groups FAQ Projects Mark Forums Read

Addon Requests If you have a request for a new addon or want to know where to find a specific addon, ask it here!

Reply
 
Thread Tools
Old 03-14-2017, 08:41 PM   #61
fred18
Addon Developer

Default

Quote:
Originally Posted by gattispilot View Post
 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.

Quote:
Originally Posted by Trekkie View Post
 How are the Gates linked together?
I posted the code for it here:

http://www.orbiter-forum.com/showthr...5&postcount=21
fred18 is offline   Reply With Quote
Thanked by:
Old 03-14-2017, 08:43 PM   #62
Trekkie
Starfleet Captain
 
Trekkie's Avatar
Default

Quote:
Originally Posted by fred18 View Post
 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

---------- 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?
Trekkie is offline   Reply With Quote
Old 03-14-2017, 08:50 PM   #63
gattispilot
Addon Developer
 
gattispilot's Avatar
Default

And can we make it either way coming and going into the gateway. So it is a 2 way gate?
gattispilot is offline   Reply With Quote
Old 03-14-2017, 08:52 PM   #64
Trekkie
Starfleet Captain
 
Trekkie's Avatar
Default

Quote:
Originally Posted by gattispilot View Post
 And can we make it either way coming and going into the gateway. So it is a 2 way gate?
A 1 way would resemble like an unstable wormhole
Trekkie is offline   Reply With Quote
Old 03-14-2017, 09:35 PM   #65
fred18
Addon Developer

Default

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.
fred18 is offline   Reply With Quote
Thanked by:
Old 03-14-2017, 10:43 PM   #66
Trekkie
Starfleet Captain
 
Trekkie's Avatar
Default

Quote:
Originally Posted by fred18 View Post
 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?
Trekkie is offline   Reply With Quote
Old 03-14-2017, 11:46 PM   #67
fred18
Addon Developer

Default

Quote:
Originally Posted by Trekkie View Post
 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.
fred18 is offline   Reply With Quote
Thanked by:
Old 03-19-2017, 11:15 AM   #68
gattispilot
Addon Developer
 
gattispilot's Avatar
Default

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?
gattispilot is offline   Reply With Quote
Old 03-19-2017, 11:43 AM   #69
fred18
Addon Developer

Default

Quote:
Originally Posted by gattisplot
 So the gateway is 2 way right now, right?
Quote:
Originally Posted by fred18
 The code is for a 2 ways single wormhole.
Quote:
Originally Posted by gattisplot
 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))
fred18 is offline   Reply With Quote
Thanked by:
Old 03-19-2017, 07:13 PM   #70
gattispilot
Addon Developer
 
gattispilot's Avatar
Default

Quote:
Originally Posted by fred18 View Post
 
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


If I go thru and then reverse thruster I go thru?


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


}
gattispilot is offline   Reply With Quote
Old 03-21-2017, 11:02 AM   #71
gattispilot
Addon Developer
 
gattispilot's Avatar
Default

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?
gattispilot is offline   Reply With Quote
Old 03-21-2017, 11:31 AM   #72
Urwumpe
Certain Super User
 
Urwumpe's Avatar

Default

Quote:
Originally Posted by gattispilot View Post
 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?
Urwumpe is offline   Reply With Quote
Old 03-21-2017, 12:15 PM   #73
gattispilot
Addon Developer
 
gattispilot's Avatar
Default

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.
gattispilot is offline   Reply With Quote
Old 03-21-2017, 12:34 PM   #74
Urwumpe
Certain Super User
 
Urwumpe's Avatar

Default

Quote:
Originally Posted by gattispilot View Post
 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.
Urwumpe is offline   Reply With Quote
Thanked by:
Old 03-21-2017, 12:40 PM   #75
gattispilot
Addon Developer
 
gattispilot's Avatar
Default

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?
gattispilot is offline   Reply With Quote
Reply

  Orbiter-Forum > Orbiter Addons > Addon Requests


Thread Tools

Posting Rules
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
Forum Jump


All times are GMT. The time now is 04:14 AM.

Quick Links Need Help?


About Us | Rules & Guidelines | TOS Policy | Privacy Policy

Orbiter-Forum is hosted at Orbithangar.com
Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright 2007 - 2012, Orbiter-Forum.com. All rights reserved.