One time collision detection

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
turboferret
Posts: 49
Joined: Thu Aug 12, 2004 12:42 pm
Location: Sweden
Contact:

One time collision detection

Post by turboferret »

What's the simplest way of doing a one-time check of collision between two objects?

I have created a triangle selector of the objects and this is the code I use right now, but it gets very slow:

Code: Select all

bool cI::objectsCollide(int obj1, int obj2)
{
	if(obj1 < 0 || obj1 >= maxObjects || obj2 < 0 || obj2 >= maxObjects)
		return false;
	if(!objects[obj1].initialized || !objects[obj2].initialized)
		return false;
	if(!objects[obj1].node->getTransformedBoundingBox().intersectsWithBox(objects[obj2].node->getTransformedBoundingBox()))
		return false;
	for(int i1 = 0; i1 < objects[obj1].triangleCount; i1++)
	{
		for(int i2 = 0; i2 < objects[obj2].triangleCount; i2++)
		{
			if(objects[obj1].triangles[i1].getPlane().existsInterSection(objects[obj2].triangles[i2].getPlane()))
			{
				triangleObj1 = i1;
				triangleObj2 = i2;
				return true;
			}
		}
	}
	return false;
}
any ideas?
This monkey is useless, it only has ONE ass!!!
bal
Posts: 829
Joined: Fri Jun 18, 2004 5:19 pm
Location: Geluwe, Belgium

Post by bal »

You're checking if every triangle collides, there's no need for that. That's what makes it slow.
General Tools List
General FAQ
System: AMD Barton 2600+, 512MB, 9600XT 256MB, WinXP + FC3
turboferret
Posts: 49
Joined: Thu Aug 12, 2004 12:42 pm
Location: Sweden
Contact:

Post by turboferret »

yeah, I know :)
but is this the way Irrlicht handles its internal collision detection? is it a good way? then I can just check the outer triangles of the meshes.
This monkey is useless, it only has ONE ass!!!
the_viking
Posts: 23
Joined: Fri Aug 06, 2004 12:28 pm

Post by the_viking »

You shall firstly test if the AABBs of the Objects itnersects each other. Then you can go into more detail and check if there is a intersection on triangle-level. That would be much faster then as your code now ;)

Further you can implement a Hierarchical AABB tree and you could sort your Object-AABBs into a Quadtree like structure.. but there are many docs in the Internet you can read about this topics, so i won't talk anymore about this.. ;)
turboferret
Posts: 49
Joined: Thu Aug 12, 2004 12:42 pm
Location: Sweden
Contact:

Post by turboferret »

Code: Select all

if(!objects[obj1].node->getTransformedBoundingBox().intersectsWithBox(objects[obj2].node->getTransformedBoundingBox())) 
      return false;
I wonder what this is... ;)
I'll take your advise and read some docs on the net.
thanks, the_viking
This monkey is useless, it only has ONE ass!!!
Post Reply