From 69cd53de2a73856127f64340e2a8b878d1c5e596 Mon Sep 17 00:00:00 2001 From: ulteq Date: Sun, 13 Nov 2016 15:43:07 +0100 Subject: [PATCH] Optimized ATragMX solution calculations --- .../functions/fnc_calculate_range_card.sqf | 2 +- .../functions/fnc_calculate_solution.sqf | 42 +++++++++++-------- .../fnc_calculate_target_solution.sqf | 2 +- 3 files changed, 26 insertions(+), 20 deletions(-) diff --git a/addons/atragmx/functions/fnc_calculate_range_card.sqf b/addons/atragmx/functions/fnc_calculate_range_card.sqf index 0b6d0a177b..fa7793ebd5 100644 --- a/addons/atragmx/functions/fnc_calculate_range_card.sqf +++ b/addons/atragmx/functions/fnc_calculate_range_card.sqf @@ -71,5 +71,5 @@ if (GVAR(currentUnit) == 1) then { GVAR(rangeCardData) = []; -private _result = [_scopeBaseAngle, _bulletMass, _boreHeight, _airFriction, _muzzleVelocity, _temperature, _barometricPressure, _relativeHumidity, 1000, +private _result = [_scopeBaseAngle, _bulletMass, _boreHeight, _airFriction, _muzzleVelocity, _temperature, _barometricPressure, _relativeHumidity, 100, [_windSpeed1, _windSpeed2], _windDirection, _inclinationAngle, _targetSpeed, _targetRange, _bc, _dragModel, _atmosphereModel, true, _stabilityFactor, _twistDirection, _latitude, _directionOfFire] call FUNC(calculate_solution); diff --git a/addons/atragmx/functions/fnc_calculate_solution.sqf b/addons/atragmx/functions/fnc_calculate_solution.sqf index 940b3dc2ec..f50f502cc4 100644 --- a/addons/atragmx/functions/fnc_calculate_solution.sqf +++ b/addons/atragmx/functions/fnc_calculate_solution.sqf @@ -51,7 +51,10 @@ params [ ]; _windSpeed params ["_windSpeed1", "_windSpeed2"]; -private ["_bulletPos", "_bulletVelocity", "_bulletAccel", "_bulletSpeed", "_gravity", "_deltaT"]; +private ["_tx", "_tz", "_lastBulletPos", "_bulletPos", "_bulletVelocity", "_bulletAccel", "_bulletSpeed", "_gravity", "_deltaT"]; +_tx = 0; +_tz = 0; +_lastBulletPos = [0, 0, 0]; _bulletPos = [0, 0, 0]; _bulletVelocity = [0, 0, 0]; _bulletAccel = [0, 0, 0]; @@ -74,9 +77,10 @@ _horizontalDeflection = 0; _spinDrift = 0; _spinDeflection = 0; -private ["_n", "_range", "_rangeFactor"]; +private ["_n", "_range", "_trueRange", "_rangeFactor"]; _n = 0; _range = 0; +_trueRange = 0; _rangeFactor = 1; if (_storeRangeCardData) then { if (GVAR(currentUnit) == 1) then { @@ -133,22 +137,25 @@ while {_TOF < 15 && (_bulletPos select 1) < _targetRange} do { _bulletAccel = _bulletAccel vectorAdd _gravity; + _lastBulletPos = _bulletPos; + _bulletPos = _bulletPos vectorAdd (_bulletVelocity vectorMultiply (_deltaT * 0.5)); _bulletVelocity = _bulletVelocity vectorAdd (_bulletAccel vectorMultiply _deltaT); - _bulletPos = _bulletPos vectorAdd (_bulletVelocity vectorMultiply _deltaT); + _bulletPos = _bulletPos vectorAdd (_bulletVelocity vectorMultiply (_deltaT * 0.5)); _TOF = _TOF + _deltaT; if (_storeRangeCardData) then { _range = GVAR(rangeCardStartRange) + _n * GVAR(rangeCardIncrement); if ((_bulletPos select 1) * _rangeFactor >= _range && _range <= GVAR(rangeCardEndRange)) then { - if ((_bulletPos select 1) > 0) then { - _elevation = - atan((_bulletPos select 2) / (_bulletPos select 1)); - _windage1 = - atan((_bulletPos select 0) / (_bulletPos select 1)); - _windDrift = (_wind2 select 0) * (_TOF - (_range / _rangeFactor) / _muzzleVelocity); - _windage2 = - atan(_windDrift / (_bulletPos select 1)); - }; - if (_range != 0) then { - _lead = (_targetSpeed * _TOF) / (Tan(3.38 / 60) * _range); + _trueRange = _range / _rangeFactor; + if (_trueRange != 0) then { + _tx = (_lastBulletPos select 0) + (_trueRange - (_lastBulletPos select 1)) * ((_bulletPos select 0) - (_lastBulletPos select 0)) / ((_bulletPos select 1) - (_lastBulletPos select 1)); + _tz = (_lastBulletPos select 2) + (_trueRange - (_lastBulletPos select 1)) * ((_bulletPos select 2) - (_lastBulletPos select 2)) / ((_bulletPos select 1) - (_lastBulletPos select 1)); + _elevation = - atan(_tz / _trueRange); + _windage1 = - atan(_tx / _trueRange); + _windDrift = (_wind2 select 0) * (_TOF - _trueRange / _muzzleVelocity); + _windage2 = - atan(_windDrift / _trueRange); + _lead = (_targetSpeed * _TOF) / (Tan(3.38 / 60) * _trueRange); }; _kineticEnergy = 0.5 * (_bulletMass / 1000 * (_bulletSpeed ^ 2)); _kineticEnergy = _kineticEnergy * 0.737562149; @@ -176,14 +183,13 @@ while {_TOF < 15 && (_bulletPos select 1) < _targetRange} do { }; }; -if ((_bulletPos select 1) > 0) then { - _elevation = - atan((_bulletPos select 2) / (_bulletPos select 1)); - _windage1 = - atan((_bulletPos select 0) / (_bulletPos select 1)); - _windDrift = (_wind2 select 0) * (_TOF - _targetRange / _muzzleVelocity); - _windage2 = - atan(_windDrift / (_bulletPos select 1)); -}; - if (_targetRange != 0) then { + _tx = (_lastBulletPos select 0) + (_targetRange - (_lastBulletPos select 1)) * ((_bulletPos select 0) - (_lastBulletPos select 0)) / ((_bulletPos select 1) - (_lastBulletPos select 1)); + _tz = (_lastBulletPos select 2) + (_targetRange - (_lastBulletPos select 1)) * ((_bulletPos select 2) - (_lastBulletPos select 2)) / ((_bulletPos select 1) - (_lastBulletPos select 1)); + _elevation = - atan(_tz / _targetRange); + _windage1 = - atan(_tx / _targetRange); + _windDrift = (_wind2 select 0) * (_TOF - _targetRange / _muzzleVelocity); + _windage2 = - atan(_windDrift / _targetRange); _lead = (_targetSpeed * _TOF) / (Tan(3.38 / 60) * _targetRange); }; diff --git a/addons/atragmx/functions/fnc_calculate_target_solution.sqf b/addons/atragmx/functions/fnc_calculate_target_solution.sqf index eb4f2817c8..bdc8f0ab11 100644 --- a/addons/atragmx/functions/fnc_calculate_target_solution.sqf +++ b/addons/atragmx/functions/fnc_calculate_target_solution.sqf @@ -70,7 +70,7 @@ _inclinationAngle = GVAR(inclinationAngle) select GVAR(currentTarget); _targetSpeed = GVAR(targetSpeed) select GVAR(currentTarget); _targetRange = GVAR(targetRange) select GVAR(currentTarget); -GVAR(targetSolutionInput) = [_scopeBaseAngle, _bulletMass, _boreHeight, _airFriction, _muzzleVelocity, _temperature, _barometricPressure, _relativeHumidity, 1000, +GVAR(targetSolutionInput) = [_scopeBaseAngle, _bulletMass, _boreHeight, _airFriction, _muzzleVelocity, _temperature, _barometricPressure, _relativeHumidity, 100, [_windSpeed1, _windSpeed2], _windDirection, _inclinationAngle, _targetSpeed, _targetRange, _bc, _dragModel, _atmosphereModel, false, _stabilityFactor, _twistDirection, _latitude, _directionOfFire]; private _result = GVAR(targetSolutionInput) call FUNC(calculate_solution);