[Help]RaySceneQuery doesnt return any movable object in PLSM

ndoxx

13-03-2008 14:42:45

Hi,

I have problem with selecting object in PLSM with rayscenequery. My code for selecting movable objects is here :


std::cout << "Raycasting . . ." << std::endl;
Ray t_MouseRay = ((MapOgre*)(Game::GetSingletonPtr()->GetActiveMap()))->GetCamera()->getCameraToViewportRay(((float)m_PointerPosition.X/p_Evt.state.width), ((float)m_PointerPosition.Y/p_Evt.state.height));
m_RaySceneQuery->setRay(t_MouseRay);
m_RaySceneQuery->setWorldFragmentType(SceneQuery::WFT_SINGLE_INTERSECTION);
//std::cout << "Query Mask " << m_RaySceneQuery->getQueryMask();
RaySceneQueryResult& t_Result = m_RaySceneQuery->execute();
std::cout << "done, iterating result with " << t_Result.size() << " intersection";
for (RaySceneQueryResult::iterator t_Itr = t_Result.begin(); t_Itr != t_Result.end(); t_Itr++)
{
if (t_Itr->worldFragment)
{
// handling code
}
else if (t_Itr->movable)
{
// handling code
}
std::cout << std::endl << "done iterating result" << std::endl;
}


It worked well with my previous application using Terrain Scene Manager, but doesn't work with application using PLSM.

The problem is my RaySceneQueryResult always contains only one result, which is the world fragment and never the movable object. If an object clicked, the RaySceneQueryResult(t_Result variable) will contain only the world fragment intersection clicked, but not the movable object(s) clicked.

does it somehow related with PLSM? because with other scenemanager it worked well

Thanks.
Ndoxx.

ndoxx

15-03-2008 09:41:20

has anyone experienced same problem with me? I read in PLSM wiki that it is build on top of octree scene manager that handles all query, what does that mean? and does it have anything to do with my problem?

Thanks,
Ndoxx

Rowan

18-03-2008 08:19:44

I'm kind of just lurking, thought I'd post some code in case it helps.
I'm pretty sure there is a bug with PLSM2 whereby it won't return both a world intersection and an entity in one query, so you have to do 2, here is some of my dodgy code ::


//--Get Entities
mRaySceneQuery->setSortByDistance( true );
mRaySceneQuery->setQueryTypeMask( SceneManager::ENTITY_TYPE_MASK );
mRaySceneQuery->setQueryMask( ~EXCLUDE_QMASK );
RaySceneQueryResult &RsqResultSet = mRaySceneQuery->execute( );
RaySceneQueryResult::iterator RsqItr = RsqResultSet.begin( );
if( RsqItr != RsqResultSet.end() )
{ mCurrentPickedMob = static_cast<Mob *> ( RsqItr->movable->getUserObject( ) ); } else
{ mCurrentPickedMob = NULL; }

//--Get World Fragment
mRaySceneQuery->setQueryTypeMask( SceneManager::WORLD_GEOMETRY_TYPE_MASK );
mRaySceneQuery->setWorldFragmentType( SceneQuery::WFT_SINGLE_INTERSECTION );
RsqResultSet = mRaySceneQuery->execute( );
RsqItr = RsqResultSet.begin( );
if( RsqItr != RsqResultSet.end() ) {
mTerrainHitLoc = RsqItr->worldFragment->singleIntersection;
mTerrainHitLocPtr = &mTerrainHitLoc;
} else mTerrainHitLocPtr = NULL;



Hope it helps!

ndoxx

18-03-2008 12:30:06

Hi, thanks for your reply rowan.

I modified my code, masking query for returning just Entity, but it doesn't seem to be working. here is my modified code :


Ray t_MouseRay = ((MapOgre*)(Game::GetSingletonPtr()->GetActiveMap()))->GetCamera()->getCameraToViewportRay(((float)m_PointerPosition.X/p_Evt.state.width), ((float)m_PointerPosition.Y/p_Evt.state.height));
m_RaySceneQuery->setRay(t_MouseRay);
//m_RaySceneQuery->setWorldFragmentType(SceneQuery::WFT_SINGLE_INTERSECTION);
m_RaySceneQuery->setQueryTypeMask(SceneManager::ENTITY_TYPE_MASK);
RaySceneQueryResult& t_Result = m_RaySceneQuery->execute();
std::cout << "done, iterating result with " << t_Result.size() << " intersection";
for (RaySceneQueryResult::iterator t_Itr = t_Result.begin(); t_Itr != t_Result.end(); t_Itr++)
{
if (t_Itr->worldFragment)
{
...
}
if (t_Itr->movable)
{
...
}
}


The problem is now the RaySceneQueryResult vector just empty, so even if the rayquery masked only to test against world entities, not world plane, it doesn't return any result. Weird problem . . .

btw, what is EXCLUDE_QMASK you use for query flag? is it your custom flag? I checked my query flag and object flag, and is the same

Thanks for your help though

Rowan

18-03-2008 12:46:56

Yeah, could be something to do with your Ray perhaps.
I'd try manually setting up a Ray pointing directly at an entity sitting on some terrain, so you know you should get results, sometimes the 'getCameraToViewportRay( )' operations can throw in some unforeseen trouble.

ndoxx

18-03-2008 13:12:36

The world intersection returned by my rayquery seems to be right. I place an object when i click on the terrain, and it appears right at the point i clicked.

I'll try your suggestion, and let you know. Thank you very much!

jianfei5

30-03-2008 08:53:44

i discovered the Ray method have a bug,
if the Origin vector preponderate over 20000,the RaySceneQuery will not work well.

for example:

Ray r=new Ray(Vector3(20000,1,1));
RaySceneQuery *rayQuery = mSceneMgr->createRayQuery (r);
RaySceneQueryResult& result = rayQuery->execute();


result can not return movable objects.