|
2 | 2 | /*
|
3 | 3 | * Author: mharis001
|
4 | 4 | * Returns a world position based on the given screen position.
|
5 |
| - * Will attempt to find a flat position on an intersecting surface if enabled. |
| 5 | + * Can attempt to find a flat position on an intersecting surface if enabled. |
6 | 6 | *
|
7 | 7 | * Arguments:
|
8 | 8 | * 0: Screen Position <ARRAY> (default: getMousePosition)
|
9 |
| - * 1: Check Intersections <BOOL> (default: true) |
| 9 | + * 1: Check Intersections <BOOL|NUMBER> (default: true) |
| 10 | + * - 0, false: Do not check for intersections, return position on terrain. |
| 11 | + * - 1, true: Check for intersections with surfaces. |
| 12 | + * - 2: Check for intersections and attempt to find a flat surface. |
10 | 13 | *
|
11 | 14 | * Return Value:
|
12 | 15 | * Position ASL <ARRAY>
|
|
19 | 22 |
|
20 | 23 | #define MAX_RESULTS 5
|
21 | 24 |
|
22 |
| -params [["_screenPos", getMousePosition, [[]], 2], ["_checkIntersections", true, [true]]]; |
| 25 | +params [["_screenPos", getMousePosition, [[]], 2], ["_checkIntersections", true, [true, 0]]]; |
| 26 | + |
| 27 | +if (_checkIntersections isEqualType true) then { |
| 28 | + _checkIntersections = parseNumber _checkIntersections; |
| 29 | +}; |
23 | 30 |
|
24 | 31 | if (visibleMap) then {
|
25 | 32 | private _ctrlMap = findDisplay IDD_RSCDISPLAYCURATOR displayCtrl IDC_RSCDISPLAYCURATOR_MAINMAP;
|
26 |
| - private _pos2D = _ctrlMap ctrlMapScreenToWorld _screenPos; |
27 |
| - |
28 |
| - AGLtoASL (_pos2D + [0]) |
| 33 | + AGLToASL (_ctrlMap posScreenToWorld _screenPos) |
29 | 34 | } else {
|
30 |
| - private _position = AGLtoASL screenToWorld _screenPos; |
| 35 | + private _position = AGLToASL screenToWorld _screenPos; |
31 | 36 |
|
32 |
| - if (_checkIntersections) then { |
33 |
| - { |
34 |
| - _x params ["_intersectPos", "_surfaceNormal"]; |
| 37 | + switch (_checkIntersections) do { |
| 38 | + case 0: { |
| 39 | + _position |
| 40 | + }; |
| 41 | + case 1: { |
| 42 | + lineIntersectsSurfaces [getPosASL curatorCamera, _position] param [0, []] param [0, _position] |
| 43 | + }; |
| 44 | + case 2: { |
| 45 | + { |
| 46 | + _x params ["_intersectPos", "_surfaceNormal"]; |
35 | 47 |
|
36 |
| - // Use the intersection position if the surface is relatively flat |
37 |
| - if (_surfaceNormal vectorDotProduct [0, 0, 1] > 0.5) exitWith { |
38 |
| - _position = _intersectPos; |
39 |
| - }; |
40 |
| - } forEach lineIntersectsSurfaces [getPosASL curatorCamera, _position, objNull, objNull, true, MAX_RESULTS, "VIEW", "FIRE", false]; |
41 |
| - }; |
| 48 | + // Always keep the first intersection as a fallback |
| 49 | + if (_forEachIndex == 0) then { |
| 50 | + _position = _intersectPos; |
| 51 | + }; |
| 52 | + |
| 53 | + // Use the intersection position if the surface is relatively flat |
| 54 | + if (_surfaceNormal vectorDotProduct [0, 0, 1] > 0.5) exitWith { |
| 55 | + _position = _intersectPos; |
| 56 | + }; |
| 57 | + } forEach lineIntersectsSurfaces [getPosASL curatorCamera, _position, objNull, objNull, true, MAX_RESULTS, "VIEW", "FIRE", false]; |
42 | 58 |
|
43 |
| - _position |
| 59 | + _position |
| 60 | + }; |
| 61 | + }; |
44 | 62 | };
|
0 commit comments