RaySceneQuery doesn't work..

travelan

20-07-2006 12:04:38

Hi all!

I have a problem with RaySceneQuery. This is my code:
Ray mouseRay = VP.mCamera1.GetCameraToViewportRay(e.X, e.Y);
VP.mRaySceneQuery.setRay(mouseRay);

RaySceneQueryResult result = VP.mRaySceneQuery.execute();
RaySceneQueryResult.RaySceneQueryResultEnumerator itr = result.GetEnumerator();

if (itr.MoveNext())
{
VP.mCurrentObject.SetPosition(itr.Current.getWorldFragment().getSingleIntersection());
}


itr.MoveNext() is returning false at all times... I think I'm missing something very stupid.

Peace,

Trav

rastaman

20-07-2006 15:34:33

search works :lol:
http://www.ogre3d.org/phpBB2addons/viewtopic.php?t=1070&highlight=getcameratoviewportray

travelan

21-07-2006 10:26:18

Thanks, I didn't understand how to use rayscenequeries by picking in a WinForms control.
For others with the same problem, this post by Mwr helped me out:
if you aren't using the OgreDotNet event handlers, but are using a mouse click event on a windows form panel then the e.X and e.Y are returning int values while the GetCameraToViewportRay is expecting floats in the range [0,1].

so you need to divide the e.X and e.Y values by the size of your viewport/panel.

The following code is a example where the panel/viewport is 800x600 (you should really use the properties of the panel to find its size though rather than hard code them like here.

Ray mouseray=appl.camera.GetCameraToViewportRay((float) e.X/800,(float)e.Y/600);
appl.mRayQuery.setRay(mouseray);
RaySceneQueryResult result = appl.mRayQuery.execute();


Thanks again,

Trav