[Snippet] GetWidgetMeasures

Scripts

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


Code (jass) Select
/******************************************************************
*                     GEOMETRY MEASURES V1.1                      *
*                           By moyack                             *
*                              2012                               *
*              ===================================                *
*              Exclusive resource from wc3jass.com                *
*              ===================================                *
******************************************************************/

library GetWidgetMeasures requires GeometryLibBase
/*This is the first of a set of libraries focused in the usage of
proper geometry functions.

Here we'll aim to make the code as modular as possible so we can
reduce the code amount in map but offering the neccesary tools
for modders

Here we offer some basic functions realated to widgets (units,
destructables and items):

GetWidgetsDistance: allows to calculate the distance between 2 widgets.
                    Here you can have any combination: unit-unit, unit-
                    destructable, item unit, etc.
       
GetWidgetsAngle: Gets the angle between 2 widgets. Like the previus
                 function, it allows to compare between units, unit-item,
                 unit-destructable, etc.
                 
GetUnitsDistanceZ: Get the distance between 2 units, taking into account
                   their respectives locations and flyheights.

GetUnitsZAngle: Returns the elevation angle between unit a and unit b.

IMPORTANT NOTE: GetWidgetsAngle and GetUnitsZAngle returns angles in RADIANS.
*/
function GetWidgetsDistance takes widget a, widget b returns real
    return GetDistance(GetWidgetX(a), GetWidgetY(a), GetWidgetX(b), GetWidgetY(b))
endfunction

function GetWidgetsAngle takes widget a, widget b returns real
    return Atan3(GetWidgetX(a), GetWidgetY(a), GetWidgetX(b), GetWidgetY(b))
endfunction

function GetUnitsDistanceZ takes unit a, unit b returns real
    local real z = GetUnitZ(b) - GetUnitZ(a)
    local real d = GetWidgetsDistance(a, b)
    return SquareRoot(d * d + z * z)
endfunction

function GetUnitsZAngle takes unit a, unit b returns real
    return Acos(GetWidgetsDistance(a, b) / GetUnitsDistanceZ(a, b))
endfunction

endlibrary


Changelog:
v1.0: Initial release
v1.1: Added new functions that match with the library dependencies
13 years
Snippet updated. Please check first post.
13 years
BUMP of glory!!!
13 years
This is a nice utility.
Approved.
13 years
Thanks man!!!