Skip to content

Commit 7a7e0b2

Browse files
committed
Fixing sling load attachment points
1 parent a0977d0 commit 7a7e0b2

1 file changed

Lines changed: 35 additions & 4 deletions

File tree

addons/SA_AdvancedSlingLoading/functions/fn_advancedSlingLoadingInit.sqf

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ ASL_Rope_Get_Lift_Capability = {
2828
_slingLoadMaxCargoMass;
2929
};
3030

31+
ASL_SLING_LOAD_POINT_CLASS_HEIGHT_OFFSET = [
32+
["All", [-0.05, -0.05, -0.05]],
33+
["CUP_B_CH47F_USA", [-0.05, -2, -0.05]]
34+
];
35+
3136
ASL_Get_Sling_Load_Points = {
3237
params ["_vehicle"];
3338
private ["_slingLoadPointsArray","_cornerPoints","_rearCenterPoint","_vehicleUnitVectorUp"];
@@ -41,13 +46,39 @@ ASL_Get_Sling_Load_Points = {
4146
_middleCenterPoint = ((_frontCenterPoint vectorDiff _rearCenterPoint) vectorMultiply 0.5) vectorAdd _rearCenterPoint;
4247
_vehicleUnitVectorUp = vectorNormalized (vectorUp _vehicle);
4348

49+
_slingLoadPointHeightOffset = 0;
50+
{
51+
if(_vehicle isKindOf (_x select 0)) then {
52+
_slingLoadPointHeightOffset = (_x select 1);
53+
};
54+
} forEach ASL_SLING_LOAD_POINT_CLASS_HEIGHT_OFFSET;
55+
4456
_slingLoadPoints = [];
4557
{
4658
_modelPoint = _x;
4759
_modelPointASL = AGLToASL (_vehicle modelToWorldVisual _modelPoint);
48-
_surfaceIntersectStartASL = _modelPointASL vectorAdd ( _vehicleUnitVectorUp vectorMultiply 5 );
49-
_surfaceIntersectEndASL = _modelPointASL vectorAdd ( _vehicleUnitVectorUp vectorMultiply -5 );
50-
_surfaces = lineIntersectsSurfaces [_surfaceIntersectStartASL, _surfaceIntersectEndASL, objNull, objNull, false, 100];
60+
_surfaceIntersectStartASL = _modelPointASL vectorAdd ( _vehicleUnitVectorUp vectorMultiply -5 );
61+
_surfaceIntersectEndASL = _modelPointASL vectorAdd ( _vehicleUnitVectorUp vectorMultiply 5 );
62+
63+
// Determine if the surface intersection line crosses below ground level
64+
// If if does, move surfaceIntersectStartASL above ground level (lineIntersectsSurfaces
65+
// doesn't work if starting below ground level for some reason
66+
// See: https://en.wikipedia.org/wiki/Line%E2%80%93plane_intersection
67+
68+
_la = ASLToAGL _surfaceIntersectStartASL;
69+
_lb = ASLToAGL _surfaceIntersectEndASL;
70+
71+
if(_la select 2 < 0 && _lb select 2 > 0) then {
72+
_n = [0,0,1];
73+
_p0 = [0,0,0];
74+
_l = (_la vectorFromTo _lb);
75+
if((_l vectorDotProduct _n) != 0) then {
76+
_d = ( ( _p0 vectorAdd ( _la vectorMultiply -1 ) ) vectorDotProduct _n ) / (_l vectorDotProduct _n);
77+
_surfaceIntersectStartASL = AGLToASL ((_l vectorMultiply _d) vectorAdd _la);
78+
};
79+
};
80+
81+
_surfaces = lineIntersectsSurfaces [_surfaceIntersectStartASL, _surfaceIntersectEndASL, objNull, objNull, true, 100];
5182
_intersectionASL = [];
5283
{
5384
_intersectionObject = _x select 2;
@@ -56,7 +87,7 @@ ASL_Get_Sling_Load_Points = {
5687
};
5788
} forEach _surfaces;
5889
if(count _intersectionASL > 0) then {
59-
_intersectionASL = _intersectionASL vectorAdd (( _surfaceIntersectStartASL vectorFromTo _surfaceIntersectEndASL ) vectorMultiply 0.2);
90+
_intersectionASL = _intersectionASL vectorAdd (( _surfaceIntersectStartASL vectorFromTo _surfaceIntersectEndASL ) vectorMultiply (_slingLoadPointHeightOffset select (count _slingLoadPoints)));
6091
_slingLoadPoints pushBack (_vehicle worldToModelVisual (ASLToAGL _intersectionASL));
6192
} else {
6293
_slingLoadPoints pushBack [];

0 commit comments

Comments
 (0)