本文整理汇总了C++中ogre::RaySceneQuery类的典型用法代码示例。如果您正苦于以下问题:C++ RaySceneQuery类的具体用法?C++ RaySceneQuery怎么用?C++ RaySceneQuery使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了RaySceneQuery类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
Ogre::Vector3 CCS::FreeCameraMode::getFirstRealHit(Ogre::Vector3 origin, Ogre::Vector3 direction)
{
Ogre::Vector3 hit = origin;
Ogre::Real minDistance = std::numeric_limits<Ogre::Real>::max();
Ogre::RaySceneQuery *raySceneQuery = mCameraCS2->getSceneManager()->createRayQuery(Ogre::Ray(origin, direction));
Ogre::RaySceneQueryResult &result = raySceneQuery->execute();
Ogre::RaySceneQueryResult::iterator itr = result.begin();
bool intersect = false;
while (itr != result.end() /*&& !intersect*/) // ToDo: are the results ordered ??
{
if( itr->distance < minDistance // take the shorter
&& itr->movable->getParentSceneNode() != mCameraCS2->getCameraSceneNode()
&& itr->movable->getParentSceneNode() != mCameraCS2->getTargetSceneNode())
{
minDistance = itr->distance;
intersect = true;
if(itr->worldFragment)
{
hit = itr->worldFragment->singleIntersection;
}
else //if(itr->movable)
{
hit = origin + (direction * itr->distance);
}
}
itr++;
}
mCameraCS2->getSceneManager()->destroyQuery(raySceneQuery);
return hit;
}
示例2: mousePressed
bool BaselinePattern::mousePressed(const OIS::MouseEvent &evt, OIS::MouseButtonID id)
{
Ogre::Ray ray = OgreFramework::getSingletonPtr()->getCursorRay();
Ogre::RaySceneQuery* query = OgreFramework::getSingletonPtr()->m_pSceneMgr->createRayQuery(ray);
query->setSortByDistance(true);
Ogre::RaySceneQueryResult result = query->execute();
//Handle Selection
if (stage->selected == NULL) {
if (result.size() > 0 && result[0].movable != NULL) {
for (int i = 0; i < stage->poppies.size(); ++i)
if ( stage->poppies[i]->hasEntity( (Ogre::Entity*)result[0].movable ) ) {
stage->poppies[i]->setColor(getRandomPotColor());
stage->selected = stage->poppies[i];
stage->poppies[i]->deactivateJump();
//soundPickUp->play();
}
for (int i = 0; i < stage->pots.size(); ++i)
if (stage->pots[i]->hasEntity( (Ogre::Entity*)result[0].movable) )
stage->pots[i]->setColor(getRandomPotColor());
}
}
return true;
}
示例3: quickSelect
bool DemoApp::quickSelect()
{
// Create RaySceneQuery
Ogre::Ray mouseRay = mCamera->getCameraToViewportRay(static_cast<float>(mMouse->getMouseState().X.abs)/mMouse->getMouseState().width, static_cast<float>(mMouse->getMouseState().Y.abs)/mMouse->getMouseState().height);
Ogre::RaySceneQuery * mRaySceneQuery = mSceneMgr->createRayQuery(Ogre::Ray());
// Set ray
mRaySceneQuery->setRay(mouseRay);
mRaySceneQuery->setQueryTypeMask(Ogre::SceneManager::ENTITY_TYPE_MASK);
mRaySceneQuery->setSortByDistance(true);
// Ray-cast and get first hit
Ogre::RaySceneQueryResult &result = mRaySceneQuery->execute();
Ogre::RaySceneQueryResult::iterator itr = result.begin();
if((itr != result.end() && itr->movable))
{
//Get hit location
Ogre::String name = itr->movable->getName();
bool found=false;
if(name=="Box")
{
itr++;
name = itr->movable->getName();
}
for(int i=0;i<TANK_LIMIT;i++)
{
if(name=="Tank"+std::to_string(i))
{
tanks.at(i).selected=true;
if(tanks.at(i).mSelectionCircle->getParentSceneNode()!=tanks.at(i).tankNode)
tanks.at(i).tankNode->attachObject(tanks.at(i).mSelectionCircle);
if(tanks.at(i).mHealthBar->getParentSceneNode()!=tanks.at(i).tankNode)
tanks.at(i).tankNode->attachObject(tanks.at(i).mHealthBar);
found=true;
tanks.at(i).path2->setVisible(true);
}
else if(controlPressed==false)
{
tanks.at(i).selected=false;
if(tanks.at(i).mSelectionCircle->getParentSceneNode()==tanks.at(i).tankNode)
tanks.at(i).tankNode->detachObject(tanks.at(i).mSelectionCircle);
if(tanks.at(i).mHealthBar->getParentSceneNode()==tanks.at(i).tankNode)
tanks.at(i).tankNode->detachObject(tanks.at(i).mHealthBar);
tanks.at(i).path2->setVisible(false);
}
}
if(found==false)
return false;
else return true;
}
return false;
}
示例4: collision
//-------------------------------------------------------------------------------------
///controls collision in given direction (true-front false-back)
bool Player::collision(bool goAhead){
Ogre::Ray ray = Ogre::Ray(sceneNode->getPosition(), getDirection(sceneNode->getOrientation(),goAhead));
Ogre::RaySceneQuery* mRaySceneQuery = manager->createRayQuery(ray);
Ogre::RaySceneQueryResult result = mRaySceneQuery->execute();
for(Ogre::RaySceneQueryResult::iterator it = result.begin(); it != result.end() ; ++it){
if((it->distance < farFarAway)&& (it->distance > 0)){
return true;
}
}
return false;
}
示例5: make_pair
std::pair<DetectionResult, DetectionIterator&> ViewDetection::detectObjects() {
//Ogre::ResourceGroupManager::getSingletonPtr();
//Ogre::OverlayManager* mg = Ogre::OverlayManager::getSingletonPtr();
//Ogre::Overlay* ov = mg->getByName("TestScriptOverlay");
Ogre::RaySceneQuery* rayQuery = viewManager->createRayQuery(*detection);
rayQuery->setSortByDistance(true);
DetectionResult result = rayQuery->execute();
DetectionIterator& endOfResult = filterObjects(result);
return std::make_pair(result, endOfResult);
}
示例6: ray
const ActorVector& OgreRaySceneQuery::execute()
{
// Clear last results
mResult.clear();
Ray ray(getRayStart(), (getRayEnd() - getRayStart()).normalisedCopy());
Ogre::RaySceneQuery* query = CoreSubsystem::getSingleton().getWorld()->getSceneManager()
->createRayQuery(ray, getQueryMask());
query->execute(this);
return mResult;
}
示例7: CheckAndRespawnPlayers
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();
}
}
}
示例8: pSceneNode
//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
void
RenderingCanvas::querySceneNodes(Math::Real _x, Math::Real _y, I_SceneNodeVisitor& _visitor)
{
Ogre::Camera& camera = m_pCurrentCamera->getOgreCamera();
Ogre::Vector3 position;
if( camera.getParentSceneNode() )
{
position = camera.getParentSceneNode()->_getDerivedPosition();
}
else
{
position = camera.getDerivedPosition();
}
Ogre::RaySceneQuery* pSceneQuery =
m_pSceneManager->createRayQuery(camera.getCameraToViewportRay(_x, _y));
pSceneQuery->setSortByDistance(true);
Ogre::RaySceneQueryResult::const_iterator iter;
const Ogre::RaySceneQueryResult& queryResult = pSceneQuery->execute();
_visitor.begin();
for(iter = queryResult.begin(); iter != queryResult.end(); iter++)
{
const Ogre::RaySceneQueryResultEntry& result = *iter;
// Check to see if this is a scene node.
if (result.movable != NULL)
{
Ogre::SceneNode *pNode = dynamic_cast<Ogre::SceneNode*>(result.movable->getParentSceneNode());
if (pNode)
{
if (!pNode->getUserAny().isEmpty())
{
SceneNode* pRawSceneNode = Ogre::any_cast<SceneNode*>(pNode->getUserAny());
I_SceneNodeVisitor::pSceneNode_type pSceneNode(pRawSceneNode->getSelfReference().lock());
_visitor.visit(pSceneNode);
}
}
}
}
_visitor.end();
delete pSceneQuery;
}
示例9: createPalms
void createPalms(Ogre::SceneManager *mSceneMgr)
{
const int NumberOfPalms = 12;
Ogre::SceneNode* mPalmsSceneNode = mSceneMgr->getRootSceneNode()->createChildSceneNode();
for (int k = 0; k < NumberOfPalms; k++)
{
Ogre::Vector3 RandomPos = Ogre::Vector3(rnd_(500,2500),
0,
rnd_(500,2500));
Ogre::RaySceneQuery * raySceneQuery = mSceneMgr->
createRayQuery(Ogre::Ray(RandomPos + Ogre::Vector3(0,1000000,0),
Ogre::Vector3::NEGATIVE_UNIT_Y));
Ogre::RaySceneQueryResult& qryResult = raySceneQuery->execute();
Ogre::RaySceneQueryResult::iterator i = qryResult.begin();
if (i != qryResult.end() && i->worldFragment)
{
if (i->worldFragment->singleIntersection.y>105 || i->worldFragment->singleIntersection.y<20)
{
k--;
continue;
}
RandomPos.y = i->worldFragment->singleIntersection.y;
}
else
{
k--;
continue;
}
Ogre::Entity *mPalmEnt = mSceneMgr->createEntity("Palm"+Ogre::StringConverter::toString(k), "Palm.mesh");
Ogre::SceneNode *mPalmSN = mPalmsSceneNode->createChildSceneNode();
mPalmSN->rotate(Ogre::Vector3(-1,0,rnd_(-0.3,0.3)), Ogre::Degree(90));
mPalmSN->attachObject(mPalmEnt);
Ogre::Real Scale = rnd_(50,75);
mPalmSN->scale(Scale,Scale,Scale);
mPalmSN->setPosition(RandomPos);
}
}
示例10: mouseMoved
bool BaselinePattern::mouseMoved(const OIS::MouseEvent &evt)
{
Ogre::Ray ray = OgreFramework::getSingletonPtr()->getCursorRay();
Ogre::RaySceneQuery* query = OgreFramework::getSingletonPtr()->m_pSceneMgr->createRayQuery(ray);
query->setSortByDistance(true);
Ogre::RaySceneQueryResult result = query->execute();
if (stage->selected && stage->selected->getType() == Selectable::TYPE_POPPY)
for (int i = 0; i < result.size(); ++i)
if (stage->ground->hasEntity( (Entity*)result[i].movable )) {
Poppy* toMove = (Poppy*)stage->selected;
Vector3 hoverPos = ray * result[i].distance;
hoverPos.y = poppyRadius;
toMove->setPosition(hoverPos);
}
return true;
}
示例11: checkCameraHeight
void checkCameraHeight()
{
Ogre::RaySceneQuery *raySceneQuery =
m_sceneManager->
createRayQuery(Ogre::Ray(m_camera->getPosition() + Ogre::Vector3(0,10000,0),
Ogre::Vector3::NEGATIVE_UNIT_Y));
Ogre::RaySceneQueryResult& qryResult = raySceneQuery->execute();
Ogre::RaySceneQueryResult::iterator i = qryResult.begin();
if (i != qryResult.end() && i->worldFragment)
{
if (m_camera->getPosition().y < i->worldFragment->singleIntersection.y + 30)
{
m_camera->setPosition(m_camera->getPosition().x, i->worldFragment->singleIntersection.y + 30, m_camera->getPosition().z);
}
}
delete raySceneQuery;
}
示例12: mouseReleased
bool BaselinePattern::mouseReleased(const OIS::MouseEvent &evt, OIS::MouseButtonID id)
{
Ogre::Ray ray = OgreFramework::getSingletonPtr()->getCursorRay();
Ogre::RaySceneQuery* query = OgreFramework::getSingletonPtr()->m_pSceneMgr->createRayQuery(ray);
query->setSortByDistance(true);
Ogre::RaySceneQueryResult result = query->execute();
if (stage->selected != NULL && stage->selected->getType() == Selectable::TYPE_POPPY && result.size() > 0) {
Poppy* old = (Poppy*)stage->selected;
stage->selected = NULL;
Vector3 placeDest = ray * result[0].distance;
placeDest.y = poppyRadius;
old->setPosition(placeDest);
old->activateJump();
}
return true;
}
示例13: finalCameraPosition
Ogre::Vector3 CCS::CollidableOrbitalCameraMode::DefaultCollisionDetectionFunction(Ogre::Vector3 cameraTargetPosition, Ogre::Vector3 cameraPosition)
{
Ogre::Vector3 finalCameraPosition (cameraPosition.x, cameraPosition.y, cameraPosition.z);
Ogre::RaySceneQuery *raySceneQuery = mCameraCS->getSceneManager()->createRayQuery(Ogre::Ray(cameraTargetPosition, cameraPosition));
// Perform the scene query
Ogre::RaySceneQueryResult &result = raySceneQuery->execute();
Ogre::RaySceneQueryResult::iterator itr = result.begin();
// Get the results, set the camera height
if (itr != result.end() && itr->worldFragment)
{
finalCameraPosition = itr->worldFragment->singleIntersection;
}
mCameraCS->getSceneManager()->destroyQuery(raySceneQuery);
return finalCameraPosition;
}
示例14: catch
WorldObject *RTSState::getObjectUnderRay(const Ogre::Ray &ray) const
{
EngineManager *mng = m_gameEngine->getManager();
Ogre::RaySceneQuery *query = mng->getGraphic()->getSceneManager()->createRayQuery(ray);
Ogre::RaySceneQueryResult &queryResult = query->execute();
for (Ogre::RaySceneQueryResultEntry & entry : queryResult)
{
if (entry.movable)
{
WorldObject *worldObject;
try
{
worldObject = Ogre::any_cast<WorldObject *>(entry.movable->getUserObjectBindings().getUserAny());
if (worldObject)
return worldObject;
}
catch (...) {}
}
}
mng->getGraphic()->getSceneManager()->destroyQuery(query);
return nullptr;
}
示例15: mouseReleaseEvent
void QOgreWindow::mouseReleaseEvent(QMouseEvent *e)
{
if (camMan) camMan->injectMouseUp(*e);
QPoint pos = e->pos();
Ogre::Ray mouseRay = oCam->getCameraToViewportRay(
(Ogre::Real)pos.x() / oWin->getWidth(),
(Ogre::Real)pos.y() / oWin->getHeight());
Ogre::RaySceneQuery* sceneQuery = oSceneMgr->createRayQuery(mouseRay);
sceneQuery->setSortByDistance(true);
Ogre::RaySceneQueryResult vResult = sceneQuery->execute();
for (size_t ui = 0; ui < vResult.size(); ui++)
{
if (vResult[ui].movable)
{
if (vResult[ui].movable->getMovableType().compare("Entity") == 0)
{
emit entitySelected((Ogre::Entity*)vResult[ui].movable);
}
}
}
oSceneMgr->destroyQuery(sceneQuery);
}