Doom-Angel
Jass User (Just started using NewGen)
- Reaction score
- 167
Get Shape Point
this system is made to make things easier for all those who hate doing all this math\geometric stuff and to make it easy to use shapes when using it.
this system might look a bit complicated but it's only because i gave it wide sum of options so you could manipulate your shapes anyway you possibly could think of using my system and get what you ask for and after learning it i think you would find it very easy and useful.
k so first the system code:
JASS:
//==============================================================================================
// Get(Shape)Point System
//
// Made by Doom-Angel
//==============================================================================================
//=========================== Descriptions and Instructions for each Shape ===========================
//===== Line ======
//***Description***: Takes two points to make a line between them and dividing that
//line equally by distance to the amount sended in order to recieve from the function
//the desired point out of the divided line.
//======================
//***How to use***: call the function by using Custom script and entering the right values
//to get the required outcome - use this simple call for this function:
//call GetLinePoint(Starting Point,Ending Point,Divided Part number(integer),Amount of division in line(integer))
//to get the points of the whole line just use Integer A loop(from 0 to divided amount) and place the integer A in the Divided part and you
//will receive each part of the line you just divided,also just to add to put 0 in the divided line part would return the starting point
//Note - asking for parts of the line higher than the amount divided would extend it beyond the size of the line (above the ending point).
//====== Triangle =======
//***Description***: Gets the point from triangle by taking the center point and creating a triangle
//around it toward facing value also takes position to return one of the edges in the
//triangle - the 1st point is the edge point infront of the facing,the 2nd point is the edge point
//to the left of the facing and the 3rd point is the edge point to the right of the facing.
//===========================
//***How to use***: call the function by using Custom script and entering the right values
//to get the required outcome - use this simple call for this function:
//call GetTrianglePoint(Center Point,Size of triangle(real),Facing(real),Edge Point - 1/2/3(integer))
//Note - to create a whole triangle just combine this function using the point edges recieved with the GetLinePoint function above.
//====== Rectangle ======
//***Description***: Gets the point from rectangle by taking the center point and creating a rectangle
//around it also takes position to return one of the edges in the rectangle - the 1st point is the
//edge point from the upper left of the point received,the 2nd point is the edge point from
//the upper right of the point received,the 3rd point is the edge point from the lower right of
//the point received and the 4th point is the edge point from the lower left of the point received.
//===========================
//***How to use***: call the function by using Custom script and entering the right values
//to get the required outcome - use this simple call for this function:
//call GetRectanglePoint(Center Point,Length of rectangle(real),Width of rectangle(real),Edge Point - 1/2/3/4(integer))
//Note - to create a whole rectangle just combine this function using the point edges recieved with the GetLinePoint function above.
//====== Circle ======
//***Description***: Gets the point from circle divided by the amount of value received and returns
//the number of part received in value(starts from the right of the center and continues by clockwise)
//the circle could be divided to any number above 0 and will be divided equally to return the needed
//point to form a circle the circle will also receive a radius to decide the size of it.
//===========================
//***How to use***: call the function by using Custom script and entering the right values
//to get the required outcome - use this simple call for this function:
//call GetCirclePoint(Center Point,Radius(real),Divided Part number(integer),Amount of division in circle(integer))
//to get the points of the whole circle just use Integer A loop(from 1 to divided amount) and place
//the integer A in the Divided part and you will receive each part of the circle you just divided.
//Note - asking for parts of the circle higher than the amount divided would just return the same points
//it would receive in lower numbers (since it's circling around).
//=========================== Definition Range ===========================
//here i will post the Definition range for the values entered for each shape.
//why is this important?
//because giving an invalid value which is not under the definition range would mess the whole
//function and therefore it would return you null point and will show you a warning messege.
//so here is the Definition Range for each function<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite3" alt=":(" title="Frown :(" loading="lazy" data-shortname=":(" />avoid entering values which doesn't fit this range)
//Line:
//GetLinePoint(loc,target,position,amount)
// amount > 0 // position >= 0 (Greater or equal)
//Triangle:
//GetTrianglePoint(loc,distance,facing,position)
// distance > 0 // 4 > position > 0
//Rectangle:
//GetRectanglePoint(loc,length,width,position)
// length > 0 // width > 0// 5 > position > 0
//Circle:
//GetCirclePoint(loc,radius,position,amount)
// radius > 0 // amount > 0 // position >= 0 (Greater or equal)
//just follow these value definition ranges and you won't get any errors.
//i hope you find this system useful and easy to use.
//Good Luck using it.
//All credits goes to Doom-Angel - if you use it give credit.
//If you don't know what you are doing don't touch anything from here on.
function GetLinePoint takes location loc,location target,integer position,integer amount returns location
local real x = GetLocationX(loc)
local real y = GetLocationY(loc)
local real targetX = GetLocationX(target)
local real targetY = GetLocationY(target)
local real angle = Atan2(targetY - y, targetX - x)
local real gap = SquareRoot(((targetX - x) * (targetX - x)) + ((targetY - y) * (targetY - y)))/amount
if(amount <= 0 or position < 0) then
call BJDebugMsg("Error: Invalid values received")
return null
endif
set x = x + (gap*position) * Cos(angle)
set y = y + (gap*position) * Sin(angle)
return Location(x,y)
endfunction
function GetTrianglePoint takes location loc,real distance,real facing,integer position returns location
local real x = GetLocationX(loc)
local real y = GetLocationY(loc)
if(distance <= 0 or position < 1 or position > 3) then
call BJDebugMsg("Error: Invalid values received")
return null
endif
set facing = bj_DEGTORAD * (facing + 120 * (position - 1))
set x = x + distance * Cos(facing)
set y = y + distance * Sin(facing)
return Location(x,y)
endfunction
function GetRectanglePoint takes location loc,real length,real width,integer position returns location
local real x = GetLocationX(loc)
local real y = GetLocationY(loc)
local integer valueX = 1
local integer valueY = 1
if(length <= 0 or width <= 0 or position < 1 or position > 4) then
call BJDebugMsg("Error: Invalid values received")
return null
endif
if(position == 1 or position == 4) then
set valueX = -1
endif
if(position == 3 or position == 4) then
set valueY = -1
endif
set x = x + (valueX*(length/2))
set y = y + (valueY*(width/2))
return Location(x,y)
endfunction
function GetCirclePoint takes location loc,real radius,integer position,integer amount returns location
local real x = GetLocationX(loc)
local real y = GetLocationY(loc)
if(radius <= 0 or position < 0 or amount <= 0) then
call BJDebugMsg("Error: Invalid values received")
return null
endif
set position = ModuloInteger(position,amount+1)
if(position == 0) then
set position = 1
endif
set x = radius*Cos(I2R(position)/I2R(amount)*2*bj_PI) + x
set y = radius*Sin(I2R(position)/I2R(amount)*2*bj_PI) + y
return Location(x,y)
endfunction
so first of all:
How do i implement the system in my map?
To implement this system just copy the code above and paste it to your map header.Map header? what is that?
Map header is in the trigger editor and it's the map icon with map name.
in case still don't understand what im talking about just look at this picture:
Explanation on the different shapes and how they work
k so here i will show how each shape function is working and i think this is important to read this explanation before trying to work with them.Line function
i bet most of you are already familiar with this one which is used alot: a simple stright line created from a starting point and reaching an ending point.
so first all a bit of description:
Gets the points from line(which is based of starting and ending points) which is divided equally by distance to the amount sended to the function and returns the desired point out of the divided line.
so as far as you see taking a line and giving it amount of 10 will split it in 10 equal pieces and should be something like that:
didn't came out accurate but it gives the main idea - as you see asking for the 0 part in this divided line will give us the starting point while 10 gives the ending point and 5 gives the middle one - using all this point you could form a line or half a line or whatever you like to form in this line.
another thing to add is that you can ask for parts which are above amount of the divided line parts for exampe - we divided the line to 10 parts and asked for the 15th part - this will give us a point which is beyond the ending point and would help us forum a line which is 150% bigger than the distance beetwen the the points - that way you could perform lines which are 2 or 3 times bigger as you wish.
and here's a sample picture of the line in work(splited to 10 and receives parts 1 to 10):
Triangle function
Description: Gets the point from triangle by taking the center point and creating a triangle around it toward facing value also takes position and returns the edges of the triangle - the 1st point is the edge point infront of the facing,the 2nd point is the edge point to the left of the facing and the 3rd point is the edge point to the right of the facing.
with this function you could receive the points of the triangle edges within a distance value and change it's rotation towards the chosen facing.
here's an image which would explain how it should be:
another bad image made by me - anyway as you see this demonstrated which point is returned for each part.
another thing you might have noticed is that you got only 3 edges and you probably asking how is that giving me a triangle - well the answer is that having this edges basically gave you the base for the triangle and the only thing needs to be done now in order to get a full triangle is using the edged points you received from this function and use them with the line function for each point to another(1-2,2-3,3-1) and there you got a whole triangle.
here's a sample picture of the triangle in work:
Rectangle function
for some of you this function is gonna look a bit useless since you could do the same using rects but i thought making it anyway and also the fact that this function doedn't create a rect i think it should be easier and more useful.
Description: Gets the point from rectangle by taking the center point and creating a rectangle around it also takes position and returns the edges of the rectangle - the 1st point is the edge point from the upper left of the point received,the 2nd point is the edge point from the upper right of the point received,the 3rd point is the edge point from the lower right of the point received and the 4th point is the edge point from the lower left of the point received.
so this function would require basically length width center point and the position of the edge you need.
if you didn't understand the description try checking this picture:
as you see after sending the center point length(200) and width(100) the only thing left to send is the position which will return one of the numbered edges depending on the number you sent.
also for those who don't know giving the function an matching value for the length and width will form a square instead. (e.g: length = 200,width = 200)
and another thing to add here is that here as same as the triangle in order to form a full rectangle you would have to combine this function with the line function.
here's a sample picture of the rectangle in work:
Circle function
Description: Gets the point from circle divided by the amount of value received and returns the number of part received in value(starts from the right of the center and continues by clockwise) the circle could be divided to any number above 0 and will be divided equally to return the needed point to form a circle the circle will also receive a radius to decide the size of it.
so now that you read the description i will show in picture how it works and splits up:
in the above picture you 3 same sized circles each one splited intro 2,3 and 4 parts each while the point in position 1 will always starts from the right spot as you see the rest of the points in this circle will be going one after each other in clockwise direction.
also notice i marked the Radius so you notice the radius is the value that will decide how big the circle would be from the center point you have sent.
this circle function can split a circle from 1 part to endless amounts of parts (though i do not recommend using high amounts of parts since it might cause lag depending on your actions)
another thing to your attention is what if you entered a value of a position higher the number of parts you splited?
well in that case it will just go on since it's a circle the points splited will keep rolling around so basically a 5 position in a 4 parts splited circle will return the 1st part and the 6th will return the 2nd and so on.
here's a sample picture of the circle in work:
How do i use these functions in my trigger?
to call those function from a GUI trigger open a "Custom script" action and in it you have to write these lines for each function:Line
JASS:
of course what i gave you won't actually run and it only tells you what values you need to enter on the needed spots i also made in brackets the value type required.
here's an example for working function call:
Code:
Custom script: set udg_TestLoc = GetLinePoint(udg_Loc,udg_TargetLoc,bj_forLoopAIndex,10)
Triangle
JASS:
same here as above this won't run either and it's just to tell you what values to insert
here's an example for working function call:
Code:
Custom script: set udg_TestLoc = GetTrianglePoint(udg_Loc,500,90,bj_forLoopAIndex)
Rectangle
JASS:
same here as above this won't run either and it's just to tell you what values to insert
here's an example for working function call:
Code:
Custom script: set udg_TestLoc = GetRectanglePoint(udg_Loc,300,200,bj_forLoopAIndex)
Circle
JASS:
same here as above this won't run either and it's just to tell you what values to insert
here's an example for working function call:
Code:
Custom script: set udg_TestLoc = GetCirclePoint(udg_Loc,400,bj_forLoopAIndex,10)
for those who don't know how to use variables in this Jass calls just simply add "udg_" prefix to your variable name.
for exmple if i have an integer variable named Count and i wanna send it as a value to one of the function i would have wrote in: "udg_Count" (also remember it's case-sensitive so it must be Count and not count).
Definition Range
this part here is to give you heads up for what values you may never use in this functions.when using those "out of definition range" values you will just receive error messege and receive a null point since the function isn't able to deal with values for example like negative numbers or others so im gonna right for each function what values are in your definition range and are allowed to be used in those functions:
Line:
function:
JASS:
GetLinePoint(loc,target,position,amount)
Definition Range:
amount > 0
position >= 0 (Greater or equal)
Triangle:
function:
JASS:
GetTrianglePoint(loc,distance,facing,position)
Definition Range:
distance > 0
4 > position > 0
Rectangle:
function:
JASS:
GetRectanglePoint(loc,length,width,position)
Definition Range:
length > 0
width > 0
5 > position > 0
Circle:
function:
JASS:
GetCirclePoint(loc,radius,position,amount)
Definition Range:
radius > 0
amount > 0
position > 0
if any of your values isn't in the ranges i just gave above expect for an error.
also in case any of you wonder if a value from a function isn't listed above in the definition range it means that you may enter any value you want.
Change Log:
- Made the comments easier to read and a bit smaller
- removed parallelogram due to impractical usage of it
- a few small changes in code functions
that's it i hope you guys would find my system useful and easy to use also im sorry for making it so long and probably boring for some of you but i wanted to make it as noob friendly as possible.
also attached a sample map for the system below if you would like to check.
Enjoy!