A Flash Developer Resource Site

Results 1 to 10 of 10

Thread: [help] OBB (Orientated Bounding Box) Collisions

  1. #1
    Senior Member chriserrorplain's Avatar
    Join Date
    Aug 2002
    Location
    london village
    Posts
    623

    [help] OBB (Orientated Bounding Box) Collisions

    ok...so after a few hours of pounding my head against the Internet and damning my lacking Maths skills, I need to ask some of you guys if you can help.

    I am trying to detect a collision between bounding boxes which can be rotated. I currently have got the corners of box boxes and have also got the min / max x and y, but I am just reeeally struggling in getting the final algorith to return whether they intersect. Any help will so appreciated that I don't think I would be able to put it into words....


    ChrisError x

  2. #2
    CostomJunky Xploder's Avatar
    Join Date
    Jun 2003
    Location
    Canada
    Posts
    635
    Hey chris you need to look into projecting boxes onto a line.
    If the lines of the squished boxes overlap along all normals, you have a colision.
    This method can be used for pretty much any shape: http://gpwiki.org/index.php/VB:Tutor...tion_Detection

  3. #3
    Senior Member tonypa's Avatar
    Join Date
    Jul 2001
    Location
    Estonia
    Posts
    8,223
    In theory (not talking about separating axes here) 2 rotated boxes are overlapped if at least one side of box A is intersecting with any side of box B. Create lines representing each sides and find if they intersect using lineToLine intersection. This will need 16 tests max (4 sides of box A each tested against 4 sides of box B).

    Its also possible that one box is completely inside other box. Not sure if you consider it collision or if its even possible in your game.

  4. #4
    Senior Member UnknownGuy's Avatar
    Join Date
    Jul 2003
    Location
    Canada
    Posts
    1,361
    Hey Chris,

    From years ago Blink(I believe) posted an example of this. I still have an .fla that I modified using it, which shows it working.

    Here it is online in action: http://www.whatboxstudios.com/FK/collision8.swf

    And here is the source: http://www.whatboxstudios.com/FK/collision8.fla

    The algorithm I never really understood, and it is uses the fact there is a nested movieclip and gets the size of the width once rotated I believe(or some trick like that), which could be done another way.

    Hope that helps!
    Last edited by UnknownGuy; 03-08-2009 at 02:18 PM. Reason: Captilization

  5. #5
    Senior Member
    Join Date
    May 2006
    Location
    Manhattan
    Posts
    246
    yeah, you definitely don't want to do 16 line intersection tests, this is a simple separating axis test:
    1. transform each box's vertices into global coordinates
    2. use each adjacent pair of vertices to define an edge vector for each edge
    3. define a potentially separating axis as the vector perpendicular to each edge
    4. project all vertices onto this axis, storing a minimum and maximum for each box (if you're only interested in whether they are overlapping and not by how much, you only need to solve for the dot product instead of projection)
    5. if the 2 ranges don't overlap, the boxes are not intersecting
    6. if they do, proceed to the next set (2 vertices -> edge -> normal)
    7. if the ranges overlap on all edge normals, they are intersecting

  6. #6
    Custom User Title Incrue's Avatar
    Join Date
    Feb 2004
    Posts
    973

  7. #7
    Senior Member chriserrorplain's Avatar
    Join Date
    Aug 2002
    Location
    london village
    Posts
    623
    thanks for the all the help guys. Trying to dot his has finally forced me to sit down for a few hours and learn the theory and not just find a solution, so I spent a good part fo yesterday working through Tony PA's Vector tutorials with pen and paper, and now later on today I am going to try that link you sent Xploder, it seems very well written and not _too_ complicated. Thanks for all the help guys, btw if you wanna see what it's for, I'm making a MicroMachines-esque game called 'Toy Town Racers' you can see and early alpha of the engine here :

    http://www.kill5.com/games/ttr/
    (cursors to control car)


    ChrisError x

  8. #8
    ....he's amazing!!! lesli_felix's Avatar
    Join Date
    Nov 2000
    Location
    London UK
    Posts
    1,506
    if the distance between a corner of box A and *all* points of box B is less than the diagonal of box B, then they intersect.

    remember to run the check the other way around, making sure that no points of box B intersect box A

    that should do it.

  9. #9
    ....he's amazing!!! lesli_felix's Avatar
    Join Date
    Nov 2000
    Location
    London UK
    Posts
    1,506
    Quote Originally Posted by lesli_felix View Post
    if the distance between a corner of box A and *all* points of box B is less than the diagonal of box B, then they intersect.
    My bad, that would be very approximate.

    The best way is to consider one of the boxes level with the ground, then finding intersecting points is easy. I've done this before, I just can't remember how, but it wasn't that difficult.

  10. #10
    Senior Member
    Join Date
    Oct 2009
    Posts
    117
    Just for the record, here is the SAT based solution:

    http://www.euclideanspace.com/threed...ions/index.htm

    If you know your vector math, it's actually pretty easy!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center