I'm having some problems with collision detection here:
I have 2 cars viewed from above, so I want 2d collision detection on them while there actualy 3d, and those cars can rotate in any degree.
From those cars, I have following data:
* Their centerpoint(x,z; y is height) around which they rotate,
* Their rotation angle,
* Their lenght and width
There is of course the simple collision detection between to rectangles (=lenghts and widths), but you already see this would be a bad detection method cause when rotating, the rectangle is not straight anymore.
Therefore I'm looking for a (mathematical, but functional would be much better for me) collision detection between rotatable rectangles that is perfect.
Can anyone help me with that ?
Thanks in advance,
Egsoc
I would suggest a 2-stage approach. Step one determines, if there is a possible collision and step two then determines the whether there actually is a collision.
Step 1: calculate the distance between both center points and compare it to the sum of diagonals of both cars divided by 2. if( distance <= ( d1 + d2 ) / 2 ) a possible collision has occured. To speed up the process you can use the square of both sides of the inequation to avoid the computationally rather expensive square roots.
Step 2: only necessary, if the test in Step 1 was successful. Check all 4 corners of car 1 if it is inside car 2.
There are however potential problems. The biggest one being that one of the cars could be so fast, that it goes right through the other car, without noticing it, i.e. the collision occurs between two calls to your detection function. This is rather hard to solve. One way to go would be to make your physics engine run at a constant rate independant of the rendering.
.f