Results 1 to 13 of 13

Thread: Collision Detection between rotated squares

  1. #1

    Thread Starter
    Hyperactive Member singularis's Avatar
    Join Date
    Nov 2006
    Location
    Over There!
    Posts
    372

    Collision Detection between rotated squares

    How would you go about detecting collision between rotated squares?

    I have googled it with little success.
    If what I said was helpful, give me rep!

    My Complete Games: -- 2D Zone (Space Shooter game) || _2D Zone 2_ || Ninja Blob (2D platformer) || Dren (Co-op up to 4 player base defence game)

    My Projects: -- The Dread Engine (2D VB game Engine) || A* Path Finding


    An excellent site for learning DirectX7, 8 & 9 (for VB6, C# & VB.net) would be: directx4vb.vbgamer.com --- For my projects and games see: pieper.freehostia.com

  2. #2
    Hyperactive Member
    Join Date
    Aug 2006
    Posts
    367

    Re: Collision Detection between rotated squares

    Are they rotated randomly, or do they follow a position function?

  3. #3
    Frenzied Member
    Join Date
    Oct 2003
    Posts
    1,301

    Re: Collision Detection between rotated squares

    Test if their sides (which are lines) intersect eachother.

  4. #4
    Lively Member
    Join Date
    Jul 2002
    Posts
    86

    Re: Collision Detection between rotated squares

    A really easy (but not entirely accurate way) is to have a bounding sphere that approximates the square. Or you can do what jeroen said, test if the sides intersect. Other than that, you would have to do pixel perfect collision techniques. Just search on the forums or google it, there is lots of pages on it.

  5. #5

    Thread Starter
    Hyperactive Member singularis's Avatar
    Join Date
    Nov 2006
    Location
    Over There!
    Posts
    372

    Re: Collision Detection between rotated squares

    Bounding sphere eh? Since my objects are not polygons (they are textures) it does not matter if the collisions are perfect.

    Should I just test to see if the line drawn between centers of the objects is below a certain amount? e.g. the object's size
    If what I said was helpful, give me rep!

    My Complete Games: -- 2D Zone (Space Shooter game) || _2D Zone 2_ || Ninja Blob (2D platformer) || Dren (Co-op up to 4 player base defence game)

    My Projects: -- The Dread Engine (2D VB game Engine) || A* Path Finding


    An excellent site for learning DirectX7, 8 & 9 (for VB6, C# & VB.net) would be: directx4vb.vbgamer.com --- For my projects and games see: pieper.freehostia.com

  6. #6
    Hyperactive Member
    Join Date
    Aug 2006
    Posts
    367

    Re: Collision Detection between rotated squares

    I was going to suggest a bouding box region as large as the squares can be when rotated (1.41*length).. To do the really cpu intensive polling, then if an intersection is 'possible' further analyze with trig/euclidean geometry..

  7. #7
    Lively Member
    Join Date
    Jul 2002
    Posts
    86

    Re: Collision Detection between rotated squares

    Quote Originally Posted by singularis
    Bounding sphere eh? Since my objects are not polygons (they are textures) it does not matter if the collisions are perfect.

    Should I just test to see if the line drawn between centers of the objects is below a certain amount? e.g. the object's size
    Basically yes. I meant to say bounding circles, lol, but it is the same in 2D as 3D, just with the Z dimension. Just see if the distance is less than the the sum of half of each square's side length (for example with squares of length 4 and 6 check if the distance between the centres is < root(2+3) [root(half of 4 + half of 6)]). If it is less than, then there is a collision.

    You can fiddle around with what the value has to be less than to make the collisions "good", make it a constant times the sum of the radii of the squares.

    Just a quick question, how many objects will be on screen at any time?

    The one I suggested will work better with lots of objects on screen and is somewhat accurate where the one jeroen79 suggested is perfect for small numbers of objects and is accurate.
    Last edited by fartman_900; Feb 24th, 2007 at 07:14 PM.

  8. #8

    Thread Starter
    Hyperactive Member singularis's Avatar
    Join Date
    Nov 2006
    Location
    Over There!
    Posts
    372

    Re: Collision Detection between rotated squares

    Yes I understand the difference between accuracy and speed . I am not a complete freshman.

    There is going to be 100 or so objects on the screen.
    If what I said was helpful, give me rep!

    My Complete Games: -- 2D Zone (Space Shooter game) || _2D Zone 2_ || Ninja Blob (2D platformer) || Dren (Co-op up to 4 player base defence game)

    My Projects: -- The Dread Engine (2D VB game Engine) || A* Path Finding


    An excellent site for learning DirectX7, 8 & 9 (for VB6, C# & VB.net) would be: directx4vb.vbgamer.com --- For my projects and games see: pieper.freehostia.com

  9. #9
    Frenzied Member
    Join Date
    Oct 2003
    Posts
    1,301

    Re: Collision Detection between rotated squares

    What? You're only half a freshman?

  10. #10

    Thread Starter
    Hyperactive Member singularis's Avatar
    Join Date
    Nov 2006
    Location
    Over There!
    Posts
    372

    Re: Collision Detection between rotated squares

    If what I said was helpful, give me rep!

    My Complete Games: -- 2D Zone (Space Shooter game) || _2D Zone 2_ || Ninja Blob (2D platformer) || Dren (Co-op up to 4 player base defence game)

    My Projects: -- The Dread Engine (2D VB game Engine) || A* Path Finding


    An excellent site for learning DirectX7, 8 & 9 (for VB6, C# & VB.net) would be: directx4vb.vbgamer.com --- For my projects and games see: pieper.freehostia.com

  11. #11
    G&G Moderator chemicalNova's Avatar
    Join Date
    Jun 2002
    Location
    Victoria, Australia
    Posts
    4,246

    Re: Collision Detection between rotated squares

    I would set up a UDT which holds 4 points for each square. Then, if the points intersected, the collision had happened. Kind of a hack way to do it..

    chem

    Visual Studio 6, Visual Studio.NET 2005, MASM

  12. #12
    Lively Member
    Join Date
    Jul 2002
    Posts
    86

    Re: Collision Detection between rotated squares

    Thats actually not a bad idea chem, you gave me an idea on a way to do it. You can think of the edges of the squares as planes, and find the normal and do a dot product to see if the value <= 0 (or >= 0 I forget) for a collision. It should be pretty fast and its precise.

  13. #13

    Thread Starter
    Hyperactive Member singularis's Avatar
    Join Date
    Nov 2006
    Location
    Over There!
    Posts
    372

    Re: Collision Detection between rotated squares

    And test the normal against what? the normal of the other square, would that not just tell us if they are facing the same way
    If what I said was helpful, give me rep!

    My Complete Games: -- 2D Zone (Space Shooter game) || _2D Zone 2_ || Ninja Blob (2D platformer) || Dren (Co-op up to 4 player base defence game)

    My Projects: -- The Dread Engine (2D VB game Engine) || A* Path Finding


    An excellent site for learning DirectX7, 8 & 9 (for VB6, C# & VB.net) would be: directx4vb.vbgamer.com --- For my projects and games see: pieper.freehostia.com

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