/** * @brief * Performs the picking */ void MyPicking::PerformPicking() { // Get the default input controller of the application Controller *pController = reinterpret_cast<Controller*>(m_pApplication->GetInputController()); if (pController && pController->GetActive()) { // Get the "MouseLeft" control Control *pControl = pController->GetControl("MouseLeft"); if (pControl && pControl->GetType() == ControlButton) { Button *pButton = reinterpret_cast<Button*>(pControl); SceneNode *pPickedSceneNode = nullptr; // If the left mouse button is currently down, do NOT perform new picking if (!pButton->IsPressed()) { // Get the current time data const uint64 nPastTime = Timing::GetInstance()->GetPastTime(); // Perform mouse picking - do not make this test each frame because it may cost some performance if ((nPastTime-m_nLastPickingTime) > 100) { m_nLastPickingTime = nPastTime; // Perform picking - "PerformMousePicking()" is using the current mouse position inside the main window // and the currently used camera in order to find the scene node under the mouse cursor PickingResult cPickingResult; if (PerformMousePicking(cPickingResult)) pPickedSceneNode = cPickingResult.GetSceneNode(); } else { // Use the previous result pPickedSceneNode = m_cCurrentPickedSceneNodeHandler.GetElement(); } // Picked changed? if (pPickedSceneNode != m_cCurrentPickedSceneNodeHandler.GetElement()) { // Backup the currently picked scene node m_cCurrentPickedSceneNodeHandler.SetElement(pPickedSceneNode); } } // Is currently anything picked? if (pButton->IsHit() && pPickedSceneNode) { // Toggle the debug mode of the picked scene node if (pPickedSceneNode->GetDebugFlags() & SceneNode::DebugEnabled) { // Disable debug mode pPickedSceneNode->SetDebugFlags(pPickedSceneNode->GetDebugFlags() & ~SceneNode::DebugEnabled); } else { // Enable debug mode pPickedSceneNode->SetDebugFlags(pPickedSceneNode->GetDebugFlags() |SceneNode::DebugEnabled); } } } } }
void SceneNode::SetDebugFlags(uint32 _debugFlags, bool isRecursive) { debugFlags = _debugFlags; if (isRecursive) { std::vector<SceneNode*>::iterator it = childs.begin(); std::vector<SceneNode*>::iterator childsEnd = childs.end(); for(; it != childsEnd; it++) { SceneNode *n = (*it); n->SetDebugFlags(_debugFlags, isRecursive); } } }