getscenenodeandcollisionpointfromray() return nothing

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
Jackie1234
Posts: 15
Joined: Thu Aug 18, 2011 11:50 am
Location: France

getscenenodeandcollisionpointfromray() return nothing

Post by Jackie1234 »

Hi,

I have a problem with getscenenodeandcollisionpointfromray(), this fonctio always return a null sceneNode.
I have checked that the ray what i use cross some other nodes with draw3Dline, but the fonction getscenenodeandcollisionpointfromray() don't return a node.
I want to check all the scene.

My code (take in example 7, collision)

Code: Select all

irr::scene::ISceneCollisionManager* collMan = m_scnMgr->getSceneCollisionManager();
 
irr::core::line3d<f32> ray;
irr::core::vector3df p = m_perso->getNode()->getPosition();
p.X -= 20;
                ray.start = m_perso->getNode()->getPosition();
                ray.end = p;
 
                irr::core::vector3df intersection;
                irr::core::triangle3df hitTriangle;
 
                irr::scene::ISceneNode * selectedSceneNode =
                        collMan->getSceneNodeAndCollisionPointFromRay(
                                        ray,
                                        intersection, 
                                        hitTriangle, 
                                        m_scnMgr->getRootSceneNode()->getID(), // or just 0
                                        0); 
 
if (selectedSceneNode || collMan->getSceneNodeAndCollisionPointFromRay(
                                        ray,
                                        intersection, 
                                        hitTriangle, 
                                        m_scnMgr->getRootSceneNode()->getID(), // or just 0
                                        0))
cout << "The code works !" << endl;
 
else
cout << ":-(" << endl;
 
 
My code is correct ?
Have you got an idea of the origin of the problem ?

Thank you and sorry for my poor english.
CuteAlien
Admin
Posts: 9716
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: getscenenodeandcollisionpointfromray() return nothing

Post by CuteAlien »

When using m_scnMgr->getRootSceneNode()->getID() it might not work but seeing that you wrote "or just 0" you have probably tested with 0 as well. Otherwise from what I see in the code you posted above it looks correct. So not sure where your problem is.
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
Jackie1234
Posts: 15
Joined: Thu Aug 18, 2011 11:50 am
Location: France

Re: getscenenodeandcollisionpointfromray() return nothing

Post by Jackie1234 »

Yes i have try 0.
smso
Posts: 246
Joined: Fri Jun 04, 2010 3:28 pm
Location: Hong Kong

Re: getscenenodeandcollisionpointfromray() return nothing

Post by smso »

My guess is something wrong with:

Code: Select all

ray.end = p;
try:

Code: Select all

p.X -= 2000.0f; // or higher
...
ray.end = p;
blAaarg
Posts: 94
Joined: Tue Mar 02, 2010 9:11 pm
Location: SoCal

Re: getscenenodeandcollisionpointfromray() return nothing

Post by blAaarg »

Yes, as CuteAlien pointed out, you have your last two parameters swapped when you call "getSceneNodeAndCollisionPointFromRay()". Also, each node that you test against has to have a triangle selector set for it or that method ("getSceneNodeAndCollisionPointFromRay()") won't work for that node.

Use the scene manager to createTriangleSelector() for the node and then call setTriangleSelector(). According to the documentation:
Some nodes may create their own selector by default, so it would be good to check if there is already a selector in this node by calling ISceneNode::getTriangleSelector().
In which case, I don't know, you have some other problem.


Also, as smso pointed out, your test numbers seem obscure and might not actually be making a collision, but that's hard to tell with what you have shown, so maybe that part is okay. :?:
"Computers don't make mistakes! What they do they do on purpose!!"

-Dale Gribble
Jackie1234
Posts: 15
Joined: Thu Aug 18, 2011 11:50 am
Location: France

Re: getscenenodeandcollisionpointfromray() return nothing

Post by Jackie1234 »

Also, each node that you test against has to have a triangle selector set for it or that method ("getSceneNodeAndCollisionPointFromRay()") won't work for that node.
Is it possible that my code don't work because I have ->drop(); my selectors and metaselectors ?
smso
Posts: 246
Joined: Fri Jun 04, 2010 3:28 pm
Location: Hong Kong

Re: getscenenodeandcollisionpointfromray() return nothing

Post by smso »

Have you set up the triangle selector?

Regards from
smso
Jackie1234
Posts: 15
Joined: Thu Aug 18, 2011 11:50 am
Location: France

Re: getscenenodeandcollisionpointfromray() return nothing

Post by Jackie1234 »

Yes.
But I shouldn't drop them ?
smso
Posts: 246
Joined: Fri Jun 04, 2010 3:28 pm
Location: Hong Kong

Re: getscenenodeandcollisionpointfromray() return nothing

Post by smso »

Jackie1234 wrote:Yes.
But I shouldn't drop them ?
Just try!

Regards
smso
serengeor
Posts: 1712
Joined: Tue Jan 13, 2009 7:34 pm
Location: Lithuania

Re: getscenenodeandcollisionpointfromray() return nothing

Post by serengeor »

Jackie1234 wrote:Yes.
But I shouldn't drop them ?
You should drop them after you attach them to nodes, as you need to decrease the reference counter.
Working on game: Marrbles (Currently stopped).
Jackie1234
Posts: 15
Joined: Thu Aug 18, 2011 11:50 am
Location: France

Re: getscenenodeandcollisionpointfromray() return nothing

Post by Jackie1234 »

Use the scene manager to createTriangleSelector() for the node and then call setTriangleSelector(). According to the documentation:
I'm a noob, I hadn't use setTriangleSelector !
It works very well, happy ! :D
Thank you :D
Post Reply