Page 1 of 1

Collision Detection- beyond the example

Posted: Thu Jan 18, 2007 6:00 pm
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));
		}

Posted: Thu Jan 18, 2007 7:16 pm
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

What about createTriangleSelectorFromBoundingBox

Posted: Fri Jan 19, 2007 12:02 am
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?

Posted: Fri Jan 19, 2007 12:47 pm
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

Simple Collision Example...

Posted: Tue Jan 23, 2007 9:34 pm
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

Posted: Tue Jan 23, 2007 9:36 pm
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;

Posted: Wed Jan 24, 2007 3:16 pm
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)