Thread: Collision boxes,zones, and allocation

  1. #1
    Registered User ~Kyo~'s Avatar
    Join Date
    Jun 2004
    Posts
    320

    Collision boxes,zones, and allocation

    I have come to the conclusion that dividing a large map into zones is probably the best way to handle having many updates all the time for things that would be trivial to players. So my thought is to use bounding boxes to limit player's movements throughout the world.

    I have come to the point where I am wondering how to make a bounding box divide itself into multiple sub boxes if one is placed over a zone seam...

    example: lets say zones are 10 by 10 units big and we want a 10 by 10 unit box starting on zone0 5,5 and extending to zone4 5,5 making it a 10 by 10 bounding box. Now each zone would need it's own 5x5 box to use for updates in that specific zone. What routine would I use to split that box into sub boxes?

    something like this maybe?:

    Code:
    if(box_x + box_w > zone_max)//push into next zone dec box_w by zone_max - box_x

  2. #2
    Just a pushpin. bernt's Avatar
    Join Date
    May 2009
    Posts
    426
    Something like this?
    Code:
    zones = set of zones this box intersects
    
    if (size of 'zones' == 1)
        exit //don't have to split this box
    else
        for each 'z' in 'zones':
            create a box that covers the intersection of this box and 'z'
    
        delete this box //the boxes we made cover the same area
    end
    So then it remains to get this set of zones (which can be done with some simple rectangle intersection tests) and to be able to find the intersection of two rectangles:
    Code:
    box intersect; //will contain a intersect b
    intersect.xmin = max(a.xmin, b.xmin);
    intersect.ymin = max(a.ymin, b.ymin);
    intersect.xmax = min(a.xmax, b.xmax);
    intersect.ymax = min(a.ymax, b.ymax);
    You could probably combine these two steps, finding the set and finding the intersections (eg, find the "intersection" and create a box only if it is a valid area: width and height > 0).
    Last edited by bernt; 11-28-2011 at 10:30 AM.
    Consider this post signed

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. FireWire and the difficulty of time zones
    By Aparavoid in forum A Brief History of Cprogramming.com
    Replies: 4
    Last Post: 05-27-2009, 03:56 PM
  2. collision
    By ichijoji in forum Game Programming
    Replies: 8
    Last Post: 07-13-2004, 07:04 PM
  3. Edit boxes, and list boxes
    By osal in forum Windows Programming
    Replies: 2
    Last Post: 07-07-2004, 12:34 PM
  4. collision
    By lambs4 in forum Game Programming
    Replies: 3
    Last Post: 10-07-2003, 06:42 PM
  5. Box Collision
    By Shiftytitan in forum Game Programming
    Replies: 2
    Last Post: 12-31-2002, 06:19 PM