Collision Detection- beyond the example

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
funxer
Posts: 10
Joined: Thu Jan 04, 2007 6:25 pm

Collision Detection- beyond the example

Post by funxer »

Image

Image

I have a question about collision detection as you can see from the 2 images I have posted, the triangles are being drawn and collision is being detected...however it is not being updated as the mesh is being animated.

I tried:
GATEselector = smgr->createTriangleSelectorFromBoundingBox(GATEnode);

...but it didn't give me any triangles on the gate, is this because I havn't called a bounding box for my GATEnode?

Code: Select all

	// add Gate, 
	scene::IAnimatedMeshSceneNode* GATEnode = 0;
	scene::IAnimatedMesh* gate = smgr->getMesh("../../media/CASTLEGate.x");
	GATEnode = smgr->addAnimatedMeshSceneNode(gate);
	GATEnode->setMaterialFlag(video::EMF_LIGHTING, false);



	scene::ITriangleSelector* GATEselector = 0;

	if (GATEnode)
	{		

		GATEselector = smgr->createOctTreeTriangleSelector(gate->getMesh(0), GATEnode, 128);
		GATEnode->setTriangleSelector(GATEselector);
		GATEselector->drop();
	}

Code: Select all

		if (smgr->getSceneCollisionManager()->getCollisionPoint(
			line, GATEselector, intersection, tri))
		{
			bill->setPosition(intersection);
				
			driver->setTransform(video::ETS_WORLD, core::matrix4());
			driver->setMaterial(material);
			driver->draw3DTriangle(tri, video::SColor(0,255,0,0));
		}
r-type
Posts: 41
Joined: Sun Feb 12, 2006 1:54 am

Post by r-type »

it is because a triangleselector uses a mesh to do its work. An animated mesh consists of multiple meshes (not entirely true but to keep things simple) thats why an animatedmesh has a getmesh(n) function.

Constantly updating triangleselectors is not a good idea. A solution could be to create 2 triangleselectors and do some logic to track whether the door is closed or not and use the according triangleselector.

Or you could animate the door programmatically by making it a seperate node and rotate/move it in your code.

Hope it helps
funxer
Posts: 10
Joined: Thu Jan 04, 2007 6:25 pm

What about createTriangleSelectorFromBoundingBox

Post by funxer »

Thanx R-Type

What about using the createTriangleSelectorFromBoundingBox command,

how would I use this, it says in the documentation that this is good for animated meshes.

Yet it doesn't draw any triangles for me, the program doesn't fail or give me errors, just no triangles drawn on the Gate.

Shouldn't I be calling for a bounding box somewhere, or how does it find the bounding box?
r-type
Posts: 41
Joined: Sun Feb 12, 2006 1:54 am

Post by r-type »

hi,

It creates a triangleselector from the boundingbox which is spanned around your entire animated mesh. So its not much use for you i guess
funxer
Posts: 10
Joined: Thu Jan 04, 2007 6:25 pm

Simple Collision Example...

Post by funxer »

Hi, I'm still trying to get a handle of this collision detection exercise.

I've replaced the 3 fairies in the example with just one "prop" that i exported from Maya into a .x format. And I was hoping for the same behavior that I was getting with the Fairies...
ie: The Prop should be dark when it's not being detected and Lit up when it IS detected. Yet it stays dark regardless, why is this not working...The Fairies work fine.

Please look at my .exe and code here: http://www.3drobert.com/cgtalk/CollisionTESTS.zip
funxer
Posts: 10
Joined: Thu Jan 04, 2007 6:25 pm

Post by funxer »

Code: Select all

	//
	//
	//Add Prop
	material.Texture1 = driver->getTexture("../../media/JanaCASTLEtex.png");
	material.Lighting = true;

	scene::IAnimatedMeshSceneNode* propNode = 0;
	scene::IAnimatedMesh* Prop = smgr->getMesh("../../media/prop.x");

	if (Prop)
	{
		propNode = smgr->addAnimatedMeshSceneNode(Prop);
		propNode->getMaterial(0) = material;
	}

	material.Texture1 = 0;
	material.Lighting = false;

Code: Select all

		selectedSceneNode = smgr->getSceneCollisionManager()->getSceneNodeFromCameraBB(camera);

		if (lastSelectedSceneNode)
			lastSelectedSceneNode->setMaterialFlag(video::EMF_LIGHTING, true);

		if (selectedSceneNode == floorNode  || selectedSceneNode == bill)
			selectedSceneNode = 0;

		if (selectedSceneNode == propNode)
			selectedSceneNode->setMaterialFlag(video::EMF_LIGHTING, false);

		lastSelectedSceneNode = selectedSceneNode;
d00d
Posts: 7
Joined: Tue Jan 23, 2007 7:07 pm

Post by d00d »

could either of you (with the problems) tell me what logic you are using to create the line? like are you using a fps camera and where are the start/end coordinates for the line you are using to find the intersection? (not in terms of x,y,z but in terms of camera->getPosition() or whatever it is you are using)
Post Reply