From e38417e66256f08732e4bf3fdb745d04a14d9250 Mon Sep 17 00:00:00 2001 From: cc9cii Date: Mon, 6 Oct 2014 13:55:36 +1100 Subject: [PATCH] Visibility mask implemented. For testing rigged up 'M' and 'N' keys for show/hide. The scenewidget doesn't receive any mouse events for about a second after toggling the visibility flag. No idea what is causing this. --- .../view/render/pagedworldspacewidget.cpp | 83 ++++++++++++++++--- .../view/render/pagedworldspacewidget.hpp | 1 + apps/opencs/view/render/scenewidget.cpp | 26 +++++- apps/opencs/view/render/scenewidget.hpp | 2 + apps/opencs/view/render/textoverlay.cpp | 14 +--- apps/opencs/view/render/textoverlay.hpp | 2 +- 6 files changed, 101 insertions(+), 27 deletions(-) diff --git a/apps/opencs/view/render/pagedworldspacewidget.cpp b/apps/opencs/view/render/pagedworldspacewidget.cpp index e4677b78d..2755d9db1 100644 --- a/apps/opencs/view/render/pagedworldspacewidget.cpp +++ b/apps/opencs/view/render/pagedworldspacewidget.cpp @@ -8,8 +8,10 @@ #include #include #include -#include // FIXME -#include // FIXME +#include +#include +#include +#include #include #include "../../../../components/esm/loadland.hpp" @@ -115,32 +117,88 @@ bool CSVRender::PagedWorldspaceWidget::adjustCells() void CSVRender::PagedWorldspaceWidget::mouseReleaseEvent (QMouseEvent *event) { - //std::cout << "Qt x: " + std::to_string(event->x()) << ", y: " + std::to_string(event->y()) << std::endl; + std::list::iterator iter = mTextOverlays.begin(); + for(; iter != mTextOverlays.end(); ++iter) + { + if(mDisplayCellCoord && + (*iter)->isEnabled() && (*iter)->container().contains(event->x(), event->y())) + { + std::cout << "clicked: " << (*iter)->getCaption() << std::endl; + //(*iter)->enable(false); // FIXME: for testing only + } + } +#if 0 + // mouse picking int viewportWidth = getCamera()->getViewport()->getActualWidth(); int viewportHeight = getCamera()->getViewport()->getActualHeight(); - Ogre::Ray mouseRay = getCamera()->getCameraToViewportRay(event->x()/viewportWidth, event->y()/viewportHeight); + Ogre::Ray mouseRay = getCamera()->getCameraToViewportRay((float)(event->x()/viewportWidth), + (float)(event->y()/viewportHeight)); Ogre::RaySceneQuery *rayScnQuery = getSceneManager()->createRayQuery(Ogre::Ray()); rayScnQuery->setRay(mouseRay); - Ogre::RaySceneQueryResult &result = rayScnQuery->execute(); - Ogre::RaySceneQueryResult::iterator it = result.begin(); + rayScnQuery->setSortByDistance(true); + Ogre::RaySceneQueryResult result = rayScnQuery->execute(); - std::list::iterator iter = mTextOverlays.begin(); - for(; iter != mTextOverlays.end(); ++iter) + Ogre::RaySceneQueryResult::iterator it = result.begin(); + for (; it != result.end(); it++) { - if((*iter)->isEnabled() && (*iter)->container().contains(event->x(), event->y())) + if(it->worldFragment) { - std::cout << "clicked: " << (*iter)->getCaption() << std::endl; - (*iter)->enable(false); + // FIXME: just testing + std::string str; + if (it->worldFragment->fragmentType == Ogre::SceneQuery::WorldFragmentType::WFT_NONE) + str = "no world geometry hits"; + else if (it->worldFragment->fragmentType == Ogre::SceneQuery::WorldFragmentType::WFT_PLANE_BOUNDED_REGION) + str = "pointers to convex plane-bounded regions"; + else if (it->worldFragment->fragmentType == Ogre::SceneQuery::WorldFragmentType::WFT_SINGLE_INTERSECTION) + str = "single intersection point"; + else if(it->worldFragment->fragmentType == Ogre::SceneQuery::WorldFragmentType::WFT_CUSTOM_GEOMETRY) + str = "custom geometry"; + else if (it->worldFragment->fragmentType == Ogre::SceneQuery::WorldFragmentType::WFT_RENDER_OPERATION) + str = "general render operation structure"; + + std::cout << "fragment type: " << str << std::endl; + } + else if (it->movable) + { + // FIXME: just testing + it->movable->getParentSceneNode()->showBoundingBox(true); + + std::cout << "movable object: " + it->movable->getName() << std::endl; } + else + std::cout << "nothing: " << std::endl; } + getSceneManager()->destroyQuery(rayScnQuery); +#endif + SceneWidget::mouseReleaseEvent(event); } void CSVRender::PagedWorldspaceWidget::updateOverlay() { + Ogre::OverlayManager &overlayMgr = Ogre::OverlayManager::getSingleton(); + Ogre::Overlay* overlay = overlayMgr.getByName("CellIDPanel"); + if(overlay && !mTextOverlays.empty()) + { + if(getCamera()->getViewport()) + { + if((uint32_t)getCamera()->getViewport()->getVisibilityMask() + & (uint32_t)CSVRender::Elements::Element_CellMarker) + { + mDisplayCellCoord = true; + overlay->show(); + } + else + { + mDisplayCellCoord = false; + overlay->hide(); + } + } + } + if(!mTextOverlays.empty()) { std::list::iterator it = mTextOverlays.begin(); @@ -229,7 +287,8 @@ std::string CSVRender::PagedWorldspaceWidget::getStartupInstruction() } CSVRender::PagedWorldspaceWidget::PagedWorldspaceWidget (QWidget* parent, CSMDoc::Document& document) -: WorldspaceWidget(document, parent), mDocument(document), mWorldspace("std::default"), mTextOverlays(0) +: WorldspaceWidget(document, parent), mDocument(document), mWorldspace("std::default"), mDisplayCellCoord(true) +, mTextOverlays(0) { QAbstractItemModel *cells = document.getData().getTableModel (CSMWorld::UniversalId::Type_Cells); diff --git a/apps/opencs/view/render/pagedworldspacewidget.hpp b/apps/opencs/view/render/pagedworldspacewidget.hpp index 42a7ef45d..c6c8d8e13 100644 --- a/apps/opencs/view/render/pagedworldspacewidget.hpp +++ b/apps/opencs/view/render/pagedworldspacewidget.hpp @@ -22,6 +22,7 @@ namespace CSVRender std::map mCells; std::string mWorldspace; CSVWidget::SceneToolToggle *mControlElements; + bool mDisplayCellCoord; std::list mTextOverlays; std::map mEntities; diff --git a/apps/opencs/view/render/scenewidget.cpp b/apps/opencs/view/render/scenewidget.cpp index d70346f81..8835f857a 100644 --- a/apps/opencs/view/render/scenewidget.cpp +++ b/apps/opencs/view/render/scenewidget.cpp @@ -18,6 +18,7 @@ #include "navigation.hpp" #include "lighting.hpp" +#include "elements.hpp" // FIXME: for testing only namespace CSVRender { @@ -58,7 +59,7 @@ namespace CSVRender setLighting (&mLightingDay); - Ogre::OverlaySystem *mOverlaySystem = new Ogre::OverlaySystem(); // FIXME: delete + Ogre::OverlaySystem *mOverlaySystem = new Ogre::OverlaySystem(); mSceneMgr->addRenderQueueListener(mOverlaySystem); QTimer *timer = new QTimer (this); @@ -162,8 +163,17 @@ namespace CSVRender if (mWindow) Ogre::Root::getSingleton().destroyRenderTarget (mWindow); + if (mOverlaySystem) + { + if (mSceneMgr) + mSceneMgr->removeRenderQueueListener (mOverlaySystem); + + delete mOverlaySystem; + } + if (mSceneMgr) Ogre::Root::getSingleton().destroySceneManager (mSceneMgr); + } void SceneWidget::setVisibilityMask (unsigned int mask) @@ -287,6 +297,20 @@ namespace CSVRender break; + //FIXME: for testing only + case Qt::Key_N: + setVisibilityMask((uint32_t)mViewport->getVisibilityMask() + & ~(uint32_t)CSVRender::Elements::Element_CellMarker); + updateOverlay(); + break; + + //FIXME: for testing only + case Qt::Key_M: + setVisibilityMask((uint32_t)mViewport->getVisibilityMask() + | (uint32_t)CSVRender::Elements::Element_CellMarker); + updateOverlay(); + break; + default: QWidget::keyReleaseEvent (event); } } diff --git a/apps/opencs/view/render/scenewidget.hpp b/apps/opencs/view/render/scenewidget.hpp index 1dab9a978..05d5c7621 100644 --- a/apps/opencs/view/render/scenewidget.hpp +++ b/apps/opencs/view/render/scenewidget.hpp @@ -15,6 +15,7 @@ namespace Ogre class SceneManager; class RenderWindow; class Viewport; + class OverlaySystem; } namespace CSVWidget @@ -89,6 +90,7 @@ namespace CSVRender Ogre::SceneManager* mSceneMgr; Ogre::RenderWindow* mWindow; Ogre::Viewport *mViewport; + Ogre::OverlaySystem *mOverlaySystem; Navigation *mNavigation; Lighting *mLighting; diff --git a/apps/opencs/view/render/textoverlay.cpp b/apps/opencs/view/render/textoverlay.cpp index 91fb88385..377810ef4 100644 --- a/apps/opencs/view/render/textoverlay.cpp +++ b/apps/opencs/view/render/textoverlay.cpp @@ -259,20 +259,8 @@ int TextOverlay::fontHeight() return mFontHeight; } -void TextOverlay::update(bool toggleOverlay) +void TextOverlay::update() { - if(toggleOverlay) - mEnabled = !mEnabled; - - if (!mEnabled) - { - mOverlay->hide(); - Ogre::Root::getSingleton().renderOneFrame(); - return; - } - else - mOverlay->show(); - float min_x, max_x, min_y, max_y; getMinMaxEdgesOfTopAABBIn2D(min_x, min_y, max_x, max_y); diff --git a/apps/opencs/view/render/textoverlay.hpp b/apps/opencs/view/render/textoverlay.hpp index 3f0c6ac57..30a5e3524 100644 --- a/apps/opencs/view/render/textoverlay.hpp +++ b/apps/opencs/view/render/textoverlay.hpp @@ -50,7 +50,7 @@ namespace CSVRender void enable(bool enable); bool isEnabled(); void setCaption(const Ogre::String& text); - void update(bool toggleOverlay = false); + void update(); QRect container(); Ogre::String getCaption() { return mCaption; } // FIXME: debug };