void Game::CheckAndRespawnPlayers() { // When A Player is dead, he is simply invisible for (std::vector<RenderableChar*>::iterator ite = local_players.begin(); ite != local_players.end(); ++ite) { if ( (*ite)->getCharState() == RenderableChar::SPAWNING ) { std::cout << "I should respawn!" << std::endl; (*ite)->resetVelX(); (*ite)->resetVelY(); (*ite)->setCharState(RenderableChar::IDLE); bool free = false; Ogre::RaySceneQuery* msq; float x; float y; int c = 0; // Here, we look for a position in the level which is collision free // TODO: IN NARROW LEVELS, THIS CAN LEAD TO INFINITE LOOPS! do { if (c > 20) { x = 10.0f; y = 10.0f; free = true; } x = Ogre::Math::RangeRandom(myLevel->getObjectSide(), myLevel->getObjectSide() * (myLevel->getWidth() -1)); y = Ogre::Math::RangeRandom(myLevel->getObjectSide(), myLevel->getObjectSide() * (myLevel->getHeight())); std::cout << "GENX: " << x << " --- GENY: " << y << std::endl; msq = OgreFW::getSingletonPtr()->m_pSceneMgr->createRayQuery(Ogre::Ray(Ogre::Vector3(x, y, 0.0f), Ogre::Vector3::UNIT_Y)); msq->setSortByDistance(true, 3); //Ogre::RaySceneQuery msq->setRay(Ogre::Ray( ( (*ite)->getWorldPosition() + Ogre::Vector3(0.0f, (*ite)->getAABB().getHalfSize().y, 0.0f) ), Ogre::Vector3::UNIT_Y )); Ogre::RaySceneQueryResult& result = msq->execute(); for (Ogre::RaySceneQueryResult::iterator itr = result.begin(); itr != result.end(); ++itr) { if ( itr->distance >= (*ite)->getAABB().getSize().x ){ free = true; break; } } c++; } while (free != true); (*ite)->SetPosition(Ogre::Vector3(x, y + 0.1, 0.0f)); (*ite)->setVisible(true); msq->clearResults(); } } }
//------------------------------------------------------------------------------------- bool RollerCoaster::Querytest() { Ogre::RaySceneQuery *mQuery = mSceneMgr->createRayQuery(Ogre::Ray()); Ogre::Vector3 direction =trainNode->getPosition()+ trainNode->_getDerivedOrientation()*Ogre::Vector3::UNIT_Z; Ogre::Ray objRay( trainNode->getPosition(),direction); mQuery->setRay(objRay); Ogre::RaySceneQueryResult &result = mQuery->execute(); Ogre::RaySceneQueryResult::iterator iter = result.begin(); for (iter; iter!=result.end(); iter++) { if((*iter).movable->getName()== "mTarget") { return true; } } mQuery->clearResults(); return false; }