Created
July 10, 2016 01:26
-
-
Save jameslkingsley/dbea351846fc1c2385aaf74706585de1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Author: Kingsley, 654wak654 | |
* Draws a bounding box around the given object in 3D space | |
* Must be called every frame | |
* | |
* Arguments: | |
* 0: Object <OBJECT> | |
* 1: Color (optional) <RGBA ARRAY> | |
* 2: Offset in world position (AGL) (optional) <ARRAY> | |
* 3: Rotation of bounding box (optional) <NUMBER> | |
* | |
* Return Value: | |
* None | |
* | |
* Example: | |
* [player, [1,0,0,1], [0,0,0], 45] call mars_editor_fnc_drawBoundingBox; | |
* | |
* Public: Yes | |
*/ | |
#include "script_component.hpp" | |
params [ | |
["_target", objNull, [objNull]], | |
["_color", [1,1,1,1], [[]]], | |
["_offset", [0,0,0], [[]]], | |
["_direction", 0, [0]] | |
]; | |
if (isNull _target) exitWith {}; | |
_color set [3, [0.5, 1] select (_target in GVAR(selection))]; | |
(boundingBoxReal _target) params ["_box0", "_box1"]; | |
{ | |
_x params ["_start", "_end"]; | |
if (_direction != 0) then { | |
_direction = _direction % 360; | |
_start = [ | |
((_start select 0) * cos (360 - _direction)) - ((_start select 1) * sin (360 - _direction)), | |
((_start select 0) * sin (360 - _direction)) + ((_start select 1) * cos (360 - _direction)), | |
_start select 2 | |
]; | |
_end = [ | |
((_end select 0) * cos (360 - _direction)) - ((_end select 1) * sin (360 - _direction)), | |
((_end select 0) * sin (360 - _direction)) + ((_end select 1) * cos (360 - _direction)), | |
_end select 2 | |
]; | |
}; | |
drawLine3D [ | |
(_target modelToWorldVisual _start) vectorAdd _offset, | |
(_target modelToWorldVisual _end) vectorAdd _offset, | |
_color | |
]; | |
false | |
} count [ | |
// Left Front Bottom -> Right Front Bottom | |
[ | |
_box0, | |
[_box1 select 0, _box0 select 1, _box0 select 2] | |
], | |
// Left Front Bottom -> Left Back Bottom | |
[ | |
_box0, | |
[_box0 select 0, _box1 select 1, _box0 select 2] | |
], | |
// Left Front Bottom -> Left Front Top | |
[ | |
_box0, | |
[_box0 select 0, _box0 select 1, _box1 select 2] | |
], | |
// Right Back Top -> Left Back Top | |
[ | |
_box1, | |
[_box0 select 0, _box1 select 1, _box1 select 2] | |
], | |
// Right Back Top -> Right Front Top | |
[ | |
_box1, | |
[_box1 select 0, _box0 select 1, _box1 select 2] | |
], | |
// Right Back Top -> Right Back Bottom | |
[ | |
_box1, | |
[_box1 select 0, _box1 select 1, _box0 select 2] | |
], | |
// Right Back Bottom -> Right Front Bottom | |
[ | |
[_box1 select 0, _box1 select 1, _box0 select 2], | |
[_box1 select 0, _box0 select 1, _box0 select 2] | |
], | |
// Right Front Top -> Left Front Top | |
[ | |
[_box1 select 0, _box0 select 1, _box1 select 2], | |
[_box0 select 0, _box0 select 1, _box1 select 2] | |
], | |
// Right Front Bottom -> Right Front Top | |
[ | |
[_box1 select 0, _box0 select 1, _box0 select 2], | |
[_box1 select 0, _box0 select 1, _box1 select 2] | |
], | |
// Left Back Top -> Left Front Top | |
[ | |
[_box0 select 0, _box1 select 1, _box1 select 2], | |
[_box0 select 0, _box0 select 1, _box1 select 2] | |
], | |
// Left Back Top -> Left Back Bottom | |
[ | |
[_box0 select 0, _box1 select 1, _box1 select 2], | |
[_box0 select 0, _box1 select 1, _box0 select 2] | |
], | |
// Left Back Bottom -> Right Back Bottom | |
[ | |
[_box0 select 0, _box1 select 1, _box0 select 2], | |
[_box1 select 0, _box1 select 1, _box0 select 2] | |
] | |
]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment