WC3 Modding Information Center

Warcraft (WC3) Modding => Warcraft III Spells and Systems => Warcraft III Resources => Codes & Snippets => Topic started by: moyack on October 01, 2012, 09:31:36 PM

Title: [Snippet] GetWidgetMeasures
Post by: moyack on October 01, 2012, 09:31:36 PM
Category: Geometry, Units
Language: vJASS

Related Topics or Resources


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
  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 of
  12. proper geometry functions.
  13.  
  14. Here we'll aim to make the code as modular as possible so we can
  15. reduce the code amount in map but offering the neccesary tools
  16. for modders
  17.  
  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 previus
  26.                  function, it allows to compare between units, unit-item,
  27.                  unit-destructable, etc.
  28.                  
  29. GetUnitsDistanceZ: Get the distance between 2 units, taking into account
  30.                    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. endfunction
  38.  
  39. function GetWidgetsAngle takes widget a, widget b returns real
  40.     return Atan3(GetWidgetX(a), GetWidgetY(a), GetWidgetX(b), GetWidgetY(b))
  41. endfunction
  42.  
  43. function GetUnitsDistanceZ takes unit a, unit b returns real
  44.     local real z = GetUnitZ(b) - GetUnitZ(a)
  45.     local real d = GetWidgetsDistance(a, b)
  46.     return SquareRoot(d * d + z * z)
  47. endfunction
  48.  
  49. function GetUnitsZAngle takes unit a, unit b returns real
  50.     return Acos(GetWidgetsDistance(a, b) / GetUnitsDistanceZ(a, b))
  51. endfunction
  52.  
  53. endlibrary

Changelog:
v1.0: Initial release
v1.1: Added new functions that match with the library dependencies
Title: Re: GetWidgetMeasures
Post by: moyack on October 11, 2012, 09:17:09 PM
Snippet updated. Please check first post.
Title: Re: GetWidgetMeasures
Post by: moyack on December 11, 2012, 12:53:51 AM
BUMP of glory!!!
Title: Re: [snippet] GetWidgetMeasures
Post by: Magtheridon96 on December 12, 2012, 09:48:09 AM
This is a nice utility.
Approved.
Title: Re: [Snippet] GetWidgetMeasures
Post by: moyack on December 12, 2012, 10:07:43 AM
Thanks man!!!