Arras Terrain scenenode and Irrlicht collisions

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!
Post Reply
Xplod
Posts: 32
Joined: Sat Mar 29, 2008 5:48 pm
Contact:

Arras Terrain scenenode and Irrlicht collisions

Post by Xplod »

Hello everybody,

I wonder if it's possible to use Irrlicht's collision system with arras terrain scene node ? And how ? I checked and there's no way get terrain mesh to create an OctTreeTriangleSelector or something like that.

Can someone help me?
I'm Ouverta on the chat |
Project leader/Lead Developer of Ouverta project.
Insomniacp
Posts: 288
Joined: Wed Apr 16, 2008 1:45 am
Contact:

Post by Insomniacp »

Seeing as I will also need this I will come up with a way to create one unless someone has got a solution :P.

EDIT: Here is my plan. add an bool var to TlTSector to check to see if the sector has been added to the triangle selector. if yes and the sector is visible then do nothing. if the sector is visible and it is not added, add it and change the var. if it is not visible check to see if it is in the triangle selector if so remove it. This would be added to the render function of the terrain node. This will allow for an updating triangle selector that won't be enormous if your terrain node is large. Someone can program this but I have started on it but I have a lot going on tomorrow so I most likely won't finish it, possibly on Sunday though or next week.
Xplod
Posts: 32
Joined: Sat Mar 29, 2008 5:48 pm
Contact:

Post by Xplod »

I think my solution will be easier : I'll make a collision class which does collisions for both terrain and objects on it.
So I set a CollisionResponseAnimator on the object with a very low gravity to check if the object collides with other objects than the terrain, and I create my own slope detection, using getHeight() method, when terrain collisions are needed. That way, I can optimize collisions detection and use my own gravity system.

I think it's not the better way to do it, but it's the more flexible and easy way I found. If someone is interested, I'll post the code as soon as it's finished.
I'm Ouverta on the chat |
Project leader/Lead Developer of Ouverta project.
Insomniacp
Posts: 288
Joined: Wed Apr 16, 2008 1:45 am
Contact:

Post by Insomniacp »

okay, this is what I did.
add following function

Code: Select all

// return the Triangle Selector added by Pat Koeller
scene::ITriangleSelector* ShTlTerrainSceneNode::getTriangleSelector()
{
	//make new mesh and mesh buffers
	TriangleMesh=new scene::SMesh();
	TriangleMeshBuffer=new scene::SMeshBuffer();
	//loop through sectors
	for(s32 j=0; j<Sector.height(); j++)
	{
		for(s32 i=0; i<Sector.width(); i++)
		{
			//add new indices to mesh buffer
			for(int x=0;x<Sector(i,j).Index.size();x++)
			{
				TriangleMeshBuffer->Indices.push_back(Sector(i,j).Index[x]);
			}
			//add new vertices to mesh buffer
			for(int x=0;x<Sector(i,j).Vertex.size();x++)
			{
				TriangleMeshBuffer->Vertices.push_back(Sector(i,j).Vertex[x]);
			}
		}
	}
	//add buffer to mesh
	TriangleMesh->addMeshBuffer(TriangleMeshBuffer);
	//make a new triangle selector and set to this scene node
	TriangleSelector= localsmgr->createOctTreeTriangleSelector(TriangleMesh, this);
	this->setTriangleSelector(TriangleSelector);
	//return the selector that was made
	return TriangleSelector;
}
Also add the following variables to the class

Code: Select all

	// triangle selector added by Pat Koeller
	scene::ITriangleSelector* TriangleSelector;

	// triangle selector's mesh added by Pat Koeller
	scene::SMesh* TriangleMesh;

	// triangle selector's mesh's buffer added by Pat Koeller
	scene::SMeshBuffer* TriangleMeshBuffer;

	// Scene manager for this node added by Pat Koeller
	scene::ISceneManager* localsmgr;
During the construction function set the scene manager like so

Code: Select all

//store scene manager, added by Pat Koeller
	localsmgr=smgr;
And that should do it, just call terrainnode->getTriangleSelector() to get the triangle selector based off the current information. You will have to call again to get it if you change the ground height.
Post Reply