diff --git a/apps/opencs/model/settings/usersettings.cpp b/apps/opencs/model/settings/usersettings.cpp index 1813a97ff..9fe947b68 100644 --- a/apps/opencs/model/settings/usersettings.cpp +++ b/apps/opencs/model/settings/usersettings.cpp @@ -150,6 +150,13 @@ void CSMSettings::UserSettings::buildSettingModelDefaults() ritd->setDeclaredValues (values); } + declareSection ("debug", "Debug Options"); + { + Setting *mousePicking = createSetting (Type_CheckBox, "mouse-picking", "Debug Render Mouse-Picking"); + mousePicking->setDefaultValue ("false"); + mousePicking->setToolTip ("Enable redering debug information for mouse picking. " + "This option may be removed in future once the mouse picking feature is completed."); + } { /****************************************************************** diff --git a/apps/opencs/view/render/pagedworldspacewidget.cpp b/apps/opencs/view/render/pagedworldspacewidget.cpp index 8f8b2de65..2bb95912b 100644 --- a/apps/opencs/view/render/pagedworldspacewidget.cpp +++ b/apps/opencs/view/render/pagedworldspacewidget.cpp @@ -19,6 +19,7 @@ #include "../../model/world/tablemimedata.hpp" #include "../../model/world/idtable.hpp" +#include "../../model/settings/usersettings.hpp" #include "../widget/scenetooltoggle.hpp" #include "../world/physicssystem.hpp" @@ -185,9 +186,12 @@ void CSVRender::PagedWorldspaceWidget::mouseReleaseEvent (QMouseEvent *event) break; } } - } - else - { + + CSMSettings::UserSettings &userSettings = CSMSettings::UserSettings::instance(); + bool debug = userSettings.setting ("debug/mouse-picking", QString("false")) == "true" ? true : false; + if(!debug) + return; + // mouse picking // FIXME: need to virtualise mouse buttons int viewportWidth = getCamera()->getViewport()->getActualWidth(); @@ -196,12 +200,12 @@ void CSVRender::PagedWorldspaceWidget::mouseReleaseEvent (QMouseEvent *event) float mouseX = (float) event->x()/viewportWidth; float mouseY = (float) event->y()/viewportHeight; - // Need to set each time in case there are multiple subviews + // Need to set scene manager each time in case there are multiple subviews CSVWorld::PhysicsSystem::instance()->setSceneManager(getSceneManager()); - std::pair result = CSVWorld::PhysicsSystem::instance()->castRay(mouseX, mouseY, NULL, NULL, getCamera()); + std::pair result = + CSVWorld::PhysicsSystem::instance()->castRay(mouseX, mouseY, NULL, NULL, getCamera()); if(result.first) { - flagAsModified(); std::cout << "ReferenceId: " << result.second << std::endl; const CSMWorld::CellRef& cellref = mDocument.getData().getReferences().getRecord (result.second).get(); //std::cout << "CellRef mId: " << cellref.mId << std::endl; // Same as ReferenceId @@ -223,11 +227,12 @@ void CSVRender::PagedWorldspaceWidget::mouseReleaseEvent (QMouseEvent *event) { if(iter->first.getId("dummy") == cellref.mCell) { - std::cout << "Cell found" << std::endl; + //std::cout << "Cell found" << std::endl; break; } ++iter; } + flagAsModified(); } } } @@ -238,9 +243,15 @@ void CSVRender::PagedWorldspaceWidget::mouseDoubleClickEvent (QMouseEvent *event { std::cout << "double clicked" << std::endl; - // Need to set each time in case there are multiple subviews + CSMSettings::UserSettings &userSettings = CSMSettings::UserSettings::instance(); + bool debug = userSettings.setting ("debug/mouse-picking", QString("false")) == "true" ? true : false; + if(!debug) + return; + + // Need to set scene manager each time in case there are multiple subviews CSVWorld::PhysicsSystem::instance()->setSceneManager(getSceneManager()); CSVWorld::PhysicsSystem::instance()->toggleDebugRendering(); + flagAsModified(); } } diff --git a/apps/opencs/view/world/physicssystem.cpp b/apps/opencs/view/world/physicssystem.cpp index 31413ac71..6db38dd87 100644 --- a/apps/opencs/view/world/physicssystem.cpp +++ b/apps/opencs/view/world/physicssystem.cpp @@ -148,7 +148,9 @@ namespace CSVWorld void PhysicsSystem::toggleDebugRendering() { - if(!mSceneMgr) + CSMSettings::UserSettings &userSettings = CSMSettings::UserSettings::instance(); + bool debug = userSettings.setting ("debug/mouse-picking", QString("false")) == "true" ? true : false; + if(!mSceneMgr || !debug) return; // FIXME: add a warning message mEngine->toggleDebugRendering(); @@ -158,6 +160,8 @@ namespace CSVWorld std::pair PhysicsSystem::castRay(float mouseX, float mouseY, Ogre::Vector3* normal, std::string* hit, Ogre::Camera *camera) { + CSMSettings::UserSettings &userSettings = CSMSettings::UserSettings::instance(); + bool debug = userSettings.setting ("debug/mouse-picking", QString("false")) == "true" ? true : false; if(!mSceneMgr) return std::make_pair(false, ""); // FIXME: add a warning message @@ -168,7 +172,6 @@ namespace CSVWorld camera->setNearClipDistance(nearClipDistance); Ogre::Vector3 from = ray.getOrigin(); - CSMSettings::UserSettings &userSettings = CSMSettings::UserSettings::instance(); float farClipDist = userSettings.setting("Scene/far clip distance", QString("300000")).toFloat(); Ogre::Vector3 to = ray.getPoint(farClipDist); @@ -193,7 +196,7 @@ namespace CSVWorld Ogre::SceneNode *scene = mSceneMgr->getSceneNode(sceneNode); std::map >::iterator iter = mSelectedEntities.find(sceneNode); - if(iter != mSelectedEntities.end()) // currently selected + if(debug && iter != mSelectedEntities.end()) // currently selected { std::vector clonedEntities = mSelectedEntities[sceneNode]; while(!clonedEntities.empty()) @@ -207,9 +210,12 @@ namespace CSVWorld } mSelectedEntities.erase(iter); - removeHitPoint(mSceneMgr, sceneNode); // FIXME: for debugging + bool debugCursor = userSettings.setting ( + "debug/mouse-position", QString("false")) == "true" ? true : false; + if(debugCursor) // FIXME: show cursor position for debugging + removeHitPoint(mSceneMgr, sceneNode); } - else + else if(debug) { std::vector clonedEntities; Ogre::SceneNode::ObjectIterator iter = scene->getAttachedObjectIterator(); @@ -244,19 +250,12 @@ namespace CSVWorld } mSelectedEntities[sceneNode] = clonedEntities; - // FIXME: show cursor position for debugging + bool debugCursor = userSettings.setting ( + "debug/mouse-position", QString("false")) == "true" ? true : false; + if(debugCursor) // FIXME: show cursor position for debugging showHitPoint(mSceneMgr, sceneNode, ray.getPoint(farClipDist*result.second)); } -#if 0 - std::cout << "hit " << result.first - + " result " + std::to_string(result.second*farClipDist) << std::endl; - std::cout << "normal " + std::to_string(norm.x) - + ", " + std::to_string(norm.y) - + ", " + std::to_string(norm.z) << std::endl; - std::cout << "hit pos "+ std::to_string(ray.getPoint(farClipDist*result.second).x) - + ", " + std::to_string(ray.getPoint(farClipDist*result.second).y) - + ", " + std::to_string(ray.getPoint(farClipDist*result.second).z) << std::endl; -#endif + return std::make_pair(true, result.first); } }