MetaTriangleSelector

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
dejai
Posts: 522
Joined: Sat Apr 21, 2007 9:00 am

MetaTriangleSelector

Post by dejai »

I was having a lot of trouble with the MetaTriangle selector and could not find out how to use it, this was mainly due to the lack of source. Yet an example can be found in irrlicht/demo/CDemo.cpp and CDemo.h

This Snippet is just an example of its use not a complete program.


Code: Select all

// Add A Tree Mesh
IAnimatedMesh* tree = smgr->getMesh("media/tree.x");// Declare Trees
IAnimatedMeshSceneNode* tree_node = smgr->addAnimatedMeshSceneNode(tree);

// Initialize a Triangle Selector.
ITriangleSelector* tree_selector = 0;

// Initialize a Meta Triangle selector
IMetaTriangleSelector * metaSelector = smgr->createMetaTriangleSelector();

// Declare the position of the trees
if (tree_node)////// Trees ////////////
{
tree_node->setMaterialFlag(EMF_LIGHTING, false);
tree_node->setScale(vector3df(100,100,100)); 
tree_node->setPosition(vector3df(3999,200,1000));
tree_selector = smgr->createOctTreeTriangleSelector(tree->getMesh(0), tree_node, 128);
metaSelector->addTriangleSelector(tree_selector);
tree_selector->drop();
   

tree_node = smgr->addAnimatedMeshSceneNode(tree);   
tree_node->setMaterialFlag(EMF_LIGHTING, false);
tree_node->setScale(vector3df(100,100,100)); 
tree_node->setPosition(vector3df(4300,200,1200));   
tree_selector = smgr->createOctTreeTriangleSelector(tree->getMesh(0), tree_node, 128);
metaSelector->addTriangleSelector(tree_selector);
tree_selector->drop();


tree_node = smgr->addAnimatedMeshSceneNode(tree);   
tree_node->setMaterialFlag(EMF_LIGHTING, false);
tree_node->setScale(vector3df(100,100,100)); 
tree_node->setPosition(vector3df(4000,200,-1233));
tree_selector = smgr->createOctTreeTriangleSelector(tree->getMesh(0), tree_node, 128);
metaSelector->addTriangleSelector(tree_selector);
tree_selector->drop();
}

tree_selector = smgr->createOctTreeTriangleSelector(
tree->getMesh(0), tree_node, 128); // Declares which mesh and node it is assigned to

	
camera->setTriangleSelector(tree_selector);// Sets the camera to the bass selector

tree_selector->drop();

 // Drop selector
// create collision response animator and attach it to the camera

ISceneNodeAnimator* anim4 = smgr->createCollisionResponseAnimator(
 metaSelector, camera, core::vector3df(60,100,60),
	core::vector3df(0,0,0), // This Sets Gravity VERY important, -1 keeps you grounded
	core::vector3df(0,0,0));
metaSelector->drop();
camera->addAnimator(anim4);// Camera add animatior
anim4->drop();// drop animator



Thanks People at IRC Chat.

This is just a snippet don't flame me but comments are welcome.
Programming Blog: http://www.uberwolf.com
lester
Posts: 86
Joined: Mon Jan 29, 2007 3:33 pm

Post by lester »

Just to mention

you can use TriangleSelector instead when creating your custom scene node like that:

Code: Select all

TriangleSelector = (ITriangleSelector *)smgr->createMetaTriangleSelector();
Then all irrlicht mechanism will use a getTriangleSelector() as it might be.
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Post by rogerborg »

Code: Select all

camera->setTriangleSelector(tree_selector);// Sets the camera to the bass selector 
What's the purpose of this line?
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
dejai
Posts: 522
Joined: Sat Apr 21, 2007 9:00 am

Post by dejai »

Hmm Thanks for the advice. As for that line you mentioned. Thats an accidental left over from when it was a triangle selector for a single tree opps :/
still it does not effect the code.

Still I am a Newbie
Programming Blog: http://www.uberwolf.com
christianclavet
Posts: 1638
Joined: Mon Apr 30, 2007 3:24 am
Location: Montreal, CANADA
Contact:

Post by christianclavet »

Hi. Can you give us more details about the problem? What happen? From what I see from the snippet, it should work.

But I'm not sure about this line of code I've never used before:

Code: Select all

tree_node = smgr->addAnimatedMeshSceneNode(tree);
This seem to duplicate your tree node.

The tree placement, could be easier than this if done in IRRedit. If you would have to do a forest like this, it would be very time consuming.
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Post by rogerborg »

He's not having a problem; this is the working version.
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
christianclavet
Posts: 1638
Joined: Mon Apr 30, 2007 3:24 am
Location: Montreal, CANADA
Contact:

Post by christianclavet »

Opps! :oops: I misread the thread completely! :wink: Sorry!
dejai
Posts: 522
Joined: Sat Apr 21, 2007 9:00 am

Post by dejai »

Haha, well in that case thanks for the complement. Its not a very good metatriangle selector yet it is my first attempt at it. It seems to be working very well.

I will be posting the source code to The Glade Soon and Asking A Question about camera Angles
Programming Blog: http://www.uberwolf.com
Post Reply