Rewritten changeProjectileDirection

This commit is contained in:
esteldunedain 2015-04-06 18:10:17 -03:00
parent aec9962121
commit 09461d94ef

View File

@ -29,31 +29,25 @@ _adjustSpeed = if (count _this > 3) then {
["CPD", [_fnc_scriptNameParent, _adjustDir, _adjustUp, _adjustSpeed], nil, false] call FUNC(log);
// get old direction vector
_vdir = vectorDir _projectile;
_vdir = vectorNormalized velocity _projectile;
// get azimuth and inclination and apply corrections
_dir = (_vdir select 0) atan2 (_vdir select 1) + _adjustDir;
_up = sqrt ((_vdir select 1) ^ 2 + (_vdir select 0) ^ 2) atan2 - (_vdir select 2) + _adjustUp;
_up = asin (_vdir select 2) + _adjustUp;
// get new direction vector (this is a unit vector)
_vdir = [
sin _dir * sin _up,
cos _dir * sin _up,
- cos _up
sin _dir * cos _up,
cos _dir * cos _up,
sin _up
];
// get best up vector
_l = sqrt ((_vdir select 0) ^ 2 + (_vdir select 1) ^ 2); if (_l == 0) then {diag_log text format ["[ACE] ERROR: %1, %2, %3, %4, %5, %6, %7", _projectile, _adjustDir, _adjustUp, vectorDir _projectile, _vdir, _dir, _up]};
_r = -(_vdir select 2) / _l;
_vup = [
(_vdir select 0) * _r,
(_vdir select 1) * _r,
_l
];
_vlat = vectorNormalized (_vdir vectorCrossProduct [0,0,1]);
_vup = _vlat vectorCrossProduct _vdir;
// get new speed vector. Keep total speed, but change to new direction. Yay for vector commands.
_vel = _vdir vectorMultiply _adjustSpeed + vectorMagnitude velocity _projectile;
_vel = _vdir vectorMultiply (_adjustSpeed + vectorMagnitude velocity _projectile);
// set projectile direction dir and up. Projectiles are long objects, especially with tracers, so it would look dumb otherwise.
_projectile setVectorDirAndUp [_vdir, _vup];