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:
And this is the declaration of "System.Camera.getRay"-method:
And this is the way I´m initializing "myRayQuery"-pointer:
I hope you could help me..
P.S. CURRENT_SCENE_MANAGER equals 2.
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..
P.S. CURRENT_SCENE_MANAGER equals 2.