How to implement better Collision detection

Started by
15 comments, last by Khatharr 11 years ago

You don't even need trig to do ellipse vs. point collision. If the ellipse is axis aligned (i.e. not rotated), just transform the ellipse into a circle by scaling the x and y offsets of the distance between the ellipse centre and the point, then do circle vs. point collision.

It's only slightly more complicated if the ellipse isn't axis aligned.

"Most people think, great God will come from the sky, take away everything, and make everybody feel high" - Bob Marley
Advertisement
so what you're really asking for and what nobody seems to be suggesting is using SAT tests to determine collision and the minimum separation vector required to separate the two objects after a collision.

it's quite complicated and math heavy but theres a great tutorial about it here http://www.metanetsoftware.com/technique/tutorialA.html from the creaters of N .

The post I made earlier literally walks through how to do ellipse collision detection step by step

I've had the post up on a tab for some hours and didn't refresh it so only saw 1 reply, my bad.

You don't even need trig to do ellipse vs. point collision. If the ellipse is axis aligned (i.e. not rotated), just transform the ellipse into a circle by scaling the x and y offsets of the distance between the ellipse centre and the point, then do circle vs. point collision.

It's only slightly more complicated if the ellipse isn't axis aligned.

How do you do CvP without trig?
void hurrrrrrrr() {__asm sub [ebp+4],5;}

There are ten kinds of people in this world: those who understand binary and those who don't.

Well you need Pythagoras but not sin/cos/tan, which is what I was talking about. Just transform the coordinate space so that the ellipse is circular, then do a squared distance test.

"Most people think, great God will come from the sky, take away everything, and make everybody feel high" - Bob Marley

Another option, which may or may not have been mentioned, is that you can use the stencil buffer to perform collision detection. If more than one object occupies the same pixel, then you can be sure there is collision between them. Then, once you examine the stencil buffer and determine the places where more than one fragment was rendered, you can then determine which objects are located at these positions, and then the collision will be known. Not saying this is the only way, but is ONE way if you are looking for an absolutely exact collision (which you will not get when using 2D sprites with AABB approximations).

A second option, is tesselate your objects into triangles and create a convex hull. A convex hull is a much tighter approximation than a simple AABB. This will give you also, a better approximation. Convex hull collision is a well studied area, you should be able to find an algorithm for collision. If you go with this method however, you should first cull out results which do not pass the AABB test, as convex hull tests are much more expensive.

Well you need Pythagoras but not sin/cos/tan, which is what I was talking about. Just transform the coordinate space so that the ellipse is circular, then do a squared distance test.

Ah, for some reason when I thought CvP I thought of atan2. Ignore me. I'm not right in the head.
void hurrrrrrrr() {__asm sub [ebp+4],5;}

There are ten kinds of people in this world: those who understand binary and those who don't.

This topic is closed to new replies.

Advertisement