lineIntersectsSurfaces: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
mNo edit summary
m (Some wiki formatting)
(49 intermediate revisions by 4 users not shown)
Line 1: Line 1:
{{Command|= Comments
{{RV|type=command
____________________________________________________________________________________________


| arma3 |= Game name
|game1= arma3
|1.50|= Game version
|version1= 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. 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. '''NOTE:''' 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.<br><br>
|gr1= Math - Geometry
Since Arma v1.51.131920 it is possible to indicate primary and secondary [[LOD]] to look for intersection. Available options are:
 
|descr= Returns a list of intersections with surfaces and ground from ''begPosASL'' to ''endPosASL''. Doesn't return intersection with sea surface. Works underwater, unlike [[lineIntersects]]. Hardcoded max distance: 5000m.
{{Feature|important|
* if ''begPosASL'' is under the ground and ''endPosASL'' is above it, the command will only return intersection with the ground, this is an engine limitation and none of the intersectXXX commands will work when initiated from under the ground.
* only a single LOD is checked for intersection. LOD2 will only be checked if LOD1 is unavailable.
}}
 
|s1= [[lineIntersectsSurfaces]] [begPosASL, endPosASL, ignoreObj1, ignoreObj2, sortMode, maxResults, LOD1, LOD2, returnUnique]
 
|p1= begPosASL: [[PositionASL]] - virtual line start
 
|p2= endPosASL: [[PositionASL]] - virtual line end
 
|p3= ignoreObj1: [[Object]] - (Optional, default [[objNull]]) first object to ignore
 
|p4= ignoreObj2: [[Object]] - (Optional, default [[objNull]]) second object to ignore
 
|p5= sortMode: [[Boolean]] -  (Optional, default [[true]]) [[true]]: closest to furthest, [[false]]: furthest to closest
 
|p6= maxResults: [[Number]] - (Optional, default 1) max results to return. -1 to return every result
 
|p7= LOD1: [[String]] - (Optional, default "VIEW") primary [[LOD]] to look for intersection. Can be one of:
* "FIRE"
* "FIRE"
* "VIEW"
* "VIEW"
* "GEOM"
* "GEOM"
* "IFIRE" - ("I" stands for Indirect, almost the same as FIRE)
* "IFIRE" - ("I" stands for Indirect, ''almost'' identical to "FIRE")
* "NONE"
* "NONE"
* {{GVI|arma3|2.02|size=0.8}} "PHYSX" - PhysX geometry LOD
|p7since= arma3 1.52


Default [[LOD]]s are "VIEW" and "FIRE" |= Description
|p8= LOD2: [[String]] - (Optional, default "FIRE") secondary [[LOD]] to look for intersection. See ''LOD1'' for possible values
____________________________________________________________________________________________
|p8since= arma3 1.52


| '''lineIntersectsSurfaces''' [begPosASL, endPosASL, ignoreObj1, ignoreObj2, sortMode, maxResults, LOD1, LOD2, returnUnique] |= Syntax
|p9= returnUnique: [[Boolean]] - (Optional, default [[true]]) when [[false]], all intersections in the same object are included, otherwise only the first one
|p1= [begPosASL, endPosASL, ignoreObj1, ignoreObj2, sortMode, maxResults, LOD1, LOD2]: [[Array]]|= Parameter 0
|p9since= arma3 1.70
|p2= begPosASL: [[PositionASL]] - virtual line start |= Parameter 1
|p3= endPosASL: [[PositionASL]] - virtual line end |= Parameter 2
|p4= ignoreObj1 (Optional): [[Object]] - first object to ignore or [[objNull]]: Default: [[objNull]]|=Parameter 3
|p5= ignoreObj2 (Optional): [[Object]] - second object to ignore or [[objNull]]: Default: [[objNull]] |= Parameter 4
|p6= sortMode (Optional): [[Boolean]] - [[true]]: closest to furthest, [[false]]: furthest to closest. Default: [[true]] |= Parameter 5
|p7= maxResults (Optional): [[Number]] - Max results to return. -1 to return every result. Default: 1|= Parameter 6
|p8= LOD1 (Optional): [[String]] (added in v1.51.131920) - Primary [[LOD]] to look for intersection. Default: "VIEW" |= Parameter 5
|p9= LOD2 (Optional): [[String]] (added in v1.51.131920) - Secondary [[LOD]] to look for intersection. Default: "FIRE" |= Parameter 6
|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]] |= Parameter 6


| [[Array]] of intersections in format <nowiki>[</nowiki>[intersectPosASL, surfaceNormal, intersectObj, parentObject],...] where:
|r1= [[Array]] of intersections in format [<nowiki/>[intersectPosASL, surfaceNormal, intersectObj, parentObject], ...] where:
* intersectPosASL - the actual position where line intersects surface
* 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) - [[objNull]] if terrain
* 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 |= Return value
* parentObject - the object proxy object belongs to (not always the same as intersect object) - [[objNull]] if terrain
____________________________________________________________________________________________
 
|x1= <code>_intersections = [[lineIntersectsSurfaces]] <nowiki>[</nowiki>[[eyePos]] [[player]], [[aimPos]] chopper, [[player]], chopper, [[true]], -1];</code> |= Example 1
|x1= <code>_intersections = [[lineIntersectsSurfaces]] [<nowiki/>[[eyePos]] [[player]], [[aimPos]] chopper, [[player]], chopper, [[true]], -1];</code>


|x2= <code>arrow = "Sign_Arrow_F" [[createVehicle]] [0,0,0];
|x2= <code>arrow = "Sign_Arrow_F" [[createVehicle]] [0,0,0];
Line 45: Line 57:
[[player]]
[[player]]
];
];
[[if]] ([[count]] _ins == 0) [[exitWith]] {arrow [[setPosASL]] [0,0,0]};
[[if]] ([[count]] _ins == 0) [[exitWith]] { arrow [[setPosASL]] [0,0,0] };
arrow [[setPosASL]] (_ins [[select]] 0 [[select]] 0);  
arrow [[setPosASL]] (_ins [[select]] 0 [[select]] 0);
arrow [[setVectorUp]] (_ins [[select]] 0 [[select]] 1);
arrow [[setVectorUp]] (_ins [[select]] 0 [[select]] 1);
[[hintSilent]] [[str]] _ins;
[[hintSilent]] [[str]] _ins;
};</code> |= Example 2
};</code>


|x3= This should detect glass windows and wire fences (since Arma v1.51.131920): <code>wirefence = "Land_New_WiredFence_5m_F" [[createVehicle]] [[position]] [[player]];
|x3= This should detect glass windows and wire fences (since Arma v1.52): <code>wirefence = "Land_New_WiredFence_5m_F" [[createVehicle]] [[position]] [[player]];
arrow = "Sign_Arrow_F" [[createVehicle]] [0,0,0];
arrow = "Sign_Arrow_F" [[createVehicle]] [0,0,0];
[[onEachFrame]] {
[[onEachFrame]] {
Line 64: Line 76:
"NONE"
"NONE"
];
];
[[if]] ([[count]] _ins == 0) [[exitWith]] {arrow [[setPosASL]] [0,0,0]};
[[if]] ([[count]] _ins == 0) [[exitWith]] { arrow [[setPosASL]] [0,0,0] };
arrow [[setPosASL]] (_ins [[select]] 0 [[select]] 0);  
arrow [[setPosASL]] (_ins [[select]] 0 [[select]] 0);
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]], [[terrainIntersectAtASL]], [[lineIntersects]], [[intersect]], [[cursorObject]], [[cursorTarget]], [[checkVisibility]] |= See also
|seealso= [[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>
<h3 style="display:none">Bottom Section</h3>
[[Category:Scripting Commands Arma 3|{{uc:{{PAGENAME}}}}]]
[[Category:Scripting Commands|{{uc:{{PAGENAME}}}}]]


<!-- CONTINUE Notes -->
<dt></dt>
<dl class="command_description">
<dd class="notedate">Posted on August 27, 2015 - 12:44 (UTC)</dd>
<dd class="notedate">Posted on August 27, 2015 - 12:44 (UTC)</dd>
<dt class="note">[[User:Killzone Kid|Killzone Kid]]</dt>
<dt class="note">[[User:Killzone Kid|Killzone Kid]]</dt>
<dd class="note">
<dd class="note">
Fast check if object is in a house:<code>KK_fnc_inHouse = {
Fast check if the player is in a house:<code>KK_fnc_inHouse = {
[[lineIntersectsSurfaces]] [
[[lineIntersectsSurfaces]] [
[[getPosWorld]] _this,  
[[getPosWorld]] _this,  
Line 95: Line 98:
_this, [[objNull]], [[true]], 1, "GEOM", "NONE"
_this, [[objNull]], [[true]], 1, "GEOM", "NONE"
] [[select]] 0 [[params]] ["","","","_house"];
] [[select]] 0 [[params]] ["","","","_house"];
[[if]] (_house [[isKindOf]] "House") [[exitWith]] {[[true]]};
[[if]] (_house [[isKindOf]] "House") [[exitWith]] { [[true]] };
[[false]]
[[false]]
};
};
[[onEachFrame]] {[[hintSilent]] [[str]] ([[player]] [[call]] KK_fnc_inHouse)};</code>
[[onEachFrame]] { [[hintSilent]] [[str]] ([[player]] [[call]] KK_fnc_inHouse) };</code>
</dd>
</dd>
</dl>


<dl class="command_description">
<dt></dt>
<dd class="notedate">Posted on January 30, 2016 - 20:10 (UTC)</dd>
<dd class="notedate">Posted on January 30, 2016 - 20:10 (UTC)</dd>
<dt class="note">[[User:Pierre MGI|Pierre MGI]]</dt>
<dt class="note">[[User:Pierre MGI|Pierre MGI]]</dt>
<dd class="note">
<dd class="note">
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:
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:
<code>
<code>MGI_fnc_setPosAGLS = {
MGI_fnc_setPosAGLS = {
[[params]] ["_obj", "_pos"];
  [[params]] ["_obj", "_pos"];
_wh_pos = [[getPosASL]] _obj;
  _wh_pos = [[getPosASL]] _obj;


  _pos [[set]] [2, ([[ATLtoASL]] _pos [[select]] 2)-10];
_pos [[set]] [2, ([[ATLtoASL]] _pos [[select]] 2) - 10];
_ins = [[lineIntersectsSurfaces]] [_wh_pos, _pos,_obj,[[objNull]], [[true]],1,"VIEW","FIRE"];
_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}];
_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)];
_wh_pos [[set]] [2, ([[getPosASL]] _obj [[select]] 2) - (_surface_distance)];
_weaponholder [[setPosASL]] _wh_pos;
_weaponholder [[setPosASL]] _wh_pos;
};
};
</code>
</code>
After the position (_pos) obtained in BIS_fnc_buidingPositions array:
After the position (_pos) obtained in BIS_fnc_buidingPositions array:
<code>
<code>[[private]] _weaponHolder = [[createVehicle]] ["groundWeaponHolder", _pos, [], 0, "CAN_COLLIDE"];
_weaponholder = [[createVehicle]] ["groundWeaponHolder", _pos, [], 0, "CAN_COLLIDE"];
[_weaponHolder, _pos] [[call]] MGI_fnc_setPosAGLS;
[_weaponholder,_pos] [[call]] MGI_fnc_setPosAGLS;
Then fill your weapon holder.
Then fill your weapon holder.
</code>
</code>
</dd>
</dd>
</dl>
</dl>
<!-- DISCONTINUE Notes -->

Revision as of 01:50, 11 August 2021

Hover & click on the images for description

Description

Description:
Returns a list of intersections with surfaces and ground from begPosASL to endPosASL. Doesn't return intersection with sea surface. Works underwater, unlike lineIntersects. Hardcoded max distance: 5000m.
  • if begPosASL is under the ground and endPosASL is above it, the command will only return intersection with the ground, this is an engine limitation and none of the intersectXXX commands will work when initiated from under the ground.
  • only a single LOD is checked for intersection. LOD2 will only be checked if LOD1 is unavailable.
Groups:
Math - Geometry

Syntax

Syntax:
lineIntersectsSurfaces [begPosASL, endPosASL, ignoreObj1, ignoreObj2, sortMode, maxResults, LOD1, LOD2, returnUnique]
Parameters:
begPosASL: PositionASL - virtual line start
endPosASL: PositionASL - virtual line end
ignoreObj1: Object - (Optional, default objNull) first object to ignore
ignoreObj2: Object - (Optional, default objNull) second object to ignore
sortMode: Boolean - (Optional, default true) true: closest to furthest, false: furthest to closest
maxResults: Number - (Optional, default 1) max results to return. -1 to return every result
since Arma 3 logo black.png1.52
LOD1: String - (Optional, default "VIEW") primary LOD to look for intersection. Can be one of:
  • "FIRE"
  • "VIEW"
  • "GEOM"
  • "IFIRE" - ("I" stands for Indirect, almost identical to "FIRE")
  • "NONE"
  • Arma 3 logo black.png2.02 "PHYSX" - PhysX geometry LOD
since Arma 3 logo black.png1.52
LOD2: String - (Optional, default "FIRE") secondary LOD to look for intersection. See LOD1 for possible values
since Arma 3 logo black.png1.70
returnUnique: Boolean - (Optional, default true) when false, all intersections in the same object are included, otherwise only the first one
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.52): 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 the player 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: private _weaponHolder = createVehicle ["groundWeaponHolder", _pos, [], 0, "CAN_COLLIDE"]; [_weaponHolder, _pos] call MGI_fnc_setPosAGLS; Then fill your weapon holder.