-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #143 from Sparker95/improve-safe-spawning
Civilian vehicle spawning
- Loading branch information
Showing
14 changed files
with
511 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
// Class: Location | ||
/* | ||
Method: (static)isPosEvenSafer | ||
Returns true if the place is guaranteed safe for spawning specific vehicle. | ||
It is very conservative and as such will disallow spawning in buildings or too close | ||
to existing objects. | ||
Parameters: _pos, _dir, _className | ||
_pos - position ATL | ||
_dir - direction | ||
_className - vehicle class name | ||
Returns: Bool | ||
Author: Sparker 29.07.2018 | ||
*/ | ||
|
||
//#define DEBUG | ||
|
||
pr0_fn_getGlobalRectAndSize = { | ||
params [["_pos", [], [[]]], ["_dir", 0, [0]], ["_bbox", [], [[]]] ]; | ||
|
||
private _bx = _bbox select 1 select 0; //width | ||
private _by = _bbox select 1 select 1; //length | ||
private _bz = _bbox select 1 select 2; //height | ||
|
||
private _c = cos _dir; | ||
private _s = sin _dir; | ||
|
||
private _posASL = ATLTOASL _pos; | ||
private _pos_0 = _posASL vectorAdd [_bx*_c + _by*_s, -_bx*_s + _by*_c, 0]; | ||
private _pos_1 = _posASL vectorAdd [_bx*_c - _by*_s, -_bx*_s - _by*_c, 0]; | ||
private _pos_2 = _posASL vectorAdd [-_bx*_c - _by*_s, _bx*_s - _by*_c, 0]; | ||
private _pos_3 = _posASL vectorAdd [-_bx*_c + _by*_s, _bx*_s + _by*_c, 0]; | ||
private _rect = [_pos_0, _pos_1, _pos_2, _pos_3]; | ||
[_rect, [_bx, _by, _bz]] | ||
}; | ||
|
||
params [ ["_thisClass", "", [""]], ["_pos", [], [[]]], ["_dir", 0, [0]], ["_className", "", [""]] ]; | ||
|
||
// Bail if Z is below surface, as it happens with positions of bridges | ||
if (_pos#2 < -0.3) exitWith { | ||
false | ||
}; | ||
|
||
([ | ||
_pos, _dir, | ||
[_className] call misc_fnc_boundingBoxReal | ||
] call pr0_fn_getGlobalRectAndSize) params ["_rect3D", "_size"]; | ||
|
||
// TODO: expand the class set here? | ||
private _o = nearestObjects [_pos, [], 15, true] - (_pos nearRoads 15); | ||
|
||
_o findIf { | ||
#ifndef _SQF_VM | ||
private _bbox = 0 boundingBoxReal _x; | ||
#else | ||
private _bbox = [[0,0,0],[1,1,1],1]; | ||
#endif | ||
([getPos _x, getDir _x, _bbox] call pr0_fn_getGlobalRectAndSize) params ["_oRect3D", "_oSize"]; | ||
if(_oSize#2 > 0.3) then { | ||
[_rect3D, _oRect3D] call misc_fnc_polygonCollision | ||
} else { | ||
false | ||
} | ||
} == -1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// See https://gist.github.com/nyorain/dc5af42c6e83f7ac6d831a2cfd5fbece | ||
private _fn_separatedPolys = { | ||
params ["_a", "_b"]; | ||
private _result = false; | ||
for "_i" from 0 to (count _a - 1) do | ||
{ | ||
// calculate the normal vector of the current edge | ||
// this is the axis will we check in this loop | ||
private _current = _a select _i; | ||
private _next = _a select ((_i + 1) % count _a); | ||
private _edge = [_next#0 - _current#0, _next#1 - _current#1]; | ||
private _axis = [-(_edge#1), _edge#0]; | ||
|
||
// loop over all vertices of both polygons and project them | ||
// onto the axis. We are only interested in max/min projections | ||
private _aMaxProj = -1000000; | ||
private _aMinProj = 1000000; | ||
private _bMaxProj = -1000000; | ||
private _bMinProj = 1000000; | ||
|
||
{ | ||
private _proj = _axis#0 * _x#0 + _axis#1 * _x#1; | ||
_aMinProj = _aMinProj min _proj; | ||
_aMaxProj = _aMaxProj max _proj; | ||
} forEach _a; | ||
|
||
{ | ||
private _proj = _axis#0 * _x#0 + _axis#1 * _x#1; | ||
_bMinProj = _bMinProj min _proj; | ||
_bMaxProj = _bMaxProj max _proj; | ||
} forEach _b; | ||
|
||
// now check if the intervals the both polygons projected on the | ||
// axis overlap. If they don't, we have found an axis of separation and | ||
// the given polygons cannot overlap | ||
if(_aMaxProj < _bMinProj or _aMinProj > _bMaxProj) exitWith { | ||
_result = true; | ||
}; | ||
}; | ||
_result | ||
}; | ||
|
||
params ["_a", "_b"]; | ||
|
||
!(([_a, _b] call _fn_separatedPolys) or {([_b, _a] call _fn_separatedPolys)}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.