createTerrainTriangleSelector crashes...

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
fitfool
Posts: 20
Joined: Sun Jul 15, 2007 5:40 am

createTerrainTriangleSelector crashes...

Post by fitfool »

hmm, ive been trying to implement collision with importing a .irr file. Ive been able to implement OCT_TREES but i cant get it right with ESNT_TERRAIN...

Code: Select all

void Level::RecursiveSelector( ISceneNode* Node )
{
	if( Node == NULL )
		return;

	if( Node->getType() == ESNT_OCT_TREE )
	{
		IAttributes* Attribs = Globals::Device->getFileSystem()->createEmptyAttributes(); 
		
		if( Attribs ) 
		{
			Node->serializeAttributes( Attribs ); 
			core::stringc Name = Attribs->getAttributeAsString( "Mesh" ); 
			Attribs->drop(); 
			
			IAnimatedMesh* Mesh = Globals::SceneManager->getMesh( Name.c_str() );
			
			if( Mesh ) 
			{ 
				scene::ITriangleSelector* Selector = 
					Globals::SceneManager->createOctTreeTriangleSelector( Mesh->getMesh(0), Node, 128 );
				
				Node->setTriangleSelector( Selector );
				
				TriangleSelectors.push_back( Selector );
				
				Selector->drop();
			}
		}
	}
	else if( Node->getType() == ESNT_TERRAIN )
	{
		IAttributes* Attribs = Globals::Device->getFileSystem()->createEmptyAttributes(); 
	
		if( Attribs ) 
		{
			Node->serializeAttributes( Attribs ); 
			core::stringc Name = Attribs->getAttributeAsString( "Heightmap" ); 
			Attribs->drop(); 
			
			ITerrainSceneNode* TerrainNode = Globals::SceneManager->addTerrainSceneNode( Name.c_str() );
			
			if( TerrainNode )
			{ 
				scene::ITriangleSelector* Selector = 
					Globals::SceneManager->createTerrainTriangleSelector( TerrainNode, 4 );
				
				Node->setTriangleSelector( Selector );
				
				TriangleSelectors.push_back( Selector );
				
				Selector->drop();
			}
		}
	}

    core::list<ISceneNode*>::Iterator Begin = Node->getChildren().begin(); 
    core::list<ISceneNode*>::Iterator End = Node->getChildren().end();

    for ( ; Begin != End; Begin++ ) 
		RecursiveSelectorAdder( *Begin );
}
it crashes when i pass 4 throught cene::ITriangleSelector* Selector =
Globals::SceneManager->createTerrainTriangleSelector( TerrainNode, 4 );

but of i pass 0, the output says it just keeps outputting "Generated terrain data". when i pass 4 it crashes and vc++ outputs "std::bad_alloc"...

Thanks!
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

Code: Select all

ITerrainSceneNode* TerrainNode = Globals::SceneManager->addTerrainSceneNode( Name.c_str() ); 
I'm pretty sure that line is your problem. If your scene has a terrain scene node, you create a new terrain scene node and create collision information for that one. Later, you will process the new terrain scene node. When processing that one you will create a new one and give it collision information, and again, and again, and again.

If you are going to try to do collision using Irrlicht's primitive collision system, you should probably see the the original code I posted here and here. It worked with terrains.

Travis
fitfool
Posts: 20
Joined: Sun Jul 15, 2007 5:40 am

Post by fitfool »

Thanks a lot Vitek! it now will load mesh and terrain collision. But there is a problemo. I set up a FPSCamera with some gravity, but when i try to walk, its really bumpy, unrealistic, and sometimes i get stuck in the terrain. How could i make it so the collision is nice and smooth, like counterstrike, or quake?

Thanks a bunch!
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

That is likely a result of the collision response animator implementation and the gravity factor that you've set. You can try to mess with the factors a bit, but I doubt that you'll get anything that is totally satisfying.

Travis
fitfool
Posts: 20
Joined: Sun Jul 15, 2007 5:40 am

Post by fitfool »

What do you think would be the best way to set up a decent FPS Camera that utilizes terrain?

thanks
dlangdev
Posts: 1324
Joined: Tue Aug 07, 2007 7:28 pm
Location: Beaverton OR
Contact:

Post by dlangdev »

fitfool wrote:Thanks a lot Vitek! it now will load mesh and terrain collision. But there is a problemo. I set up a FPSCamera with some gravity, but when i try to walk, its really bumpy, unrealistic, and sometimes i get stuck in the terrain. How could i make it so the collision is nice and smooth, like counterstrike, or quake?

Thanks a bunch!
sounds like the sliding plane isn't working.

do you have a steep slope in the terrain?
Image
fitfool
Posts: 20
Joined: Sun Jul 15, 2007 5:40 am

Post by fitfool »

Yeah the terrain is pretty steep and mountainy. When i make my camera really large, (the bounding box), its a lot smoother. But for some reason, i cant Jump when im on the terrain. the camera looks like its bouncing up and down really fast.
dlangdev
Posts: 1324
Joined: Tue Aug 07, 2007 7:28 pm
Location: Beaverton OR
Contact:

Post by dlangdev »

* slaps forehead *

aha!

let me consult my grand majestic all-knowing soothsayer, be right back real quick.
Image
fitfool
Posts: 20
Joined: Sun Jul 15, 2007 5:40 am

Post by fitfool »

Would using a physics engine better suite my needs?
dlangdev
Posts: 1324
Joined: Tue Aug 07, 2007 7:28 pm
Location: Beaverton OR
Contact:

Post by dlangdev »

ok, i see what you mean by getting stuck.

i got stuck too in one demo prog i made back a while ago.

it really depends on the terrain, make sure the ellipsoid bounding the camera/actor is on the terrain. use the jump key to change the currentPosition.
Image
Post Reply