
Originally Posted by
Myke
I have to read through those answers after i got some sleep, right now i can't follow it pretty far but i'm sure it probably lacks of my knowledge rather than on the explanations.
To give an idea what the purpose is, it is about to fill this gauge with more or less sensefull life:
The compass itself is just a regular compass, not involved in this problem here.
The part with the 4 dots horizontally and the pointer which points to the N on the pic does rotate depending on the set curse (waypoints-like but not from actual position but from WP to WP). And finally the vertical line which on the pic is on the far left and which indicates where the Flightpath relative to the plane is located. This line rotates along with the underlying curse indicator and moves only in a transitional path. The plane symbol in the middle is fixed and doesn't rotate nor move at all, indicating actual heading of the plane.
The far goal is to simulate VOR/ILS functionality, more than ArmA 2 actually provides as usable data. Also flight path (waypoint-like) should be displayed with this gauge with data provided from avionics system of the plane.
Ok emulating a VOR is fairly easy, basically all aVOR gauge does is track how many degrees you are off your desired track that you entered into the gauge.
As such a VOR gauge is more sensitive the closer you get to the vor station.
So all you need to do is enter the desired beaing, then check that against the aircrafts actual direction to the vor station. The needle deflection is then calulated relative to the amount of difference between the two values.
Here is a quick script I used for my own testing. Note you would need further code when checking the 360-0 mark one when one value is on one sid and the other is on the other side of 0 degrees.
Code:
_point2 = getmarkerpos "w2";
_pointA = position player;
private ["_Left","_Right","_offset","_lineHeading"];
while {true} do
{
_lineHeading = 327;
_lineHeadingP = [_pointA, _point2] call BIS_fnc_dirTo;
if (_lineHeadingP < 0) then
{
_lineHeadingP = 360 + _lineHeadingP ;
};
_diff = _lineHeading - _lineHeadingP;
If (_diff < 0) then
{
hint format [" Track %1 Left of Track %2",abs(floor(_lineHeading)),abs(floor(_diff))];
}
else
{
hint format ["Track %1 Right of Track %2", abs(floor(_lineHeading)),abs(floor(_diff))];
};
sleep 2;
_point1 = getmarkerpos "w1";
_point2 = getmarkerpos "w2";
_pointA = position player;
};
Now if you emulating a gps you might have to go complicated like this to calculated the distance off track. So the below script checks the distance of the line perpendicular to the desired track. Not the angle. It's a bit rough but I mocked it up to test my theories validity.
This one is based one my first posts theory, and doesn't include the special case of a N-S S-N tracks where x1 and x2 are equal.
Code:
_point1 = getmarkerpos "w1";
_point2 = getmarkerpos "w2";
_pointA = position player;
private ["_Left","_Right","_offset","_lineHeading"];
while {true} do
{
//Left and Right represent the formulae sides as per the two point form in the link.
// http://en.wikipedia.org/wiki/Linear_equation
If (_point1 select 0 != _point2 select 0) then
{
_Left = ((_pointA select 1) - (_point1 select 1));
_Right = ((_point2 select 1) - (_point1 select 1))/((_point2 select 0) - (_point1 select 0) )*((_pointA select 0) - (_point1 select 0));
};
//Obtain line direction and convert to 0-360 format.
_lineHeading = [_point1, _point2] call BIS_fnc_dirTo;
if (_lineHeading < 0) then
{
_lineHeading = 360 + _lineHeading ;
};
//Need to check direction of the line to determine if being above or below means to the left or to the right.
_dist = abs(floor(_Left - _Right)) * sin _lineHeading;
if (_lineHeading < 180) then
{
if (_Left < _Right) then
{
_offset = format ["Right of track %1" ,_dist];
}
else
{
_offset = format ["Left of track %1" ,_dist];
};
}
else
{
if (_Left < _Right) then
{
_offset = format ["Left of track %1" ,_dist];
}
else
{
_offset = format ["Right of track %1" ,_dist];
};
};
//_dist = abs(floor(_Left - _Right)) * sin _lineHeading;
hint format ["Dir %1 : %2", floor(_lineHeading),_offset];
//hint format ["Dir %1 : %2", floor(_lineHeading),_dist];
sleep 3;
_point1 = getmarkerpos "w1";
_point2 = getmarkerpos "w2";
_pointA = position player;
};