Collision Detction nadn response with a number of Nodes

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
TH
Posts: 5
Joined: Sun Sep 12, 2004 4:58 pm

Collision Detction nadn response with a number of Nodes

Post by TH »

Well i am having problem with collision detection in Irrlicht:

Well we got ISceneNodeAnimatorCollisionResponse which do automatic collision detection for a scene node.The problem is that i let me do collision detection with only one node. But i want to do collision detection (also Response similar to the above interface) for "a large number of nodes( high polygon nodes)".

Surely there is a ISceneCollisionManager for doing this but does not it is very inefficient to do the collision detection for all the scene nodes linearly. Because i might be some scene nodes are very far apart form player whish do not require detection.

Is there any way to efficiently do collision detection and also response (as ISceneNodeAnimatorCollisionResponse do) with large number of scene nodes.

Regards,

TH
TH
Posts: 5
Joined: Sun Sep 12, 2004 4:58 pm

Post by TH »

Oops! Sorry to bother you guys! I did not know there is a search feature in the forum too! :oops:

Well "meta triangle selector" is the anwser.

thanks any way!

TH
Peter Müller
Posts: 292
Joined: Sun Mar 14, 2004 5:28 pm
Location: Germany
Contact:

Post by Peter Müller »

TH wrote:I did not know there is a search feature in the forum too! :oops:
lol, a joke, isn't it?
http://www.games-forge.de - Die Community für Nachwuchsprogrammierer
Guest

Post by Guest »

Well what else you think it is!

TH
TH
Posts: 5
Joined: Sun Sep 12, 2004 4:58 pm

Post by TH »

Ok guys this time serious!
Well i am trying to use the IMetaTriangleSelector, but rather moving around in the world i am "stucked" at one position :cry:. here is what i am doing can any body tell me is that the corrcet way to use IMetaTriangleSelector.

Code: Select all

scene::ICameraSceneNode* camera = 0;
camera = smgr->addCameraSceneNodeFPS(0,100.0f,300.0f);
camera->setPosition(core::vector3df(10,50,10));
camera->setFarValue(500);

IMetaTriangleSelector* metaselector = smgr->createMetaTriangleSelector();
ISceneCollisionManager* collisionmanager = smgr->getSceneCollisionManager();
triangle3df outtri;
bool flag = false;
		
vector3df lastposition =  camera->getPosition();
while(device->run())
{
	driver->beginScene(true, true, video::SColor(0,100,100,100));
	smgr->drawAll();
	driver->endScene();

	vector3df direction = (lastposition - camera->getPosition());
	
                vector3df newposition = 
                collisionmanager->getCollisionResultPosition(metaselector,
                           camera->getPosition(),
	           core::vector3df30,50,30) ,direction,outtri,flag,0.000500,
                           core::vector3df(0,0,0)
                           );
		

	lastposition = newposition;
	camera->setPosition(newposition);
}
Also when i try to set the gravityDirectionAndSpeed to (0,-100,0) i fall done form my world floor!!!

plz help!
regards,

TH

PS: This time i have done the serachign and this question hasnot been not asked!
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

You have to add all meshes needet for collision detection to the meta selector...

Use: addTriangleSelector(ITriangleSelector* toAdd)
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
TH
Posts: 5
Joined: Sun Sep 12, 2004 4:58 pm

Post by TH »

Well i have been after trying for hours and hours and unable to do collision detection! :x
As Acki mention i have also this time used the addTriangleSelector() too! but still the user is stuck at one position.

Here what i am doing:

Code: Select all

 
if(housemesh == NULL)
{
	return 0;
}

scene::IAnimatedMesh* floormesh = smgr->getMesh("data\\floor_patch.x");
if(floormesh == NULL)
{
	return 0;
}

scene::ITriangleSelector* selector = 0;
IMetaTriangleSelector* metaselector = smgr->createMetaTriangleSelector();

bool flag = false;
for(int i = 0; i < 10; i++)
{
	for(int j = 0; j < 10; j++)
	{
		if(flag == false)
		{
			node = smgr->addMeshSceneNode(floormesh->getMesh(0));
			node->setPosition(core::vector3df(i*20,0,j*20));
			node->setScale(core::vector3df(2.0,2.0,2.0));

			selector = smgr->createTriangleSelector(floormesh->getMesh(0),node);
			node->setTriangleSelector(selector);
			metaselector->addTriangleSelector(selector);
			selector->drop();


			flag = !flag;
		}
		else
		{
			node = smgr->addMeshSceneNode(housemesh->getMesh(0));
			node->setPosition(core::vector3df(i*20,0,j*20));

			selector = smgr->createTriangleSelector(housemesh->getMesh(0),node);
			node->setTriangleSelector(selector);
			metaselector->addTriangleSelector(selector);
			selector->drop();

			flag = !flag;
		}
	}
}

smgr->addLightSceneNode(0,core::vector3df(100,10,100));
smgr->addLightSceneNode(0,core::vector3df(10,10,10));

scene::ICameraSceneNode* camera =
	smgr->addCameraSceneNodeFPS(0,100.0f,300.0f);
camera->setPosition(core::vector3df(30,5,30));

scene::ISceneNodeAnimator* anim = smgr->createCollisionResponseAnimator(
	metaselector, camera, core::vector3df(20,50,20),
	core::vector3df(0,-100,0), 100.0f,
	core::vector3df(0,50,0));
camera->addAnimator(anim);
anim->drop();

device->getCursorControl()->setVisible(false);
while(device->run())
{
	driver->beginScene(true, true, video::SColor(0,100,100,100));
	smgr->drawAll();
	driver->endScene();
}

metaselector->drop();
device->drop();
The two for loops add sence node for floor(a small horizontal quad) and a house alternatively.So i it makes a little urban town wih streets and house!

Please Help!

(Sorry the code listing is a little long)

TH
Kande
Posts: 19
Joined: Fri Sep 10, 2004 9:37 pm
Location: Mannheim / Germany
Contact:

Post by Kande »

I am not sure, it is just a thought.

Maybe the cameras elipsoid is created within another object, thats why it is stuck.

I wasnt checking your code carefully, it looks fine tome, as i mentioned, its just a thought.
Life is expensive..... but a trip around the sun is included.
Guest

Post by Guest »

Thanks Kande for the reply
i first also thought that i was placing the camera in the BB of some object. But i have tried changing the camera position and elipsoid raduis.
I have spent hours changing different parameter but useless. :cry:

I am sure it must be some stupid mistake! :? but can please any body point out the mistake.

regards,

TH
Dogs
Posts: 195
Joined: Wed Sep 15, 2004 1:04 am
Location: michigan

Post by Dogs »

Im going to check back at this post ... Id like to know as well...

Sorry I wish I could help... But what you are doing im sure ill be doing here in the next day or so myself... So id like to know the answer as well..

lol :?
Post Reply