News

WC3 Modding Information Center is being upgraded!! new theme, new layout 100% mobile friendly and more is coming. Please share the rejoice of a new home and give you support through your messages here or in social networks like facebook and Discord

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

moyack · 10368

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 »


We can give you full hosting for your projects, a complete page!!

A custom altered melee map where you can play Naga and Demons. Check it out!!
Use Dropbox...


Reply #1 on: October 11, 2012, 09:17:09 PM
Snippet updated. Please check first post.


We can give you full hosting for your projects, a complete page!!

A custom altered melee map where you can play Naga and Demons. Check it out!!
Use Dropbox...


Reply #2 on: December 11, 2012, 12:53:51 AM
BUMP of glory!!!


We can give you full hosting for your projects, a complete page!!

A custom altered melee map where you can play Naga and Demons. Check it out!!
Use Dropbox...


Reply #3 on: December 12, 2012, 09:48:09 AM
This is a nice utility.
Approved.



Reply #4 on: December 12, 2012, 10:07:43 AM
Thanks man!!!


We can give you full hosting for your projects, a complete page!!

A custom altered melee map where you can play Naga and Demons. Check it out!!
Use Dropbox...


 

Power of Corruption - A Warcraft III altered melee map   Chaos Realm - The world of Game modders and wc3 addicts