Finish guidance rewrite.

This commit is contained in:
jaynus 2015-04-14 08:24:13 -07:00
parent 22d90fee9a
commit 376f924999
4 changed files with 125 additions and 63 deletions

View File

@ -40,12 +40,12 @@ class CfgAmmo {
trackLead = 0;
// Begin ACE guidance Configs
class ACE_MissileGuidance {
class ADDON {
enabled = 1;
minDeflection = 0.005; // Minium flap deflection for guidance
maxDeflection = 0.025; // Maximum flap deflection for guidance
incDeflection = 0.005; // The incrmeent in which deflection adjusts.
minDeflection = 0.0005; // Minium flap deflection for guidance
maxDeflection = 0.0025; // Maximum flap deflection for guidance
incDeflection = 0.0005; // The incrmeent in which deflection adjusts.
//minDeflection = 0.005;
//maxDeflection = 0.5;
//incDeflection = 0.005;
@ -110,7 +110,7 @@ class CfgAmmo {
//trackLead = 0;
// Begin ACE guidance Configs
class ACE_MissileGuidance {
class ADDON {
enabled = 1;
minDeflection = 0.005; // Minium flap deflection for guidance

View File

@ -1,4 +1,54 @@
//#define DEBUG_MODE_FULL
#include "script_component.hpp"
_this call FUNC(attackProfile_LIN);
EXPLODE_7_PVT(((_this select 1) select 0),_shooter,_weapon,_muzzle,_mode,_ammo,_magazine,_projectile);
private["_targetPos", "_projectilePos", "_target", "_seekerTargetPos", "_launchParams", "_targetLaunchParams"];
private["_distanceToTarget", "_distanceToShooter", "_addHeight", "_returnTargetPos"];
_seekerTargetPos = _this select 0;
_launchParams = _this select 1;
_target = _launchParams select 0;
_targetLaunchParams = _launchParams select 1;
_shooterPos = getPosASL _shooter;
_projectilePos = getPosASL _projectile;
_distanceToTarget = _projectilePos vectorDistance _seekerTargetPos;
_distanceToShooter = _projectilePos vectorDistance _shooterPos;
TRACE_2("", _distanceToTarget, _distanceToShooter);
// Add height depending on distance for compensate
_addHeight = [0,0,0];
// Always climb an arc on initial launch if we are close to the round
if( ((ASLtoATL _projectilePos) select 2) < 5 && _distanceToShooter < 15) then {
_addHeight = _addHeight vectorAdd [0,0,_distanceToTarget];
} else {
// If we are below the target, increase the climbing arc
if((_projectilePos select 2) < (_seekerTargetPos select 2) && _distanceToTarget > 100) then {
_addHeight = _addHeight vectorAdd [0,0, ((_seekerTargetPos select 2) - (_projectilePos select 2))];
};
};
// Handle arcing terminal low for high decent
if( (_projectilePos select 2) > (_seekerTargetPos select 2) && _distanceToTarget < 100) then {
_addHeight = _addHeight vectorDiff [0,0, ((_projectilePos select 2) - (_seekerTargetPos select 2)) * 0.5];
} else {
if((_projectilePos select 2) > (_seekerTargetPos select 2) && _distanceToTarget > 100) then {
_addHeight = _addHeight vectorAdd [0,0, _distanceToTarget*0.02];
};
};
TRACE_3("", _distanceToTarget,_distanceToShooter,_addHeight);
_returnTargetPos = _seekerTargetPos vectorAdd _addHeight;
#ifdef DEBUG_MODE_FULL
drawLine3D [(ASLtoATL _returnTargetPos) vectorAdd _addHeight, ASLtoATL _returnTargetPos, [0,1,0,1]];
#endif
TRACE_1("Adjusted target position", _returnTargetPos);
_returnTargetPos;

View File

@ -13,7 +13,7 @@ PARAMS_7(_shooter,_weapon,_muzzle,_mode,_ammo,_magazine,_projectile);
// Bail on not missile
if(! (_ammo isKindOf "MissileBase") ) exitWith { false };
_config = configFile >> "CfgAmmo" >> _ammo >> "ACE_MissileGuidance";
_config = configFile >> "CfgAmmo" >> _ammo >> QUOTE(ADDON);
_enabled = getNumber ( _config >> "enabled");
// Bail if guidance is not enabled

View File

@ -1,16 +1,20 @@
#define DEBUG_MODE_FULL
//#define DEBUG_MODE_FULL
#include "script_component.hpp"
#define TIMESTEP_FACTOR 0.01
private["_args", "_stateParams", "_launchParams", "_targetLaunchParams", "_config", "_flightParams", "_seekerParams", "_seekerTargetPos"];
private["_lastRunTime", "_runtimeDelta", "_profileAdjustedTargetPos", "_targetVectorSeeker", "_targetVector"];
private["_minDeflection", "_maxDeflection", "_incDeflection", "_adjustTime"];
private["_yVec", "_zVec", "_xVec"];
private["_launchParams", "_targetLaunchParams", "_flightParams", "_seekerParams", "_stateParams"];
private["_lastRunTime", "_runtimeDelta", "_adjustTime", "_args", "_seekerTargetPos", "_projectilePos"];
private["_profileAdjustedTargetPos", "_incDeflection", "_minDeflection", "_maxDeflection"];
private["_targetVector", "_adjustVector", "_finalAdjustVector", "_changeVector", "_pitch", "_yaw", "_roll"];
_args = _this select 0;
EXPLODE_7_PVT((_args select 0),_shooter,_weapon,_muzzle,_mode,_ammo,_magazine,_projectile);
if(!alive _projectile || isNull _projectile || isNull _shooter) exitWith {
[(_this select 1)] call cba_fnc_removePerFrameHandler;
};
_launchParams = _args select 1;
_targetLaunchParams = _launchParams select 1;
_flightParams = _args select 2;
@ -19,9 +23,9 @@ _seekerParams = _args select 3;
_stateParams = _args select 4;
_lastRunTime = _stateParams select 0;
_runtimeDelta = diag_tickTime - _lastRunTime;
_adjustTime = 1;
if(accTime > 0) then {
_adjustTime = 1/accTime;
_adjustTime = _adjustTime * (_runtimeDelta / TIMESTEP_FACTOR);
@ -29,61 +33,69 @@ if(accTime > 0) then {
} else {
_adjustTime = 0;
};
_config = configFile >> "CfgAmmo" >> _ammo >> "ACE_MissileGuidance";
if(!alive _projectile || isNull _projectile || isNull _shooter) exitWith {
[(_this select 1)] call cba_fnc_removePerFrameHandler;
};
_minDeflection = ((_flightParams select 0) - ((_flightParams select 0) * _adjustTime)) max 0;
_maxDeflection = (_flightParams select 1) * _adjustTime;
_incDeflection = _flightParams select 2;
// TODO: placeholder for "last seek target position"
_projectilePos = getPosASL _projectile;
// @TODO: placeholder for "last seek target position"
// Last target pos should be optional based on the seeker unit
_seekerTargetPos = [ [0,0,0], _args, (_stateParams select 1)] call FUNC(doSeekerSearch);
if(!isNil "_seekerTargetPos") then {
_profileAdjustedTargetPos = [_seekerTargetPos,_args, (_stateParams select 2)] call FUNC(doAttackProfile);
_minDeflection = ((_flightParams select 0) - ((_flightParams select 0) * _adjustTime)) max 0;
_maxDeflection = (_flightParams select 1) * _adjustTime;
_incDeflection = _flightParams select 2;
_projectilePos = getPosASL _projectile;
_targetVector = _projectile worldToModelVisual _profileAdjustedTargetPos;
_targetVectorSeeker = [0,0,0] vectorFromTo _targetVector;
TRACE_1("", _targetVectorSeeker, _targetVector);
private["_yaw", "_pitch"];
_yaw = 0;
_pitch = 0;
if((_targetVectorSeeker select 0) < 0) then {
_yaw = - ( (_minDeflection max (abs(_targetVector select 0) min _maxDeflection) ) );
} else {
if((_targetVectorSeeker select 0) > 0) then {
_yaw = ( (_minDeflection max ((_targetVector select 0) min _maxDeflection) ) );
};
if(isNil "_seekerTargetPos") then {
_seekerTargetPos = _seekerTargetPos vectorAdd ((velocity _projectile) vectorMultiply 5);
} else {
if( (vectorMagnitude _seekerTargetPos) == 0) then {
_seekerTargetPos = _seekerTargetPos vectorAdd ((velocity _projectile) vectorMultiply 5);
};
if((_targetVectorSeeker select 2) < 0) then {
_pitch = - ( (_minDeflection max (abs(_targetVector select 2) min _maxDeflection) ) );
} else {
if((_targetVectorSeeker select 2) > 0) then {
_pitch = ( (_minDeflection max ((_targetVector select 2) min _maxDeflection) ) );
};
};
if(accTime > 0) then {
private["_outVector", "_vectorTo"];
_finalVector = _projectilePos vectorFromTo _profileAdjustedTargetPos;
_projectile setVectorDirAndUp [_finalVector, vectorUp _projectile];
};
#ifdef DEBUG_MODE_FULL
drawIcon3D ["\a3\ui_f\data\IGUI\Cfg\Cursors\selectover_ca.paa", [1,1,1,1], ASLtoATL _projectilePos, 0.75, 0.75, 0, str _vectorTo, 1, 0.025, "TahomaB"];
drawLine3D [ASLtoATL _projectilePos, ASLtoATL _profileAdjustedTargetPos, [1,0,0,1]];
hintSilent format["d: %1", _distanceToTarget];
#endif
};
_profileAdjustedTargetPos = [_seekerTargetPos,_args, (_stateParams select 2)] call FUNC(doAttackProfile);
_targetVector = _projectilePos vectorFromTo _profileAdjustedTargetPos;
_adjustVector = _targetVector vectorDiff (vectorDir _projectile);
_yaw = 0;
_pitch = 0;
_roll = 0;
if((_adjustVector select 0) < 0) then {
_yaw = - ( (_minDeflection max (abs(_adjustVector select 0) min _maxDeflection) ) );
} else {
if((_adjustVector select 0) > 0) then {
_yaw = ( (_minDeflection max ((_adjustVector select 0) min _maxDeflection) ) );
};
};
if((_adjustVector select 1) < 0) then {
_roll = - ( (_minDeflection max (abs(_adjustVector select 1) min _maxDeflection) ) );
} else {
if((_adjustVector select 1) > 0) then {
_roll = ( (_minDeflection max ((_adjustVector select 1) min _maxDeflection) ) );
};
};
if((_adjustVector select 2) < 0) then {
_pitch = - ( (_minDeflection max (abs(_adjustVector select 2) min _maxDeflection) ) );
} else {
if((_adjustVector select 2) > 0) then {
_pitch = ( (_minDeflection max ((_adjustVector select 2) min _maxDeflection) ) );
};
};
_finalAdjustVector = [_yaw, _roll, _pitch];
TRACE_2("", _pitch, _yaw);
TRACE_4("", _targetVector, _targetRelativeVector, _adjustVector, _finalAdjustVector);
if(accTime > 0) then {
_changeVector = (vectorDir _projectile) vectorAdd _finalAdjustVector;
//_changeVector = (vectorDir _projectile) vectorAdd _adjustVector; // Test direct to target
_projectile setVectorDirAndUp [_changeVector, vectorUp _projectile];
};
#ifdef DEBUG_MODE_FULL
drawIcon3D ["\a3\ui_f\data\IGUI\Cfg\Cursors\selectover_ca.paa", [1,1,1,1], ASLtoATL _projectilePos, 0.75, 0.75, 0, str _vectorTo, 1, 0.025, "TahomaB"];
drawLine3D [ASLtoATL _projectilePos, ASLtoATL _profileAdjustedTargetPos, [1,0,0,1]];
hintSilent format["d: %1", _distanceToTarget];
#endif
_stateParams set[0, diag_tickTime];
_args set[4, _stateParams];