[SOLVED] A basic question about collision

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
Amt0571
Posts: 128
Joined: Mon Mar 06, 2006 6:29 pm

[SOLVED] A basic question about collision

Post by Amt0571 »

Hi,

I have a very basic question about collision and triangleselector:

I want my camera scene node to collide with various meshes, do I have to create a different triangleselector and a CollisionResponseAnimator for every mesh I want the camera to collide with? or is there a way to make it collide with a single triangleselector and CollisionResponseAnimator?

By the way, I know how to use the OctTreeTriangleSelector that is described in the example, but after looking around for a while, I'm unable to find how to use the other two triangleselectors.

Oh, and a last question: it's me or the forums are slow lately?


EDIT: Thanks! I'll tried it today and worked as expected :)


Thanks!
Last edited by Amt0571 on Fri Sep 08, 2006 12:05 am, edited 1 time in total.
Zar
Posts: 29
Joined: Mon Aug 07, 2006 4:46 pm
Location: Brazil

Post by Zar »

Amt,

This is a topic that everybody ask and probably will be replied with "use the search button". But, since this issue almost drives me crazy and took a lot of time to find an example using IMetaTriangleSelector, here is the direct link to the solution. Look at the "ming" post in the topic below:

http://irrlicht.sourceforge.net/phpBB2/ ... leselector

Be carefull, since he is using "createTriangleSelectorFromBoundingBox" instead of "createOctTreeTriangleSelector"

Here is my code to apply collision detection to 4 identical meshes (guarita), placed at different coordinates. Use it at your own risk, because I'm not a programmer and I'm not sure if this is the best way to do it. It works for me.

Code: Select all

    /* add 3d mesh guarita */
    
    IAnimatedMesh* guarita = 0;
	guarita = smgr->getMesh("./media/meshes/guarita.obj");

	/* display multiple meshes of guarita node*/

    ISceneNode* guaritanode = 0;
    ITriangleSelector* guaritaselector = 0;  
    IMetaTriangleSelector* mainTriangleSelector =      smgr->createMetaTriangleSelector(); 
 	
	guaritanode = smgr->addOctTreeSceneNode(guarita);
	guaritanode->setPosition(core::vector3df(-1400,0,1800));
	guaritanode->setScale(vector3df(10,10,10));
	guaritanode->setRotation(core::vector3df(270,0,0));	
	guaritanode->setMaterialFlag(video::EMF_LIGHTING,true);
	guaritanode->setMaterialFlag(video::EMF_NORMALIZE_NORMALS, true);
	guaritanode->setMaterialFlag(EMF_FOG_ENABLE,true); //enables fog
	
    guaritaselector = smgr->createOctTreeTriangleSelector(guarita->getMesh(0), guaritanode, 128);
    guaritanode->setTriangleSelector(guaritaselector);
    mainTriangleSelector->addTriangleSelector(guaritaselector); 
    guaritaselector->drop();	


	guaritanode = smgr->addOctTreeSceneNode(guarita);
	guaritanode->setPosition(core::vector3df(-1400,0,-1800)); 
	guaritanode->setScale(vector3df(10,10,10));
	guaritanode->setRotation(core::vector3df(270,0,0));
	guaritanode->setMaterialFlag(video::EMF_LIGHTING,true);
	guaritanode->setMaterialFlag(video::EMF_NORMALIZE_NORMALS, true);
	guaritanode->setMaterialFlag(EMF_FOG_ENABLE,true); //enables fog  
	
    guaritaselector = smgr->createOctTreeTriangleSelector(guarita->getMesh(0), guaritanode, 128);
    guaritanode->setTriangleSelector(guaritaselector);
    mainTriangleSelector->addTriangleSelector(guaritaselector); 
    guaritaselector->drop();

	guaritanode = smgr->addOctTreeSceneNode(guarita);
 	guaritanode->setPosition(core::vector3df(1400,0,-1800));  
	guaritanode->setScale(vector3df(10,10,10));
	guaritanode->setRotation(core::vector3df(270,0,0));	
	guaritanode->setMaterialFlag(video::EMF_LIGHTING,true);
	guaritanode->setMaterialFlag(video::EMF_NORMALIZE_NORMALS, true);
	guaritanode->setMaterialFlag(EMF_FOG_ENABLE,true); //enables fog
	
    guaritaselector = smgr->createOctTreeTriangleSelector(guarita->getMesh(0), guaritanode, 128);
    guaritanode->setTriangleSelector(guaritaselector);
    mainTriangleSelector->addTriangleSelector(guaritaselector); 
    guaritaselector->drop();

	
	guaritanode = smgr->addOctTreeSceneNode(guarita); 
	guaritanode->setPosition(core::vector3df(1400,0,1800));
	guaritanode->setScale(vector3df(10,10,10));
	guaritanode->setRotation(core::vector3df(270,0,0));	
	guaritanode->setMaterialFlag(video::EMF_LIGHTING,true);
	guaritanode->setMaterialFlag(video::EMF_NORMALIZE_NORMALS, true);
	guaritanode->setMaterialFlag(EMF_FOG_ENABLE,true); //enables fog
	
    guaritaselector = smgr->createOctTreeTriangleSelector(guarita->getMesh(0), guaritanode, 128);
    guaritanode->setTriangleSelector(guaritaselector);
    mainTriangleSelector->addTriangleSelector(guaritaselector); 
    guaritaselector->drop();

    /*collision detection guaritas*/
    
    ISceneNodeAnimator* animaguarita4 = smgr->createCollisionResponseAnimator(
		mainTriangleSelector, camera, core::vector3df(30,30,30),
		core::vector3df(0,0,0), 
		core::vector3df(0,30,0));
	camera->addAnimator(animaguarita4);
	animaguarita4->drop();		
hope this help

by the way, the foruns are slow for me too. I think they are adding some phpBB MODS
Amt0571
Posts: 128
Joined: Mon Mar 06, 2006 6:29 pm

Post by Amt0571 »

Sorry for not using the search engine (which I usually do), I couldn't because it gave me a timeout error everytime I tried...

Anyway, thanks for your helpfulness, this is what I was looking for. I'm going to sleep now, but tomorrow I will try to get collision detection to run.


Thanks a lot!
Post Reply