Accurate Collision Detection with Terrains

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
DarkWhoppy
Posts: 386
Joined: Thu Sep 25, 2003 12:43 pm
Contact:

Accurate Collision Detection with Terrains

Post by DarkWhoppy »

Is there a way to get more accurate collision detection when using a terrain (model) or heightmap file? I've been trying... but when I use a heightmap file I can't actually get ahold of the mesh for the triangle selector so that doesn't work.

When using a terrain generated with MilkShape the model I use for testing 'floats' over the terrain making the shadow appear afew 100 units to the left/right (depending on what position I move to) of the model.
ScreenShot: www.phyer.net/whoppyarts/temp/shadow_funny.JPG

Yes, I tried decreasing the radius of the ellipsoid, that didn't work. But, the model does move "up and down" along with the hills of the terrain.

If anyone has a solution to this please let me know.
Programmer of the Irrlicht Scene Editor:
Homepage - Forum Thread
Version 2 on its way!!
Peter Müller
Posts: 292
Joined: Sun Mar 14, 2004 5:28 pm
Location: Germany
Contact:

Post by Peter Müller »

I take an ITriangleSelector to get the current hight of the terrain for characters and for jeeps for something you should use an physik engine
http://www.games-forge.de - Die Community für Nachwuchsprogrammierer
DarkWhoppy
Posts: 386
Joined: Thu Sep 25, 2003 12:43 pm
Contact:

Post by DarkWhoppy »

Jeeps? I didn't mention anything about a vehicle... :?
Programmer of the Irrlicht Scene Editor:
Homepage - Forum Thread
Version 2 on its way!!
Peter Müller
Posts: 292
Joined: Sun Mar 14, 2004 5:28 pm
Location: Germany
Contact:

Post by Peter Müller »

This was only an example :D

Edit:
My models stand on the floor, using the method, I explained:
http://raf.games-forge.de/v07/source/pr ... 20aussieht.
http://www.games-forge.de - Die Community für Nachwuchsprogrammierer
DarkWhoppy
Posts: 386
Joined: Thu Sep 25, 2003 12:43 pm
Contact:

Post by DarkWhoppy »

Peter Müller wrote:I take an ITriangleSelector to get the current hight of the terrain for characters
I don't understand what you're doing there, could you explain further?
Programmer of the Irrlicht Scene Editor:
Homepage - Forum Thread
Version 2 on its way!!
thesmileman
Posts: 360
Joined: Tue Feb 10, 2004 2:20 am
Location: Lubbock, TX

Post by thesmileman »

DarkWhoopy, if you are using a TerrainSceneNode you can just modify the models Z cordinates and set it equal to the height of the terrain at that point

Code: Select all

//Move node in the direction you want then:

vector3df pos3d = fairyNode->getPosition();
pos3d.z = terNode->getHeight(vector2d(pos3d.X,pos3d.Y))  //modify height to match terrain height
fairyNode->setPosition(pos3d);
Oh and don't trust my sintax.
DarkWhoppy
Posts: 386
Joined: Thu Sep 25, 2003 12:43 pm
Contact:

Post by DarkWhoppy »

Ah dammit, didn't check the API for a getHeight function :wink:

Thanks
Programmer of the Irrlicht Scene Editor:
Homepage - Forum Thread
Version 2 on its way!!
DarkWhoppy
Posts: 386
Joined: Thu Sep 25, 2003 12:43 pm
Contact:

Post by DarkWhoppy »

Now she falls right through the terrain but stops at the bottom of its bounding box... :roll:

Code: Select all

mTerrain = mhandle->getSmgr()->addTerrainSceneNode(0,1,
                    mhandle->driver->createImageFromFile("Data/maps/grassplain_sk.bmp"),
                    mhandle->driver->createImageFromFile("Data/maps/terrian1.bmp"),0,
                    core::dimension2d< f32 >(10.0f, 10.0f), 150.0f, core::dimension2d< s32 >(64, 64));
mTerrain->setMaterialFlag(EMF_LIGHTING, false);

//Inside update function

vector3df pos3d = vector3df(mPlayerNode->getPosition()); 
    mTerrain->getHeight(core::vector2d<f32>(pos3d.X,pos3d.Z),pos3d.Y);  
    mPlayerNode->setPosition(pos3d); 
I can't get the mesh for the triangle selector :?:
Someone have a terrian/collision example? :roll:
Programmer of the Irrlicht Scene Editor:
Homepage - Forum Thread
Version 2 on its way!!
thesmileman
Posts: 360
Joined: Tue Feb 10, 2004 2:20 am
Location: Lubbock, TX

Post by thesmileman »

I wouldn't think bounding box collision would work very well with terrains onless they are flat have you tried the other types of collision detection?
DarkWhoppy
Posts: 386
Joined: Thu Sep 25, 2003 12:43 pm
Contact:

Post by DarkWhoppy »

The engine has other types besides BoundingBox collision? :oops:

(been a while since I last used Irrlicht)
Programmer of the Irrlicht Scene Editor:
Homepage - Forum Thread
Version 2 on its way!!
Peter Müller
Posts: 292
Joined: Sun Mar 14, 2004 5:28 pm
Location: Germany
Contact:

Post by Peter Müller »

Get the hight of the terrain at an position (x/z) using the ITriangleSelector an any other getHeight method.
Then get the relative vector form the cradle (origin) of your model to the position, where the model should stand on the floor.

Then
amsnModel->setPosition(vector3df(x + vRelVector.X, fTerrainHeight + vRelVector.Y, z + vRelVector.Z));
http://www.games-forge.de - Die Community für Nachwuchsprogrammierer
thesmileman
Posts: 360
Joined: Tue Feb 10, 2004 2:20 am
Location: Lubbock, TX

Post by thesmileman »

DarkWhoppy wrote:The engine has other types besides BoundingBox collision? :oops:

(been a while since I last used Irrlicht)
Yea check out the tutorials on colission detection all three types are shown I think.
Peter Müller
Posts: 292
Joined: Sun Mar 14, 2004 5:28 pm
Location: Germany
Contact:

Post by Peter Müller »

Three? I thougt, two, BoundingBox and TriangleSelection
http://www.games-forge.de - Die Community für Nachwuchsprogrammierer
thesmileman
Posts: 360
Joined: Tue Feb 10, 2004 2:20 am
Location: Lubbock, TX

Post by thesmileman »

Plus "manual scene node picking"
DarkWhoppy
Posts: 386
Joined: Thu Sep 25, 2003 12:43 pm
Contact:

Post by DarkWhoppy »

No wonder! I checked the source files and.... I guess i'll have to find another solution for now

Code: Select all

//! Calculates height of a point in the terrain
bool CTerrainSceneNode::getHeight(core::vector2d<f32> pos, f32& outHeight)
{
	return false;
}
Post Reply