Chaosy
Tutorial Reviewer
- Joined
- Jun 9, 2011
- Messages
- 13,239
Basically I want to divide a rect into smaller ones. I managed to do this but I did not manage to make it dynamic.
At the moment the rect is divided into 4 parts, but I want this to be configurable.
I don't think it's that difficult to create but my brain just gets confused when creating this with loops for whatever reason.
I used the following image while working with the calculation, maybe that will clearify what I want.
At the moment the rect is divided into 4 parts, but I want this to be configurable.
I don't think it's that difficult to create but my brain just gets confused when creating this with loops for whatever reason.
JASS:
//The code is the converted edition from the jasshelper after I made a syntax error on purpose.
//It's originally written in Zinc which might be confusing to some so I think this is preferable?
function divide takes nothing returns nothing
local rect r=corpsRegions[myCorps.size-1]
local real xMax=GetRectMaxX(r)
local real xMin=GetRectMinX(r)
local real xDif=xMax-xMin
local real yMax=GetRectMaxY(r)
local real yMin=GetRectMinY(r)
local real yDif=yMax-yMin
set subRects[myCorps.size-1][0]=Rect(xMin,yMin,xMax-(xDif/2),yMax-(yDif/2))
set subRects[myCorps.size-1][1]=Rect(xMin,yMin+(yDif/2),xMax-(xDif/2),yMax)
set subRects[myCorps.size-1][2]=Rect(xMin+(xDif/2),yMin,xMax,yMax-(yDif/2))
set subRects[myCorps.size-1][3]=Rect(xMin+(xDif/2),yMin+(yDif/2),xMax,yMax,s)
endfunction
JASS:
function divide()
{
rect r = corpsRegions[myCorps.size - 1];
real xMax = GetRectMaxX(r);
real xMin = GetRectMinX(r);
real xDif = xMax - xMin;
real yMax = GetRectMaxY(r);
real yMin = GetRectMinY(r);
real yDif = yMax - yMin;
subRects[myCorps.size - 1][0] = Rect(xMin, yMin, xMax - (xDif / 2), yMax - (yDif / 2));
subRects[myCorps.size - 1][1] = Rect(xMin, yMin + (yDif / 2), xMax - (xDif / 2), yMax);
subRects[myCorps.size - 1][2] = Rect(xMin + (xDif / 2), yMin, xMax, yMax - (yDif / 2));
subRects[myCorps.size - 1][3] = Rect(xMin + (xDif / 2), yMin + (yDif / 2), xMax, yMax);
}
