How would you go about detecting collision between rotated squares?
I have googled it with little success. :(
Printable View
How would you go about detecting collision between rotated squares?
I have googled it with little success. :(
Are they rotated randomly, or do they follow a position function?
Test if their sides (which are lines) intersect eachother.
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.
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
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..
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.Quote:
Originally Posted by singularis
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.
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.
What? You're only half a freshman? :p
:lol:
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
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.
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 :ehh: