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:
- /******************************************************************2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
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:
- /******************************************************************
* GEOMETRY LIB PACK V1.3 ** By moyack ** 2012 ** =================================== ** Exclusive resource from wc3jass.com ** =================================== *******************************************************************/library GeometryLibBase requires GetZ
/*This is the first of a set of libraries focused in the usage ofproper geometry functions.Here we'll aim to make the code as modular as possible so we canreduce the code amount in map but offering the neccesary tools for moddersHere we offer the most basic functions ever needed:Atan3: to calculate PROPERLY the correct angle. the values (x1;y1) will be the pivot and (x2;y2) the extreme point. GetDistance: Get the distance from (x1;y1) and (x2;y2). simple as hellGetDistanceZ: Similar to GetDistance, but this one takes into account the terrain height.Zangle: Returns the angle in Z coordinate (height) between 2 points.GetPolarX: returns the X coordinate o a point from an initial value of "x" at an "angle" specified in a distance "d" GetPolarY: returns the Y coordinate o a point from an initial value of "y" at an "angle" specified in a distance "d" Important Note: Atan3 and Zangle returns the angles in RADIANS. GetPolaX/Y takes angles in RADIANS.*/function Atan3 takes real x1, real y1, real x2, real y2 returns real
local real a = Atan2(y2 - y1, x2 - x1)
if a < 0 then
return 2 * bj_PI + a
endif return aendfunctionfunction GetDistance takes real x1, real y1, real x2, real y2 returns real
local real dx = x2 - x1
local real dy = y2 - y1
return SquareRoot( dx * dx + dy * dy )
endfunctionfunction GetDistanceZ takes real x1, real y1, real x2, real y2 returns real
local real dx = x2 - x1
local real dy = y2 - y1
local real dz = GetPointZ(x2, y2) - GetPointZ(x1, y1)
return SquareRoot( dx * dx + dy * dy + dz * dz)
endfunctionfunction GetZangle takes real x1, real y1, real x2, real y2 returns real
return Acos(GetDistance(x1, y1, x2, y2) / GetDistanceZ(x1, y1, x2, y2))
endfunctionfunction GetPolarX takes real x, real radians, real d returns real
return x + Cos(radians) * d
endfunctionfunction GetPolarY takes real y, real radians, real d returns real
return y + Sin(radians) * d
endfunctionendlibrary