raySceneQueryResult.execute() not working

som

29-07-2008 13:06:29

hi guys...
try
{
//mRaySceneQuery = sceneMgr.CreateRayQuery(new Ray());
// Setup the ray scene query
Ray mouseRay = sceneManager.CameraManager.GetCamera.GetCameraToViewportRay(XAbs / (float)sceneManager.CameraManager.GetViewport.ActualWidth,
YAbs / (float)sceneManager.CameraManager.GetViewport.ActualHeight);

//mRaySceneQuery.Ray = mouseRay;
RaySceneQuery mRaySceneQuery = sceneMgr.CreateRayQuery(mouseRay);
mRaySceneQuery.SetSortByDistance(true);
// Execute query
mRaySceneQuery.Execute();
RaySceneQueryResult result = mRaySceneQuery.GetLastResults();

for (int i = 0; i < result.Count; i++)
{
if ((result[i].movable != null) && (result[i].movable.MovableType.CompareTo("Entity") == 0)
&& (result[i].movable.QueryFlags == (uint)QueryMask.ENTITY_MASK))
{
if (mEntity != (Entity)result[i].movable)
{
mCurrentObject = result[i].movable.ParentSceneNode;
mEntity = (Entity)result[i].movable;
break;
}
}
}
}
catch (System.Exception e)
{
MessageBox.Show(e.Message);
}


m using this code to achieve mouse picking..
when i'm clicking on any object in the scene, raySceneQueryResult shows a system.exception for the Back & Front properties of it.
This results in no picking as result.count = 0..
guys can any one give me a solution..

Thanx as alwayz... :) :) :) :)

Mephs

29-07-2008 15:02:17

I'm having a similar problem, anyone have a clue? =S

http://www.ogre3d.org/phpBB2/viewtopic.php?t=43232

Mephs

30-07-2008 04:30:35

I figured it out!

This may or may not be the same solution, but this whole time I was trying to render this grid to the map... WHEN THE MAP HADNT EVEN BEEN RENDERED YET /forehead.

Solution:

Call Root.RenderOneFrame(), then your first RayQuery. Once there's things rendered on the map you can query them with rays, if you do it before there's anything to query, apparently it says NO and gives you those null pointers.

som

30-07-2008 06:33:49

thanx mephs for ur solution..

But i still face the same problem and one thing before this function get called,
i am starting with the root.renderOneFrame()..

So i think this is not the exact problem with me..
I dont understand , when i am trying it in a test project it works..

But one thing i noticed is that when i am clicking on the viewport far away from the object,it gives the same type of exception in the test project also..

Anybody..any clue to that.. :? :? :? :? :? :? :? :? :? :? :? :? :? :? :? :( :( :( :( :( :( :( :( :( :( :(

som

31-07-2008 13:36:44

guys to bring to everyones notice,
m facing the same problem when i am doing a volume query...
is it some thing related sceneManager, then m using the general one.

any one ......
thanks.. :? :?

Nexam

09-08-2008 19:28:04

same problem for me...

Solution somewhere ?

Beauty

13-08-2008 23:23:59

I'm tired, drunken and can't use my brain very much.
It is possible that you get NULL results if nothing was hit by ray.

Here are some links. I'm not shure if this helps, but maybe.

www.ogre3d.org/wiki/index.php/MOGRE_MousePickingExample

www.ogre3d.org/wiki/index.php/RayTracing_with_MOGRE
(This is my code. It use it with TerrainSceneManager and I had no problem.)

www.ogre3d.org/wiki/index.php/RayTracin ... s_in_MOGRE
(On newer pictures I added the result var type. I forgot to upload them)

Anngel

10-09-2012 22:04:27

Hi, guys.
The way you using ray is correct for Terrain Scene Manager, i.e. for OGRE version less then 1.8.
You probably use new version of terrain, so you should search for result in Ogre::TerrainGroup::RayResult. Just look through the example:

CEGUI::Point mousePos = CEGUI::MouseCursor::getSingleton().getPosition();
Ogre::Ray mouseRay = mCamera->getCameraToViewportRay(mousePos.d_x/float(evt.state.width), mousePos.d_y/float(evt.state.height));

Ogre::TerrainGroup::RayResult RayResult = mTerrainGroup->rayIntersects( mouseRay );
if( RayResult.hit )
{
//your code
}


Hope it will help.

Spesial thanks for hoppelmoppel who helped me to solve this problem.
http://www.ogre3d.org/forums/viewtopic.php?f=2&t=67556

RcALTIN

11-09-2012 02:48:28

i'm using this to getting terrain height with TSM :

Mogre.Vector3 cp = new Mogre.Vector3(10, 0, 10); //y = will calculated height from terrain at x=10,z=10 point
RaySceneQuery rsq = sceneMgr.CreateRayQuery(new Ray());
Ray ray = new Ray(new Mogre.Vector3(cp.x, 10000, cp.z), Mogre.Vector3.NEGATIVE_UNIT_Y); //if max point of terrain above than 10000
rsq.Ray = ray;
RaySceneQueryResult res = rsq.Execute();
RaySceneQueryResult.Iterator itr = res.Begin();
if (itr != res.End())
cp = ray.GetPoint(itr.Value.distance)); // y is calculated now

Beauty

27-10-2012 19:05:49

One ray query can have several results. So often it's needed to use a loop to check them all (or break if you found the wanted result).

To query the terrain of the TerrainSceneManager, you should loop until you find the RaySceneQueryResultEntry, where the property worldFragment is not null.

In the wiki I published some ray query code for Mogre. There you can see how it works:
http://www.ogre3d.org/tikiwiki/tiki-ind ... with+MOGRE