Home   Help Search Login Register  

Author Topic: Gun angle  (Read 1347 times)

0 Members and 2 Guests are viewing this topic.

Offline Luke

  • Members
  • *
  • Thank God! The OFPEC Staff are here!
Gun angle
« on: 13 Aug 2008, 02:30:09 »
How does one find the vertical angle at which a static gun is pointing?

Luke
Pesky Human!!
Wort Wort Wort.

Offline h-

  • OFPEC Site
  • Administrator
  • *****
  • Formerly HateR_Kint
    • OFPEC
Re: Gun angle
« Reply #1 on: 13 Aug 2008, 08:48:08 »
By calculating from the weaponDirection vector? :dunno:

You can get the weapon direction of, say, the static M2 with
Code: [Select]
mgname weaponDirection "M2"
Project MCAR   ---   Northern Fronts   ---   Emitter 3Ditor
INFORMATIVE THREAD TITLES PLEASE. "PLEASE HELP" IS NOT ONE..
Chuck Norris can divide by zero.

Offline Spooner

  • Members
  • *
  • Mostly useless
    • Community Base Addons
Re: Gun angle
« Reply #2 on: 13 Aug 2008, 11:35:47 »
The horizontal angle is the azimuth (0 = north) and the vertical angle is the elevation (0 = horizontal):

Code: [Select]
_vector = mgname weaponDirection "M2";
_horizontalAngle = (_vector select 0) atan2 (_vector select 1); // Range: -180 to 180
_azimuth =  ((_horizontalAngle  + 360) mod 360); // Range: 0 to 360
_elevation = (_vector select 2) atan2 (sqrt(((_vector select 0) ^ 2) + ((_vector select 1) ^ 2)));
[Arma 2] CBA: Community Base Addons
[Arma 1] SPON Core (including links to my other scripts)

Offline Luke

  • Members
  • *
  • Thank God! The OFPEC Staff are here!
Re: Gun angle
« Reply #3 on: 13 Aug 2008, 17:50:58 »
OK thanx.

However what's the difference between azimuth and elevation.

also

wouldn't
Code: [Select]
(_horizontalangle + 360) mod 360 just equal _horizontalAngle anyway?
Pesky Human!!
Wort Wort Wort.

Offline Spooner

  • Members
  • *
  • Mostly useless
    • Community Base Addons
Re: Gun angle
« Reply #4 on: 13 Aug 2008, 18:21:14 »
The horizontal angle is the azimuth, which is the number of degrees clockwise from North (0 = North; 90 = East, 180 = South, 270 = West) and the vertical angle is the elevation above the horizontal (0 = horizontal; +90 is up; -90 is down). I can't make it clearer than that!

_horizontalAngle, in my algorithm, is given in a range of -180 to 180, which is the normal mathematical way to show the angle, but not the way angles are normally shown in game or, for that matter, by the military. Normally, directions in ArmA are 0 to 360, such as the result from getDir, so that last line will convert it to a proper azimuth value for consistency. The "horizontal angle" and azimuth can be used interchangably in, say, setDir.
[Arma 2] CBA: Community Base Addons
[Arma 1] SPON Core (including links to my other scripts)

Offline jones

  • Members
  • *
Re: Gun angle
« Reply #5 on: 13 Aug 2008, 20:37:29 »
here is the code i use on my artillery mod, it might help you.

Code: [Select]
while {( ( vehicle player ) == ( vehicle _LRM119 ) ) } do
    {
    _tangent = ( ( vehicle player weaponDirection "LRM119" ) select 0 ) atan2 ( ( ( vehicle player weaponDirection "LRM119" ) ) select 1 );
        _elevation = asin( ( vehicle player weaponDirection "LRM119" ) select 2 ) - asin( vectorDir vehicle player select 2 );
               
if ( _tangent < 0 ) then
    {
        _tangent = _tangent + 360
    };

hint format[ "Tanget: %1\nElevation: %2", _tangent, _elevation];

Sleep 0.2;
        };

If you want to display it in mils then you can add this

Code: [Select]
if ( _tangent < 0 ) then
    {
        _tangent = _tangent + 360
    };


_tangent =  _tangent * 17.777777777777777777777777777778;
_tangent = _tangent - (_tangent mod 1);



Just change the _tangent to _elevation and it will be converted to mills (mils are the 360 degree range expressed in increments from 0 to 6400) the ( _tangent mod 1); is just to round it down to the nearest 1 to eleminate decimals. if you want decimals remove that
         

« Last Edit: 13 Aug 2008, 20:52:57 by jones »