problem with mousepicking.


30-09-2008 13:55:10

Hi all.

i use rays to pick objects in the 3d scene and also update the position on the field\plane where i got my cursor. it works perfecly as long i i keep the camera close to the origo(0,0,0) it seems. when i move away further than +-(20000,0,20000) the cameraray hits like a dead zone.. i mean that most of the places where i click on the field the rayquery is empty. except from center around origo(0,0,0).

the scene is a empty 3d space with a field thats made of a plane.mesh. more like a beginning of an editor.

from a 2d viewpoint:
when the camera is inside the red box i can update the fieldposition and pick an object i want on the field.


when im outside of this "area" the raypick returns 0 hits on the field. its only has a "working area" around the origo.

code i am using.

float scrx = (float)e.X / Viewport.ActualWidth;
float scry = (float)e.Y / Viewport.ActualHeight;

Ray ray = mCamera.GetCameraToViewportRay(scrx, scry);

RaySceneQuery query = mSceneMgr.CreateRayQuery(ray);

RaySceneQueryResult result;
result = query.Execute();
itr = result.Begin();

has anybody seen anything like this?




02-10-2008 07:14:50



02-10-2008 10:44:16

I had a similar problem yesterday, which may be different to what you're observing, but may be of use to you. A shortened version of what I do is:

When you iterate through your scene query results:

foreach (RaySceneQueryResultEntry result in results) {
if(result.movable != null && (result.movable as Entity)!=null)
//Then it's a valid result



The second condition seems to get rid of something that is selected when I'm far out. I don't really know why it works / what is being detected though.

The first condition may or may not be right for you (if you are selecting terrain, it probably isn't movable for instance)

The OgreDotNet Intermediate Tutorial 2 C# code for MOGRE has a functon IsAccurateHit(...) that might be worth looking at.


02-10-2008 11:51:08

Just an idea:
If you use a TerrainSceneManager maybe it depents to its BoundingBox?
I don't know if in Ogre scene a world size is defined, but with Newton physics I had problems, because I forgot to set the right world size.

If you don't get an answer here in Mogre forum (only a few active users) then ask in Ogre main forum. This is a generally Ogre question (not only Mogre related). So there are much more people who could answer :wink:


02-10-2008 12:03:50

For a ray you need a startPosition and a direction.
Are you shure that you set correct values?
For testing purpose you can set them manually instead of GetCameraToViewportRay().

Also check if the ray result of GetCameraToViewportRay() is right.
Print the values of ray.Direction and ray.Origin.
Maybe there is something wrong.

In the wiki I wrote something about rays. Maybe there is something useful for you:


09-10-2008 08:53:38

Thanks guys! im going to try this at once. :)