bool COgreVRApplication::initOIS() { OIS::ParamList l_oParamList; size_t windowHnd = 0; std::ostringstream windowHndStr; // Retrieve the rendering window RenderWindow* window = Ogre::Root::getSingleton().getAutoCreatedWindow(); window->getCustomAttribute("WINDOW", &windowHnd); windowHndStr << windowHnd; l_oParamList.insert(make_pair(std::string("WINDOW"), windowHndStr.str())); l_oParamList.insert(std::make_pair(std::string("x11_mouse_grab"), std::string("false"))); l_oParamList.insert(std::make_pair(std::string("x11_keyboard_grab"), std::string("false"))); // Create the input manager m_poInputManager = OIS::InputManager::createInputSystem( l_oParamList ); //Create all devices m_poKeyboard = static_cast<OIS::Keyboard*>(m_poInputManager->createInputObject( OIS::OISKeyboard, true )); m_poMouse = static_cast<OIS::Mouse*>(m_poInputManager->createInputObject( OIS::OISMouse, true )); m_poKeyboard->setEventCallback(this); m_poMouse->setEventCallback(this); std::cout<<"OIS initialised"<<std::endl; return true; }
void OgreWiiApp::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); int nJoys = mInputManager->numJoySticks(); try { mKeyboard = static_cast<OIS::Keyboard*>(mInputManager->createInputObject(OIS::OISKeyboard, true)); mMouse = static_cast<OIS::Mouse*>(mInputManager->createInputObject(OIS::OISMouse, true)); for (int i=0; i < nJoys; ++i) { OIS::JoyStick* joy = static_cast<OIS::JoyStick*>(mInputManager->createInputObject(OIS::OISJoyStick, true)); mJoys[String(joy->vendor())] = joy; } } catch (const OIS::Exception &e) { throw new Exception(42, e.eText, "Application::setupInputSystem"); } }
void go(void) { // OGRE의 메인 루트 오브젝트 생성 #if !defined(_DEBUG) mRoot = new Root("plugins.cfg", "ogre.cfg", "ogre.log"); #else mRoot = new Root("plugins_d.cfg", "ogre.cfg", "ogre.log"); #endif // 초기 시작의 컨피규레이션 설정 - ogre.cfg 이용 if (!mRoot->restoreConfig()) { if (!mRoot->showConfigDialog()) return; } mWindow = mRoot->initialise(true, "Hello Professor : Copyleft Dae-Hyun Lee"); // ESC key를 눌렀을 경우, 오우거 메인 렌더링 루프의 탈출을 처리 size_t windowHnd = 0; std::ostringstream windowHndStr; OIS::ParamList pl; mWindow->getCustomAttribute("WINDOW", &windowHnd); windowHndStr << windowHnd; pl.insert(std::make_pair(std::string("WINDOW"), windowHndStr.str())); mInputManager = OIS::InputManager::createInputSystem(pl); mKeyboard = static_cast<OIS::Keyboard*>(mInputManager->createInputObject(OIS::OISKeyboard, false)); mESCListener = new ESCListener(mKeyboard); mRoot->addFrameListener(mESCListener); mSceneMgr = mRoot->createSceneManager(ST_GENERIC); mCamera = mSceneMgr->createCamera("camera"); mCamera->setPosition(0.0f, 200.0f, 300.0f); mCamera->lookAt(0.0f, 100.0f, 0.00f); mCamera->setNearClipDistance(5.0f); mViewport = mWindow->addViewport(mCamera); mViewport->setBackgroundColour(ColourValue(0.0f,0.0f,0.5f)); mCamera->setAspectRatio(Real(mViewport->getActualWidth()) / Real(mViewport->getActualHeight())); ResourceGroupManager::getSingleton().addResourceLocation("resource.zip", "Zip"); ResourceGroupManager::getSingleton().initialiseAllResourceGroups(); mSceneMgr->setAmbientLight(ColourValue(1.0f, 1.0f, 1.0f)); Entity* daehyunEntity = mSceneMgr->createEntity("Daehyun", "DustinBody.mesh"); SceneNode* daehyunNode = mSceneMgr->getRootSceneNode()->createChildSceneNode(); daehyunNode->attachObject(daehyunEntity); mRoot->startRendering(); mInputManager->destroyInputObject(mKeyboard); OIS::InputManager::destroyInputSystem(mInputManager); delete mRoot; }
void InputHandlerOIS::_inputWindowChanged(const RenderWindow& win) { UINT64 hWnd = 0; win.getCustomAttribute("WINDOW", &hWnd); std::string normalString = toString(hWnd).c_str(); mKeyboard->setCaptureContext(normalString); mMouse->setCaptureContext(normalString); }
void setupInputSystem() { size_t windowHnd = 0; std::ostringstream windowHndStr; OIS::ParamList pl; RenderWindow *win = mWindow; 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)); mMouse = static_cast<OIS::Mouse*>(mInputManager->createInputObject(OIS::OISMouse, true)); //mJoy = static_cast<OIS::JoyStick*>(mInputManager->createInputObject(OIS::OISJoyStick, false)); } catch (const OIS::Exception &e) { throw Exception(42, e.eText, "Application::setupInputSystem"); } }
int mainSetupAndRunOgre() { Ogre::LogManager* log_manager = 0; Ogre::Root* root = 0; #ifdef FREEORION_MACOSX OISInput* ois_input_plugin = 0; #elif defined(OGRE_STATIC_LIB) OISInput* ois_input_plugin = 0; Ogre::OctreePlugin* octree_plugin = 0; Ogre::ParticleFXPlugin* particle_fx_plugin = 0; Ogre::GLPlugin* gl_plugin = 0; #endif try { using namespace Ogre; log_manager = new LogManager(); log_manager->createLog((GetUserDir() / "ogre.log").string(), true, false); root = new Root((GetRootDataDir() / "ogre_plugins.cfg").string()); // this line is needed on some Linux systems which otherwise will crash with // errors about GLX_icon.png being missing. Ogre::ResourceGroupManager::getSingleton().addResourceLocation((ClientUI::ArtDir() / ".").string(), "FileSystem", "General"); #if defined(OGRE_STATIC_LIB) octree_plugin = new Ogre::OctreePlugin; particle_fx_plugin = new Ogre::ParticleFXPlugin; gl_plugin = new Ogre::GLPlugin; root->installPlugin(octree_plugin); root->installPlugin(particle_fx_plugin); root->installPlugin(gl_plugin); #endif RenderSystem* selected_render_system = root->getRenderSystemByName("OpenGL Rendering Subsystem"); if (selected_render_system == 0) throw std::runtime_error("Failed to find an Ogre GL render system."); root->setRenderSystem(selected_render_system); int colour_depth = GetOptionsDB().Get<int>("color-depth"); bool fullscreen = GetOptionsDB().Get<bool>("fullscreen"); std::pair<int, int> width_height = HumanClientApp::GetWindowWidthHeight(selected_render_system); int width(width_height.first), height(width_height.second); selected_render_system->setConfigOption("Full Screen", fullscreen ? "Yes" : "No"); std::string video_mode_str = boost::io::str(boost::format("%1% x %2% @ %3%-bit colour") % width % height % colour_depth); selected_render_system->setConfigOption("Video Mode", video_mode_str); RenderWindow* window = root->initialise(true, "FreeOrion " + FreeOrionVersionString()); #ifdef FREEORION_WIN32 # ifdef IDI_ICON1 // set window icon to embedded application icon HWND hwnd; window->getCustomAttribute("WINDOW", &hwnd); HINSTANCE hInst = (HINSTANCE)GetModuleHandle(NULL); SetClassLong (hwnd, GCL_HICON, (LONG)LoadIcon (hInst, MAKEINTRESOURCE (IDI_ICON1))); # endif #endif SceneManager* scene_manager = root->createSceneManager("OctreeSceneManager", "SceneMgr"); Camera* camera = scene_manager->createCamera("Camera"); camera->setPosition(Vector3(0, 0, 500)); // Position it at 500 in Z direction camera->lookAt(Vector3(0, 0, -300)); // Look back along -Z camera->setNearClipDistance(5); Viewport* viewport = window->addViewport(camera); viewport->setBackgroundColour(ColourValue(0, 0, 0)); //EntityRenderer entity_renderer(scene_manager); parse::init(); HumanClientApp app(root, window, scene_manager, camera, viewport, (GetRootDataDir() / "OISInput.cfg").string()); #ifdef FREEORION_MACOSX ois_input_plugin = new OISInput; root->installPlugin(ois_input_plugin); #elif defined(OGRE_STATIC_LIB) ois_input_plugin = new OISInput; root->installPlugin(ois_input_plugin); #else root->loadPlugin(OGRE_INPUT_PLUGIN_NAME); #endif if (GetOptionsDB().Get<bool>("quickstart")) { // immediately start the server, establish network connections, and // go into a single player game, using default universe options (a // standard quickstart, without requiring the user to click the // quickstart button). app.NewSinglePlayerGame(true); // acceptable to call before app() } std::string load_filename = GetOptionsDB().Get<std::string>("load"); if (load_filename != "") { // immediately start the server, establish network connections, and // go into a single player game, loading the indicated file // (without requiring the user to click the load button). app.LoadSinglePlayerGame(load_filename); // acceptable to call before app() } // run rendering loop app(); // calls GUI::operator() which calls OgreGUI::Run() which starts rendering loop } catch (const HumanClientApp::CleanQuit&) { // do nothing std::cout << "mainSetupAndRunOgre caught CleanQuit" << std::endl; } catch (const std::invalid_argument& e) { Logger().errorStream() << "main() caught exception(std::invalid_argument): " << e.what(); std::cerr << "main() caught exception(std::invalid_arg): " << e.what() << std::endl; } catch (const std::runtime_error& e) { Logger().errorStream() << "main() caught exception(std::runtime_error): " << e.what(); std::cerr << "main() caught exception(std::runtime_error): " << e.what() << std::endl; } catch (const boost::io::format_error& e) { Logger().errorStream() << "main() caught exception(boost::io::format_error): " << e.what(); std::cerr << "main() caught exception(boost::io::format_error): " << e.what() << std::endl; } catch (const GG::ExceptionBase& e) { Logger().errorStream() << "main() caught exception(" << e.type() << "): " << e.what(); std::cerr << "main() caught exception(" << e.type() << "): " << e.what() << std::endl; } catch (const std::exception& e) { Logger().errorStream() << "main() caught exception(std::exception): " << e.what(); std::cerr << "main() caught exception(std::exception): " << e.what() << std::endl; } catch (...) { Logger().errorStream() << "main() caught unknown exception."; std::cerr << "main() caught unknown exception." << std::endl; } if (root) { #ifdef FREEORION_MACOSX root->uninstallPlugin(ois_input_plugin); delete ois_input_plugin; #elif defined(OGRE_STATIC_LIB) root->uninstallPlugin(ois_input_plugin); root->uninstallPlugin(octree_plugin); root->uninstallPlugin(particle_fx_plugin); root->uninstallPlugin(gl_plugin); delete ois_input_plugin; delete octree_plugin; delete particle_fx_plugin; delete gl_plugin; #else root->unloadPlugin(OGRE_INPUT_PLUGIN_NAME); #endif delete root; } if (log_manager) delete log_manager; return 0; }
void go(void) { // OGRE의 메인 루트 오브젝트 생성 #if !defined(_DEBUG) mRoot = new Root("plugins.cfg", "ogre.cfg", "ogre.log"); #else mRoot = new Root("plugins_d.cfg", "ogre.cfg", "ogre.log"); #endif // 초기 시작의 컨피규레이션 설정 - ogre.cfg 이용 if (!mRoot->restoreConfig()) { if (!mRoot->showConfigDialog()) return; } mWindow = mRoot->initialise(true, CLIENT_DESCRIPTION " : Copyleft by Dae-Hyun Lee"); mSceneMgr = mRoot->createSceneManager(ST_GENERIC, "main"); mCamera = mSceneMgr->createCamera("main"); mCamera->setPosition(0.0f, 150.0f, 1000.0f); mCamera->lookAt(0.0f, 100.0f, 0.0f); mViewport = mWindow->addViewport(mCamera); mViewport->setBackgroundColour(ColourValue(0.0f, 0.0f, 0.5f)); mCamera->setAspectRatio(Real(mViewport->getActualWidth()) / Real(mViewport->getActualHeight())); ResourceGroupManager::getSingleton().addResourceLocation("resource.zip", "Zip"); ResourceGroupManager::getSingleton().initialiseAllResourceGroups(); mSceneMgr->setAmbientLight(ColourValue(1.0f, 1.0f, 1.0f)); // 좌표축 표시 Ogre::Entity* mAxesEntity = mSceneMgr->createEntity("Axes", "axes.mesh"); mSceneMgr->getRootSceneNode()->createChildSceneNode("AxesNode", Ogre::Vector3(0, 0, 0))->attachObject(mAxesEntity); mSceneMgr->getSceneNode("AxesNode")->setScale(5, 5, 5); _drawGridPlane(); Entity* entity1 = mSceneMgr->createEntity("Ninja", "ninja.mesh"); SceneNode* node1 = mSceneMgr->getRootSceneNode()->createChildSceneNode("Ninja", Vector3(-100.0f, 0.0f, 0.0f)); node1->attachObject(entity1); Entity* entity2 = mSceneMgr->createEntity("Professor", "DustinBody.mesh"); SceneNode* node2 = mSceneMgr->getRootSceneNode()->createChildSceneNode("Professor", Vector3(200.0f, 0.0f, 200.0f)); node2->attachObject(entity2); #if 0 Entity* entity2 = mSceneMgr->createEntity("Ninja", "ninja.mesh"); SceneNode* node2 = mSceneMgr->getRootSceneNode()->createChildSceneNode("Ninja", Vector3(0.0f, 0.0f, 0.0f)); node2->attachObject(entity2); node2->setOrientation(Ogre::Quaternion(Ogre::Degree(180), Ogre::Vector3::UNIT_Y)); #endif size_t windowHnd = 0; std::ostringstream windowHndStr; OIS::ParamList pl; mWindow->getCustomAttribute("WINDOW", &windowHnd); windowHndStr << windowHnd; pl.insert(std::make_pair(std::string("WINDOW"), windowHndStr.str())); 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"))); mInputManager = OIS::InputManager::createInputSystem(pl); mKeyboard = static_cast<OIS::Keyboard*>(mInputManager->createInputObject(OIS::OISKeyboard, true)); mMouse = static_cast<OIS::Mouse*>(mInputManager->createInputObject(OIS::OISMouse, true)); InputController* inputController = new InputController(mRoot, mKeyboard, mMouse); mRoot->addFrameListener(inputController); ProfessorController* professorController = new ProfessorController(mRoot); mRoot->addFrameListener(professorController); mRoot->startRendering(); mInputManager->destroyInputObject(mKeyboard); mInputManager->destroyInputObject(mMouse); OIS::InputManager::destroyInputSystem(mInputManager); delete professorController; delete inputController; delete mRoot; }
//--------------------------------------------------------------------------------// void GLXProc( const XEvent &event ) { //We have to find appropriate window based on window id ( kindof hackish :/, //but at least this only happens when there is a Window's event - and not that often WindowEventUtilities::Windows::iterator i = WindowEventUtilities::_msWindows.begin(), e = WindowEventUtilities::_msWindows.end(); RenderWindow* win = 0; for(; i != e; ++i ) { std::size_t wind = 0; (*i)->getCustomAttribute("WINDOW", &wind); if( event.xany.window == wind ) { win = *i; break; } } //Sometimes, seems we get other windows, so just ignore if( win == 0 ) return; //Now that we have the correct RenderWindow for the generated Event, get an iterator for the listeners WindowEventUtilities::WindowEventListeners::iterator start = WindowEventUtilities::_msListeners.lower_bound(win), end = WindowEventUtilities::_msListeners.upper_bound(win); switch(event.type) { case ClientMessage: { ::Atom atom; win->getCustomAttribute("ATOM", &atom); if(event.xclient.format == 32 && event.xclient.data.l[0] == (long)atom) { //Window Closed (via X button) //Send message first, to allow app chance to unregister things that need done before //window is shutdown for( ; start != end; ++start ) (start->second)->windowClosed(win); win->destroy(); } break; } case ConfigureNotify: //Moving or Resizing unsigned int width, height, depth; int left, top; win->getMetrics(width, height, depth, left, top); //determine if moving or sizing: if( left == event.xconfigure.x && top == event.xconfigure.y ) { //Resize width, height win->windowMovedOrResized(); for( ; start != end; ++start ) (start->second)->windowResized(win); } else if( width == event.xconfigure.width && height == event.xconfigure.height ) { //Moving x, y win->windowMovedOrResized(); for( ; start != end; ++start ) (start->second)->windowMoved(win); } break; case MapNotify: //Restored win->setActive( true ); for( ; start != end; ++start ) (start->second)->windowFocusChange(win); break; case UnmapNotify: //Minimised win->setActive( false ); win->setVisible( false ); for( ; start != end; ++start ) (start->second)->windowFocusChange(win); break; case VisibilityNotify: switch(event.xvisibility.state) { case VisibilityUnobscured: win->setActive( true ); win->setVisible( true ); break; case VisibilityPartiallyObscured: win->setActive( true ); win->setVisible( true ); break; case VisibilityFullyObscured: win->setActive( false ); win->setVisible( false ); break; } //Notify Listeners that focus of window has changed in some way for( ; start != end; ++start ) (start->second)->windowFocusChange(win); break; default: break; } //End switch event.type }
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; }
void go(void) { // OGRE의 메인 루트 오브젝트 생성 #if !defined(_DEBUG) mRoot = new Root("plugins.cfg", "ogre.cfg", "ogre.log"); #else mRoot = new Root("plugins_d.cfg", "ogre.cfg", "ogre.log"); #endif // 초기 시작의 컨피규레이션 설정 - ogre.cfg 이용 if (!mRoot->restoreConfig()) { if (!mRoot->showConfigDialog()) return; } mWindow = mRoot->initialise(true, "Moving Professor & Ninja : Copyleft by Dae-Hyun Lee"); // ESC key를 눌렀을 경우, 오우거 메인 렌더링 루프의 탈출을 처리 size_t windowHnd = 0; std::ostringstream windowHndStr; OIS::ParamList pl; mWindow->getCustomAttribute("WINDOW", &windowHnd); windowHndStr << windowHnd; pl.insert(std::make_pair(std::string("WINDOW"), windowHndStr.str())); mInputManager = OIS::InputManager::createInputSystem(pl); mKeyboard = static_cast<OIS::Keyboard*>(mInputManager->createInputObject(OIS::OISKeyboard, false)); // Fill Here -------------------------------------------------------------- // ------------------------------------------------------------------------ mCamera->setPosition(0.0f, 100.0f, 500.0f); mCamera->lookAt(0.0f, 100.0f, 0.0f); mCamera->setNearClipDistance(5.0f); mViewport = mWindow->addViewport(mCamera); mViewport->setBackgroundColour(ColourValue(0.0f,0.0f,0.5f)); mCamera->setAspectRatio(Real(mViewport->getActualWidth()) / Real(mViewport->getActualHeight())); ResourceGroupManager::getSingleton().addResourceLocation("resource.zip", "Zip"); ResourceGroupManager::getSingleton().initialiseAllResourceGroups(); mSceneMgr->setAmbientLight(ColourValue(1.0f, 1.0f, 1.0f)); // 좌표축 표시 Ogre::Entity* mAxesEntity = mSceneMgr->createEntity("Axes", "axes.mesh"); mSceneMgr->getRootSceneNode()->createChildSceneNode("AxesNode",Ogre::Vector3(0,0,0))->attachObject(mAxesEntity); mSceneMgr->getSceneNode("AxesNode")->setScale(5, 5, 5); _drawGridPlane(); Entity* entity1 = mSceneMgr->createEntity("Professor", "DustinBody.mesh"); Entity* entity2 = mSceneMgr->createEntity("Ninja", "ninja.mesh"); SceneNode* node1 = mSceneMgr->getRootSceneNode()->createChildSceneNode("Professor", Vector3(0.0f, 0.0f, 0.0f)); node1->attachObject(entity1); SceneNode* node2 = mSceneMgr->getRootSceneNode()->createChildSceneNode("Ninja", Vector3(200.0f, 0.0f, -200.0f)); node2->attachObject(entity2); // Fill Here ---------------------------------------------- // -------------------------------------------------------- mRoot->startRendering(); mInputManager->destroyInputObject(mKeyboard); OIS::InputManager::destroyInputSystem(mInputManager); delete mRoot; }
int mainSetupAndRunOgre() { Ogre::LogManager* log_manager = 0; Ogre::Root* root = 0; OISInput* ois_input_plugin = 0; #ifdef OGRE_STATIC_LIB Ogre::OctreePlugin* octree_plugin = 0; Ogre::ParticleFXPlugin* particle_fx_plugin = 0; Ogre::GLPlugin* gl_plugin = 0; #endif try { using namespace Ogre; log_manager = new LogManager(); #ifndef FREEORION_WIN32 log_manager->createLog((GetUserDir() / "ogre.log").string(), true, false); root = new Root((GetRootDataDir() / "ogre_plugins.cfg").string()); // this line is needed on some Linux systems which otherwise will crash with // errors about GLX_icon.png being missing. Ogre::ResourceGroupManager::getSingleton().addResourceLocation((ClientUI::ArtDir() / ".").string(), "FileSystem", "General"); #else boost::filesystem::path::string_type file_native = (GetUserDir() / "ogre.log").native(); std::string ogre_log_file; utf8::utf16to8(file_native.begin(), file_native.end(), std::back_inserter(ogre_log_file)); log_manager->createLog(ogre_log_file, true, false); // for some reason, for this file, the built-in path conversion seems to work properly std::string plugins_cfg_file = (GetRootDataDir() / "ogre_plugins.cfg").string(); root = new Root(plugins_cfg_file); #endif #if defined(OGRE_STATIC_LIB) octree_plugin = new Ogre::OctreePlugin; particle_fx_plugin = new Ogre::ParticleFXPlugin; gl_plugin = new Ogre::GLPlugin; root->installPlugin(octree_plugin); root->installPlugin(particle_fx_plugin); root->installPlugin(gl_plugin); #endif RenderSystem* selected_render_system = root->getRenderSystemByName("OpenGL Rendering Subsystem"); if (!selected_render_system) throw std::runtime_error("Failed to find an Ogre GL render system."); root->setRenderSystem(selected_render_system); int colour_depth = GetOptionsDB().Get<int>("color-depth"); bool fullscreen = GetOptionsDB().Get<bool>("fullscreen"); std::pair<int, int> width_height = HumanClientApp::GetWindowWidthHeight(selected_render_system); int width(width_height.first), height(width_height.second); std::pair<int, int> left_top = HumanClientApp::GetWindowLeftTop(); int left(left_top.first), top(left_top.second); root->initialise(false); Ogre::NameValuePairList misc_window_params; misc_window_params["title"] = "FreeOrion " + FreeOrionVersionString(); misc_window_params["colourDepth"] = boost::lexical_cast<std::string>(colour_depth); misc_window_params["left"] = boost::lexical_cast<std::string>(left); misc_window_params["top"] = boost::lexical_cast<std::string>(top); misc_window_params["macAPI"] = "carbon"; misc_window_params["border"] = "resize"; if (fullscreen) misc_window_params["monitorIndex"] = boost::lexical_cast<std::string>( GetOptionsDB().Get<int>("fullscreen-monitor-id")); RenderWindow* window = root->createRenderWindow("FreeOrion " + FreeOrionVersionString(), width, height, fullscreen, &misc_window_params); #ifdef FREEORION_WIN32 # ifdef IDI_ICON1 // set window icon to embedded application icon HWND hwnd; window->getCustomAttribute("WINDOW", &hwnd); HINSTANCE hInst = (HINSTANCE)GetModuleHandle(NULL); SetClassLong (hwnd, GCL_HICON, (LONG)LoadIcon (hInst, MAKEINTRESOURCE (IDI_ICON1))); # endif #endif SceneManager* scene_manager = root->createSceneManager("OctreeSceneManager", "SceneMgr"); Camera* camera = scene_manager->createCamera("Camera"); camera->setPosition(Vector3(0, 0, 500)); // Position it at 500 in Z direction camera->lookAt(Vector3(0, 0, -300)); // Look back along -Z camera->setNearClipDistance(5); Viewport* viewport = window->addViewport(camera); viewport->setBackgroundColour(ColourValue(0, 0, 0)); //EntityRenderer entity_renderer(scene_manager); parse::init(); HumanClientApp app(root, window, scene_manager, camera, viewport, GetRootDataDir() / "OISInput.cfg"); ois_input_plugin = new OISInput; ois_input_plugin->SetRenderWindow(window); root->installPlugin(ois_input_plugin); if (GetOptionsDB().Get<bool>("quickstart")) { // immediately start the server, establish network connections, and // go into a single player game, using default universe options (a // standard quickstart, without requiring the user to click the // quickstart button). app.NewSinglePlayerGame(true); // acceptable to call before app() } std::string load_filename = GetOptionsDB().Get<std::string>("load"); if (!load_filename.empty()) { // immediately start the server, establish network connections, and // go into a single player game, loading the indicated file // (without requiring the user to click the load button). app.LoadSinglePlayerGame(load_filename); // acceptable to call before app() } // run rendering loop app(); // calls GUI::operator() which calls OgreGUI::Run() which starts rendering loop } catch (const HumanClientApp::CleanQuit&) { // do nothing std::cout << "mainSetupAndRunOgre caught CleanQuit" << std::endl; } catch (const std::invalid_argument& e) { Logger().errorStream() << "main() caught exception(std::invalid_argument): " << e.what(); std::cerr << "main() caught exception(std::invalid_arg): " << e.what() << std::endl; } catch (const std::runtime_error& e) { Logger().errorStream() << "main() caught exception(std::runtime_error): " << e.what(); std::cerr << "main() caught exception(std::runtime_error): " << e.what() << std::endl; } catch (const boost::io::format_error& e) { Logger().errorStream() << "main() caught exception(boost::io::format_error): " << e.what(); std::cerr << "main() caught exception(boost::io::format_error): " << e.what() << std::endl; } catch (const GG::ExceptionBase& e) { Logger().errorStream() << "main() caught exception(" << e.type() << "): " << e.what(); std::cerr << "main() caught exception(" << e.type() << "): " << e.what() << std::endl; } catch (const std::exception& e) { Logger().errorStream() << "main() caught exception(std::exception): " << e.what(); std::cerr << "main() caught exception(std::exception): " << e.what() << std::endl; } catch (...) { Logger().errorStream() << "main() caught unknown exception."; std::cerr << "main() caught unknown exception." << std::endl; } if (root) { root->uninstallPlugin(ois_input_plugin); delete ois_input_plugin; #ifdef OGRE_STATIC_LIB root->uninstallPlugin(octree_plugin); root->uninstallPlugin(particle_fx_plugin); root->uninstallPlugin(gl_plugin); delete octree_plugin; delete particle_fx_plugin; delete gl_plugin; #endif delete root; } if (log_manager) delete log_manager; return 0; }