Page 1 of 1

Collision detection between vector and Mesh

Posted: Sat Jan 22, 2005 1:39 pm
by Guest
Hi,
i want to test, if a vector has a collision with my level.
How can I test this case?
Bye,
Christ/off

Posted: Sat Jan 22, 2005 1:40 pm
by Christ/off
Hopefully somone can help!

Posted: Sat Jan 22, 2005 10:44 pm
by Morrog
irr::scene::ISceneCollisionManager::getCollisionPoint
look it up in the manual :)

BTW Irrlicht's collision code is slow. It isn't that slow, it can be used for a few tests per frame, but beware of it when you're into anything more than, say, 10 tests a frame.
colDet is much better when it comes to collisions. And then a physics engine might also do the job.

Posted: Sun Jan 23, 2005 4:21 pm
by oconv
colDet is much better when it comes to collisions
what is colDet, Morrog? is it easy to implement in irrlicht?

Posted: Sun Jan 23, 2005 9:51 pm
by Morrog
colDet is what you think it is, a collision library. ;)

It's pretty simple to use with Irrlicht. You just do this:

Code: Select all

CollisionModel *model = newCollisionModel();
model->addTriangle(....);
model->addTriangle(....);
model->addTriangle(....);
...
model->finalize();
and then you can do mesh-mesh collision, sphere-mesh collisions, ray-mesh collisions, and so forth.

Just google for colDet, it'll come up.

EDIT: Oh, and here's how I build the mesh in my current engine:

Code: Select all

void CLevelManager::createCollisionModel(IMesh *mesh)
{
	if(m_collision_model)
	{
		delete m_collision_model;
		m_collision_model = NULL;
	}

	m_collision_model = newCollisionModel3D(true);

	for(int i = 0; i < mesh->getMeshBufferCount(); ++i)
	{
		IMeshBuffer *mesh_buffer = mesh->getMeshBuffer(i);

		if(mesh_buffer->getVertexType() == EVT_STANDARD)
		{
			S3DVertex *vertices = (S3DVertex *)mesh_buffer->getVertices();
			u16 *indices = mesh_buffer->getIndices();

			for(int i = 0; i < mesh_buffer->getIndexCount(); i += 3)
			{
				m_collision_model->addTriangle(
					vertices[i].Pos.X, vertices[i].Pos.Y, vertices[i].Pos.Z,
					vertices[i + 1].Pos.X, vertices[i + 1].Pos.Y, vertices[i + 1].Pos.Z,
					vertices[i + 2].Pos.X, vertices[i + 2].Pos.Y, vertices[i + 2].Pos.Z
					);
			}
		}
		else
		{
			S3DVertex2TCoords *vertices = (S3DVertex2TCoords *)mesh_buffer->getVertices();
			u16 *indices = mesh_buffer->getIndices();

			for(int i = 0; i < mesh_buffer->getIndexCount(); i += 3)
			{
				m_collision_model->addTriangle(
					vertices[i].Pos.X, vertices[i].Pos.Y, vertices[i].Pos.Z,
					vertices[i + 1].Pos.X, vertices[i + 1].Pos.Y, vertices[i + 1].Pos.Z,
					vertices[i + 2].Pos.X, vertices[i + 2].Pos.Y, vertices[i + 2].Pos.Z
					);
			}
		}
	}

	m_collision_model->finalize();
}

Posted: Tue Jan 25, 2005 7:49 am
by oconv
thanks Morrog. :) for you it's simple, but not for me. :?

could you make an example putting the code into the collision tutorial 7?
so that dummies like me can make a working example from which they can go on.

Posted: Tue Jan 25, 2005 1:48 pm
by Electron
It would be possible to modify the OctTreeTriangleSelector so that it gave accurate detection using the octree to avoid testign uneccesary areas. Currently the OctTreeTriangleSelector function for getting triangles from a ray returns all triangles that intersect with the ray's aabb -- not very useful.

Posted: Wed Jan 26, 2005 8:59 am
by etcaptor
Good idea.

Posted: Wed Jan 26, 2005 10:00 pm
by kaeles-notlogged
so that explains why the octtreeselector eats my cpu ...
hmmm
lol