13 years
edited 8 years
Description
This library provides a set of functions to get distance and angles between widgets (units, destructibles, items). Here you can get any of these measures no matter the type of the widget, like measuring the distance between unit-unit, unit-destructable, unit-item, item-unit, etc.
Requirements
- Geometry Lib Base
Actual Code
Changelog:
v1.0: Initial release
v1.1: Added new functions that match with the library dependencies
This library provides a set of functions to get distance and angles between widgets (units, destructibles, items). Here you can get any of these measures no matter the type of the widget, like measuring the distance between unit-unit, unit-destructable, unit-item, item-unit, etc.
Requirements
- Geometry Lib Base
Actual Code
1 /******************************************************************2 * GEOMETRY MEASURES V1.1 *3 * By moyack *4 * 2012 *5 * =================================== *6 * Exclusive resource from wc3jass.com *7 * =================================== *8 ******************************************************************/9 10 library GetWidgetMeasures requires GeometryLibBase
11 /*This is the first of a set of libraries focused in the usage of12 proper geometry functions.13
14 Here we'll aim to make the code as modular as possible so we can15 reduce the code amount in map but offering the neccesary tools 16 for modders17
18 Here we offer some basic functions realated to widgets (units,19 destructables and items):20
21 GetWidgetsDistance: allows to calculate the distance between 2 widgets.22 Here you can have any combination: unit-unit, unit-23 destructable, item unit, etc.24 25 GetWidgetsAngle: Gets the angle between 2 widgets. Like the previus26 function, it allows to compare between units, unit-item,27 unit-destructable, etc.28 29 GetUnitsDistanceZ: Get the distance between 2 units, taking into account30 their respectives locations and flyheights.31
32 GetUnitsZAngle: Returns the elevation angle between unit a and unit b.33
34 IMPORTANT NOTE: GetWidgetsAngle and GetUnitsZAngle returns angles in RADIANS.35 */36 function GetWidgetsDistance takes widget a, widget b returns real
37 return GetDistance(GetWidgetX(a), GetWidgetY(a), GetWidgetX(b), GetWidgetY(b))
38 endfunction39 40 function GetWidgetsAngle takes widget a, widget b returns real
41 return Atan3(GetWidgetX(a), GetWidgetY(a), GetWidgetX(b), GetWidgetY(b))
42 endfunction43 44 function GetUnitsDistanceZ takes unit a, unit b returns real
45 local real z = GetUnitZ(b) - GetUnitZ(a)
46 local real d = GetWidgetsDistance(a, b)
47 return SquareRoot(d * d + z * z)
48 endfunction49 50 function GetUnitsZAngle takes unit a, unit b returns real
51 return Acos(GetWidgetsDistance(a, b) / GetUnitsDistanceZ(a, b))
52 endfunction53 54 endlibrary
Changelog:
v1.0: Initial release
v1.1: Added new functions that match with the library dependencies