Ogre立方体查询
2015-07-29 14:35
295 查看
Ogre立方体查询
ogre还有一个立方体查询。
ogre还有一个立方体查询。
//--------------------------------------------------------------------------- TutorialApplication::TutorialApplication(void):mRenderer(0),mSelectionBox(0),mSelecting(false) { } //--------------------------------------------------------------------------- TutorialApplication::~TutorialApplication(void) { CEGUI::OgreRenderer::destroySystem(); if(mSelectionBox) delete mSelectionBox; } //--------------------------------------------------------------------------- void TutorialApplication::createScene(void) { // Create your scene here :) setupCEGui(); // 设置环境光 mSceneMgr->setAmbientLight(Ogre::ColourValue(0.7,0.7,0.7)); for (int i= 0; i<10;++i) for (int j = 0;j < 10; ++j) { Ogre::Entity* ent = mSceneMgr->createEntity("robot.mesh"); Ogre::SceneNode* node = mSceneMgr->getRootSceneNode()->createChildSceneNode(); node->setPosition(Ogre::Vector3(i*15,0,j*15)); node->attachObject(ent); node->setScale(0.2,0.2,0.2); } mCamera->setPosition(-60,100,-60); mCamera->lookAt(60,0,60); mSelectionBox = new SelectionBox("SelectionBox"); mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(mSelectionBox); CEGUI::WindowManager& wmgr = CEGUI::WindowManager::getSingleton(); CEGUI::Window* rootWin = wmgr.createWindow("DefaultWindow", "CEGUIDemo/Sheet"); CEGUI::System::getSingleton().getDefaultGUIContext().setRootWindow(rootWin); mVolQuery = mSceneMgr->createPlaneBoundedVolumeQuery(Ogre::PlaneBoundedVolumeList()); } bool TutorialApplication::quit(const CEGUI::EventArgs &e) { mShutDown = true; return true; } //--------------------------------------------------------------------------- bool TutorialApplication::mouseMoved(const OIS::MouseEvent &arg) { //关联鼠标 if(CEGUI::System::getSingleton().getDefaultGUIContext().injectMouseMove(arg.state.X.rel, arg.state.Y.rel)) { if(mSelecting) { CEGUI::MouseCursor* mouse = &CEGUI::System::getSingleton().getDefaultGUIContext().getMouseCursor(); mStop.x = mouse->getPosition().d_x/(float)arg.state.width; mStop.y = mouse->getPosition().d_y/(float)arg.state.height; mSelectionBox->setCorners(mStart,mStop); } return true; } return BaseApplication::mouseMoved(arg); } //--------------------------------------------------------------------------- bool TutorialApplication::mousePressed(const OIS::MouseEvent &arg, OIS::MouseButtonID id) { CEGUI::GUIContext& context = CEGUI::System::getSingleton().getDefaultGUIContext(); if(context.injectMouseButtonDown(convertButton(id))) { if (id == OIS::MB_Left) { CEGUI::MouseCursor* mouse = &context.getMouseCursor(); mStart.x = mouse->getPosition().d_x/(float)arg.state.width; mStart.y = mouse->getPosition().d_y/(float)arg.state.height; mStop = mStart; mSelecting = true; mSelectionBox->clear(); mSelectionBox->setVisible(true); } else if (id == OIS::MB_Right) { } return true; } //关联鼠标 return BaseApplication::mousePressed(arg,id); } //--------------------------------------------------------------------------- bool TutorialApplication::mouseReleased(const OIS::MouseEvent &arg, OIS::MouseButtonID id) { if (id == OIS::MB_Left) { performSelection(mStart, mStop); mSelecting = false; mSelectionBox->setVisible(false); } //关联鼠标 if(CEGUI::System::getSingleton().getDefaultGUIContext().injectMouseButtonUp(convertButton(id))) return true; return BaseApplication::mouseReleased(arg,id); } CEGUI::MouseButton TutorialApplication::convertButton(OIS::MouseButtonID buttonID) { //关联鼠标按键 switch (buttonID) { case OIS::MB_Left: return CEGUI::LeftButton; break; case OIS::MB_Right: return CEGUI::RightButton; break; case OIS::MB_Middle: return CEGUI::MiddleButton; break; default: return CEGUI::LeftButton; break; } } void TutorialApplication::setupCEGui() { Ogre::LogManager::getSingletonPtr()->logMessage("*** Initializing CEGUI ***"); mRenderer = &CEGUI::OgreRenderer::bootstrapSystem(); //设置资源路径 CEGUI::ImageManager::setImagesetDefaultResourceGroup("Imagesets"); CEGUI::Font::setDefaultResourceGroup("Fonts"); CEGUI::Scheme::setDefaultResourceGroup("Schemes"); CEGUI::WidgetLookManager::setDefaultResourceGroup("LookNFeel"); CEGUI::WindowManager::setDefaultResourceGroup("Layouts"); //设置鼠标图片 CEGUI::SchemeManager::getSingleton().createFromFile("TaharezLook.scheme"); CEGUI::FontManager::getSingleton().createFromFile("DejaVuSans-10.font"); CEGUI::System::getSingleton().getDefaultGUIContext().getMouseCursor().setDefaultImage("TaharezLook/MouseArrow"); CEGUI::GUIContext& context = CEGUI::System::getSingleton().getDefaultGUIContext(); context.setDefaultFont("DejaVuSans-10"); context.getMouseCursor().setDefaultImage("TaharezLook/MouseArrow"); Ogre::LogManager::getSingletonPtr()->logMessage("Finished"); } void TutorialApplication::destroyScene() { } void TutorialApplication::swap(float& x,float& y) { float temp = x; x = y; y = temp; } void TutorialApplication::performSelection(const Ogre::Vector2& first,const Ogre::Vector2& second) { float left = first.x,right = second.x; float top = first.y, bottom = second.y; if(left > right) swap(left,right); if (top > bottom) swap(top,bottom); if ((right - left)*(bottom - top) < 0.0001) return; Ogre::Ray topLeft = mCamera->getCameraToViewportRay(left,top); Ogre::Ray topRight = mCamera->getCameraToViewportRay(right,top); Ogre::Ray bottomLeft = mCamera->getCameraToViewportRay(left,bottom); Ogre::Ray bottomRight = mCamera->getCameraToViewportRay(right,bottom); Ogre::Plane frontPlane, topPlane, leftPlane, bottomPlane, rightPlane; frontPlane = Ogre::Plane( topLeft.getOrigin(), topRight.getOrigin(), bottomRight.getOrigin()); topPlane = Ogre::Plane( topLeft.getOrigin(), topLeft.getPoint(10), topRight.getPoint(10)); leftPlane = Ogre::Plane( topLeft.getOrigin(), bottomLeft.getPoint(10), topLeft.getPoint(10)); bottomPlane = Ogre::Plane( bottomLeft.getOrigin(), bottomRight.getPoint(10), bottomLeft.getPoint(10)); rightPlane = Ogre::Plane( topRight.getOrigin(), topRight.getPoint(10), bottomRight.getPoint(10)); Ogre::PlaneBoundedVolume vol; vol.planes.push_back(frontPlane); vol.planes.push_back(topPlane); vol.planes.push_back(leftPlane); vol.planes.push_back(bottomPlane); vol.planes.push_back(rightPlane); Ogre::PlaneBoundedVolumeList volList; volList.push_back(vol); mVolQuery->setVolumes(volList); Ogre::SceneQueryResult result = mVolQuery->execute(); deselectObjects(); Ogre::SceneQueryResultMovableList::iterator it; for (it = result.movables.begin(); it != result.movables.end(); ++it) { std::cout << (*it)->getParentSceneNode()->getPosition() << std::endl;; selectObject(*it); } } void TutorialApplication::deselectObjects() { std::list<Ogre::MovableObject*>::iterator it; for (it = mSelected.begin(); it != mSelected.end(); ++it) (*it)->getParentSceneNode()->showBoundingBox(false); } void TutorialApplication::selectObject(Ogre::MovableObject* obj) { obj->getParentSceneNode()->showBoundingBox(true); mSelected.push_back(obj); }
相关文章推荐
- Kafka: 大数据处理的利器
- 使用Jenkins进行持续集成(三)-邮箱与用户
- Android问题-selection contains a component,button7,introduced in an ancestor and cannot be deleted.
- hdu 1166 敌兵布阵 【线段树】
- redis.conf详解
- BaseAdapter使用
- iOS开发UI篇—Quartz2D使用(绘制基本图形)
- git入门资料整理
- css3列表属性
- DEDECMS教程:首页实现分页的两种方法
- leetcode-Product of Array Except Self
- Win10安装失败怎么办?Win10缺少boot.wim文件无法安装解决方法
- java异常处理机制
- 链式线性表C++ 实现
- 推荐几个很好的编程在线测试平台 online judge
- HDU5326.Work
- CircleImageView自定义圆形控件的使用
- ${}的用法
- 跳伞的时候,伞包拉不开,如何自救?在线等... ..
- hdu5312 Sequence 三角形数的应用