RayQuery strangeness

mihaim

06-03-2006 01:10:47

I ran into problems again:
Situation :
1. plsm2 loaded map hf_129_3 ( tried with ps_height_1k too with the same results )
2. Camera setting :

m_camera->setPosition( 450, 450, 450 );
m_camera->lookAt(Vector3(450,450,-450));


3. Trying to add an object to the scene using the following code

bool Renderer :: AddObject(Real x , Real y)
{
Ogre::Vector3 cs , v1;
Ogre::Entity *ent;
Ogre::SceneNode *mCurrentObject;
char name[16];

Ray cameraRay = m_camera->getCameraToViewportRay(x,y);
RaySceneQuery *raySceneQuery = m_scene_mgr->createRayQuery(cameraRay);
RaySceneQueryResult result = raySceneQuery->execute( );
RaySceneQueryResult::iterator rayIterator = result.begin();

if ( rayIterator != result.end() && rayIterator->worldFragment)
{
sprintf( name, "tree%d", obj_no++ );
v1 = rayIterator->worldFragment->singleIntersection;

ent = m_scene_mgr->createEntity( String(name), "tree.mesh" );
mCurrentObject = m_scene_mgr->getRootSceneNode()->createChildSceneNode(String(name));
mCurrentObject->attachObject(ent);
mCurrentObject->setPosition(v1);
mCurrentObject->showBoundingBox( true );
}

raySceneQuery->clearResults( );
m_scene_mgr->destroyQuery( raySceneQuery );
return true;
}


4. Result and the problem a):
It doesn't matter where i click with the mouse . The object will be added kind of under camera . and the vector rayIterator->worldFragment->singleIntersection is not influenced by the mouse position.

What am I doing wrong ?

tuan kuranes

06-03-2006 09:10:27

try adding this

raySceneQuery ->setSortByDistance (true, 1); not useful on only one result shot
raySceneQuery ->setQueryMask (RSQ_FirstTerrain); //PLSM2 only

mihaim

06-03-2006 20:35:40

Ty ty ty ty. It worked like a charm.