HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Cross-checking real locations

01-11-2008, 06:52 PM#1
Zandose
Sorry if I wasn't clear before. First I have a rect which is a select area, and in this case I have two rects which both cover a 768 by 768 area. I personaly think of it as a 6x6 area (768 divided by 128 equals 6). Anyways, this rect or area is perfectly aligned to the games 128 grid; each block/terrain area is 128. Next, within these rects are locations (or points in GUI) which are a X and Y real number (0.00). So each rect/area has 6*6 (36) locations/points which I need to check with another rect/area, 36 locations/points vs. 36 locations/points (1296). 1296 is a high number for the game to deal with and may cause it to crash or hit the op limit. I can't use waits/sleeps in my code because the trigger is started by a timer, and for some reason it stops the trigger when I add one in. I'm looking for a way around it but haven't found one yet. So the questions still stands, I need ideas of how to fix this.
Collapse JASS:
//This is just an example
scope te

globals
    private constant integer RADIUS = 3 //Can be any number
endglobals

private struct blank
    real x
    real y
    real x2
    real y2
endstruct

private function check takes nothing returns nothing
    local integer array i
    local blank b = GetTimerStructA(GetExpiredTimer())
    local real x = b.x
    local real y = b.y
    local real x2 = b.x2
    local real y2 = b.y2
    set i[1] = 0 //x
    set i[2] = 0 //y
    set i[3] = 0 //x2
    set i[4] = 0 //y2
    loop //x
        loop //y
            loop //x2
                loop //y2
                    //Checks x/y vs. x2/y2
                    if x + (i[1] * 128) == x2 + (i[3] * 128) and y - (i[2] * 128) == y2 - (i[4] * 128) then
                        //Actions.... (special effect or something)
                    endif
                    set i[3] = i[3] + 1
                    exitwhen i[3] == RADIUS * 2  
                endloop
                set i[3] = 0
                set i[4] = i[4] + 1
                exitwhen i[4] == RADIUS * 2  
            endloop
            set i[1] = i[1] + 1
            exitwhen i[1] == RADIUS * 2    
        endloop
        set i[1] = 0
        set i[2] = i[2] + 1
        exitwhen i[2] == RADIUS * 2
    endloop
endfunction

private function Actions takes nothing returns nothing
    local timer t = CreateTimer()
    local blank b = blank.create()
    call TimerStart(t, 1.00, false, function check)
    call SetTimerStructA(t, b)
endfunction

public function InitTrig takes nothing returns nothing
    local trigger trig = CreateTrigger()
    local integer i = 0
    loop
        call TriggerRegisterPlayerChatEvent(trig, Player(i), "1", true)
        set i = i + 1
        exitwhen i == 12
    endloop
    call TriggerAddAction(trig, function Actions)
endfunction

endscope
01-12-2008, 07:33 AM#2
xombie
What exactly do you mean, you need to check their locations against each other?
01-12-2008, 03:10 PM#3
Vexorian
Could you please explain what you want to do? Cause right now I have no idea.
01-12-2008, 03:19 PM#4
Zandose
Please read my first post, I've changed it.
01-12-2008, 03:45 PM#5
rain9441
So you want to find the overlap of 2 rects?

In that case...

http://www.google.com/search?hl=en&q...=Google+Search

The second listing seems pretty thorough on an optimized way of doing it.
01-12-2008, 04:30 PM#6
Zandose
Quote:
Originally Posted by rain9441
So you want to find the overlap of 2 rects?

In that case...

http://www.google.com/search?hl=en&q...=Google+Search

The second listing seems pretty thorough on an optimized way of doing it.
Very interesting. I'll try something similar later on today.
01-12-2008, 08:40 PM#7
Vexorian
Quote:
Sorry if I wasn't clear before. First I have a rect which is a select area, and in this case I have two rects which both cover a 768 by 768 area. I personaly think of it as a 6x6 area (768 divided by 128 equals 6). Anyways, this rect or area is perfectly aligned to the games 128 grid; each block/terrain area is 128. Next, within these rects are locations (or points in GUI) which are a X and Y real number (0.00). So each rect/area has 6*6 (36) locations/points which I need to check with another rect/area, 36 locations/points vs. 36 locations/points (1296).

Seriously.

Why 6 locations?

What do you mean by check?

I doubt 1296 crashes the thread.
01-12-2008, 09:26 PM#8
Zandose
Why 6 locations?
Each rect is 768 by 768. If you divide each by 128 you get 6 by 6. My code deals with changing the games terrain, and each terrain block is 128 by 128. So I align the rect's to the closeest 128*integer location/point on the map.

What do you mean by check?
As in comparing all the locations/points from one rect to another rect and seeing if any match and thus I know if there is anything overlapping.

I doubt 1296 crashes the thread.
You couldnt be right but I don't want to take that chance. Also, size of the rect's can be made bigger and then the amount of comparisons increases; 6*6=1296, 7*7=2401, and 8*8=4096. I don't knwo how big it's going to be so I need to put safeguards in place.
01-12-2008, 10:20 PM#9
Vexorian
Quote:
As in comparing all the locations/points from one rect to another rect and seeing if any match and thus I know if there is anything overlapping.

At least based from what you say, they are rects, meaning they are rectangles, so, first of all you only need 4 reals per rect, x1,x2,y1 and y2 and checking if two rects overlap is like checking if two intervals overlap, but in 2D...