//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~ 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; }
//! //! Deletes a whole scene node tree (including attached objects). //! //! \param sceneNode The scene node containing the tree to delete. //! \param sceneManager The scene manager to use for destroying the scene node. //! \param deleteRoot Flag to control whether to delete the given scene node. //! void OgreTools::deepDeleteSceneNode ( Ogre::SceneNode *sceneNode, Ogre::SceneManager *sceneManager /* = 0 */, bool deleteRoot /* = false */ ) { // make sure the given scene node is valid if (!sceneNode) { Log::error("The given scene node is invalid.", "OgreTools::deepDeleteSceneNode"); return; } // make sure a valid scene manager is available if (!sceneManager) sceneManager = sceneNode->getCreator(); if (!sceneManager) { Log::error("No valid scene manager available.", "OgreTools::deepDeleteSceneNode"); return; } // iterate over the list of attached objects Ogre::SceneNode::ObjectIterator objectIterator = sceneNode->getAttachedObjectIterator(); while (objectIterator.hasMoreElements()) { Ogre::MovableObject *movableObject = objectIterator.getNext(); sceneNode->detachObject(movableObject); Ogre::SceneManager *movableSceneManager = movableObject->_getManager(); if (!movableSceneManager) { Log::error("The Ogre scene manager could not be obtained.", "OgreTools::deepDeleteSceneNode"); return; } Ogre::Any customData = movableObject->getUserAny(); if (!customData.isEmpty()) { OgreContainer *ogreContainer = Ogre::any_cast<OgreContainer *>(customData); if (ogreContainer) { delete ogreContainer; ogreContainer = 0; } } movableSceneManager->destroyMovableObject(movableObject); } // iterate over the list of child nodes Ogre::SceneNode::ChildNodeIterator childNodeIterator = sceneNode->getChildIterator(); while (childNodeIterator.hasMoreElements()) { Ogre::SceneNode *childSceneNode = dynamic_cast<Ogre::SceneNode *>(childNodeIterator.getNext()); if (childSceneNode) { Ogre::Any customData = childSceneNode->getUserAny(); if (!customData.isEmpty()) { OgreContainer *ogreContainer = Ogre::any_cast<OgreContainer *>(customData); if (ogreContainer) { delete ogreContainer; ogreContainer = 0; } else { CameraInfo *cameraInfo = Ogre::any_cast<CameraInfo *>(customData); if (cameraInfo) { delete cameraInfo; cameraInfo = 0; } } } deepDeleteSceneNode(childSceneNode, sceneManager); } } // destroy all child nodes of the given scene node sceneNode->removeAndDestroyAllChildren(); // check if the given scene node should be destroyed as well if (deleteRoot) { Ogre::Any customData = sceneNode->getUserAny(); if (!customData.isEmpty()) { OgreContainer *ogreContainer = Ogre::any_cast<OgreContainer *>(customData); if (ogreContainer) { delete ogreContainer; ogreContainer = 0; } else { CameraInfo *cameraInfo = Ogre::any_cast<CameraInfo *>(customData); if (cameraInfo) { delete cameraInfo; cameraInfo = 0; } } } sceneManager->destroySceneNode(sceneNode); } }
bool CombatSetupWnd::EventFilter(GG::Wnd* w, const GG::WndEvent& event) { // Turn off all event handling to lock down CombatWnd. if (m_setup_finished_waiting_for_server) return true; bool retval = false; if (event.Type() == GG::WndEvent::LButtonDown) { Ogre::MovableObject* movable_object = 0; if (!PlaceableShipNode() && (movable_object = m_get_object_under_pt(event.Point()))) { Ogre::SceneNode* node = movable_object->getParentSceneNode(); if (Ogre::any_cast<Ship*>(&node->getUserAny())) { m_button_press_placed_ship_node = node; assert(m_button_press_placed_ship_node); m_button_press_on_placed_ship = event.Point(); } } m_dragging_placed_ship = false; m_mouse_dragged = false; } else if (event.Type() == GG::WndEvent::LDrag) { HandleMouseMoves(event.Point()); if (m_button_press_placed_ship_node) { if (!m_dragging_placed_ship) { const int DRAG_THRESHOLD = 5; GG::Pt delta = event.Point() - m_button_press_on_placed_ship; if (DRAG_THRESHOLD < std::abs(Value(delta.x)) + std::abs(Value(delta.y))) m_dragging_placed_ship = true; } if (m_dragging_placed_ship) { std::pair<bool, Ogre::Vector3> intersection = m_intersect_mouse_with_ecliptic(event.Point()); Ship* ship = *Ogre::any_cast<Ship*>(&m_button_press_placed_ship_node->getUserAny()); bool valid_location = intersection.first && ValidPlacement(ship, intersection.second); if (valid_location) RepositionShip(ship, m_button_press_placed_ship_node, intersection.second); } } retval = true; m_mouse_dragged = true; } else if (event.Type() == GG::WndEvent::LButtonUp) { m_button_press_placed_ship_node = 0; m_mouse_dragged = false; } else if (event.Type() == GG::WndEvent::LClick) { Ogre::SceneNode* placement_node = PlaceableShipNode(); bool valid_placement = false; if (placement_node) { std::pair<bool, Ogre::Vector3> intersection = m_intersect_mouse_with_ecliptic(event.Point()); Ship* ship = *Ogre::any_cast<Ship*>(&placement_node->getUserAny()); valid_placement = intersection.first && ValidPlacement(ship, intersection.second); } if (valid_placement) { PlaceCurrentShip(); retval = true; } else if (m_mouse_dragged) { retval = true; } m_button_press_placed_ship_node = 0; } else if (event.Type() == GG::WndEvent::RClick) { CancelCurrentShipPlacement(); retval = true; } else if (event.Type() == GG::WndEvent::RDoubleClick) { retval = true; } else if (event.Type() == GG::WndEvent::MouseEnter) { HandleMouseMoves(event.Point()); } else if (event.Type() == GG::WndEvent::MouseHere) { HandleMouseMoves(event.Point()); } else if (event.Type() == GG::WndEvent::MouseLeave) { if (Ogre::SceneNode* placement_node = PlaceableShipNode()) placement_node->setVisible(false); } return retval; }