handling collisions between both a heightmap and Quake3 map

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
DriftRS
Posts: 8
Joined: Mon May 22, 2006 7:21 am

handling collisions between both a heightmap and Quake3 map

Post by DriftRS »

Hi, I'm a bit of a noob to this engine, just started using it late yesterday.

I've been running through the tutorials, and am now trying to create a heightmap with a quake3 map (a castle) situated in the middle. The problem is getting the camera to properly collide with both the terrain and the map at the same time.

Having no idea how to manage it, I've been fiddling myself and trying to work it out through experimentation, and, well here's the relevent code (or at least what I think is relevent).

Code: Select all

//Create two selectors
scene::ITriangleSelector* selector = 0;
scene::ITriangleSelector* selector2 = 0;

Code: Select all

//Set up first selector (well, selector2)
selector2 = smgr->createOctTreeTriangleSelector(
q3levelmesh->getMesh(0), q3node, 128);
q3node->setTriangleSelector(selector2);
selector2->drop();

Code: Select all

//Set up camera
scene::ICameraSceneNode* camera = 
		camera = smgr->addCameraSceneNodeFPS(0,100.0f,300.0f);
	camera->setPosition(core::vector3df(1900*2,255*2,3700*2));
	camera->setTarget(core::vector3df(2397*2,343*2,2700*2));
	camera->setFarValue(12000.0f);

Code: Select all

//Create terrain
	scene::ITerrainSceneNode* terrain = smgr->addTerrainSceneNode( 
		"media/terrain-heightmap.bmp");

	terrain->setScale(core::vector3df(40, 4.4f, 40));
	terrain->setMaterialFlag(video::EMF_LIGHTING, false);

	terrain->setMaterialTexture(0, driver->getTexture(
	"media/terrain-texture.jpg"));
	terrain->setMaterialTexture(1, driver->getTexture(
	"media/detailmap3.jpg"));
		
	terrain->setMaterialType(video::EMT_DETAIL_MAP);
	terrain->scaleTexture(1.0f, 20.0f);

Code: Select all

//Create second selector (for terrain)
selector =
		smgr->createTerrainTriangleSelector(terrain, 0);
	terrain->setTriangleSelector(selector);
	selector->drop();

Code: Select all

//create two animators and attatch them to the camera

scene::ISceneNodeAnimator* anim =
		smgr->createCollisionResponseAnimator(
		selector, camera, core::vector3df(30,50,30),
		core::vector3df(0,-0.5,0),
		core::vector3df(0,50,0));

		scene::ISceneNodeAnimator* anim2 = smgr->createCollisionResponseAnimator(
		selector2, camera, core::vector3df(30,50,30),
		core::vector3df(0,0,0),
		core::vector3df(0,50,0));

	camera->addAnimator(anim);
	camera->addAnimator(anim2);
	anim->drop();
I've only copied the code here that I think is relevent, being new at this I may have missed something... Basically I'm just creating two selectors then creating 2 animator's using the camera and selector and attatching the animators to the camera.

Now the method I've used there seems to allow me to walk on the terrain and inside the quake map, but for some reason I can't walk over even really small ledges in the quake map, even though when I created a quake map by itself before, I was able to walk up steps perfectly without a problem.

If anyone knows whats wrong here, or whether I'm using the correct method to handle this, please help me,

thanks alot :)
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

Instead of adding the two animators to the camera, create one animator using a metaTriangleselector into which you've placed both the triangle selectors.
Image Image Image
DriftRS
Posts: 8
Joined: Mon May 22, 2006 7:21 am

Post by DriftRS »

I just tried doing that, but I'm not exactly sure how, this is the code I used:

Code: Select all

	scene::IMetaTriangleSelector* both;
	both->addTriangleSelector(selector);
	both->addTriangleSelector(selector2);

	scene::ISceneNodeAnimator* anim =
		smgr->createCollisionResponseAnimator(
		both, camera, core::vector3df(30,50,30),
		core::vector3df(0,-0.5,0),
		core::vector3df(0,50,0));

	camera->addAnimator(anim);
	anim->drop();
It compiles, but then crashes straight away when I run it.

EDIT: lol I just realised I coded that stupidly, I think I know what the problem is now.. I'll modify it and find out. Hopefully after a bit of practice I'll stop making stupid mistakes :?
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

Presumably the mistake you noticed was that you didn't initialise both to a metaTriangleSelector. I think you do this by smgr->createMetaTriangleSelector(), or something similar. You have to do that before adding the triangle selectors to it :)
Image Image Image
DriftRS
Posts: 8
Joined: Mon May 22, 2006 7:21 am

Post by DriftRS »

haha yeah that was the problem, thanks alot for all your help, it worked brilliantly :D

I'm really starting to like irrlicht, it gives you a heap of power yet does all the basic functionality you normally have to worry about for you! I was using OpenGL before and hated having to write all the texture code and generate heightmaps and such, but irrlicht makes all that a thing of the past! It even has an inbuilt fps cam which is something you don't often see.

I think I'll be using this engine from now on, ogre is the only other one I would consider but I think irrlicht is easier to use :)
Post Reply