2018-09-17 19:19:29 +00:00
|
|
|
#include "script_component.hpp"
|
2016-10-12 22:35:24 +00:00
|
|
|
/*
|
|
|
|
* Author: jaynus / nou
|
|
|
|
* Guidance Per Frame Handler
|
|
|
|
*
|
|
|
|
* Arguments:
|
|
|
|
* 0: Guidance Arg Array <ARRAY>
|
|
|
|
* 1: PFID <NUMBER>
|
|
|
|
*
|
|
|
|
* Return Value:
|
2017-06-08 13:31:51 +00:00
|
|
|
* None
|
2016-10-12 22:35:24 +00:00
|
|
|
*
|
|
|
|
* Example:
|
|
|
|
* [[], 0] call ace_missileguidance_fnc_guidancePFH;
|
|
|
|
*
|
|
|
|
* Public: No
|
|
|
|
*/
|
2016-05-30 16:37:03 +00:00
|
|
|
|
2016-10-12 22:35:24 +00:00
|
|
|
BEGIN_COUNTER(guidancePFH);
|
2016-05-30 16:37:03 +00:00
|
|
|
|
2016-10-12 22:35:24 +00:00
|
|
|
#define TIMESTEP_FACTOR 0.01
|
2016-05-30 16:37:03 +00:00
|
|
|
|
2016-10-12 22:35:24 +00:00
|
|
|
params ["_args", "_pfID"];
|
|
|
|
_args params ["_firedEH", "_launchParams", "_flightParams", "_seekerParams", "_stateParams"];
|
|
|
|
_firedEH params ["_shooter","","","","_ammo","","_projectile"];
|
|
|
|
_launchParams params ["","_targetLaunchParams"];
|
2021-03-19 05:28:55 +00:00
|
|
|
_stateParams params ["_lastRunTime", "_seekerStateParams", "_attackProfileStateParams", "_lastKnownPosState", "_pidData"];
|
2016-05-30 16:37:03 +00:00
|
|
|
|
2016-10-12 22:35:24 +00:00
|
|
|
if (!alive _projectile || isNull _projectile || isNull _shooter) exitWith {
|
|
|
|
[_pfID] call CBA_fnc_removePerFrameHandler;
|
|
|
|
END_COUNTER(guidancePFH);
|
2016-05-30 16:37:03 +00:00
|
|
|
};
|
|
|
|
|
2016-10-12 22:35:24 +00:00
|
|
|
private _runtimeDelta = diag_tickTime - _lastRunTime;
|
|
|
|
private _adjustTime = 1;
|
2016-05-30 16:37:03 +00:00
|
|
|
|
2016-10-12 22:35:24 +00:00
|
|
|
if (accTime > 0) then {
|
2016-05-30 16:37:03 +00:00
|
|
|
_adjustTime = 1/accTime;
|
|
|
|
_adjustTime = _adjustTime * (_runtimeDelta / TIMESTEP_FACTOR);
|
|
|
|
TRACE_4("Adjust timing", 1/accTime, _adjustTime, _runtimeDelta, (_runtimeDelta / TIMESTEP_FACTOR) );
|
|
|
|
} else {
|
|
|
|
_adjustTime = 0;
|
|
|
|
};
|
|
|
|
|
2016-10-12 22:35:24 +00:00
|
|
|
private _minDeflection = ((_flightParams select 0) - ((_flightParams select 0) * _adjustTime)) max 0;
|
|
|
|
private _maxDeflection = (_flightParams select 1) * _adjustTime;
|
|
|
|
// private _incDeflection = _flightParams select 2; // todo
|
2016-05-30 16:37:03 +00:00
|
|
|
|
2016-10-12 22:35:24 +00:00
|
|
|
// Run seeker function:
|
|
|
|
private _seekerTargetPos = [[0,0,0], _args, _seekerStateParams, _lastKnownPosState] call FUNC(doSeekerSearch);
|
2016-05-30 16:37:03 +00:00
|
|
|
|
2016-11-15 02:19:24 +00:00
|
|
|
// Run attack profile function:
|
|
|
|
private _profileAdjustedTargetPos = [_seekerTargetPos, _args, _attackProfileStateParams] call FUNC(doAttackProfile);
|
2017-06-08 13:31:51 +00:00
|
|
|
|
2021-04-04 03:04:16 +00:00
|
|
|
private _projectilePos = getPosASLVisual _projectile;
|
|
|
|
|
2016-10-12 22:35:24 +00:00
|
|
|
// If we have no seeker target, then do not change anything
|
2019-06-08 04:48:37 +00:00
|
|
|
// If there is no deflection on the missile, this cannot change and therefore is redundant. Avoid calculations for missiles without any deflection
|
2021-02-27 17:05:05 +00:00
|
|
|
if ((_minDeflection != 0 || {_maxDeflection != 0}) && {_profileAdjustedTargetPos isNotEqualTo [0,0,0]}) then {
|
2021-03-19 05:28:55 +00:00
|
|
|
// Get a commanded acceleration via proportional navigation (https://youtu.be/Osb7anMm1AY)
|
|
|
|
// Use a simple PID controller to get the desired pitch, yaw, and roll
|
|
|
|
// Simulate moving servos by moving in each DOF by a fixed amount per frame
|
|
|
|
// Then setVectorDirAndUp to allow ARMA to translate the velocity to whatever PhysX says
|
2016-05-30 16:37:03 +00:00
|
|
|
|
2021-03-27 05:15:29 +00:00
|
|
|
private _rollDegreesPerSecond = 30;
|
|
|
|
private _yawDegreesPerSecond = 30;
|
|
|
|
private _pitchDegreesPerSecond = 30;
|
2016-10-12 22:35:24 +00:00
|
|
|
|
2021-03-27 05:15:29 +00:00
|
|
|
private _proportionalGain = 1;
|
2021-03-19 05:28:55 +00:00
|
|
|
private _integralGain = 0;
|
|
|
|
private _derivativeGain = 0;
|
2016-10-12 22:35:24 +00:00
|
|
|
|
2021-04-07 03:01:07 +00:00
|
|
|
private _projectileVelocity = velocity _projectile;
|
|
|
|
private _projectileSpeed = vectorMagnitude _projectileVelocity;
|
2021-04-04 03:04:16 +00:00
|
|
|
|
2021-03-31 23:16:00 +00:00
|
|
|
_pidData params ["_pid", "_lastMissileFrame", "_currentPitchYawRoll"];
|
2021-03-19 05:28:55 +00:00
|
|
|
_currentPitchYawRoll params ["_pitch", "_yaw", "_roll"];
|
2021-04-07 03:01:07 +00:00
|
|
|
_lastMissileFrame params ["_lastTargetPosition", "_lastTargetVelocity", "_lastLineOfSight"];
|
2021-03-19 05:28:55 +00:00
|
|
|
|
2021-04-02 02:12:49 +00:00
|
|
|
// Proportional navigation implemented via "Fundamentals of proportional navigation" by Stephen Murtaugh and Harry Criel
|
2021-03-19 05:28:55 +00:00
|
|
|
private _navigationGain = 3;
|
2021-03-31 23:16:00 +00:00
|
|
|
// integrate target velocity for realistic inference of velocity
|
|
|
|
private _targetVelocity = (_seekerTargetPos vectorDiff _lastTargetPosition) vectorMultiply (1 / diag_deltaTime);
|
|
|
|
private _targetAcceleration = (_targetVelocity vectorDiff _lastTargetVelocity) vectorMultiply (1 / diag_deltaTime);
|
2021-03-19 05:28:55 +00:00
|
|
|
|
2021-04-07 03:01:07 +00:00
|
|
|
private _lineOfSight = vectorNormalized (_profileAdjustedTargetPos vectorDiff _projectilePos);
|
2021-03-19 05:28:55 +00:00
|
|
|
|
2021-04-07 03:01:07 +00:00
|
|
|
private _losDelta = _lineOfSight vectorDiff _lastLineOfSight;
|
|
|
|
private _losRate = (vectorMagnitude _losDelta) / TIMESTEP_FACTOR;
|
2021-03-19 05:28:55 +00:00
|
|
|
|
2021-04-07 03:01:07 +00:00
|
|
|
private _closingVelocity = vectorMagnitude (_projectileVelocity vectorDiff _targetVelocity);
|
2016-05-30 16:37:03 +00:00
|
|
|
|
2021-04-07 03:01:07 +00:00
|
|
|
private _lateralAcceleration = (_navigationGain * _losRate * _closingVelocity * 10000000);
|
|
|
|
private _commandedAcceleration = (_projectile vectorWorldToModelVisual _lineOfSight) vectorMultiply _lateralAcceleration;
|
2021-04-02 02:12:49 +00:00
|
|
|
|
2021-04-07 03:01:07 +00:00
|
|
|
private _normalA = ((vectorDirVisual _projectile) vectorCrossProduct _lineOfSight);
|
|
|
|
private _b = ((vectorUpVisual _projectile) vectorCrossProduct _lineOfSight);
|
|
|
|
private _normalAMagnitude = vectorMagnitude _normalA;
|
|
|
|
|
|
|
|
private _t = _normalA vectorDotProduct _b;
|
|
|
|
|
|
|
|
private _normalASign = _t / abs _t;
|
|
|
|
|
|
|
|
private _normalB = (vectorUpVisual _projectile) vectorMultiply (-_normalASign * _normalAMagnitude);
|
|
|
|
|
|
|
|
_commandedAcceleration set [2, _lateralAcceleration * (_normalB#2)];
|
2021-04-02 02:12:49 +00:00
|
|
|
|
2021-04-04 03:04:16 +00:00
|
|
|
#ifdef DRAW_GUIDANCE_INFO
|
|
|
|
private _projectilePosAGL = ASLToAGL _projectilePos;
|
2021-04-02 02:12:49 +00:00
|
|
|
drawIcon3D ["\a3\ui_f\data\IGUI\Cfg\Cursors\selectover_ca.paa", [1,0,0,1], _projectilePosAGL vectorAdd [0, 0, 1], 0.75, 0.75, 0, str _commandedAcceleration, 1, 0.025, "TahomaB"];
|
|
|
|
drawIcon3D ["\a3\ui_f\data\IGUI\Cfg\Cursors\selectover_ca.paa", [1,0,0,1], ASLToAGL (_seekerTargetPos vectorAdd _targetVelocity), 0.75, 0.75, 0, "Predicted Position", 1, 0.025, "TahomaB"];
|
2021-04-04 03:04:16 +00:00
|
|
|
|
2021-04-07 03:01:07 +00:00
|
|
|
drawLine3D [_projectilePosAGL, _projectilePosAGL vectorAdd (_normalA vectorMultiply 15), [1, 0, 1, 1]];
|
|
|
|
drawLine3D [_projectilePosAGL, _projectilePosAGL vectorAdd (_normalB vectorMultiply 15), [0, 1, 1, 1]];
|
|
|
|
|
2021-04-04 03:04:16 +00:00
|
|
|
private _seekerPosAGL = ASLToAGL _seekerTargetPos;
|
|
|
|
drawLine3D [_seekerPosAGL, _seekerPosAGL vectorAdd _targetVelocity, [0, 1, 1, 1]];
|
|
|
|
drawLine3D [_seekerPosAGL, _seekerPosAGL vectorAdd (_projectilePos vectorDiff _seekerTargetPos), [0, 1, 1, 1]];
|
2021-03-19 05:43:07 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
if (!isGamePaused && accTime > 0) then {
|
2021-04-04 03:04:16 +00:00
|
|
|
_commandedAcceleration params ["_yawChange", "", "_pitchChange"];
|
|
|
|
|
|
|
|
private _clampedPitch = (_pitchChange min _pitchDegreesPerSecond) max -_pitchDegreesPerSecond;
|
2021-04-07 03:01:07 +00:00
|
|
|
private _clampedYaw = (_yawChange min _yawDegreesPerSecond) max -_yawDegreesPerSecond;
|
2021-03-19 05:28:55 +00:00
|
|
|
|
2021-03-31 23:16:00 +00:00
|
|
|
_pitch = _pitch + _clampedPitch * diag_deltaTime;
|
|
|
|
_yaw = _yaw + _clampedYaw * diag_deltaTime;
|
2021-04-04 03:04:16 +00:00
|
|
|
|
2021-03-19 05:28:55 +00:00
|
|
|
[_projectile, _pitch, _yaw, 0] call FUNC(changeMissileDirection);
|
2021-04-07 03:01:07 +00:00
|
|
|
_projectile setVelocityModelSpace [0, _projectileSpeed, 0];
|
2021-03-19 05:28:55 +00:00
|
|
|
|
|
|
|
_currentPitchYawRoll set [0, _pitch];
|
|
|
|
_currentPitchYawRoll set [1, _yaw];
|
2016-10-12 22:35:24 +00:00
|
|
|
};
|
2021-03-19 05:28:55 +00:00
|
|
|
|
|
|
|
_pidData set [0, _pid];
|
2021-03-27 05:15:29 +00:00
|
|
|
if (accTime > 0) then {
|
2021-04-07 03:01:07 +00:00
|
|
|
_pidData set [1, [_seekerTargetPos, _targetVelocity, _lineOfSight]];
|
2021-03-27 05:15:29 +00:00
|
|
|
};
|
2021-03-31 23:16:00 +00:00
|
|
|
_pidData set [2, _currentPitchYawRoll];
|
2021-03-19 05:28:55 +00:00
|
|
|
_stateParams set [4, _pidData];
|
2021-03-27 05:15:29 +00:00
|
|
|
_args set [4, _stateParams];
|
2016-05-30 16:37:03 +00:00
|
|
|
};
|
|
|
|
|
2016-10-12 22:35:24 +00:00
|
|
|
#ifdef DRAW_GUIDANCE_INFO
|
|
|
|
TRACE_3("",_projectilePos,_seekerTargetPos,_profileAdjustedTargetPos);
|
|
|
|
drawIcon3D ["\a3\ui_f\data\IGUI\Cfg\Cursors\selectover_ca.paa", [1,0,0,1], ASLtoAGL _projectilePos, 0.75, 0.75, 0, _ammo, 1, 0.025, "TahomaB"];
|
2016-05-30 16:37:03 +00:00
|
|
|
|
2021-03-31 23:16:00 +00:00
|
|
|
if (!isGamePaused && accTime > 0) then {
|
|
|
|
private _ps = "#particlesource" createVehicleLocal (ASLtoAGL _projectilePos);
|
|
|
|
_PS setParticleParams [["\A3\Data_f\cl_basic", 8, 3, 1], "", "Billboard", 1, 3.0141, [0, 0, 2], [0, 0, 0], 1, 1.275, 1, 0, [1, 1], [[1, 0, 0, 1], [1, 0, 0, 1], [1, 0, 0, 1]], [1], 1, 0, "", "", nil];
|
|
|
|
_PS setDropInterval 1.0;
|
|
|
|
};
|
2016-05-30 16:37:03 +00:00
|
|
|
#endif
|
|
|
|
|
2016-10-12 22:35:24 +00:00
|
|
|
_stateParams set [0, diag_tickTime];
|
2016-05-30 16:37:03 +00:00
|
|
|
|
2016-10-12 22:35:24 +00:00
|
|
|
END_COUNTER(guidancePFH);
|
2017-06-08 13:31:51 +00:00
|
|
|
|