Collision detection between vector and Mesh

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
Guest

Collision detection between vector and Mesh

Post 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
Christ/off
Posts: 1
Joined: Sat Jan 22, 2005 1:37 pm

Post by Christ/off »

Hopefully somone can help!
Morrog
Posts: 58
Joined: Mon Dec 13, 2004 5:13 am

Post 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.
oconv
Posts: 14
Joined: Fri Dec 17, 2004 2:12 pm

Post by oconv »

colDet is much better when it comes to collisions
what is colDet, Morrog? is it easy to implement in irrlicht?
Morrog
Posts: 58
Joined: Mon Dec 13, 2004 5:13 am

Post 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();
}
oconv
Posts: 14
Joined: Fri Dec 17, 2004 2:12 pm

Post 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.
Electron
Posts: 874
Joined: Sun Mar 14, 2004 12:05 am
Location: Massachusetts USA

Post 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.
You do a lot of programming? Really? I try to get some in, but the debugging keeps me pretty busy.

Crucible of Stars
etcaptor
Posts: 871
Joined: Fri Apr 09, 2004 10:32 pm
Location: Valhalla
Contact:

Post by etcaptor »

Good idea.
kaeles-notlogged

Post by kaeles-notlogged »

so that explains why the octtreeselector eats my cpu ...
hmmm
lol
Post Reply