Collision help [RESOLVED]

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
Dreamwalker1986
Posts: 39
Joined: Tue Sep 10, 2013 2:37 pm

Collision help [RESOLVED]

Post by Dreamwalker1986 »

OK, I am using a selector in my code, but what I want to do is collide with a specific node/mesh, like below (which compiles but doesn't work propperly:

Code: Select all

 
//get colliding nodes from *.irr file in memory
    scene::ISceneNode * house = static_cast<scene::ISceneNode*>(smgr->getSceneNodeFromId(13));
    scene::ISceneNode * tree = static_cast<scene::ISceneNode*>(smgr->getSceneNodeFromId(12));
    
    
 
    if(smgr->getSceneCollisionManager()->getCollisionPoint(line, selector, end, triangle, house))
    {
        std::cout<<"HOUSE COLLISION DETECTED ON NODE\n";
    }
    
    
    else if(smgr->getSceneCollisionManager()->getCollisionPoint(line, selector, end, triangle, tree))
    {
        std::cout<<"TREE COLLISION DETECTED ON NODE\n";
    }
    
Last edited by Dreamwalker1986 on Fri Sep 27, 2013 2:57 pm, edited 1 time in total.
CuteAlien
Admin
Posts: 9933
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Collision help

Post by CuteAlien »

This shouldn't compile like this, last parameter in getCollisionPoint is a reference to a pointer and returns the node it collides with. If you only want to collide against the selector of a single node then pass the selector of that specific node only.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Dreamwalker1986
Posts: 39
Joined: Tue Sep 10, 2013 2:37 pm

Re: Collision help

Post by Dreamwalker1986 »

CuteAlien wrote:This shouldn't compile like this, last parameter in getCollisionPoint is a reference to a pointer and returns the node it collides with. If you only want to collide against the selector of a single node then pass the selector of that specific node only.

Sorry for being noob, but could you give me an example.


P.S

I'm using a metaselector if that helps. Also I want to collide with multiple selectors/nodes, but be able to identify them individually.
Dreamwalker1986
Posts: 39
Joined: Tue Sep 10, 2013 2:37 pm

Re: Collision help

Post by Dreamwalker1986 »

Also, if I don't pass the final house parameter the compiler complains because is requires that in the function parameter.
Dreamwalker1986
Posts: 39
Joined: Tue Sep 10, 2013 2:37 pm

Re: Collision help

Post by Dreamwalker1986 »

I've tried below after a lot of experimentation, but still no joy!!!

Code: Select all

 
 //get colliding nodes from *.irr file in memory
    scene::ISceneNode * house = static_cast<scene::ISceneNode*>(smgr->getSceneNodeFromId(13));
    scene::ISceneNode * tree = static_cast<scene::ISceneNode*>(smgr->getSceneNodeFromId(12));
    scene::ISceneNode * node = 0;
    house->setTriangleSelector(selector);
    tree->setTriangleSelector(selector);
   
    
 if(receiver.MouseState.LeftButtonDown == true)
   {
 
 
    //////////////SHOOT AND COLLISION//////////////////////
      
    if(smgr->getSceneCollisionManager()->getCollisionPoint(line, house->getTriangleSelector(), end, triangle, node))
    {
        std::cout<<"HOUSE COLLISION DETECTED ON NODE\n";
    }
    
    
    if(smgr->getSceneCollisionManager()->getCollisionPoint(line, tree->getTriangleSelector(), end, triangle, node))
    {
        std::cout<<"TREE COLLISION DETECTED ON NODE\n";
    }
 
Dreamwalker1986
Posts: 39
Joined: Tue Sep 10, 2013 2:37 pm

Re: Collision help

Post by Dreamwalker1986 »

Basically I am going to have several meshes of the same type which I need to be able to collide with and individually recognize, ie;

if(targetmesh1 hit)
do something
if(targetmeshofsametype2 hit)
do something else
Dreamwalker1986
Posts: 39
Joined: Tue Sep 10, 2013 2:37 pm

Re: Collision help

Post by Dreamwalker1986 »

Or more maybe something along these lines?

Code: Select all

 
scene::ISceneNode * house = static_cast<scene::ISceneNode*>(smgr->getSceneNodeFromId(13));
    scene::ISceneNode * tree = static_cast<scene::ISceneNode*>(smgr->getSceneNodeFromId(12));
    scene::ISceneNode *node = 0;
    
    if(house->getTriangleSelector())
        selector = smgr->createTriangleSelector(((scene::IMeshSceneNode*)house)->getMesh(), house);
    if(tree->getTriangleSelector())
        selector = smgr->createTriangleSelector(((scene::IMeshSceneNode*)tree)->getMesh(), tree);
   
    
 if(receiver.MouseState.LeftButtonDown == true)
   {
 
    //////////////SHOOT AND COLLISION//////////////////////
      
       if(smgr->getSceneCollisionManager()->getCollisionPoint(line, selector, end, triangle, node))
    {
        std::cout<<"HOUSE COLLISION DETECTED ON NODE\n";
    }
    
    
       if(smgr->getSceneCollisionManager()->getCollisionPoint(line, selector, end, triangle, node))
    {
        std::cout<<"TREE COLLISION DETECTED ON NODE\n";
    }
 
Dreamwalker1986
Posts: 39
Joined: Tue Sep 10, 2013 2:37 pm

Re: Collision help

Post by Dreamwalker1986 »

For anyone that cares, I've resolved it by creating individual selectors like so:

Code: Select all

 
//SELECTORS USED TO CHOOSE WHICH NODE IS HIT
    
    scene::ITriangleSelector* house1selector = smgr->createTriangleSelector(((scene::IMeshSceneNode*)house)->getMesh(), house);
    scene::ITriangleSelector* house2selector = smgr->createTriangleSelector(((scene::IMeshSceneNode*)house2)->getMesh(), house2);
    
   
   
    
 if(receiver.MouseState.LeftButtonDown == true)
   {
 
    //////////////SHOOT AND COLLISION//////////////////////
      
    if(smgr->getSceneCollisionManager()->getCollisionPoint(line, house1selector, end, triangle, node))
        std::cout<<"HOUSE 1 COLLISION DETECTED ON NODE\n";
    
    
    
    else if(smgr->getSceneCollisionManager()->getCollisionPoint(line, house2selector, end, triangle, node))
        std::cout<<"HOUSE 2 COLLISION DETECTED ON NODE\n";
    
 
    else
        std::cout<<"NO COLLISION DETECTED\n";
    
 
CuteAlien
Admin
Posts: 9933
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Collision help [RESOLVED]

Post by CuteAlien »

Well, you got it - but in case you want to experiment more - the idea is that node receives the result. So you do one check and then compare node against tree and house after the collision call.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Post Reply