Replace remaining lineIntersects with lineIntersectsSurfaces (#6898)

* Fix explosive placement while underwater

* Apply suggestions from code review

Co-Authored-By: alganthe <alganthe@live.fr>

* Change placeApprove header to reflect changes

* Replace lineIntersectsWith in isInMedicalFacility

* Replace linesIntersects in isInRepairFacility, fix params

Public func, params should have an expected type.

* Replace linesIntersects in spallTrack

* Replace lineIntersects in getFirstObjectIntersection and findReflection

* Replace lineIntersects in advanced throwing

grenades can pass glass underwater now, I bet all of 0 person will be glad that horrendous bug is now fixed.

* Fix possible issue in pointing while underwater

* Fix possible issue while underwater in attach

* Replace count with isEqualTo in lineIntersectsSurfaces replacements

* Fix inverted conditions

* Fix drawArc

* Fix fnc_attach

* Reverse advanced_throwing and spallTrack lineIntersects changes

* Fix issues raised from code review
This commit is contained in:
Josuan Albin 2019-12-07 21:58:21 +01:00 committed by PabstMirror
parent ec27cee1ac
commit 5ae0ef6bbe
8 changed files with 17 additions and 38 deletions

View File

@ -53,7 +53,7 @@ for "_i" from 0.05 to 1.45 step 0.1 do {
if (lineIntersects [_prevTrajASL, _newTrajASL]) then { // Checks the "VIEW" LOD if (lineIntersects [_prevTrajASL, _newTrajASL]) then { // Checks the "VIEW" LOD
_cross = 2; // 2: View LOD Block (Red) _cross = 2; // 2: View LOD Block (Red)
} else { } else {
if (!((lineIntersectsSurfaces [_prevTrajASL, _newTrajASL, _activeThrowable, ACE_player, true, 1, "GEOM", "FIRE"]) isEqualTo [])) then { if !((lineIntersectsSurfaces [_prevTrajASL, _newTrajASL, _activeThrowable, ACE_player, true, 1, "GEOM", "FIRE"]) isEqualTo []) then {
_cross = 3; // 3: GEOM/FIRE LOD Block (Yellow) - pass a3 bulding glass, but blocked on some CUP glass _cross = 3; // 3: GEOM/FIRE LOD Block (Yellow) - pass a3 bulding glass, but blocked on some CUP glass
}; };
}; };

View File

@ -74,7 +74,7 @@ if (_unit == _attachToVehicle) then { //Self Attachment
_virtualPosASL = _virtualPosASL vectorAdd ((positionCameraToWorld [0.3,0,0]) vectorDiff (positionCameraToWorld [0,0,0])); _virtualPosASL = _virtualPosASL vectorAdd ((positionCameraToWorld [0.3,0,0]) vectorDiff (positionCameraToWorld [0,0,0]));
}; };
private _virtualPos = _virtualPosASL call EFUNC(common,ASLToPosition); private _virtualPos = _virtualPosASL call EFUNC(common,ASLToPosition);
private _lineInterection = lineIntersects [eyePos ACE_player, _virtualPosASL, ACE_player]; private _lineInterection = !((lineIntersectsSurfaces [eyePos ACE_player, _virtualPosASL, ACE_player]) isEqualTo []);
//Don't allow placing in a bad position: //Don't allow placing in a bad position:
if (_lineInterection && {GVAR(placeAction) == PLACE_APPROVE}) then {GVAR(placeAction) = PLACE_WAITING;}; if (_lineInterection && {GVAR(placeAction) == PLACE_APPROVE}) then {GVAR(placeAction) = PLACE_WAITING;};

View File

@ -3,7 +3,7 @@
* Author: Pabst Mirror (based on Explosive attach by Garth de Wet (LH)) * Author: Pabst Mirror (based on Explosive attach by Garth de Wet (LH))
* Approves placement of the lightObject, scans for an appropriate location and attaches * Approves placement of the lightObject, scans for an appropriate location and attaches
* A player can release the attachObject with it floating in mid-air. * A player can release the attachObject with it floating in mid-air.
* This will use lineIntersectsWith to scan towards the center of the vehicle to find a collision * This will use lineIntersectsSurfaces to scan towards the center of the vehicle to find a collision
* ArmA's collision detection is of couse terrible and often misses collisions (difference between what we see and collision LOD) * ArmA's collision detection is of couse terrible and often misses collisions (difference between what we see and collision LOD)
* So it does multiple scans at slighly different angles * So it does multiple scans at slighly different angles
* This is VERY computationaly intensive, but doesn't happen that often. * This is VERY computationaly intensive, but doesn't happen that often.

View File

@ -1,7 +1,7 @@
#include "script_component.hpp" #include "script_component.hpp"
/* /*
* Author: Ruthberg * Author: Ruthberg
* Returns the the first intersection with terrain between two positions. @todo rewrite using lineIntersectsSurfaces? * Returns the the first intersection with terrain between two positions.
* *
* Arguments: * Arguments:
* 0: PositionASL <ARRAY> * 0: PositionASL <ARRAY>
@ -18,31 +18,14 @@
* Public: Yes * Public: Yes
*/ */
params ["_source", "_destination", "_accuracy"]; params ["_source", "_destination"];
private _result = [false, [0, 0, 0]]; private _result = [false, [0, 0, 0]];
private _hits = lineIntersectsSurfaces [_source, _destination, objNull, objNull, true, -1];
private _distance = _source vectorDistance _destination; {
_x params ["_pos", "", "_obj"];
if !(lineIntersectsWith [_source, _destination] isEqualTo []) then { if (!isNull _obj) exitWith {
private _lower = 0; _result = [true, _pos];
private _upper = 1;
private _mid = 0.5;
private _dir = _source vectorFromTo _destination;
while {(_upper - _lower) * _distance > _accuracy} do {
_mid = _lower + (_upper - _lower) / 2;
if !(lineIntersectsWith [_source, _source vectorAdd (_dir vectorMultiply (_mid * _distance))] isEqualTo []) then {
_upper = _mid;
} else {
_lower = _mid;
};
}; };
} forEach _hits;
_mid = _lower + (_upper - _lower) / 2;
_result = [true, _source vectorAdd (_dir vectorMultiply (_mid * _distance))];
};
_result _result

View File

@ -80,7 +80,7 @@ GVAR(TweakedAngle) = 0;
#ifdef DEBUG_MODE_FULL #ifdef DEBUG_MODE_FULL
drawLine3d [(eyePos _unit) call EFUNC(common,ASLToPosition), (_testPos) call EFUNC(common,ASLToPosition), [1,0,0,1]]; drawLine3d [(eyePos _unit) call EFUNC(common,ASLToPosition), (_testPos) call EFUNC(common,ASLToPosition), [1,0,0,1]];
#endif #endif
if (lineIntersects [eyePos _unit, _testPos, _unit]) exitWith {_return = false;}; if !((lineIntersectsSurfaces [eyePos _unit, _testPos, _unit]) isEqualTo []) exitWith {_return = false;};
} forEach [[0,0], [-1,-1], [1,-1], [-1,1], [1,1]]; } forEach [[0,0], [-1,-1], [1,-1], [-1,1], [1,1]];
_return _return
}; };
@ -94,8 +94,8 @@ GVAR(TweakedAngle) = 0;
private _testBase = _basePosASL vectorAdd _lookDirVector; private _testBase = _basePosASL vectorAdd _lookDirVector;
{ {
private _testPos = _testBase vectorAdd [0.1 * (_x select 0) * (cos _cameraAngle), 0.1 * (_x select 0) * (sin _cameraAngle), 0.1 * (_x select 1)]; private _testPos = _testBase vectorAdd [0.1 * (_x select 0) * (cos _cameraAngle), 0.1 * (_x select 0) * (sin _cameraAngle), 0.1 * (_x select 1)];
private _intersectsWith = lineIntersectsWith [eyePos _unit, _testPos, _unit]; private _intersectObject = ((lineIntersectsSurfaces [eyePos _unit, _testPos, _unit]) param [0, objNull]) param [3, objNull];
if (count _intersectsWith == 1) exitWith {_attachVehicle = (_intersectsWith select 0);}; if !(_intersectObject isEqualTo objNull) exitWith {_attachVehicle = _intersectObject};
} forEach [[0,0], [-1,-1], [1,-1], [-1,1], [1,1]]; } forEach [[0,0], [-1,-1], [1,-1], [-1,1], [1,1]];
if ((!isNull _attachVehicle) && {[PLACE_RANGE_MIN] call _testPositionIsValid} && if ((!isNull _attachVehicle) && {[PLACE_RANGE_MIN] call _testPositionIsValid} &&
{(_attachVehicle isKindOf "Car") || {_attachVehicle isKindOf "Tank"} || {_attachVehicle isKindOf "Air"} || {_attachVehicle isKindOf "Ship"}}) then { {(_attachVehicle isKindOf "Car") || {_attachVehicle isKindOf "Tank"} || {_attachVehicle isKindOf "Air"} || {_attachVehicle isKindOf "Ship"}}) then {

View File

@ -48,7 +48,7 @@ private _nearbyMen = (ACE_player nearObjects ["CAManBase", (GVAR(maxRange) + 2)]
{alive _x} && {alive _x} &&
{(_x == (vehicle _x)) || {(vehicle _x) isKindOf "StaticWeapon"}} && {(_x == (vehicle _x)) || {(vehicle _x) isKindOf "StaticWeapon"}} &&
{GVAR(indicatorForSelf) || {_x != ACE_player}} && {GVAR(indicatorForSelf) || {_x != ACE_player}} &&
{!(lineIntersects [(eyePos _x), _playerEyePosASL, vehicle ACE_player, vehicle _x])} && {((lineIntersectsSurfaces [(eyePos _x), _playerEyePosASL, vehicle ACE_player, vehicle _x]) isEqualTo [])} &&
{[_x] call EFUNC(common,isPlayer)}) then { {[_x] call EFUNC(common,isPlayer)}) then {
_sendFingerToPlayers pushBack _x; _sendFingerToPlayers pushBack _x;

View File

@ -24,11 +24,7 @@ private _velocity = velocity _round;
private _velocityStep = _velocity vectorMultiply _delta; private _velocityStep = _velocity vectorMultiply _delta;
private _forwardPos = _curPos vectorAdd _velocityStep; private _forwardPos = _curPos vectorAdd _velocityStep;
private _intersectsWith = lineIntersectsWith [_curPos, _forwardPos]; if !((lineIntersectsSurfaces [_curPos, _forwardPos]) isEqualTo []) exitWith {};
if (_intersectsWith isEqualTo []) exitWith {};
// player sideChat format ["inter: %1", _intersectsWith];
{ {
// diag_log text format ["Adding HP: %1", _x]; // diag_log text format ["Adding HP: %1", _x];
private _index = count GVAR(spallHPData); private _index = count GVAR(spallHPData);

View File

@ -15,7 +15,7 @@
* Public: Yes * Public: Yes
*/ */
params ["_object"]; params [["_object", objNull, [objNull]]];
TRACE_1("params",_object); TRACE_1("params",_object);
private _position = getPosASL _object; private _position = getPosASL _object;