13 years
edited 8 years
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
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.
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
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 of12 proper geometry functions.13
14 Here we'll aim to make the code as modular as possible so we can15 reduce the code amount in map but offering the neccesary tools 16 for modders17
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 hell24
25 GetDistanceZ: Similar to GetDistance, but this one takes into account26 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 value30 of "x" at an "angle" specified in a distance "d" 31
32 GetPolarY: returns the Y coordinate o a point from an initial value33 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 endif44 return a45 endfunction46 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 endfunction52 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 endfunction59 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 endfunction63 64 function GetPolarX takes real x, real radians, real d returns real
65 return x + Cos(radians) * d
66 endfunction67 68 function GetPolarY takes real y, real radians, real d returns real
69 return y + Sin(radians) * d
70 endfunction71 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.