Page 2 of 3

Re: getSceneNodeAndCollisionPointFromRay works awfully

Posted: Sat Feb 20, 2016 10:10 am
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.

Re: getSceneNodeAndCollisionPointFromRay works awfully

Posted: Mon Feb 22, 2016 7:33 am
by AlexAzazel
I changed createTriangleSelector() with createTriangleSelectorFromBoundingBox(node); and it works fine now.

Re: getSceneNodeAndCollisionPointFromRay works awfully

Posted: Mon Feb 22, 2016 9:31 am
by kormoran
Hmm... mesh triangles too small to be collided? Good to know however :)

Re: getSceneNodeAndCollisionPointFromRay works awfully

Posted: Mon Feb 22, 2016 11:27 am
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.

Re: getSceneNodeAndCollisionPointFromRay works awfully

Posted: Tue Feb 23, 2016 6:30 pm
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?

Re: getSceneNodeAndCollisionPointFromRay works awfully

Posted: Wed Feb 24, 2016 6:55 pm
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.

Re: getSceneNodeAndCollisionPointFromRay works awfully

Posted: Thu Feb 25, 2016 12:18 pm
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... :|

Re: getSceneNodeAndCollisionPointFromRay works awfully

Posted: Thu Feb 25, 2016 12:36 pm
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

Re: getSceneNodeAndCollisionPointFromRay works awfully

Posted: Thu Feb 25, 2016 1:11 pm
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. :)

Re: getSceneNodeAndCollisionPointFromRay works awfully

Posted: Thu Feb 25, 2016 1:42 pm
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)

Re: getSceneNodeAndCollisionPointFromRay works awfully

Posted: Thu Feb 25, 2016 2:01 pm
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 ;)

Re: getSceneNodeAndCollisionPointFromRay works awfully

Posted: Thu Feb 25, 2016 3:15 pm
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?

Re: getSceneNodeAndCollisionPointFromRay works awfully

Posted: Thu Feb 25, 2016 3:33 pm
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;
}
 

Re: getSceneNodeAndCollisionPointFromRay works awfully

Posted: Thu Feb 25, 2016 10:03 pm
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...

Re: getSceneNodeAndCollisionPointFromRay works awfully

Posted: Fri Feb 26, 2016 8:53 am
by hendu
The frustum length, and thus far corners, is determined by farValue.