void PolygonPointPickListener::processPickResult(bool& continuePicking, Ogre::RaySceneQueryResultEntry& entry, Ogre::Ray& cameraRay, const MousePickerArgs& mousePickerArgs) { if (entry.movable) { Ogre::MovableObject* pickedMovable = entry.movable; if (pickedMovable->isVisible() && pickedMovable->getUserAny().getType() == typeid(PolygonPointUserObject*)) { //TODO: make sure that it's a point which belongs to our polygon mPickedUserObject = Ogre::any_cast<PolygonPointUserObject*>(pickedMovable->getUserAny()); continuePicking = false; } } }
bool StateTargeting::OnInputSys_MouseMove( const OIS::MouseEvent &arg ) { SelectableObject* pObj = World::GetSingleton().GetSelectedObjects().at(0); eCommandType cmd = pObj->GetActiveAbility()->m_type; //获取当前鼠标hover下的物体 Ogre::MovableObject* pMovable = World::GetSingleton().GetRaySceneQueryResult(arg, QueryTypeSelectableObject); SelectableObject* pHoverObj = nullptr; if(pMovable) { pHoverObj = Ogre::any_cast<SelectableObject*>(pMovable->getUserAny()); assert(pHoverObj); } //根据当前命令类型确定鼠标样式 Kratos::eCursorMode mode; switch (cmd) { case eCommandType_Move: { //无法移动.. if(pHoverObj) mode = Kratos::eCursorMode_TargetInvalid; else mode = Kratos::eCursorMode_TargetNone; } break; case eCommandType_Gather: { if(pHoverObj && pHoverObj->GetType() == eObjectType_Resource) mode = Kratos::eCursorMode_TargetAllied; else mode = Kratos::eCursorMode_TargetInvalid; } break; case eCommandType_Attack: { if (pHoverObj) { if(pHoverObj->GetType() == eObjectType_Resource) mode = Kratos::eCursorMode_TargetInvalid; else if(pObj->GetAi()->IsAlly(pHoverObj)) mode = Kratos::eCursorMode_TargetAllied; else mode = Kratos::eCursorMode_TargetEnemy; } else { mode = Kratos::eCursorMode_TargetNone; } } break; default: assert(0); } GUIMANAGER.SetCursorMode(mode); //让其他handler继续响应 return false; }
//! //! 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 SnapToMovement::testSnapTo(const WFMath::Point<3>& position, const WFMath::Quaternion& orientation, WFMath::Vector<3>& adjustment, EmberEntity* snappedToEntity) { try { for (std::vector<Ogre::SceneNode*>::iterator I = mDebugNodes.begin(); I != mDebugNodes.end(); ++I) { Ogre::SceneNode* node = *I; node->setVisible(false); Ogre::Entity* sphereEntity = static_cast<Ogre::Entity*> (node->getAttachedObject(0)); sphereEntity->setMaterialName("/global/authoring/point"); } } catch (const std::exception& ex) { S_LOG_WARNING("Error when setting up debug nodes for snapping." << ex); } std::vector<Ogre::SceneNode*>::iterator nodeIterator = mDebugNodes.begin(); //Use an auto pointer to allow both for undefined values and automatic cleanup when exiting the method. std::auto_ptr<SnapPointCandidate> closestSnapping(0); WFMath::AxisBox<3> currentBbox = mEntity.getBBox(); //Translate the bbox into a rotbox WFMath::RotBox<3> currentRotbox; currentRotbox.size() = currentBbox.highCorner() - currentBbox.lowCorner(); currentRotbox.corner0() = currentBbox.lowCorner(); currentRotbox.orientation().identity(); currentRotbox.rotatePoint(orientation, WFMath::Point<3>(0, 0, 0)); currentRotbox.shift(WFMath::Vector<3>(position)); //See if we should visualize debug nodes for the moved entity for (size_t j = 0; j < currentRotbox.numCorners(); ++j) { WFMath::Point<3> currentPoint = currentRotbox.getCorner(j); if (currentPoint.isValid() && nodeIterator != mDebugNodes.end()) { Ogre::SceneNode* node = *nodeIterator; node->setPosition(Convert::toOgre(currentPoint)); node->setVisible(true); nodeIterator++; } } //First find all entities which are close enough //Then try to do a snap movement based on the points of the eris bounding boxes. I.e. we only provide support for snapping one corner of a bounding box to another corner (for now). WFMath::Ball<3> boundingSphere = mEntity.getBBox().boundingSphere(); Ogre::Sphere sphere(mNode._getDerivedPosition(), boundingSphere.radius() * 2); Ogre::SphereSceneQuery* query = mSceneManager.createSphereQuery(sphere); Ogre::SceneQueryResult& result = query->execute(); for (Ogre::SceneQueryResultMovableList::const_iterator I = result.movables.begin(); I != result.movables.end(); ++I) { Ogre::MovableObject* movable = *I; if (movable->getUserAny().getType() == typeid(EmberEntityUserObject::SharedPtr)) { EmberEntityUserObject* anUserObject = Ogre::any_cast<EmberEntityUserObject::SharedPtr>(movable->getUserAny()).get(); EmberEntity& entity = anUserObject->getEmberEntity(); if (&entity != &mEntity && entity.hasBBox()) { //Ok, we have an entity which is close to our entity. Now check if any of the points of the bounding box is close. WFMath::AxisBox<3> bbox = entity.getBBox(); if (bbox.isValid()) { WFMath::RotBox<3> rotbox; rotbox.size() = bbox.highCorner() - bbox.lowCorner(); rotbox.corner0() = bbox.lowCorner(); rotbox.orientation().identity(); rotbox.rotatePoint(entity.getViewOrientation(), WFMath::Point<3>(0, 0, 0)); rotbox.shift(WFMath::Vector<3>(entity.getViewPosition())); for (size_t i = 0; i < rotbox.numCorners(); ++i) { WFMath::Point<3> point = rotbox.getCorner(i); Ogre::SceneNode* currentNode(0); //If there is any unclaimed debug node left we'll use it to visualize the corner if (nodeIterator != mDebugNodes.end()) { currentNode = *nodeIterator; currentNode->setPosition(Convert::toOgre(point)); currentNode->setVisible(true); nodeIterator++; } point.z() = 0; for (size_t j = 0; j < currentRotbox.numCorners(); ++j) { WFMath::Point<3> currentPoint = currentRotbox.getCorner(j); currentPoint.z() = 0; WFMath::CoordType distance = WFMath::Distance(currentPoint, point); if (distance <= mSnapThreshold) { if (currentNode) { Ogre::Entity* sphereEntity = static_cast<Ogre::Entity*> (currentNode->getAttachedObject(0)); if (sphereEntity) { try { sphereEntity->setMaterialName("/global/authoring/point/moved"); } catch (const std::exception& ex) { S_LOG_WARNING("Error when setting material for point." << ex); } } } if (!closestSnapping.get()) { closestSnapping = std::auto_ptr<SnapPointCandidate>(new SnapPointCandidate()); closestSnapping->entity = &entity; closestSnapping->distance = distance; closestSnapping->adjustment = point - currentPoint; } else if (distance < closestSnapping->distance) { closestSnapping->entity = &entity; closestSnapping->distance = distance; closestSnapping->adjustment = point - currentPoint; } } } } } } } } mSceneManager.destroyQuery(query); if (closestSnapping.get()) { adjustment = closestSnapping->adjustment; snappedToEntity = closestSnapping->entity; return true; } return false; }