How to add more meshes to collisiontree?

majc

24-09-2006 21:23:26

How can i add more than one mesh to collisiontree?
I have this code:



// Collision game map
Entity* map;
SceneNode* mapnode;
map = mSceneMgr->createEntity("Myplane","floor.mesh");
mapnode = mSceneMgr->getRootSceneNode()->createChildSceneNode( "MapNode" );
mapnode->attachObject( map );
map->setMaterialName( "Examples/Rockwall" );
mapnode->setPosition(0,0,0);
mapnode->scale(10,10,10);
map->setCastShadows( false );

OgreNewt::CollisionPrimitives::TreeCollisionSceneParser* stat_col = new OgreNewt::CollisionPrimitives::TreeCollisionSceneParser( m_World );
stat_col->parseScene( mapnode, true );
OgreNewt::Body* bod = new OgreNewt::Body( m_World, stat_col );
bod->attachToNode( mapnode );



Thanks in advance!

abecam

26-09-2006 11:45:51

You can create a new TreeCollision body. I am not into Ogre right now (I hope I will be back soon), but here is how I did in my "treeCollision-enhanced dotScene loader":


Entity* NewEntity = mSceneMgr->createEntity(EntityName, EntityMeshFilename);
NewNode->attachObject( NewEntity );

// Creation of the collision body

OgreNewt::Collision* colDotScen = new OgreNewt::CollisionPrimitives::TreeCollision( m_World, NewNode, false);
bodDotScen = new OgreNewt::Body( m_World, colDotScen );
delete colDotScen;

bodDotScen->attachToNode( NewNode );


So you basically add you entity as usual in Ogre, and create the tree collision body from here. Then if you want to move the entity, don't forget to move the body instead:


// We move the OgreNewt body, it will automatically move the corresponding node.
bodDotScen->setPositionOrientation(TempVec,TempQuat);


Maybe there is another way, but here it should work ! You can also remove the entity after if you only want the collision, not the entity (but there is another post about that). :)

walaber

26-09-2006 17:17:04

with the parser, you can also just make more scenenodes (with Entities attached), and attach them to your parent node.

the parser will make 1 big treecollision from all Entity's attached to all Nodes in the system.