[Solved] RaySceneQuery intersection problem

Dibalo

15-12-2006 18:47:55

Hi again.

This time my problem is that my RaySceneQuery doesn´s work right. It´s intersections don´t want to work. I think the best option is to show you what I mean. Here is the program: http://koti.mbnet.fi/masa_89/pelit/ChaosEditorAlpha.rar (working at least in Win XP Pro). You can place selected objects to the world clicking left mousebutton. Try to place objects to different kind of places (to middle of the steeps, to flat areas...).

As you can see, if you try to add objects to middle of mountains, objects don´t get right position. If you try to place object to flat areas, everyhing is right. I´m wondering what I´m doing wrong... :(

Here is the code, which does the intersection check:// this code is in frameStarted()-method

if( System.Mouse.hitted(0) && !var::mouseInsideGUIelement )
{
Ogre::RaySceneQueryResult& res = System.Camera.getRay( System.Mouse.getX(), System.Mouse.getY() );
Ogre::RaySceneQueryResult::iterator it = res.begin();

if( it != res.end() && it->worldFragment )
{
var::createModel( it->worldFragment->singleIntersection );
System.Window->setDebugText( Ogre::StringConverter::toString(it->worldFragment->singleIntersection) );
}

}


// and here is the function

void createModel(const Vector3& pos)
{
CEGUI::TabControl* tc = (CEGUI::TabControl*)modelTab->element;
CEGUI::Listbox* openList = (CEGUI::Listbox*)tc->getTabContentsAtIndex( tc->getSelectedTabIndex() )->getChild(0);

if( openList->getSelectedCount() )
{
String entName = openList->getFirstSelectedItem()->getText().c_str();

Ogre::Entity* ent = System.SceneManager->createEntity("NewEntity_"+Ogre::StringConverter::toString(++nodeCount), entName + ".mesh");
Ogre::SceneNode* node = System.SceneManager->getRootSceneNode()->createChildSceneNode("NewNode_"+Ogre::StringConverter::toString(++nodeCount));
node->attachObject( ent );

node->setPosition( pos );
}
}



And this is the declaration of "System.Camera.getRay"-method:Ogre::RaySceneQueryResult& Camera::getRay(Ogre::Real x, Ogre::Real y, bool sort)
{

#if CURRENT_SCENE_MANAGER == 2

myRayQuery->setRay( node->getCameraToViewportRay(x, y) );
myRayQuery->setQueryTypeMask(Ogre::SceneManager::WORLD_GEOMETRY_TYPE_MASK);
myRayQuery->setWorldFragmentType(Ogre::SceneQuery::WFT_SINGLE_INTERSECTION);
//myRayQuery->setSortByDistance(true, 1);
//myRayQuery->setQueryMask(Ogre::RSQ_FirstTerrain);

return myRayQuery->execute();


#else

myRayQuery->setRay( node->getCameraToViewportRay(x, y) );
myRayQuery->setSortByDistance(sort);
return myRayQuery->execute();

#endif
}



And this is the way I´m initializing "myRayQuery"-pointer:myRayQuery = smgr->createRayQuery( Ogre::Ray() );
myRayQuery->setWorldFragmentType(Ogre::SceneQuery::WFT_SINGLE_INTERSECTION);


I hope you could help me.. :roll:
P.S. CURRENT_SCENE_MANAGER equals 2.

tuan kuranes

16-12-2006 15:56:35

There is a known bug with ray that cross page boundaries.
does it works with ray that doesn't do that ?

Dibalo

17-12-2006 17:33:15

There is a known bug with ray that cross page boundaries.
does it works with ray that doesn't do that ?

I´m using "hf"-map so its only one page. Is this some kind of problem?

tuan kuranes

18-12-2006 15:49:04

No. So it's a new bug => http://www.ogre3d.org/phpBB2addons/viewtopic.php?t=3047

Dibalo

18-12-2006 17:18:08

Ok.. I had to go around a little detour but i solved this one too! :lol:
I needed a physics engine so I chose OgreNewt, because it meets my needs the best. So I use newton´s collision rays now and it works perfect. 8)

Thank you for you help again tuan! :)

tuan kuranes

18-12-2006 17:30:46

How did you fixed it ?

Dibalo

18-12-2006 19:04:35

How did you fixed it ?
By using Newton collision rays... :lol: