本文整理汇总了C++中ogre::RaySceneQuery::setRay方法的典型用法代码示例。如果您正苦于以下问题:C++ RaySceneQuery::setRay方法的具体用法?C++ RaySceneQuery::setRay怎么用?C++ RaySceneQuery::setRay使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ogre::RaySceneQuery
的用法示例。
在下文中一共展示了RaySceneQuery::setRay方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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;
}
示例2: Querytest
//-------------------------------------------------------------------------------------
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;
}
示例3: getSceneManager
void
System::makeObjectTransparent( const Ogre::Vector3 &start, const Ogre::Vector3 &end, float nNewTrans, float nDelay, IObjectFilter *pFilter )
{
Ogre::Vector3 vDirction = (start-end);
Ogre::Real fDistance = vDirction.length();
Ogre::Ray ray = Ogre::Ray(end,vDirction);
Ogre::RaySceneQuery* raySceneQuery = getSceneManager()->createRayQuery(Ogre::Ray());
std::set<Fairy::Object*> setCurrentTransparentObjects;
raySceneQuery->setRay(ray);
const Ogre::RaySceneQueryResult& queryResult = raySceneQuery->execute();
for (Ogre::RaySceneQueryResult::const_iterator it = queryResult.begin(); it != queryResult.end(); ++it)
{
Ogre::MovableObject* pMovable = it->movable;
Ogre::Vector3 vObjectPos = pMovable->getParentNode()->getPosition();
Ogre::Vector3 vObjectDir = (vObjectPos-end);
Fairy::ObjectPtr pObject = Fairy::getObjectFromMovable(pMovable);
if(pObject)
{
// 当满足以下条件时设置透明: 1.是StaticEntity类型; 2.相交; 3.允许透明
if(pObject->getType() == "StaticEntity" && vObjectDir.dotProduct(vDirction) > 0 && static_cast<Fairy::StaticEntityObject*>(pObject.get())->getEnableTransparency())
{
Fairy::StaticEntityObject* pModel = static_cast<Fairy::StaticEntityObject*>(pObject.get());
pModel->setTransparency(0.5f);
// 删除原有的Object,放到临时的Set中
m_setTransparencyObjects.erase(pObject.get());
setCurrentTransparentObjects.insert(pObject.get());
}
}
}
std::set<Fairy::Object*>::iterator iter = m_setTransparencyObjects.begin();
std::set<Fairy::Object*>::iterator tempIter;
while (iter != m_setTransparencyObjects.end())
{
tempIter = iter;
++iter;
// 恢复没有遮挡的Object的透明度为0
Fairy::StaticEntityObject* pModel = static_cast<Fairy::StaticEntityObject*>(*tempIter);
pModel->setTransparency(0);
// 删除透明度为0的Object
if (pModel->getTransparency()==0)
{
m_setTransparencyObjects.erase(tempIter);
}
}
// 将遮挡的Object放到m_setTransparencyObjects
for (std::set<Fairy::Object*>::iterator it = setCurrentTransparentObjects.begin(); it != setCurrentTransparentObjects.end(); ++it)
{
m_setTransparencyObjects.insert(*it);
}
if(raySceneQuery)
{
getSceneManager()->destroyQuery(raySceneQuery);
raySceneQuery = NULL;
}
}
示例4: generatePath
void DemoApp::generatePath()
{
for(int j = 0; j < TOTAL_NODES; j++)
{
if(pathFindingGraph->getContent(j) == 2)
pathFindingGraph->setContent(j, 0);
}
for(int i = 0; i < TANK_LIMIT; i++)
{
//if path already exists
if(tanks.at(i).mCurrentState > 1)
{
// reset
tanks.at(i).mCurrentState = 0;
tanks.at(i).path2->clear();
}
if(playerControlled == i) //player-controlled tank movement
{
// 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);
// Ray-cast and get first hit
Ogre::RaySceneQueryResult &result = mRaySceneQuery->execute();
Ogre::RaySceneQueryResult::iterator itr = result.begin();
// if hit an object
if((itr != result.end()))
{
//Get hit location
Ogre::Vector3 location = mouseRay.getPoint(itr->distance);
// if hit the floor
if((location.y < 0.001 && (selectionMode==1 || selectionMode==2)) || selectionMode==0)
{
tanks.at(i).startNode = pathFindingGraph->getNode(tanks.at(i).tankNode->_getDerivedPosition());
// set goal node
if(selectionMode==0)
{
do
{
tanks.at(i).goalNode = (int)rand() % 256;
}while(pathFindingGraph->getContent(tanks.at(i).goalNode) != 0);
}
else
{
tanks.at(i).goalNode=pathFindingGraph->getNode(location);
}
// check that goal node is not the same as start node
if(tanks.at(i).goalNode != tanks.at(i).startNode)
{
findPath(i);
}
else
{
resetPath(i);
}
}
}
}
else //AI-controlled tank movement
{
/*Ogre::Vector3 location; //pre-define location for the if else
if(tanks.at(i).team == 1)
location = pathFindingGraph->getPosition((13 + rand() % 16) + rand() % (40 + 1)); //get a random position to move to
else if(tanks.at(i).team == 2)
location = pathFindingGraph->getPosition((13 + rand() % 16) * ((rand() % 40 + 1) * 42)); //get a random position to move to
*/
int location = ((13 + rand() % 16) + ((rand() % 40 + 1) * 42));
tanks.at(i).startNode = pathFindingGraph->getNode(tanks.at(i).tankNode->_getDerivedPosition());
/*
// set goal node
if(selectionMode==0)
{*/
/*do
{
tanks.at(i).goalNode = (int)rand() % 256;
}while(pathFindingGraph->getContent(tanks.at(i).goalNode) != 0);*/
/*}
else
{
tanks.at(i).goalNode = pathFindingGraph->getNode(location);
}*/
tanks.at(i).goalNode = location;
//tanks.at(i).goalNode = pathFindingGraph->getNode(location);
// check that goal node is not the same as start node
if(tanks.at(i).goalNode != tanks.at(i).startNode)
{
findPath(i);
}
else
{
resetPath(i);
}
//.........这里部分代码省略.........