void InputHandler::capture() { if (keyboard == 0 && mouse == 0) { try { keyboard = static_cast<OIS::Keyboard*> (ois->createInputObject(OIS::OISKeyboard, true)); keyboard->setEventCallback(this); mouse = static_cast<OIS::Mouse*> (ois->createInputObject(OIS::OISMouse, true)); mouse->setEventCallback(this); cout << "[libclois-lane] Keyboard and mouse acquired!" << endl; } catch (OIS::Exception &e) { cout << "[libclois-lane] " << e.eText << endl; } } else { try { keyboard->capture(); mouse->capture(); } catch (OIS::Exception &e) { cout << "[libclois-lane] " << e.eText << endl; keyboard = 0; mouse = 0; } } }
void setupInputSystem() { size_t windowHnd = 0; std::ostringstream windowHndStr; OIS::ParamList pl; RenderWindow *win = mRoot->getAutoCreatedWindow(); win->getCustomAttribute("WINDOW", &windowHnd); windowHndStr << windowHnd; pl.insert(std::make_pair(std::string("WINDOW"), windowHndStr.str())); mInputManager = OIS::InputManager::createInputSystem(pl); try { mKeyboard = static_cast<OIS::Keyboard*>(mInputManager->createInputObject(OIS::OISKeyboard, true)); mKeyboard->setEventCallback(this); //mMouse = static_cast<OIS::Mouse*>(mInputManager->createInputObject(OIS::OISMouse, false)); //mJoy = static_cast<OIS::JoyStick*>(mInputManager->createInputObject(OIS::OISJoyStick, false)); } catch (const OIS::Exception &e) { throw new Exception(42, e.eText, "Application::setupInputSystem"); } }
int main(int argc, char **argv) #endif { //----------------------------------------------------- // 1 enter ogre //----------------------------------------------------- Root* root = new Root; //----------------------------------------------------- // 2 configure resource paths //----------------------------------------------------- // Load resource paths from config file // File format is: // [ResourceGroupName] // ArchiveType=Path // .. repeat // For example: // [General] // FileSystem=media/ // Zip=packages/level1.zip ConfigFile cf; cf.load("./resources.cfg"); // Go through all sections & settings in the file ConfigFile::SectionIterator seci = cf.getSectionIterator(); String secName, typeName, archName; while (seci.hasMoreElements()) { secName = seci.peekNextKey(); ConfigFile::SettingsMultiMap *settings = seci.getNext(); ConfigFile::SettingsMultiMap::iterator i; for (i = settings->begin(); i != settings->end(); ++i) { typeName = i->first; archName = i->second; ResourceGroupManager::getSingleton().addResourceLocation( archName, typeName, secName); } } //----------------------------------------------------- // 3 Configures the application and creates the window //----------------------------------------------------- if(!root->showConfigDialog()) { //Ogre delete root; return false; // Exit the application on cancel } RenderWindow* window = root->initialise(true, "Simple Ogre App"); ResourceGroupManager::getSingleton().initialiseAllResourceGroups(); //----------------------------------------------------- // 4 Create the SceneManager // // ST_GENERIC = octree // ST_EXTERIOR_CLOSE = simple terrain // ST_EXTERIOR_FAR = nature terrain (depreciated) // ST_EXTERIOR_REAL_FAR = paging landscape // ST_INTERIOR = Quake3 BSP //----------------------------------------------------- SceneManager* sceneMgr = root->createSceneManager(ST_GENERIC); //----------------------------------------------------- // 5 Create the camera //----------------------------------------------------- Camera* camera = sceneMgr->createCamera("SimpleCamera"); //----------------------------------------------------- // 6 Create one viewport, entire window //----------------------------------------------------- Viewport* viewPort = window->addViewport(camera); //---------------------------------------------------- // 7 add OIS input handling //---------------------------------------------------- OIS::ParamList pl; size_t windowHnd = 0; std::ostringstream windowHndStr; //tell OIS about the Ogre window window->getCustomAttribute("WINDOW", &windowHnd); windowHndStr << windowHnd; pl.insert(std::make_pair(std::string("WINDOW"), windowHndStr.str())); //setup the manager, keyboard and mouse to handle input OIS::InputManager* inputManager = OIS::InputManager::createInputSystem(pl); OIS::Keyboard* keyboard = static_cast<OIS::Keyboard*>(inputManager->createInputObject(OIS::OISKeyboard, true)); OIS::Mouse* mouse = static_cast<OIS::Mouse*>(inputManager->createInputObject(OIS::OISMouse, true)); //tell OIS about the window's dimensions unsigned int width, height, depth; int top, left; window->getMetrics(width, height, depth, left, top); const OIS::MouseState &ms = mouse->getMouseState(); ms.width = width; ms.height = height; // everything is set up, now we listen for input and frames (replaces while loops) //key events SimpleKeyListener* keyListener = new SimpleKeyListener(); keyboard->setEventCallback(keyListener); //mouse events SimpleMouseListener* mouseListener = new SimpleMouseListener(); mouse->setEventCallback(mouseListener); //render events SimpleFrameListener* frameListener = new SimpleFrameListener(keyboard, mouse); root->addFrameListener(frameListener); //---------------------------------------------------- // 8 start rendering //---------------------------------------------------- root->startRendering(); // blocks until a frame listener returns false. eg from pressing escape in this example //---------------------------------------------------- // 9 clean //---------------------------------------------------- //OIS inputManager->destroyInputObject(mouse); mouse = 0; inputManager->destroyInputObject(keyboard); keyboard = 0; OIS::InputManager::destroyInputSystem(inputManager); inputManager = 0; //listeners delete frameListener; delete mouseListener; delete keyListener; //Ogre delete root; return 0; }
bool initialise() { mRoot = new Ogre::Root(PLUGINS_CFG, OGRE_CFG, OGRE_LOG); if (!mRoot->restoreConfig()) if (!mRoot->showConfigDialog()) return false; initResources(); mWindow = mRoot->initialise(true, "CS Clone Editor v0.0"); Ogre::WindowEventUtilities::addWindowEventListener(mWindow, this); mSceneMgr = mRoot->createSceneManager(Ogre::ST_GENERIC); mSceneMgr->setAmbientLight(Ogre::ColourValue(0.7, 0.7, 0.7)); mCamera = mSceneMgr->createCamera("camera"); mWindow->addViewport(mCamera); mCamera->setAutoAspectRatio(true); mCamera->setNearClipDistance(0.1); mCamera->setFarClipDistance(10000); mCamera->setPosition(10, 10, 10); // mCamera->lookAt(0, 0, 0); mRoot->addFrameListener(this); Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups(); //Initializing OIS Ogre::LogManager::getSingletonPtr()->logMessage("*-*-* OIS Initialising"); OIS::ParamList pl; size_t windowHnd = 0; mWindow->getCustomAttribute("WINDOW", &windowHnd); pl.insert(std::make_pair(std::string("WINDOW"), Ogre::StringConverter::toString(windowHnd))); #if OGRE_DEBUG_MODE == 1 #if OGRE_PLATFORM == OGRE_PLATFORM_LINUX #define NO_EXCLUSIVE_INPUT #endif #endif #ifdef NO_EXCLUSIVE_INPUT #if defined OIS_WIN32_PLATFORM pl.insert(std::make_pair(std::string("w32_mouse"), std::string("DISCL_FOREGROUND" ))); pl.insert(std::make_pair(std::string("w32_mouse"), std::string("DISCL_NONEXCLUSIVE"))); pl.insert(std::make_pair(std::string("w32_keyboard"), std::string("DISCL_FOREGROUND"))); pl.insert(std::make_pair(std::string("w32_keyboard"), std::string("DISCL_NONEXCLUSIVE"))); #elif defined OIS_LINUX_PLATFORM pl.insert(std::make_pair(std::string("x11_mouse_grab"), std::string("false"))); pl.insert(std::make_pair(std::string("x11_mouse_hide"), std::string("false"))); pl.insert(std::make_pair(std::string("x11_keyboard_grab"), std::string("false"))); pl.insert(std::make_pair(std::string("XAutoRepeatOn"), std::string("true"))); #endif #endif mInputManager = OIS::InputManager::createInputSystem(pl); mKeyboard = static_cast<OIS::Keyboard*>(mInputManager->createInputObject(OIS::OISKeyboard, true)); mKeyboard->setEventCallback(this); mMouse = static_cast<OIS::Mouse*>(mInputManager->createInputObject(OIS::OISMouse, true)); mMouse->setEventCallback(this); windowResized(mWindow); //Initialising GUI Ogre::LogManager::getSingletonPtr()->logMessage("*-*-* MyGUI Initialising"); mGUI = new MyGUI::Gui; mGUI->initialise(mWindow); mGUI->load("editor.layout"); mMenuBar = mGUI->createWidget<MyGUI::MenuBar>("MenuBar", MyGUI::IntCoord(0, 0, mGUI->getViewWidth(), 28), MyGUI::ALIGN_TOP | MyGUI::ALIGN_HSTRETCH, "Overlapped"); mMenuBar->addItem("File"); mPopupMenuFile = mMenuBar->getItemMenu(0); mPopupMenuFile->addItem("New"); mPopupMenuFile->addItem("Open ..."); mPopupMenuFile->addItem("Save"); mPopupMenuFile->addItem("Save as ...", false, true); mPopupMenuFile->addItem("Settings", false, true); mPopupMenuFile->addItem("Quit"); mMenuBar->addItem("Help"); mPopupMenuHelp = mMenuBar->getItemMenu(1); mPopupMenuHelp->addItem("Help"); mPopupMenuHelp->addItem("About ..."); return (true); }