getSceneNodeAndCollisionPointFromRay works awfully

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.
AlexAzazel
Posts: 31
Joined: Sun Jan 10, 2016 3:42 pm
Location: Tbilisi

Re: getSceneNodeAndCollisionPointFromRay works awfully

Post by AlexAzazel »

kormoran wrote:On the trivial side, have you set up triangle selectors for all of your objects? Without them, getSceneNodeAnd... returns NULL.
Some nodes create automatically a selector, some doesn't, so check this out :!:
If you mean

Code: Select all

scene::ITriangleSelector* selector = smgr->createTriangleSelector(node);
node->setTriangleSelector(selector);
selector->drop();
Sure. It wouldn't have worked at all without this. My problem here was that it only sometimes fails to work and I have to click on other parts of the node or change the camera angle and then it works.
AlexAzazel
Posts: 31
Joined: Sun Jan 10, 2016 3:42 pm
Location: Tbilisi

Re: getSceneNodeAndCollisionPointFromRay works awfully

Post by AlexAzazel »

I changed createTriangleSelector() with createTriangleSelectorFromBoundingBox(node); and it works fine now.
kormoran
Posts: 47
Joined: Mon Dec 28, 2015 4:50 pm
Location: Tolentino

Re: getSceneNodeAndCollisionPointFromRay works awfully

Post by kormoran »

Hmm... mesh triangles too small to be collided? Good to know however :)
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: getSceneNodeAndCollisionPointFromRay works awfully

Post by CuteAlien »

OK, glad it works now. I didn't get to look on it this weekend. Size of triangles shouldn't really be a problem. Basically in this kind of problems to debug it I'd have to start reducing it until I have a test-case with a single-line and triangle which should hit but don't.
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
kormoran
Posts: 47
Joined: Mon Dec 28, 2015 4:50 pm
Location: Tolentino

Re: getSceneNodeAndCollisionPointFromRay works awfully

Post by kormoran »

Hmm... if it's not a problem of tiny triangles, why alexazazel had troubles with selection until he changed function?
Doesn't this means there is a bug lurking somewhere in the get... function?
AlexAzazel
Posts: 31
Joined: Sun Jan 10, 2016 3:42 pm
Location: Tbilisi

Re: getSceneNodeAndCollisionPointFromRay works awfully

Post by AlexAzazel »

kormoran wrote:Hmm... mesh triangles too small to be collided? Good to know however :)
I doubt that's the case, upper part of the mesh (ceiling of the tank) is really big and flat square and very often I couldn't click on it either even when camera was really close. I assume this might be a bug. At least it looks like one.
kormoran
Posts: 47
Joined: Mon Dec 28, 2015 4:50 pm
Location: Tolentino

Re: getSceneNodeAndCollisionPointFromRay works awfully

Post by kormoran »

I just modified the example win32window, stopping the cam, adding a triangle selector to the cube and trying to select & rotate the cube itself by clicking on it: nothing. Can't select the cube... :|
thanhle
Posts: 325
Joined: Wed Jun 12, 2013 8:09 am

Re: getSceneNodeAndCollisionPointFromRay works awfully

Post by thanhle »

For windows in panel or surface, you have to recompute the mouse position.
Recommend searching both of the help forums.

I don't get a problem with selection when I work in QT and .Net forms with Irrlicht previously.

Also there is one example related to mouse hitting triangle on a animated mesh. That might be relevant here for high precision selection.

Regards
lumlum
Posts: 13
Joined: Mon Dec 21, 2015 10:34 am

Re: getSceneNodeAndCollisionPointFromRay works awfully

Post by lumlum »

I haven't read the full thread but as far as I'm concerned I encountered a similar issue a few weeks ago and it was caused by the fact that the farValue of my camera was too big which caused getRayFromScreenCoordinates() to be imprecise and resulted in a bad node selection. Just saying since it might help someone who comes by that thread with that issue. :)
kormoran
Posts: 47
Joined: Mon Dec 28, 2015 4:50 pm
Location: Tolentino

Re: getSceneNodeAndCollisionPointFromRay works awfully

Post by kormoran »

lumlum wrote:the farValue of my camera was too big
How big was "too big"? How much did you set it? (default = 2000)
lumlum
Posts: 13
Joined: Mon Dec 21, 2015 10:34 am

Re: getSceneNodeAndCollisionPointFromRay works awfully

Post by lumlum »

I'm not sure but if I remember correctly there was a significant difference between the drawn ray and my cursor's position at pretty big values like 1000000+, it can easily be tested with the draw3DLine function if you want.
I just wanted to say it because one might think "i'm going to set a big farValue so I won't have to bother about it" then end up with a RayCast issue and can't understand where it comes from until he thinks about what's actually behind the function, which is what happened to me when I was doing some tests ;)
kormoran
Posts: 47
Joined: Mon Dec 28, 2015 4:50 pm
Location: Tolentino

Re: getSceneNodeAndCollisionPointFromRay works awfully

Post by kormoran »

This is interesting. The camera's FarValue shouldn't matter at all for ray calculations... hmmm... maybe the FOV comes in the way?
lumlum
Posts: 13
Joined: Mon Dec 21, 2015 10:34 am

Re: getSceneNodeAndCollisionPointFromRay works awfully

Post by lumlum »

Yes it does use the view frustum to make a 3d ray from your screen coordinates, and thus the FarValue of the camera, here is the function's code :

Code: Select all

core::line3d<f32> CSceneCollisionManager::getRayFromScreenCoordinates(
    const core::position2d<s32> & pos, ICameraSceneNode* camera)
{
    core::line3d<f32> ln(0,0,0,0,0,0);
 
    if (!SceneManager)
        return ln;
 
    if (!camera)
        camera = SceneManager->getActiveCamera();
 
    if (!camera)
        return ln;
 
    const scene::SViewFrustum* f = camera->getViewFrustum();
 
    core::vector3df farLeftUp = f->getFarLeftUp();
    core::vector3df lefttoright = f->getFarRightUp() - farLeftUp;
    core::vector3df uptodown = f->getFarLeftDown() - farLeftUp;
 
    const core::rect<s32>& viewPort = Driver->getViewPort();
    core::dimension2d<u32> screenSize(viewPort.getWidth(), viewPort.getHeight());
 
    f32 dx = pos.X / (f32)screenSize.Width;
    f32 dy = pos.Y / (f32)screenSize.Height;
 
    if (camera->isOrthogonal())
        ln.start = f->cameraPosition + (lefttoright * (dx-0.5f)) + (uptodown * (dy-0.5f));
    else
        ln.start = f->cameraPosition;
 
    ln.end = farLeftUp + (lefttoright * dx) + (uptodown * dy);
 
    return ln;
}
 
kormoran
Posts: 47
Joined: Mon Dec 28, 2015 4:50 pm
Location: Tolentino

Re: getSceneNodeAndCollisionPointFromRay works awfully

Post by kormoran »

No, it does not. The ray is calculated from mouse position and far frustum corners. The farValue is not taken into account, at least not directly. It's used to calculate the transform matrix...
hendu
Posts: 2600
Joined: Sat Dec 18, 2010 12:53 pm

Re: getSceneNodeAndCollisionPointFromRay works awfully

Post by hendu »

The frustum length, and thus far corners, is determined by farValue.
Post Reply