//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);
// Execute query
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;
catch (System.Exception e)
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...
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.
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.
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 ......
same problem for me...
Solution somewhere ?
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 )
Hope it will help.
Spesial thanks for hoppelmoppel who helped me to solve this problem.
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
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: