Problem with RaySceneQuery


26-02-2009 22:23:18

I have a plane centered at the origin in my scene that is 65535 units by 65535 units. And I have the following code to find the object whose bounding box is under the mouse:

public void FindObjectUnderMouse( float MouseX, float MouseY )
Ray ray = m_Camera.GetCameraToViewportRay( MouseX, MouseY );
RaySceneQuery raySceneQuery = m_SceneMgr.CreateRayQuery( ray );
raySceneQuery.SetSortByDistance( true );
RaySceneQueryResult rayResults = raySceneQuery.Execute();

. . . where MouseX and MouseY range from 0 to 1

It works correctly most of the time . . . but there are sections of the plane, that it doesn't see (rayResults has a Count of 0). I checked the Ray . . . it seems to be correct at all points. I show the bounding box of the plane, and that is correct, too. But then when I get to certain parts of the plane, the rayResults count drops to 0, and it no longer thinks I'm over the plane.

One of my team members hypothesized that there may be clipping code that short circuits intersections that appear outside the camera frustum . . . but is it possible that the transform used for that clip is not updated, and its using an old camera frustum and short circuits the ray calculation even when I am inside the view of the 3D scene?

Has anyone else seen anything like this? Any ideas what the problem might be?


28-02-2009 02:05:06

Is there a setting for the word size/dimensions?
In Newton I had such a problem, because I forgot to set the newton world size equal to the size of terrain.
Maybe in Ogre there is something similar.

This seems to be a general question and not Mogre related. So it would be better to ask it in the main forum, because there are much more people who read it. And a better chance to get the right answer :wink:

For debugging you can draw a 3D line in the direction of your cam ray.
So you can see, if the direction is always right.
In the wiki I published a snippit how to create such a line.


01-03-2009 05:02:38

By random I found a possibly solution:


This is from here:


01-03-2009 05:10:14

oh, no so easy. Some lines more.

Port this code and try it:
AxisAlignedBox box;
Vector3 max(100000, 100000, 100000);
box.setExtents(-max, max);
sceneManager->setOption("Size", &box);

Look also to API:
* Ogre::SceneManager::setWorldGeometry
* Ogre::SceneManager::setOption


02-03-2009 18:28:00

Thanks for your help. I had done something very similar to check the camera to viewport ray. To check the object geometry, I showed the bounding box, and it is correct, so it's unlikely to be a case where I need to update the world geometry.

But I really like your idea of posting on the main Ogre forum. So, if you would like to see how it goes, the new post is here: