Warcraft 3 documentation
vJASS & Zinc Documentation
For the latest documentation about how it works vJASS and Zinc language layers for Warcraft III, please follow these links:
Jasshelper documentation - Zinc documentation - WC3 Optimizer documentation

[Snippet] GetWidgetMeasures No New Posts Codes & Snippets

Started by
moyack

0 Members and 1 Guest are viewing this topic.

[Snippet] GetWidgetMeasures
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.     return GetDistance(GetWidgetX(a), GetWidgetY(a), GetWidgetX(b), GetWidgetY(b))
  38. endfunction
  39.  
  40. function GetWidgetsAngle takes widget a, widget b returns real
  41.     return Atan3(GetWidgetX(a), GetWidgetY(a), GetWidgetX(b), GetWidgetY(b))
  42. endfunction
  43.  
  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. endfunction
  49.  
  50. function GetUnitsZAngle takes unit a, unit b returns real
  51.     return Acos(GetWidgetsDistance(a, b) / GetUnitsDistanceZ(a, b))
  52. endfunction
  53.  
  54. endlibrary

Changelog:
v1.0: Initial release
v1.1: Added new functions that match with the library dependencies
« Last Edit: December 19, 2017, 07:44:42 PM by moyack »



Re: GetWidgetMeasures
Reply #1 on: October 11, 2012, 09:17:09 PM

Snippet updated. Please check first post.


Re: GetWidgetMeasures
Reply #2 on: December 11, 2012, 12:53:51 AM

BUMP of glory!!!


Re: [snippet] GetWidgetMeasures
Reply #3 on: December 12, 2012, 09:48:09 AM

This is a nice utility.
Approved.



Re: [Snippet] GetWidgetMeasures
Reply #4 on: December 12, 2012, 10:07:43 AM

Thanks man!!!


 

Started by PitzerMike

Replies: 0
Views: 1638
Codes & Snippets

Started by Purgeandfire

Replies: 0
Views: 1714
Codes & Snippets

Started by Bribe

Replies: 0
Views: 1969
Codes & Snippets

Started by moyack

Replies: 0
Views: 9880
Codes & Snippets

Started by Magtheridon96

Replies: 1
Views: 8663
Codes & Snippets
Vivir aprendiendo.co - A place for learning stuff, in Spanish   Chaos Realm - The world of Game modders and wc3 addicts   Diplo, a gaming community   Power of Corruption, an altered melee featuring Naga and Demon. Play it now!!!   WC3JASS.com - The JASS Vault + vJASS and Zinc   Jetcraft - A Starcraft II mod   WormTastic Clan (wTc)   Warcraft RESOURCES Reforged: Modelos, mapas, proyectos y mas...