krinberry
22-12-2006 15:16:43
Hey there folks. I posted this in the main Help originally which was the wrong place, apologies to anyone this annoyed! Won't happen again. Anyways, here's the info as I posted it previously:
I've been playing around with Ogre (specifically, the Mogre SDK) and while I've found almost everything incredibly well designed and easy to use, I've run into a bit of trouble with ray queries, mainly due to my own unfamiliarity with how rays work in general. There's no tutorial on the subject for Mogre, and while there are plenty of C++ etc examples that I thought I had more-or-less converted properly for use in C#, I'm getting no love in response when I try to use them. Does anyone have any examples of ray queries in Mogre that I could perhaps take a look at? It doesn't have to be anything fancy, just something to show me the basics.
Any help at all, or even just pointing me to a good resource, would be very much appreciated. Thanks in advance!
Here's the code info from what I've been working with:
Based on posts I've read here in the forums I've tried a few different ways of handling the X and Y values from the event handler; the following are a few of the different ways I've tried (unsuccessfully):
also:
I'm not certain precisely what's wrong, to be honest; the code I used as the primary basis for most of this is from the tutorial here http://www.ogre3d.org/wiki/index.php/In ... Tutorial_3 on the site, specifically:
At any rate the loop through the iRay contents never fires, and as far as I can tell the ray always seems to original from the initial camera position regardless of any changes to its position or orientation, and doesn't seem to even act as if it was pointing towards where I'd expect it to if the camera was at its initial position.
Sorry if there's anything obviously wrong about my attempts here; the loop right now is just set to give me a messagebox, as I wanted to see a positive result before I got any further into it.
I've been playing around with Ogre (specifically, the Mogre SDK) and while I've found almost everything incredibly well designed and easy to use, I've run into a bit of trouble with ray queries, mainly due to my own unfamiliarity with how rays work in general. There's no tutorial on the subject for Mogre, and while there are plenty of C++ etc examples that I thought I had more-or-less converted properly for use in C#, I'm getting no love in response when I try to use them. Does anyone have any examples of ray queries in Mogre that I could perhaps take a look at? It doesn't have to be anything fancy, just something to show me the basics.
Any help at all, or even just pointing me to a good resource, would be very much appreciated. Thanks in advance!
Here's the code info from what I've been working with:
void MouseDownHandler(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
float mX = (float)e.X / camX; // camX contains the width of the viewport
float mY = (float)e.Y / camY; // camY contains the height of the viewport
RaySceneQuery raySceneQuery = mgr.CreateRayQuery(new Ray());
raySceneQuery.Ray = cam.GetCameraToViewportRay(mX,mY);
raySceneQuery.SetSortByDistance(true);
raySceneQuery.Execute();
RaySceneQueryResult r = raySceneQuery.GetLastResults();
RaySceneQueryResult.Iterator iRay;
for (iRay = r.Begin(); iRay != r.End(); iRay++)
{
MessageBox.Show("Found Something");
}
raySceneQuery.Dispose();
}
}
Based on posts I've read here in the forums I've tried a few different ways of handling the X and Y values from the event handler; the following are a few of the different ways I've tried (unsuccessfully):
float mX = (((float)e.X) / camX) - 0.5f;
float mY = 1f - ((((float)e.Y) / camY) + 0.5f);
also:
float mx = (float)e.X;
float my = (float)e.Y;
I'm not certain precisely what's wrong, to be honest; the code I used as the primary basis for most of this is from the tutorial here http://www.ogre3d.org/wiki/index.php/In ... Tutorial_3 on the site, specifically:
virtual void onLeftPressed( MouseEvent *e )
{
// Setup the ray scene query
Ray mouseRay = mCamera->getCameraToViewportRay( e->getX(), e->getY() );
mRaySceneQuery->setRay( mouseRay );
// Execute query
RaySceneQueryResult &result = mRaySceneQuery->execute();
RaySceneQueryResult::iterator itr = result.begin( );
// Get results, create a node/entity on the position
if ( itr != result.end() && itr->worldFragment )
{
char name[16];
sprintf( name, "Robot%d", mCount++ );
Entity *ent = mSceneMgr->createEntity( name, "robot.mesh" );
mCurrentObject = mSceneMgr->getRootSceneNode( )->createChildSceneNode( String(name) + "Node", itr->worldFragment->singleIntersection );
mCurrentObject->attachObject( ent );
mCurrentObject->setScale( 0.1f, 0.1f, 0.1f );
} // if
}
At any rate the loop through the iRay contents never fires, and as far as I can tell the ray always seems to original from the initial camera position regardless of any changes to its position or orientation, and doesn't seem to even act as if it was pointing towards where I'd expect it to if the camera was at its initial position.
Sorry if there's anything obviously wrong about my attempts here; the loop right now is just set to give me a messagebox, as I wanted to see a positive result before I got any further into it.