-
Notifications
You must be signed in to change notification settings - Fork 58
Improve attach objects module #752
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 7 commits
48cba35
4ca8c4a
0f764aa
b2a7249
04da2c1
06f0b2f
30f62b1
344cc00
a1d3005
d1ff2c8
74fb4a1
b4d6894
9dfd0aa
f62101a
4a533bf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,6 @@ | ||
| PREP(attach); | ||
| PREP(attachBone); | ||
| PREP(attachToSelection); | ||
| PREP(detach); | ||
| PREP(handleObjectEdited); | ||
| PREP(module); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| #include "script_component.hpp" | ||
| /* | ||
| * Author: Ampersand | ||
| * Attaches the given objects to a parent object selected by Zeus. | ||
| * | ||
| * Arguments: | ||
| * 0: Objects <ARRAY> | ||
| * 1: Is Bone <BOOLEAN> | ||
| * | ||
| * Return Value: | ||
| * None | ||
| * | ||
| * Example: | ||
| * [_object] call zen_attached_objects_fnc_attachBone | ||
| * | ||
| * Public: No | ||
| */ | ||
|
|
||
| [_this, { | ||
| params ["_successful", "_objects"]; | ||
|
|
||
| if (!_successful) exitWith {}; | ||
|
|
||
| curatorMouseOver params ["_type", "_entity"]; | ||
| if (_type != "OBJECT") exitWith {}; | ||
|
|
||
| // Prevent attaching object to itself | ||
| private _index = _objects find _entity; | ||
|
|
||
| if (_index != -1 && {count _objects == 1}) exitWith { | ||
| [LSTRING(CannotAttachToSelf)] call EFUNC(common,showMessage); | ||
| }; | ||
|
|
||
| _objects deleteAt _index; | ||
|
|
||
| if (isNil QGVAR(modelSelections)) then { | ||
| GVAR(modelSelections) = createHashMap; | ||
| }; | ||
|
|
||
| private _selections = GVAR(modelSelections) getOrDefaultCall [getText (configOf _entity >> "model"), { | ||
| [""] + (_entity selectionNames LOD_MEMORY select { | ||
| _entity selectionVectorDirAndUp [_x, LOD_MEMORY] isNotEqualTo [[0,0,0], [0,0,0]] | ||
| }) | ||
| }, true]; | ||
|
|
||
| [LSTRING(AttachTo), [ | ||
| [ | ||
| "COMBO", | ||
| "Selection", | ||
| [_selections, _selections, _selections find _selection] | ||
| ], | ||
| [ | ||
| "TOOLBOX", | ||
| ["Orientation", "Selection: match selection orientation (i.e. along gun barrel). Relative: maintain current orientation relative to selection."], | ||
| [true, 1, 2, ["Selection", "Relative"]], | ||
| true | ||
| ] | ||
| ], { | ||
| params ["_values", "_args"]; | ||
| _values params ["_selection", "_isRelative"]; | ||
| _args params ["_objects", "_entity"]; | ||
|
|
||
| { | ||
| if (_selection == "") then { | ||
| private _dirAndUp = [_entity vectorWorldToModel vectorDir _x, _entity vectorWorldToModel vectorUp _x]; | ||
| _x attachTo [_entity]; | ||
| [QEGVAR(common,setVectorDirAndUp), [_x, _dirAndUp], _x] call CBA_fnc_targetEvent; | ||
| } else { | ||
| [_x, _entity, _selection, _isRelative] call FUNC(attachToSelection); | ||
| }; | ||
| } forEach _objects params ["_selectionPos", "_selectionY", "_selectionZ"]; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this actually the intention ? ^ Since
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, yeah you're right. |
||
|
|
||
| private _hintPos = _entity modelToWorldVisual _selectionPos; | ||
| [[ | ||
| ["ICON", [_hintPos, "\a3\ui_f\data\IGUI\Cfg\Targeting\LaserTarget_ca.paa"]], | ||
| ["LINE", [_hintPos, _entity vectorModelToWorldVisual _selectionY vectorMultiply 2 vectorAdd _hintPos, [0, 1, 0, 1]]], | ||
| ["LINE", [_hintPos, _entity vectorModelToWorldVisual _selectionZ vectorAdd _hintPos, [0, 0, 1, 1]]] | ||
| ], 3, _entity] call EFUNC(common,drawHint); | ||
|
|
||
| [LSTRING(ObjectsAttached), count _objects] call EFUNC(common,showMessage); | ||
| }, {}, [_objects, _entity]] call EFUNC(dialog,create); | ||
|
|
||
| }, [], LSTRING(AttachTo)] call EFUNC(common,selectPosition); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| #include "script_component.hpp" | ||
| /* | ||
| * Author: Ampersand | ||
| * Attaches the child object to a selection on a parent object. | ||
| * | ||
| * Arguments: | ||
| * 0: Child <OBJECT> | ||
| * 1: Parent <OBJECT> | ||
| * 2: Selection <STRING> | ||
| * 3: Relative <BOOLEAN> True to maintain current relative orientation, false to match selection orientation | ||
| * | ||
| * Return Value: | ||
| * 0: Selection Position and Orientation <ARRAY> For drawing hints | ||
| * | ||
| * Example: | ||
| * [_child] call zen_attached_objects_fnc_attachToSelection | ||
| * | ||
| * Public: No | ||
| */ | ||
|
|
||
| params ["_child", "_parent", "_selection", ["_isRelative", true]]; | ||
|
|
||
| if (!isNull attachedTo _child) then {detach _child;}; | ||
|
|
||
| private _childPos = _parent worldToModel ASLToAGL getPosWorldVisual _child; | ||
| private _childY = _parent vectorWorldToModelVisual vectorDirVisual _child; | ||
| private _childZ = _parent vectorWorldToModelVisual vectorUpVisual _child; | ||
| private _childX = _childY vectorCrossProduct _childZ; | ||
|
|
||
| private _selectionPos = _parent selectionPosition [_selection, LOD_MEMORY]; | ||
| private _offset = _childPos vectorDiff _selectionPos; | ||
| _parent selectionVectorDirAndUp [_selection, LOD_MEMORY] params ["_selectionY", "_selectionZ"]; | ||
| private _selectionX = _selectionY vectorCrossProduct _selectionZ; | ||
|
|
||
| private _m = matrixTranspose [_selectionX, _selectionY, _selectionZ]; | ||
| private _pos = flatten ([_offset] matrixMultiply _m); | ||
| _child attachTo [_parent, _pos, _selection, true]; | ||
|
|
||
| _child setVariable [QGVAR(attachedToSelection), _selection, true]; | ||
|
|
||
| if (_isRelative) then { | ||
| [_childX, _childY, _childZ] matrixMultiply _m params ["", "_vY", "_vZ"]; | ||
| _child setVectorDirAndUp [_vY, _vZ]; | ||
| [QEGVAR(common,setVectorDirAndUp), [_child, [_vY, _vZ]], _child] call CBA_fnc_targetEvent; | ||
| }; | ||
|
|
||
| [_selectionPos, _selectionY, _selectionZ] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,3 @@ | ||
| #include "\x\zen\addons\attached_objects\script_component.hpp" | ||
|
|
||
| #define LOD_MEMORY 1e15 |
Uh oh!
There was an error while loading. Please reload this page.