Warcraft III: MapsModelsSkinsIconsSpellsToolsTutorials
WC3 JASS: Code SnippetsJASS and vJASS Spells and SystemsJass Tutorials
Chat @Discord

Author Topic: [snippet] GeometryLibBase  (Read 19315 times)

  • Site Owner
  • Administrator
  • Starter - level 4
  • *
  • Posts: 981
  • WC3 Models: 5
  • WC3 Tutorials: 11
  • WC3 Tools: 10
  • WC3 Maps: 11
  • WC3 Skins: 6
  • WC3 Icons: 2
  • WC3 Spells: 5
  • Reputation: 1153
  • Site Admin - I love fix things
    • View Profile
    • Blizzard Modding Information Center
[snippet] GeometryLibBase
« on: October 01, 2012, 09:09:32 PM »
Description

Here's the first of the codes developed to form a set of libraries with their dependencies so you can make in your map a complete but adapted geometry pack, fitting your needs and reducing redundant code. This code offers the most common functions required in geometry.

Requirements:

 - GetZ

Actual Code
Code: jass  [Select]
  1. /******************************************************************
  2. *                     GEOMETRY LIB PACK V1.3                      *
  3. *                           By moyack                             *
  4. *                              2012                               *
  5. *              ===================================                *
  6. *              Exclusive resource from wc3jass.com                *
  7. *              ===================================                *
  8. ******************************************************************/
  9.  
  10. library GeometryLibBase requires GetZ
  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 the most basic functions ever needed:
  19.  
  20. Atan3: to calculate PROPERLY the correct angle. the values (x1;y1)
  21.        will be the pivot and (x2;y2) the extreme point.
  22.        
  23. GetDistance: Get the distance from (x1;y1) and (x2;y2). simple as hell
  24.  
  25. GetDistanceZ: Similar to GetDistance, but this one takes into account
  26.               the terrain height.
  27. Zangle: Returns the angle in Z coordinate (height) between 2 points.
  28.  
  29. GetPolarX: returns the X coordinate o a point from an initial value
  30.            of "x" at an "angle" specified in a distance "d"
  31.  
  32. GetPolarY: returns the Y coordinate o a point from an initial value
  33.            of "y" at an "angle" specified in a distance "d"
  34.  
  35. Important Note: Atan3 and Zangle returns the angles in RADIANS.
  36.                 GetPolaX/Y takes angles in RADIANS.
  37. */
  38.  
  39. function Atan3 takes real x1, real y1, real x2, real y2 returns real
  40.     local real a = Atan2(y2 - y1, x2 - x1)
  41.     if a < 0 then
  42.         return 2 * bj_PI + a
  43.     endif
  44.     return a
  45. endfunction
  46.  
  47. function GetDistance takes real x1, real y1, real x2, real y2 returns real
  48.     local real dx = x2 - x1
  49.     local real dy = y2 - y1
  50.     return SquareRoot( dx * dx + dy * dy )
  51. endfunction
  52.  
  53. function GetDistanceZ takes real x1, real y1, real x2, real y2 returns real
  54.     local real dx = x2 - x1
  55.     local real dy = y2 - y1
  56.     local real dz = GetPointZ(x2, y2) - GetPointZ(x1, y1)
  57.     return SquareRoot( dx * dx + dy * dy +  dz * dz)
  58. endfunction
  59.  
  60. function GetZangle takes real x1, real y1, real x2, real y2 returns real
  61.     return Acos(GetDistance(x1, y1, x2, y2) / GetDistanceZ(x1, y1, x2, y2))
  62. endfunction
  63.  
  64. function GetPolarX takes real x, real radians, real d returns real
  65.     return x + Cos(radians) * d
  66. endfunction
  67.  
  68. function GetPolarY takes real y, real radians, real d returns real
  69.     return y + Sin(radians) * d
  70. endfunction
  71.  
  72. endlibrary

Changelog:
v1.0: Initial Release
v1.1: Added new functions. Added dependency to GetZ library.
v1.2: Added GetPolarX/Y functions.
v1.3: Changed a function name.

Any comments and suggestions are welcome.
« Last Edit: December 29, 2012, 07:08:22 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...

  • Rookie - level 1
  • *
  • Posts: 41
  • WC3 Models: 0
  • WC3 Tutorials: 0
  • WC3 Tools: 0
  • WC3 Maps: 0
  • WC3 Skins: 0
  • WC3 Icons: 0
  • WC3 Spells: 0
  • Reputation: 13
    • View Profile
Re: GeometryLibBase
« Reply #1 on: October 03, 2012, 01:54:37 AM »
Perhaps distance with z, just for kicks. I'll try to think of some more things to include.

  • Site Owner
  • Administrator
  • Starter - level 4
  • *
  • Posts: 981
  • WC3 Models: 5
  • WC3 Tutorials: 11
  • WC3 Tools: 10
  • WC3 Maps: 11
  • WC3 Skins: 6
  • WC3 Icons: 2
  • WC3 Spells: 5
  • Reputation: 1153
  • Site Admin - I love fix things
    • View Profile
    • Blizzard Modding Information Center
Re: GeometryLibBase
« Reply #2 on: October 03, 2012, 05:04:47 AM »
Perhaps distance with z, just for kicks. I'll try to think of some more things to include.

Awesome!! the idea is to make a full set of functions related for geometry. Right now I'm working in a group loop handler snippet so we can develop group units by certain conditions with less code.

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...

  • Awesome Global Code Moderator
  • Recognized User
  • Rookie - level 2
  • *
  • Posts: 83
  • WC3 Models: 0
  • WC3 Tutorials: 0
  • WC3 Tools: 0
  • WC3 Maps: 0
  • WC3 Skins: 0
  • WC3 Icons: 0
  • WC3 Spells: 0
  • Reputation: 516
  • vJass Incarnate
    • View Profile
Re: GeometryLibBase
« Reply #3 on: October 08, 2012, 01:49:04 PM »
Cool, but I'd prefer it if you added more functions like GetZAngle and name the functions properly (Distance -> GetDistance) :P

  • Site Owner
  • Administrator
  • Starter - level 4
  • *
  • Posts: 981
  • WC3 Models: 5
  • WC3 Tutorials: 11
  • WC3 Tools: 10
  • WC3 Maps: 11
  • WC3 Skins: 6
  • WC3 Icons: 2
  • WC3 Spells: 5
  • Reputation: 1153
  • Site Admin - I love fix things
    • View Profile
    • Blizzard Modding Information Center
Re: GeometryLibBase
« Reply #4 on: October 11, 2012, 09:14:24 PM »
Cool, but I'd prefer it if you added more functions like GetZAngle and name the functions properly (Distance -> GetDistance) :P

Code 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...

  • Site Owner
  • Administrator
  • Starter - level 4
  • *
  • Posts: 981
  • WC3 Models: 5
  • WC3 Tutorials: 11
  • WC3 Tools: 10
  • WC3 Maps: 11
  • WC3 Skins: 6
  • WC3 Icons: 2
  • WC3 Spells: 5
  • Reputation: 1153
  • Site Admin - I love fix things
    • View Profile
    • Blizzard Modding Information Center
Re: GeometryLibBase
« Reply #5 on: October 21, 2012, 01:16:09 PM »
Code updated :D

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...

  • Awesome Global Code Moderator
  • Recognized User
  • Rookie - level 2
  • *
  • Posts: 83
  • WC3 Models: 0
  • WC3 Tutorials: 0
  • WC3 Tools: 0
  • WC3 Maps: 0
  • WC3 Skins: 0
  • WC3 Icons: 0
  • WC3 Spells: 0
  • Reputation: 516
  • vJass Incarnate
    • View Profile
Re: GeometryLibBase
« Reply #6 on: October 28, 2012, 09:52:34 AM »
But Zangle isn't a good function name :P

  • Site Owner
  • Administrator
  • Starter - level 4
  • *
  • Posts: 981
  • WC3 Models: 5
  • WC3 Tutorials: 11
  • WC3 Tools: 10
  • WC3 Maps: 11
  • WC3 Skins: 6
  • WC3 Icons: 2
  • WC3 Spells: 5
  • Reputation: 1153
  • Site Admin - I love fix things
    • View Profile
    • Blizzard Modding Information Center
Re: GeometryLibBase
« Reply #7 on: October 28, 2012, 12:28:24 PM »
But Zangle isn't a good function name :P

Hmmm, what do you suggest???

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...

  • Awesome Global Code Moderator
  • Recognized User
  • Rookie - level 2
  • *
  • Posts: 83
  • WC3 Models: 0
  • WC3 Tutorials: 0
  • WC3 Tools: 0
  • WC3 Maps: 0
  • WC3 Skins: 0
  • WC3 Icons: 0
  • WC3 Spells: 0
  • Reputation: 516
  • vJass Incarnate
    • View Profile
Re: GeometryLibBase
« Reply #8 on: October 29, 2012, 08:24:40 AM »
A standard approach would arrive at GetZAngle :p

  • Site Owner
  • Administrator
  • Starter - level 4
  • *
  • Posts: 981
  • WC3 Models: 5
  • WC3 Tutorials: 11
  • WC3 Tools: 10
  • WC3 Maps: 11
  • WC3 Skins: 6
  • WC3 Icons: 2
  • WC3 Spells: 5
  • Reputation: 1153
  • Site Admin - I love fix things
    • View Profile
    • Blizzard Modding Information Center
Re: GeometryLibBase
« Reply #9 on: October 30, 2012, 07:13:13 AM »
A standard approach would arrive at GetZAngle :p

Ok, done. Now it's called GetZangle()

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...

  • Awesome Global Code Moderator
  • Recognized User
  • Rookie - level 2
  • *
  • Posts: 83
  • WC3 Models: 0
  • WC3 Tutorials: 0
  • WC3 Tools: 0
  • WC3 Maps: 0
  • WC3 Skins: 0
  • WC3 Icons: 0
  • WC3 Spells: 0
  • Reputation: 516
  • vJass Incarnate
    • View Profile
Re: GeometryLibBase
« Reply #10 on: November 10, 2012, 07:38:41 AM »
Approved. :D

 

[Snippet] Group Units in line, with distance and optional spread-value

Started by rvonsonsnadtzBoard Codes & Snippets

Replies: 5
Views: 11447
Last post March 13, 2013, 06:52:16 PM
by rvonsonsnadtz
[Snippet] Single Player Detector

Started by moyackBoard Codes & Snippets

Replies: 12
Views: 21008
Last post March 13, 2013, 12:48:49 PM
by Magtheridon96
[Snippet] Simple Unit Indexer

Started by moyackBoard Codes & Snippets

Replies: 17
Views: 25829
Last post September 30, 2013, 08:07:19 AM
by moyack
[Snippet] Disable Transmission Skip

Started by PurgeandfireBoard Codes & Snippets

Replies: 2
Views: 8730
Last post July 02, 2013, 01:34:55 PM
by Purgeandfire
[Snippet] Timed Effects

Started by moyackBoard Codes & Snippets

Replies: 0
Views: 7398
Last post January 09, 2012, 07:03:32 PM
by moyack
Blizzard Modding Information Center Starcraft II Modding Information Center Wacraft III Modding Information Center WC3JASS.com - The JASS Vault Chronicles of Darkness - A Warcraft III mod Jetcraft - A Starcraft II mod Troll Smash - A Warcraft III Arena
  Mod DB - Change the Game Power of Corruption - A Warcraft III altered melee map Chaos Realm - The world of Game modders and wc3 addicts Follow us on Facebook!!