getRayFromScreenCoordinates problem
-
blackMasoon
- Posts: 149
- Joined: Wed Sep 09, 2009 4:57 pm
- Contact:
getRayFromScreenCoordinates problem
Hello. I have a serious problem with that method with getting ray from screen coordinates. I passed the right 2d pos and an active camera, but it casts the ray in a completely different place in the scene. And the start point is not the camera position... One important thing is.. that the scene is beeing drawn in a different viewport. But setting it also for calculating the ray does not take an effect. I also draw the 2d pos on screen to make sure if it's right... and it is... So what may be a problem here?
Re: getRayFromScreenCoordinates problem
Can you try with latest svn-trunk version? I changed something in getRayFromScreenCoordinates a few days ago in a similar problem when using renderToTarget.
edit: Hm, forget it - I changed getScreenCoordinatesFrom3DPosition not getRayFromScreenCoordinates :-(
edit: Hm, forget it - I changed getScreenCoordinatesFrom3DPosition not getRayFromScreenCoordinates :-(
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
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
-
blackMasoon
- Posts: 149
- Joined: Wed Sep 09, 2009 4:57 pm
- Contact:
Re: getRayFromScreenCoordinates problem
The problem looks like it doesn't take the right camera position to start the ray from. And the camera with it's position is initialized for sure before using that method...
Here is the code:
And in the run loop i modify viewport before drawing the scene like this:
Here is the code:
Code: Select all
scene::IMeshSceneNode *surface = smgr->addCubeSceneNode(100,0,999,core::vector3df(0,-0.4,0), core::vector3df(0,0,0), core::vector3df(10,0.001,10));
core::array<scene::IMeshSceneNode*> car_box;
core::line3df temp_ray;
core::vector3df collisionPoint3D; // globalny punkt kolizjii
core::triangle3df collisionTriangle; // globalny trójkąt kolizjii
const scene::ISceneNode *hitNode;
scene::ITriangleSelector * selector;
selector = smgr->createTriangleSelector(surface->getMesh(), surface);
for(int i = 0; i <number_of_cars; ++i)
{
for(int j = 0; j < car[i].pos.size() ; ++j)
{
temp_ray = smgr->getSceneCollisionManager()->getRayFromScreenCoordinates(car[i].pos[j], smgr->getActiveCamera());
smgr->getSceneCollisionManager()->getCollisionPoint(temp_ray, selector, collisionPoint3D, collisionTriangle, hitNode);
collisionPoint3D.Y = 0.2f;
car[i].pos3d.push_back(collisionPoint3D);
}
car_box.push_back(smgr->addCubeSceneNode(0.1,0,i,car[i].pos3d[0]));
}
Code: Select all
driver->setViewPort(core::rect<s32>(10,230,556,660));
Last edited by blackMasoon on Fri Aug 05, 2011 11:18 am, edited 1 time in total.
Re: getRayFromScreenCoordinates problem
It uses the viewport set in the driver. Maybe it is not set at that moment?
Maybe just copy CSceneCollisionManager::getRayFromScreenCoordinates and adapt it to you needs.
Maybe just copy CSceneCollisionManager::getRayFromScreenCoordinates and adapt it to you needs.
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
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
-
blackMasoon
- Posts: 149
- Joined: Wed Sep 09, 2009 4:57 pm
- Contact:
Re: getRayFromScreenCoordinates problem
Ok... so I took the method code from SVN and mofified:
to:
And now everything seems to be ok... but there's one thing wrong... it all casts the ray like the whole scene was rotated by 45 deg in Y axis... Why is this happening?
Here's a preview:

Code: Select all
if (camera->isOrthogonal())
ln.start = f->cameraPosition + (lefttoright * (dx-0.5f)) + (uptodown * (dy-0.5f));
else
ln.start =f->cameraPosition;
Code: Select all
if (camera->isOrthogonal())
ln.start = camera->getPosition() + (lefttoright * (dx-0.5f)) + (uptodown * (dy-0.5f));
else
ln.start =camera->getPosition();
Here's a preview:
