Skip to main content
gamedev.net
🔒 Locked

Fastest algorithm

Started by bargasteh Apr 5, 2005 at 6:35 AM 5 replies 950+ views
Original Post
bargasteh
bargasteh
Hello I need to know what is the fastest algorithm or technique to check basic collision using my collision function. I have a function that return true or false if the two objects are colliding. BOOL bSphereTest(int obj1, int obj2 ) I currently using :

for (int y2 = 3; y2 <= number_of_particle; y2++)              //check for collision 
	for(int x2 = 3; x2 <= number_of_particle; x2++)
	{
		if (y2 != x2){
                                             //here I do the collision response
                                             }
}


I go through every single particle and check it against other ones. The penalty I think is f(n^2) which mean it becomes really slow as the number of particles increase. is there any faster way? Or how can I optimise this to get the best out of it ? I did study binary tree in University but if I can do it faster then I should look back into my books and do it again, I don’t even know which one is the fastest way. Thanks [Edited by - bargasteh on April 5, 2005 7:13:33 AM]
OpenGl + C++
pim
pim
Hi! This is a good method to check for particle collision:

http://freespace.virgin.net/hugo.elias/models/m_colide.htm

Apart from that I know I've seen another good method... I'll look through my books! :)
bargasteh
bargasteh
Thanks for that link its good.
it would be great if you tell me the other one from your book :)
OpenGl + C++
markr
markr
There are several things I should like to note:

- When testing for collision, you don't need to check X against Y and Y against X, so only half the number of tests are necessary
- Although it's minor, there is no need to use sqrt when comparing the distance with the combined radii, you can simply compare the distance squared with the radii squared instead
- If testing everything vs everything is fast ENOUGH, then you should do it that way. It's nice and simple.

So far I have written several games which use the everything vs everything collision detection algorithm. For small numbers of objects (say < 50), it's sufficiently performant that I haven't had to worry about it.

For 1000s of objects it's not going to work though.

Mark
bargasteh
bargasteh
My program can have even 10000 particles, its huge, maybe I should use bounding boxes to check the initial collision and then check for smaller parts!

how about binary tree
OpenGl + C++
bargasteh
bargasteh
pim I read the link you sent here, its good for 2D as author describe but I am doing 3D collision. I think there is something similare to this for 3D collision as well, but what does it called ? is it space "something" ?!
any body knows?
OpenGl + C++
pim
pim
You can partition the 3d space into cubes in stead of squares and do the same thing in 3d.. If you use an octree data structure you can subdivide the space until you have relatively few collisions..

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.