(C++) some utility functions for using irredit with newton

Post those lines of code you feel like sharing or find what you require for your project here; or simply use them as tutorials.
Post Reply
buhatkj
Posts: 444
Joined: Fri Dec 12, 2003 4:53 am
Contact:

(C++) some utility functions for using irredit with newton

Post by buhatkj »

I like irredit, But until the new IrrEdit Lib is documented it doesnt really support physics or userdata yet. However, I figured out this little hack to help myself out. One may set up their nodes in irredit with certain ID's, which will signify what type of collision we should set up for them with newton, and then using another function which I gleaned from this forum before (I apologize but i forget when/where/who I borrowed this from) you can retrieve the mesh name, and thence the mesh to make your collision. Just fill in the switch cases with the approproiate functions to make your bodies.
this is basically a re-purposed rip-off of the getSceneNodeByID routine.

Code: Select all

bool GameApp::FindPhysicsNodes(scene::ISceneNode* start){
	if (start == 0)
		start = Irr_SceneMgr->getRootSceneNode();

	//this should be a big switch that makes the different kinds of bodies for different ID's
	//does this even need a return value??
	int ID = start->getID();
	switch(ID){
		case 1:
			cout<<"found a one"<<endl;
			cout<<"got mesh name:"<<GetMeshNameFromNode(start).c_str()<<endl;
			break;
		case 2:
			cout<<"found a two"<<endl;
			cout<<"got mesh name:"<<GetMeshNameFromNode(start).c_str()<<endl;
			break;
		default:
			cout<<"found an unknown type!!"<<endl;
	}

	scene::ISceneNode* node = 0;

	const core::list<scene::ISceneNode*>& list = start->getChildren();
	core::list<scene::ISceneNode*>::Iterator it = list.begin();
	for (; it!=list.end(); ++it)
	{
		FindPhysicsNodes(*it);		
	}
	return false;
}

core::stringc GameApp::GetMeshNameFromNode(scene::ISceneNode* node){
	io::IFileSystem * FS = Irr_Device->getFileSystem();
    io::IAttributes* attribs = FS->createEmptyAttributes();  
	if (attribs){
	    node->serializeAttributes(attribs); 
	    // get the mesh name out 
	    core::stringc mesh_name = attribs->getAttributeAsString("Mesh"); 
	    attribs->drop(); 
		return mesh_name;
	}else{
		return "NULL";
	}
}
Might be irrelevent soon, since niko as usual is probably several steps ahead of me in chasing down these sorts of things, but still I thought this was interesting, so here ya all go. :-)
My irrlicht-based projects have gone underground for now, but if you want, check out my webcomic instead! http://brokenboomerang.net
Post Reply