本文整理汇总了C++中ogre::RaySceneQuery::setSortByDistance方法的典型用法代码示例。如果您正苦于以下问题:C++ RaySceneQuery::setSortByDistance方法的具体用法?C++ RaySceneQuery::setSortByDistance怎么用?C++ RaySceneQuery::setSortByDistance使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ogre::RaySceneQuery
的用法示例。
在下文中一共展示了RaySceneQuery::setSortByDistance方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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;
}
示例2: 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;
}
示例3: 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);
}
示例4: 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();
}
}
}
示例5: 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;
}
示例6: 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;
}
示例7: 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;
}
示例8: 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);
}
示例9: update
//.........这里部分代码省略.........
Ogre::Degree angle = getShootingAngle(targetPosition);
mTankTurretNode->lookAt(targetPosition, Ogre::Node::TransformSpace::TS_WORLD, Ogre::Vector3::NEGATIVE_UNIT_X);
//barrelDegree = angle;
if (weaponTimer > 4)
{
tnkMgr->createProjectile(mTankBodyNode->getPosition(), mTankTurretNode->_getDerivedOrientation(), angle, shootingVelocity, dmg);
weaponTimer = 0;
}
if (target->hp <= 0 || mTankBodyNode->getPosition().distance(target->getPosition()) > 600 )
currentState = WANDER;
}
case WANDER:
//wander(deltaTime);
wanderMovement(deltaTime);
break;
case SEEK:
//seek(mPowerUpSpawns[powerUpNo]->getPowerLocation(), deltaTime);
//seek(Ogre::Vector3::ZERO, deltaTime);
//seekMovement(deltaTime);
break;
case ESCAPE:
break;
case STOP:
break;
case POSSESSED: {
Ogre::Vector3 rayDest;
if (mMove < 0)
rayDest = mTankBodyNode->getOrientation() * Ogre::Vector3(-1,0,0);
else if (mMove > 0)
rayDest = mTankBodyNode->getOrientation() * Ogre::Vector3(1,0,0);
//THIS IS WHERE THE TANK IS MOVED WHEN PROCESSING
//if (rayDest != NULL)
{
Ogre::Ray shootToCheckWall = Ogre::Ray(mTankBodyNode->getPosition(), rayDest);
Ogre::RaySceneQuery* mRaySceneQuery = mSceneMgr->createRayQuery(shootToCheckWall, 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();
bool hit = false;
for (itr = result.begin(); itr != result.end(); itr++)
{
std::string x = itr->movable->getName();
printf("Check %s \n", x.c_str());
if (x[0] == 'C' && itr->distance < 10)
{
printf("Too close to %s: %f \n", x.c_str(), (float)itr->distance);
hit = true;
}
}
if(hit == false)
{
mTankBodyNode->translate(mMove * deltaTime * mMoveSpd, 0, 0, Ogre::Node::TransformSpace::TS_LOCAL);
}
}
mTankBodyNode->yaw(Ogre::Degree(bodyRotate * deltaTime * mRotSpd));
// Rotate the tank turret
mTankTurretNode->yaw(Ogre::Degree(turretRotation * deltaTime * mRotSpd * 1.5));
turretDegree += turretRotation;
//to move barrel change barrelRotation
float barrelChange = barrelRotation * deltaTime * mRotSpd;
barrelDegree += barrelChange;
if(barrelDegree > 30)
barrelDegree = 30;
else if(barrelDegree < 0)
barrelDegree = 0;
else
mTankBarrelNode->roll(Ogre::Degree(-barrelChange));
}
break;
}
Ogre::Vector3 setpos = mTankBodyNode->getPosition();
setpos.y = 13.f;
mTankBodyNode->setPosition(setpos);
}
示例10: Update
bool Player::Update(InputManager* input,
PhysicsManager* physics,
EWSManager* ews,
const OgreTransform& transform)
{
if(input->isCFGKeyPressed(InputManager::ENVWARNSYS))
{
placeEWS(ews,physics,transform);
}
cGunData* gun = nullptr;
if(_equippables[_curEquippable].equip->getIsWeapon())
{
gun = static_cast<cGunData*>(_equippables[_curEquippable].equip);
}
if(gun != nullptr)
{
bool movkey = false;
movkey = (input->isCFGKeyPressed(InputManager::FORWARD) ||
input->isCFGKeyPressed(InputManager::BACKWARD)||
input->isCFGKeyPressed(InputManager::RIGHT) ||
input->isCFGKeyPressed(InputManager::LEFT));
if(input->isMBPressed(OIS::MB_Left))
{
//shoot gun
//std::cout << "MB_Left pressed..." << std::endl;
gun->fire();
//check for collisions with enemies if first time through
if(gun->shouldDamage())
{
Ogre::SceneManager* scene = _equipNode->getCreator();
Ogre::Vector3 dir = transform.direction;
Ogre::Ray ray(transform.position,dir);
Ogre::RaySceneQuery* rayQuery = scene->createRayQuery(ray);
rayQuery->setSortByDistance(true);
Ogre::RaySceneQueryResult results = rayQuery->execute();
auto shot = [this,gun] (Ogre::RaySceneQueryResultEntry& entry)
{
if(entry.movable != nullptr)
{
std::string name = entry.movable->getName().substr(3,std::string::npos);
LevelData::BaseEntity* ent = LuaManager::getSingleton().getEntity(name);
if(ent != nullptr && (ent->getType() == LevelData::NPC || ent->getType() == LevelData::ENEMY))
{
_damageInterface->registerShotAtEnemy(gun->getGunshotData(),name);
}
}
};
std::for_each(results.begin(),results.end(),shot);
scene->destroyQuery(rayQuery);
}
}
else
{
gun->setFiring(false);
}
if(input->isCFGKeyPressed(InputManager::RELOAD))
{
gun->reload();
}
if(movkey)
{
gun->setMoving(true);
}
else
{
if(gun->isMoving())
{
gun->setMoving(false);
}
}
}
if(_damageInterface != nullptr)
{
//this clears out the added-up damage in the interface.
_health -= static_cast<int>(_damageInterface->getTotalDamagePlayer());
}
return true;
}
示例11: _actionLook
void NPCCharacter::_actionLook(const Ogre::Vector3& target)
{
Ogre::Bone* headBone;
std::string n = _node->getName();
Ogre::Skeleton* skel = static_cast<Ogre::Entity*>(_movableObject)->getSkeleton();
headBone = skel->getBone("Bip01_Head");
headBone->setManuallyControlled(true);
headBone->setInheritOrientation(true);
int nAnim = skel->getNumAnimations();
//have to do this to allow the head to turn properly.
for(int i = 0; i < nAnim; ++i)
{
skel->getAnimation(i)->destroyNodeTrack(headBone->getHandle());
}
Ogre::Vector3 test = headBone->_getDerivedPosition() * CHARACTER_SCALE_FACTOR + _node->getPosition();
Ogre::Vector3 dir = target - test;
Ogre::Quaternion nodeRot,boneRot;
Ogre::Euler boneEuler; boneEuler.setDirection(dir,true,false);
/*boneRot = _node->convertLocalToWorldOrientation(_node->getOrientation()) * headBone->_getDerivedOrientation();
Ogre::Vector3 boneTest = boneRot * Ogre::Vector3::UNIT_Z;*/
//Ogre::Vector3 boneTest = headBone->getOrientation() * Ogre::Vector3::UNIT_Z;
//turns the direction vector into a 2D normalized vector on the X/Z axis.
dir.y = 0;
dir.normalise();
//All of this ray query stuff is to make sure that the AI can "see" the target before attempting to look at it.
Ogre::SceneManager* scene = _node->getCreator();
Ogre::Ray ray(headBone->_getDerivedPosition() * CHARACTER_SCALE_FACTOR + _node->getPosition(),dir);
Ogre::RaySceneQuery* query = scene->createRayQuery(ray);
query->setSortByDistance(true);
query->setQueryMask(CHARACTER_MASK | SCENERY_MASK);
Ogre::RaySceneQueryResult results = query->execute();
bool withinView = false;
if(results.size() == 0)
{
withinView = true;
}
else
{
if(results.begin()->movable->getParentNode()->getName() == getName())
{
if(results.size() == 1)
{
withinView = true;
}
}
if(!withinView && results.size() > 1 && std::next(results.begin())->distance > test.distance(target))
{
withinView = true;
}
}
scene->destroyQuery(query);
if(withinView)
{
Ogre::Euler node;
Ogre::Euler t = headOrientation.getRotationTo(dir);
t.limitYaw(Ogre::Radian(3.0));
t.limitPitch(Ogre::Radian(0.0));
headOrientation = headOrientation + t;
headOrientation.limitYaw(Ogre::Degree(100));
headOrientation.limitPitch(Ogre::Degree(60));
headBone->setOrientation(headOrientation);
/*headBone->rotate(boneTest.getRotationTo(dir),Ogre::Node::TS_WORLD);
Ogre::Quaternion boneRotation = _node->convertLocalToWorldOrientation(_node->getOrientation()) * headBone->_getDerivedOrientation() * (Ogre::Quaternion(Ogre::Degree(180),Ogre::Vector3::UNIT_Y));
Ogre::Quaternion nodeRotation = _node->_getDerivedOrientation();
Ogre::Quaternion diff = nodeRotation.Inverse() * boneRotation;*/
}
_isActFinished = true;
}