mouseray = smgr->getSceneCollisionManager()

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
le2015
Posts: 6
Joined: Fri Jan 24, 2025 4:55 am

mouseray = smgr->getSceneCollisionManager()

Post by le2015 »

Thank you, the problem is solved)
Last edited by le2015 on Wed Apr 09, 2025 11:00 pm, edited 1 time in total.
CuteAlien
Admin
Posts: 9926
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: mouseray = smgr->getSceneCollisionManager()

Post by CuteAlien »

It's definitely not random. As Irrlicht is opensource you can directly look at the function (CSceneCollisionManager::getRayFromScreenCoordinates), it's pretty short and you can see yourself the calculation. Basically it's the corresponding point of the far-plane of the view frustum.

If this goes wrong the reason is likely in the surrounding code. Try to make a short example so I can reproduce it, then I can help more.
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
le2015
Posts: 6
Joined: Fri Jan 24, 2025 4:55 am

Re: mouseray = smgr->getSceneCollisionManager()

Post by le2015 »

the problem is solved)
Last edited by le2015 on Wed Apr 09, 2025 11:00 pm, edited 1 time in total.
CuteAlien
Admin
Posts: 9926
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: mouseray = smgr->getSceneCollisionManager()

Post by CuteAlien »

Sorry, I have no idea what you mean with "good". I need a real example. How do you _know_ it's good or bad?

Note that drawing that line is tricky - because it starts exactly at the center of the camera and then goes along the view-line. So if you draw it - you only get a point. It's like if you have straight line connected from one eye to any point in your room. You can't see that line itself then with that eye!

You can for example draw from the start of the center of the near-plane instead. Thought it's confusing as you lose perspective (looks just like a 2d line). But you would get that with:

Code: Select all

const scene::SViewFrustum* frustum = camera->getViewFrustum();
ray.start = frustum->getNearLeftUp() + (frustum->getNearRightDown()-frustum->getNearLeftUp())*0.5f;
Or you can draw from the point of a weapon or hand or so to the end. That will also work. Thought you better use a real 3d object which gets perspective drawing for that.

But to show you get the correct ray you can modify the ray calculation in example 07 with this code (will more or less give the same result as old one):
ray = collMan->getRayFromScreenCoordinates( device->getCursorControl()->getPosition() );
You will still get the correct collisions.
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
le2015
Posts: 6
Joined: Fri Jan 24, 2025 4:55 am

Re: mouseray = smgr->getSceneCollisionManager()

Post by le2015 »

Thank you, the problem is solved)
Last edited by le2015 on Wed Apr 09, 2025 10:59 pm, edited 1 time in total.
le2015
Posts: 6
Joined: Fri Jan 24, 2025 4:55 am

Re: mouseray = smgr->getSceneCollisionManager()

Post by le2015 »

Thank you, the problem is solved)
Post Reply