Problem Add a different kind of thrust effect

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,740
Reaction score
2,716
Points
203
Location
Dallas, TX
I added it.

Now the questions?
What should tgt and REFVEC be?
 

Urwumpe

Not funny anymore
Addon Developer
Donator
Joined
Feb 6, 2008
Messages
37,648
Reaction score
2,362
Points
203
Location
Wolfsburg
Preferred Pronouns
Sire
I added it.

Now the questions?
What should tgt and REFVEC be?

tgt is the vector from your vessel to the target in relative coordinates.
REFVEC is the direction vector from your vessel in direction that you want to scan for objects.

You can use such code for many things, for example simulating directed antennas.
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,740
Reaction score
2,716
Points
203
Location
Dallas, TX
Thanks. I think this is right.
Code:
oapiGetRelativePos(hme, hv, &tgt);
CONE_ANGLE=1;
const double COSCONE = cos(CONE_ANGLE);
  REFVEC=_V(0,0,1);
 sprintf(oapiDebugString(),"x%2f COSCONE%2f ",costgt,COSCONE);
 
 costgt = dotp(tgt, REFVEC)/ length(tgt);
  
 if(costgt <= COSCONE) {//it is inside this cone

With REFVEC=_V(0,0,1); it looks straight ahead along the Z axis, right. Is there a way to look all around. Or would I have to do different vectors?
 

Urwumpe

Not funny anymore
Addon Developer
Donator
Joined
Feb 6, 2008
Messages
37,648
Reaction score
2,362
Points
203
Location
Wolfsburg
Preferred Pronouns
Sire
Is there a way to look all around. Or would I have to do different vectors?

What do you mean with look all around? I thought the question was telling quickly, which spacecraft is left, right, up or down of a spacecraft.

You define which direction is left, right, up or down - and how much of the space around the spacecraft belongs to it. Which I solved in my example by using an infinite cone.
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,740
Reaction score
2,716
Points
203
Location
Dallas, TX
I am confused then. What is the CONEANGLE?

NEBMESHS.jpg


So if a vessel is in area 1 show mesh 1, if a vessel is where vessel 2 is then show mesh 2. ,.... It will not be precise as the meshes would not chnage but there would be several meshes to cover 360 around
 

Urwumpe

Not funny anymore
Addon Developer
Donator
Joined
Feb 6, 2008
Messages
37,648
Reaction score
2,362
Points
203
Location
Wolfsburg
Preferred Pronouns
Sire
I am confused then. What is the CONEANGLE?

So if a vessel is in area 1 show mesh 1, if a vessel is where vessel 2 is then show mesh 2. ,.... It will not be precise as the meshes would not chnage but there would be several meshes to cover 360 around

Think of it as a spot light. The angle from the direction of the spot light, that limits the light, is the cone angle. If the mesh gets lighted by being in the cone of the spotlight, it is in the space you defined.

So yes, you would need multiple meshes, unless you are only looking for the nearest vessel in the crowd. In that case there are better solutions.

This algorithm above is just the standard solution for example for telling if a spacecraft is seen by a sensor.
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,740
Reaction score
2,716
Points
203
Location
Dallas, TX
So what if the angle was all around.

Otherwise Should I have 4 different zones of detection?


Yes multiple meshes will be there. It is just a matter of seeing if another vessel is in front then show this mesh.
 

Urwumpe

Not funny anymore
Addon Developer
Donator
Joined
Feb 6, 2008
Messages
37,648
Reaction score
2,362
Points
203
Location
Wolfsburg
Preferred Pronouns
Sire
Otherwise Should I have 4 different zones of detection?

One zone per mesh of course. 4 is easily enough to cover the whole space.

(Like four thrusters is all you need for rotation-free translation, if you like wasting some fuel)
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,740
Reaction score
2,716
Points
203
Location
Dallas, TX
Except that would only cover 1 plane of the y axis. I guess you would want to know if the vessel or higher or lower also in 4 directions

---------- Post added at 09:21 PM ---------- Previous post was at 11:48 AM ----------

I am not sure if I understand.

Code:
CONE_ANGLE=0; // 0 degrees in front
const double COSCONE = cos(CONE_ANGLE);
  REFVEC=_V(0,0,1);
 sprintf(oapiDebugString(),"costgt%2f COSCONE%2f Distance%2f",costgt,COSCONE,d);
 
 costgt = dotp(tgt, REFVEC)/ length(tgt);
  
 if(costgt <= COSCONE) {//it is inside this cone

target in front
nebtargetinfront.jpg


target to the left
nebtargetleft.jpg


target to the right
nebtargetright.jpg


---------- Post added 04-24-14 at 05:57 AM ---------- Previous post was 04-23-14 at 09:21 PM ----------

This is what she looks like when the meshes are added if below 30 meters. Now it it is just a matter to tell it which mesh to be seen based off where another vessel is relative to her.
NEBPADFIRING.jpg


---------- Post added 04-25-14 at 05:46 AM ---------- Previous post was 04-24-14 at 05:57 AM ----------

Here is an image of what I understand. My vessel would be the red dot the other vessel is the blue square.
REFVEC.jpg

So to look at the 4 directions I would need 4 REFVEC's, right.
But it is the Cone Angle part I don't get?
 

Urwumpe

Not funny anymore
Addon Developer
Donator
Joined
Feb 6, 2008
Messages
37,648
Reaction score
2,362
Points
203
Location
Wolfsburg
Preferred Pronouns
Sire
Well, lets say you want to detect if a vessel is somewhere below your vessel: Simplest test: Just calculate if target Y coordinate in local vessel coordinates is negative.

If you want to do the test for multiple vessels, it is faster to check if the vessel is in that hemisphere below your vessel: ref vector is the projection of (0, -1, 0) into global coordinates (only need to do that once per time step), instead of using some sort of cosine of the cone angle 180°, you simply check if the scalar product (dotp) of that ref vector with the vector to the target in relative coordinates is zero or positive. All fine.

Important to remember (I am sure I did it wrong earlier): If you want to check if an angle is smaller than x, you have to check if the cosine of the angle is bigger than the cosine of x (for all angles of x that are smaller than 180° or Pi).

a < b --> cos(a) > cos(b)
 
Last edited:

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,740
Reaction score
2,716
Points
203
Location
Dallas, TX
Thanks,
Code:
CONE_ANGLE=0;
const double COSCONE = cos(CONE_ANGLE);
  REFVEC=_V(0,-1,0);
 sprintf(oapiDebugString(),"costgt%2f COSCONE%2f Distance%2f",costgt,COSCONE,d);
 
 costgt = dotp(tgt, REFVEC)/ length(tgt);
With another vessel right below her I get for costgt .5
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,740
Reaction score
2,716
Points
203
Location
Dallas, TX
Is there a way to compare my location and another vessels location. if his x is larger then he is to the right?,......
 

Urwumpe

Not funny anymore
Addon Developer
Donator
Joined
Feb 6, 2008
Messages
37,648
Reaction score
2,362
Points
203
Location
Wolfsburg
Preferred Pronouns
Sire
Is there a way to compare my location and another vessels location. if his x is larger then he is to the right?,......

Yes, like I have written: You then need to transform the relative position in relative coordinates into local coordinates of your vessel. But thats a bit computation heavy, if you repeat this for every vessel you want to test.
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,740
Reaction score
2,716
Points
203
Location
Dallas, TX
Do you mean this code:
Code:
for ( unsigned int i = 0; i<cnt; i++)
{hv = oapiGetVesselByIndex (i); 
//if (hV == GetHandle()) continue;
if (hme == hv) continue;
oapiGetGlobalPos (hv, &tpos);
d=dist (gpos,tpos);
oapiGetRelativePos(hme, hv, &tgt);
CONE_ANGLE=0;
const double COSCONE = cos(CONE_ANGLE);
  REFVEC=_V(0,-1,0);
 //sprintf(oapiDebugString(),"costgt%2f COSCONE%2f Distance%2f",costgt,COSCONE,d);
 
 costgt = dotp(tgt, REFVEC)/ length(tgt);

So if I do this but change the reflec vector that will tell me where another vessel is?

And if results are positive it is below. negative above in this case?
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,740
Reaction score
2,716
Points
203
Location
Dallas, TX
Then I am confused.

Would that cone of space work. But i am not sure what the cone angle and what solution values I get would mean?
 

Urwumpe

Not funny anymore
Addon Developer
Donator
Joined
Feb 6, 2008
Messages
37,648
Reaction score
2,362
Points
203
Location
Wolfsburg
Preferred Pronouns
Sire
Then I am confused.

Would that cone of space work. But i am not sure what the cone angle and what solution values I get would mean?

C%C3%B4ne_de_r%C3%A9volution.png


Alpha is the cone angle.

Now, you have cosine of the angle as result of the vector operation and that cosine function behaves like this:

500px-Cosine.svg.png


If you increase the angle x, the cosine gets smaller. You can follow me?

So, this means, if you want to test, if an angle is smaller than x, you have to test if the cosine of the angle is bigger than the cosine of x.

And refvec (not relvef or what ever you call it) is a shortened form for reference vector, which is simply the direction vector of the cone axis from the apex of the cone.
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,740
Reaction score
2,716
Points
203
Location
Dallas, TX
So if I want to look to see if a vessel is below refvec is (0,-1,0) right? But The Cone angle is in degrees? So for 45 degree cone I would use ConeAngle 45?

Code:
for ( unsigned int i = 0; i<cnt; i++)
{hv = oapiGetVesselByIndex (i); 
//if (hV == GetHandle()) continue;
if (hme == hv) continue;
oapiGetGlobalPos (hv, &tpos);
d=dist (gpos,tpos);
oapiGetRelativePos(hme, hv, &tgt);
CONE_ANGLE=0;
const double COSCONE = cos(CONE_ANGLE);
  REFVEC=_V(0,-1,0);
 //sprintf(oapiDebugString(),"costgt%2f COSCONE%2f Distance%2f",costgt,COSCONE,d);
 
 costgt = dotp(tgt, REFVEC)/ length(tgt);
  ALT=GetAltitude();
 if(costgt <= COSCONE) {//it is inside this cone


---------- Post added 04-28-14 at 05:44 AM ---------- Previous post was 04-27-14 at 01:09 PM ----------

I guess I don't get it.
here is an image with cone angle of 45 and refvec of 0,0,1.
REFVEC1.jpg

note that costgt is less than COSCONE so do something and with a short distance. But if I move forward so now the vessel is behind should the costgt be greater COSCONE?

Code:
DWORD cnt= oapiGetVesselCount();  {
OBJHANDLE hme = GetHandle(),hv; 
VECTOR3 gpos,tpos,WHERETARGET,REFVEC,tgt;
GetGlobalPos (gpos);
double d,CONE_ANGLE;

for ( unsigned int i = 0; i<cnt; i++)
{hv = oapiGetVesselByIndex (i); 
//if (hV == GetHandle()) continue;
if (hme == hv) continue;
oapiGetGlobalPos (hv, &tpos);
d=dist (gpos,tpos);
oapiGetRelativePos(hme, hv, &tgt);
CONE_ANGLE=45;
const double COSCONE = cos(CONE_ANGLE);
  REFVEC=_V(0,0,1);
 sprintf(oapiDebugString(),"costgt%2f COSCONE%2f ",costgt,COSCONE);
 
 costgt = dotp(tgt, REFVEC)/ length(tgt);
  ALT=GetAltitude();
 if(costgt <= COSCONE) {//it is inside this cone
     if (ALT<30)
 
Last edited:

Urwumpe

Not funny anymore
Addon Developer
Donator
Joined
Feb 6, 2008
Messages
37,648
Reaction score
2,362
Points
203
Location
Wolfsburg
Preferred Pronouns
Sire
But if I move forward so now the vessel is behind should the costgt be greater COSCONE?

No, opposite: If your target is inside your cone, the costgt will be bigger than COSCONE. if it is outside, it will be smaller than COSCONE.

Important is to remember what the scalar product (dotp) does:

500px-Dot_Product.svg.png
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,740
Reaction score
2,716
Points
203
Location
Dallas, TX
Ok back to being lost. In the image the DG is in front of the vessel. costgt is .42 and COSCONE is .525. So costgt is less than COSCONE.

Would an easier way be to if a vessel is say 10 meters away. then you compare ny vessel (x,y,z) location to that vessel (x,y,z). If The difference in Y is - then the ship is below. So show a below mesh.
 
Top