lineIntersectsSurfaces: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
mNo edit summary
m (Text replacement - " {2,}\}\}" to " }}")
(45 intermediate revisions by 10 users not shown)
Line 1: Line 1:
{{Command|= Comments
{{Command
____________________________________________________________________________________________


| arma3dev |= Game name
| arma3
|1.49|= Game version
|1.50
|arg= global|= Arguments in MP
|arg= global
____________________________________________________________________________________________


| Returns list of intersections with surfaces from ''begPosASL'' to ''endPosASL''. If there is ground intersection, it is also included. Works on units. Works underwater. Doesn't return intersection with sea surface. Hardcoded max distance: 5000m.|= Description
|gr1= Math - Geometry
____________________________________________________________________________________________


| '''lineIntersectsSurfaces''' [begPosASL, endPosASL, ignoreObj1, ignoreObj2, sortMode, maxResults] |= Syntax
| Returns list of intersections with surfaces from ''begPosASL'' to ''endPosASL''. If there is ground intersection, it is also included. Works on units. Works underwater. Doesn't return intersection with sea surface. Hardcoded max distance: 5000m. By default, for speed purposes, command will return only 1st intersection with unique objects. Since Arma 3 v1.69.140138, this could be tweaked with an optional param.
|p1= [begPosASL, endPosASL, ignoreObj1, ignoreObj2, sortMode, maxResults]: [[Array]]|= Parameter 0
{{Informative | If ''begPosASL'' is under the ground and ''endPosASL'' is above it, the command will only return intersection with the ground, this is engine limitation and none of the intersectXXX commands will work when initiated from under the ground.}}
|p2= begPosASL: [[PositionASL]] - virtual line start |= Parameter 1
Since Arma v1.51.131920 it is possible to indicate primary and secondary [[LOD]] to look for intersection. Available options are:
|p3= endPosASL: [[PositionASL]] - virtual line end |= Parameter 2
* "FIRE"
|p4= ignoreObj1 (Optional): [[Object]] - first object to ignore or [[objNull]]: Default: [[objNull]]|=Parameter 3
* "VIEW"
|p5= ignoreObj2 (Optional): [[Object]] - second object to ignore or [[objNull]]: Default: [[objNull]] |= Parameter 4
* "GEOM"
|p6= sortMode (Optional): [[Boolean]] - [[true]]: closest to furthest, [[false]]: furthest to closest. Default: [[true]]  |= Parameter 5
* "IFIRE" - ("I" stands for Indirect, practically the same as FIRE)
|p7= maxResults (Optional): [[Number]] - Max results to return. -1 to return every result. Default: 1|= Parameter 6
* "NONE"
* "PHYSX" - PhysX geometry LOD (since Arma 3 v2.01.146666)


| [[Array]] of intersections in format <nowiki>[</nowiki>[intersectPosASL, surfaceNormal, intersectObj, parentObject],...] where:
Default [[LOD]]s are "VIEW" and "FIRE"
* intersectPosASL - the actual position where line intersects 1st surface
{{Important | Only a single LOD is checked for intersection. LOD1 is Primary LOD and will be checked first. LOD2 is Secondary LOD. If LOD1 is not possible to check, LOD2 will be used.}}
 
| '''lineIntersectsSurfaces''' [begPosASL, endPosASL, ignoreObj1, ignoreObj2, sortMode, maxResults, LOD1, LOD2, returnUnique]
|p1= [begPosASL, endPosASL, ignoreObj1, ignoreObj2, sortMode, maxResults, LOD1, LOD2]: [[Array]]
|p2= begPosASL: [[PositionASL]] - virtual line start
 
|p3= endPosASL: [[PositionASL]] - virtual line end
|p4= ignoreObj1 (Optional): [[Object]] - first object to ignore or [[objNull]]: Default: [[objNull]]
|p5= ignoreObj2 (Optional): [[Object]] - second object to ignore or [[objNull]]: Default: [[objNull]]
|p6= sortMode (Optional): [[Boolean]] - [[true]]: closest to furthest, [[false]]: furthest to closest. Default: [[true]]
|p7= maxResults (Optional): [[Number]] - Max results to return. -1 to return every result. Default: 1
|p8= LOD1 (Optional): [[String]] (added in v1.51.131920) - Primary [[LOD]] to look for intersection. Default: "VIEW"
|p9= LOD2 (Optional): [[String]] (added in v1.51.131920) - Secondary [[LOD]] to look for intersection. Default: "FIRE"
|p10= returnUnique (Optional): [[Boolean]] (added in v1.69.140138) - When [[false]], all intersections in the same object are included not just the 1st one. Default: [[true]] |PARAMETER10=
 
| [[Array]] of intersections in format [<nowiki/>[intersectPosASL, surfaceNormal, intersectObj, parentObject],...] where:
* intersectPosASL - the actual position where line intersects surface
* [[surfaceNormal]] - a normal to the intersected surface  
* [[surfaceNormal]] - a normal to the intersected surface  
* intersectObject - the object the surface belongs to (could be proxy object)
* intersectObject - the object the surface belongs to (could be proxy object) - [[objNull]] if terrain
* parentObject - the object proxy object belongs to (not always the same as intersect object)|= Return value
* parentObject - the object proxy object belongs to (not always the same as intersect object) - objNull if terrain
____________________________________________________________________________________________
|x1= <code>_intersections = [[lineIntersectsSurfaces]] [<nowiki/>[[eyePos]] [[player]], [[aimPos]] chopper, [[player]], chopper, [[true]], -1];</code>
|x1= <code>_intersections = [[lineIntersectsSurfaces]] <nowiki>[</nowiki>[[eyePos]] [[player]], [[aimPos]] chopper, [[player]], chopper, [[true]], -1];</code> |= Example 1


|x2= <code>arrow = "Sign_Arrow_F" [[createVehicle]] [0,0,0];
|x2= <code>arrow = "Sign_Arrow_F" [[createVehicle]] [0,0,0];
[[onEachFrame]] {
[[onEachFrame]] {
_ins = [[lineIntersectsSurfaces]] [
_ins = [[lineIntersectsSurfaces]] [
[[ATLToASL]] [[positionCameraToWorld]] [0,0,0],  
[[AGLToASL]] [[positionCameraToWorld]] [0,0,0],  
[[ATLToASL]] [[positionCameraToWorld]] [0,0,1000],  
[[AGLToASL]] [[positionCameraToWorld]] [0,0,1000],  
[[player]]
[[player]]
];
];
Line 38: Line 51:
arrow [[setVectorUp]] (_ins [[select]] 0 [[select]] 1);
arrow [[setVectorUp]] (_ins [[select]] 0 [[select]] 1);
[[hintSilent]] [[str]] _ins;
[[hintSilent]] [[str]] _ins;
};</code> |= Example 2
};</code>
____________________________________________________________________________________________


| [[lineIntersectsWith]], [[lineIntersectsObjs]], [[terrainIntersect]], [[terrainIntersectASL]], [[lineIntersects]], [[intersect]] |= See also
|x3= This should detect glass windows and wire fences (since Arma v1.51.131920): <code>wirefence = "Land_New_WiredFence_5m_F" [[createVehicle]] [[position]] [[player]];
arrow = "Sign_Arrow_F" [[createVehicle]] [0,0,0];
[[onEachFrame]] {
_ins = [[lineIntersectsSurfaces]] [
[[AGLToASL]] [[positionCameraToWorld]] [0,0,0],
[[AGLToASL]] [[positionCameraToWorld]] [0,0,1000],  
[[player]],
[[objNull]],
[[true]],
1,
"GEOM",
"NONE"
];
[[if]] ([[count]] _ins == 0) [[exitWith]] {arrow [[setPosASL]] [0,0,0]};
arrow [[setPosASL]] (_ins [[select]] 0 [[select]] 0);
arrow [[setVectorUp]] (_ins [[select]] 0 [[select]] 1);
[[hintSilent]] [[str]] _ins;
};</code>


| [[lineIntersectsWith]], [[lineIntersectsObjs]], [[terrainIntersect]], [[terrainIntersectASL]], [[terrainIntersectAtASL]], [[lineIntersects]], [[intersect]], [[cursorObject]], [[cursorTarget]], [[checkVisibility]]
}}
}}


<h3 style="display:none">Notes</h3>
<dl class="command_description">
<dl class="command_description">
</dl>
</dl>


<h3 style="display:none">Bottom Section</h3>


[[Category:Scripting Commands Arma 3|{{uc:{{PAGENAME}}}}]]
{{GameCategory|arma3|Scripting Commands}}
[[Category:Scripting Commands|{{uc:{{PAGENAME}}}}]]
[[Category:Scripting Commands|{{uc:{{PAGENAME}}}}]]


You can combine with intersect command to find selection names on intersected objects (in this example priority is geom >> ifire >> fire >> view):
<!-- CONTINUE Notes -->
<dl class="command_description">
<dd class="notedate">Posted on August 27, 2015 - 12:44 (UTC)</dd>
<dt class="note">[[User:Killzone Kid|Killzone Kid]]</dt>
<dd class="note">
Fast check if object is in a house:<code>KK_fnc_inHouse = {
[[lineIntersectsSurfaces]] [
[[getPosWorld]] _this,
[[getPosWorld]] _this [[vectorAdd]] [0, 0, 50],
_this, [[objNull]], [[true]], 1, "GEOM", "NONE"
] [[select]] 0 [[params]] ["","","","_house"];
[[if]] (_house [[isKindOf]] "House") [[exitWith]] {[[true]]};
[[false]]
};
[[onEachFrame]] {[[hintSilent]] [[str]] ([[player]] [[call]] KK_fnc_inHouse)};</code>
</dd>
</dl>


<nowiki>arrow = "Sign_Arrow_F" createVehicle [0,0,0];
<dl class="command_description">
testFunc = {
<dd class="notedate">Posted on January 30, 2016 - 20:10 (UTC)</dd>
_ins = lineIntersectsSurfaces [
<dt class="note">[[User:Pierre MGI|Pierre MGI]]</dt>
ATLToASL positionCameraToWorld [0,0,0],
<dd class="note">
ATLToASL positionCameraToWorld [0,0,1000],
This command is useful to place weaponholder (and then spawned weapons) on floor of houses, correcting  the spawn position (can_collide) to intersect with floor:
player
<code>
];
MGI_fnc_setPosAGLS = {
if (count _ins == 0) exitWith {
  [[params]] ["_obj", "_pos"];
arrow setPosASL [0,0,0]
  _wh_pos = [[getPosASL]] _obj;
};
arrow setPosASL (_ins select 0 select 0);
arrow setVectorUp (_ins select 0 select 1);
_intDist = (_ins select 0 select 0) distance (ATLToASL positionCameraToWorld [0,0,0]);
_sel = "";
_dist = 10000;
{
_ins2 = [_ins select 0 select 3,_x] intersect [
positionCameraToWorld [0,0,0],
positionCameraToWorld [0,0,_intDist + 0.1]
];


{
  _pos [[set]] [2, ([[ATLtoASL]] _pos [[select]] 2)-10];
if (_x select 1 < _dist) then {
_ins = [[lineIntersectsSurfaces]] [_wh_pos, _pos,_obj,[[objNull]], [[true]],1,"VIEW","FIRE"];
_dist = _x select 1;
_surface_distance = [[if]] ([[count]] _ins > 0) [[then]] [{(_ins [[select]] 0 [[select]] 0) [[distance]] _wh_pos},{0}];
_sel = _x select 0
_wh_pos [[set]] [2, ([[getPosASL]] _obj [[select]] 2) - (_surface_distance)];
};
_weaponholder [[setPosASL]] _wh_pos;
} forEach _ins2;
};
if (_sel != "") exitWith {};
</code>
} forEach ["GEOM","IFIRE","FIRE","VIEW"];
After the position (_pos) obtained in BIS_fnc_buidingPositions array:
<code>
_weaponholder = [[createVehicle]] ["groundWeaponHolder", _pos, [], 0, "CAN_COLLIDE"];
[_weaponholder,_pos] [[call]] MGI_fnc_setPosAGLS;
Then fill your weapon holder.
</code>
</dd>
</dl>


hintsilent format ["GEOM: %1",_sel];
<!-- DISCONTINUE Notes -->
};
["sample_id","onEachFrame","testFunc"] call BIS_fnc_addStackedEventHandler;

Revision as of 01:20, 19 January 2021

Hover & click on the images for description

Description

Description:
Returns list of intersections with surfaces from begPosASL to endPosASL. If there is ground intersection, it is also included. Works on units. Works underwater. Doesn't return intersection with sea surface. Hardcoded max distance: 5000m. By default, for speed purposes, command will return only 1st intersection with unique objects. Since Arma 3 v1.69.140138, this could be tweaked with an optional param.
If begPosASL is under the ground and endPosASL is above it, the command will only return intersection with the ground, this is engine limitation and none of the intersectXXX commands will work when initiated from under the ground.

Since Arma v1.51.131920 it is possible to indicate primary and secondary LOD to look for intersection. Available options are:

  • "FIRE"
  • "VIEW"
  • "GEOM"
  • "IFIRE" - ("I" stands for Indirect, practically the same as FIRE)
  • "NONE"
  • "PHYSX" - PhysX geometry LOD (since Arma 3 v2.01.146666)

Default LODs are "VIEW" and "FIRE"

Only a single LOD is checked for intersection. LOD1 is Primary LOD and will be checked first. LOD2 is Secondary LOD. If LOD1 is not possible to check, LOD2 will be used.
Groups:
Math - Geometry

Syntax

Syntax:
lineIntersectsSurfaces [begPosASL, endPosASL, ignoreObj1, ignoreObj2, sortMode, maxResults, LOD1, LOD2, returnUnique]
Parameters:
[begPosASL, endPosASL, ignoreObj1, ignoreObj2, sortMode, maxResults, LOD1, LOD2]: Array
begPosASL: PositionASL - virtual line start
endPosASL: PositionASL - virtual line end
ignoreObj1 (Optional): Object - first object to ignore or objNull: Default: objNull
ignoreObj2 (Optional): Object - second object to ignore or objNull: Default: objNull
sortMode (Optional): Boolean - true: closest to furthest, false: furthest to closest. Default: true
maxResults (Optional): Number - Max results to return. -1 to return every result. Default: 1
LOD1 (Optional): String (added in v1.51.131920) - Primary LOD to look for intersection. Default: "VIEW"
LOD2 (Optional): String (added in v1.51.131920) - Secondary LOD to look for intersection. Default: "FIRE"
returnUnique (Optional): Boolean (added in v1.69.140138) - When false, all intersections in the same object are included not just the 1st one. Default: true
Return Value:
Array of intersections in format [[intersectPosASL, surfaceNormal, intersectObj, parentObject],...] where:
  • intersectPosASL - the actual position where line intersects surface
  • surfaceNormal - a normal to the intersected surface
  • intersectObject - the object the surface belongs to (could be proxy object) - objNull if terrain
  • parentObject - the object proxy object belongs to (not always the same as intersect object) - objNull if terrain

Examples

Example 1:
_intersections = lineIntersectsSurfaces [eyePos player, aimPos chopper, player, chopper, true, -1];
Example 2:
arrow = "Sign_Arrow_F" createVehicle [0,0,0]; onEachFrame { _ins = lineIntersectsSurfaces [ AGLToASL positionCameraToWorld [0,0,0], AGLToASL positionCameraToWorld [0,0,1000], player ]; if (count _ins == 0) exitWith {arrow setPosASL [0,0,0]}; arrow setPosASL (_ins select 0 select 0); arrow setVectorUp (_ins select 0 select 1); hintSilent str _ins; };
Example 3:
This should detect glass windows and wire fences (since Arma v1.51.131920): wirefence = "Land_New_WiredFence_5m_F" createVehicle position player; arrow = "Sign_Arrow_F" createVehicle [0,0,0]; onEachFrame { _ins = lineIntersectsSurfaces [ AGLToASL positionCameraToWorld [0,0,0], AGLToASL positionCameraToWorld [0,0,1000], player, objNull, true, 1, "GEOM", "NONE" ]; if (count _ins == 0) exitWith {arrow setPosASL [0,0,0]}; arrow setPosASL (_ins select 0 select 0); arrow setVectorUp (_ins select 0 select 1); hintSilent str _ins; };

Additional Information

See also:
lineIntersectsWithlineIntersectsObjsterrainIntersectterrainIntersectASLterrainIntersectAtASLlineIntersectsintersectcursorObjectcursorTargetcheckVisibility

Notes

Report bugs on the Feedback Tracker and/or discuss them on the Arma Discord or on the Forums.
Only post proven facts here! Add Note
Posted on August 27, 2015 - 12:44 (UTC)
Killzone Kid
Fast check if object is in a house:KK_fnc_inHouse = { lineIntersectsSurfaces [ getPosWorld _this, getPosWorld _this vectorAdd [0, 0, 50], _this, objNull, true, 1, "GEOM", "NONE" ] select 0 params ["","","","_house"]; if (_house isKindOf "House") exitWith {true}; false }; onEachFrame {hintSilent str (player call KK_fnc_inHouse)};
Posted on January 30, 2016 - 20:10 (UTC)
Pierre MGI
This command is useful to place weaponholder (and then spawned weapons) on floor of houses, correcting the spawn position (can_collide) to intersect with floor: MGI_fnc_setPosAGLS = { params ["_obj", "_pos"]; _wh_pos = getPosASL _obj; _pos set [2, (ATLtoASL _pos select 2)-10]; _ins = lineIntersectsSurfaces [_wh_pos, _pos,_obj,objNull, true,1,"VIEW","FIRE"]; _surface_distance = if (count _ins > 0) then [{(_ins select 0 select 0) distance _wh_pos},{0}]; _wh_pos set [2, (getPosASL _obj select 2) - (_surface_distance)]; _weaponholder setPosASL _wh_pos; }; After the position (_pos) obtained in BIS_fnc_buidingPositions array: _weaponholder = createVehicle ["groundWeaponHolder", _pos, [], 0, "CAN_COLLIDE"]; [_weaponholder,_pos] call MGI_fnc_setPosAGLS; Then fill your weapon holder.