Ray Query Result way off? [BUG] SOLVED

alex_dergian

06-11-2006 22:25:10

Im not sure why but when i do a mouse ray on the terrain it sends back a posstion that is very off i hcecked the objects and it is not them it is the ray, it dose set the y correcly but the x and z are way off here is the code i use for the deleration and creating of the ray Query system
mRaySceneQuery = mScene->createRayQuery( Ogre::Ray() );
Ogre::String scene = Aero::staticFunction::getOption("currentScene", mOptionAddress );
if( scene == Ogre::String("terrain") || scene == Ogre::String("inside"))
{
mRaySceneQuery->setQueryTypeMask(Ogre::SceneManager::WORLD_GEOMETRY_TYPE_MASK );
mRaySceneQuery->setWorldFragmentType(Ogre::SceneQuery::WFT_SINGLE_INTERSECTION);
}

So it casts only on terrain type worlds and i belive the other stuff i got from another post i wanted to test as much as a could before posting a question.
Anyways then i call the ray like so
if( mCState->mSceneReady == true )
{
Ogre::Ray mouseRay = mAeroCamera->ray( e->getRelX(), e->getRelY() );
mCState->editObjectMap()->getObjectRay()->setRay( mouseRay );
// Execute query
Ogre::RaySceneQueryResult &result = mCState->editObjectMap()->getObjectRay()->execute();
Ogre::RaySceneQueryResult::iterator itr = result.begin( );

// Get results, move the player to the possition
if ( itr != result.end() && itr->worldFragment )
{
//Create test at point

//mPlayer->setMovePoint(itr->worldFragment->singleIntersection);
mCState->editObjectMap()->addObject("folaige_tree_treetest", itr->worldFragment->singleIntersection);
}
}

I would tell you how far off the system is but i never know where my mouse is and the placment is more random then consistant, i guess with the resualts i could feed the random seed generater for some intresting resulats but i would rather have a working ray system.
Thanks in advance!

alex_dergian

13-11-2006 20:28:51

I donwloaded the latist CVS compiled and patched but im still gitting the same issue has anyone else had this issue and is there a fix along the way? Or is my code just off?

alex_dergian

14-11-2006 17:39:46

Ireceived a e-mail from an unknown source that subjested to change the code in the plsm2 as follows

[in OgrePagingLandScapeTile.cpp]

(line 403)
const Real invScaledDirZ = dir.x * invScale.z;

to

const Real invScaledDirZ = dir.z * invScale.z;

(line 405)
Real invScaledRayZ = (ray.x * invScale.z) - data->getShiftZ ();

to

Real invScaledRayZ = (ray.z * invScale.z) - data->getShiftZ ();


Along with some of my own code changes as follows

Framelistener
Ogre::Ray mouseRay = mAeroCamera->ray( e->getRelX(), e->getRelY() );
mCState->editObjectMap()->getObjectRay()->setRay( mouseRay );
// Execute query
Ogre::String scene = Aero::staticFunction::getOption("currentScene", mCState->getOptionAddress() );
if( scene == Ogre::String("terrain") || scene == Ogre::String("inside"))
{
mCState->editObjectMap()->getObjectRay()->setQueryTypeMask(Ogre::SceneManager::WORLD_GEOMETRY_TYPE_MASK );
mCState->editObjectMap()->getObjectRay()->setWorldFragmentType(Ogre::SceneQuery::WFT_SINGLE_INTERSECTION);
}
Ogre::RaySceneQueryResult &result = mCState->editObjectMap()->getObjectRay()->execute();
Ogre::RaySceneQueryResult::iterator itr = result.begin( );

// Get results, move the player to the possition
if ( itr != result.end() && itr->worldFragment )
{
//Create test at point

//mPlayer->setMovePoint(itr->worldFragment->singleIntersection);
mCState->editObjectMap()->addObject("folaige_tree_oakBase", itr->worldFragment->singleIntersection);
}

Cam ray function
Ogre::Ray clsAeroCam::ray(Ogre::Real X, Ogre::Real Y)
{
return mInputCam->getCameraToViewportRay( X, Y );
}

Ray constuced function

clsAeroObject::clsAeroObject(Ogre::SceneManager *currentScene, std::vector<Aero::objOptions> *options, std::vector<objAeroObjectQue> *que)
{
mOptionAddress = options;
mObjectQue = que;
mScene = currentScene;
mRaySceneQuery = mScene->createRayQuery( Ogre::Ray() );
Ogre::String scene = Aero::staticFunction::getOption("currentScene", mOptionAddress );
}


The line mCState->editObjectMap()->getObjectRay() gets the ray pointer from the above class constructer the ray is still casting nowhere near my terrain click, i have it creating objects to the point and the objects appear behind sometimes to the side but never in the spot i click, one thing i my note is i change the cam direction with the player but would this offset the ray? I don't think that i would but figured i would include that
Thanks in advance

kartweel

26-12-2006 14:32:02

I'm having the same problem and can't seem to work around it. Have you come across any alternative methods we can try to achieve the same thing?

alex_dergian

13-02-2007 18:05:13

First using the e->getRelX was need to be replaced with e->getX cause using the rel mouse point is small values which can offset everything this with the other ogre patchs fixed it mostly it is still slightly off on the y but i can work with it, after applying the patch above i found y to work perfectly now the ray is perfect!

tuan kuranes

24-02-2007 11:47:34

Thanks for pointing that out. Fixed in CVS (CVS is now Eihort compatible too.)