DataContainer GraphicsImpl::getData(const DataIdentifier& id) { if (id == "window.handle") { std::ostringstream windowHndStr; size_t windowHnd = 0; window->getCustomAttribute("WINDOW", &windowHnd); windowHndStr << windowHnd; return DataContainer(windowHndStr.str()); } return DataContainer(); }
VIEW_API void windowAttributes(size_t& handle, u32& width, u32& height) { Ogre::Root* root = Ogre::Root::getSingletonPtr(); if (! root) throw std::logic_error ("View::windowAttributes: Ogre hasn't been initialized yet."); Ogre::RenderWindow* win = root->getAutoCreatedWindow(); win->getCustomAttribute("WINDOW", &handle); height = win->getHeight(); width = win->getWidth(); }
void ClipboardManager::initialise() { MYGUI_ASSERT(false == mIsInitialise, INSTANCE_TYPE_NAME << " initialised twice"); MYGUI_LOG(Info, "* Initialise: " << INSTANCE_TYPE_NAME); #if OGRE_PLATFORM == OGRE_PLATFORM_WIN32 Ogre::RenderWindow * window = Gui::getInstance().getRenderWindow(); if (window != nullptr) { window->getCustomAttribute("WINDOW", &mHwnd); } #endif MYGUI_LOG(Info, INSTANCE_TYPE_NAME << " successfully initialized"); mIsInitialise = true; }
void application::create_frame_listener() { Ogre::LogManager::getSingletonPtr() -> logMessage("Initializing OIS"); OIS::ParamList pl; size_t wndhnd = 0; std::ostringstream wndhndstr; wnd->getCustomAttribute ("WINDOW", &wndhnd); wndhndstr << wndhnd; pl.insert (std::make_pair (std::string {"WINDOW"}, wndhndstr.str())); input = OIS::InputManager::createInputSystem(pl); kbd = static_cast<OIS::Keyboard*> (input->createInputObject (OIS::OISKeyboard, true)); mouse = static_cast<OIS::Mouse*> (input->createInputObject (OIS::OISMouse, true)); mouse -> setEventCallback(this); kbd -> setEventCallback(this); windowResized(wnd); Ogre::WindowEventUtilities::addWindowEventListener (wnd, this); OgreBites::InputContext inctx; inctx.mMouse = mouse; inctx.mKeyboard = kbd; tray_mgr = new OgreBites::SdkTrayManager ("InterfaceName", wnd, inctx, this); tray_mgr->showFrameStats(OgreBites::TL_BOTTOMLEFT); tray_mgr->showLogo(OgreBites::TL_BOTTOMRIGHT); tray_mgr->hideCursor(); Ogre::StringVector items; items.push_back("cam.pX"); items.push_back("cam.pY"); items.push_back("cam.pZ"); items.push_back(""); items.push_back("cam.oW"); items.push_back("cam.oX"); items.push_back("cam.oY"); items.push_back("cam.oZ"); items.push_back(""); items.push_back("Filtering"); items.push_back("Poly Mode"); root->addFrameListener(this); }
void OISInput::initialise() { Ogre::RenderWindow* window = GetRenderWindow(); OIS::ParamList param_list; std::size_t window_handle = 0; window->getCustomAttribute("WINDOW", &window_handle); typedef OIS::ParamList::value_type ParamType; param_list.insert( ParamType("WINDOW", boost::lexical_cast<std::string>(window_handle))); OgreGUI* gui = OgreGUI::GetGUI(); assert(gui); const Ogre::SharedPtr<Ogre::DataStream>& config_file_stream = gui->ConfigFileStream(); if (!config_file_stream.isNull()) { Ogre::ConfigFile config_file; config_file.load(config_file_stream); for (Ogre::ConfigFile::SettingsIterator it = config_file.getSettingsIterator(); it.hasMoreElements(); it.getNext()) { param_list.insert(ParamType(it.peekNextKey(), it.peekNextValue())); Ogre::LogManager::getSingleton().logMessage("OISPlugin using config setting " + it.peekNextKey() + "=" + it.peekNextValue()); } } m_input_manager = OIS::InputManager::createInputSystem(param_list); m_keyboard = boost::polymorphic_downcast<OIS::Keyboard*>( m_input_manager->createInputObject(OIS::OISKeyboard, true)); m_keyboard->setEventCallback(this); m_mouse = boost::polymorphic_downcast<OIS::Mouse*>( m_input_manager->createInputObject(OIS::OISMouse, true)); m_mouse->setEventCallback(this); const OIS::MouseState& mouse_state = m_mouse->getMouseState(); mouse_state.width = Value(gui->AppWidth()); mouse_state.height = Value(gui->AppHeight()); ConnectHandlers(); }
bool OISManager::init() { OIS::ParamList pl; size_t windowHnd = 0; std::ostringstream windowHndStr; Ogre::RenderWindow* rw = OgreManager::getInstance().getRenderWindow(); rw->getCustomAttribute("WINDOW", &windowHnd); windowHndStr << windowHnd; pl.insert(std::make_pair(std::string("WINDOW"), windowHndStr.str())); _inputManager = OIS::InputManager::createInputSystem( pl ); _keyboard = static_cast<OIS::Keyboard*>(_inputManager->createInputObject( OIS::OISKeyboard, true )); _mouse = static_cast<OIS::Mouse*>(_inputManager->createInputObject( OIS::OISMouse, true )); const OIS::MouseState &ms = _mouse->getMouseState(); ms.width = static_cast<int>(rw->getWidth()); ms.height = static_cast<int>(rw->getHeight()); _keyboard->setEventCallback(this); _mouse->setEventCallback(this); _L = ScriptManager::getInstance().getLuaVM(); return true; }
// Sets up input devices and event callbacks void InputManager::initialize() { _lastKeyPressedEvt = NULL; _lastKeyReleasedEvt = NULL; _lastMouseMovedEvt = NULL; _lastMousePressedEvt = NULL; _lastMouseReleasedEvt = NULL; OIS::ParamList pl; size_t windowHnd = 0; std::ostringstream windowHndStr; Ogre::RenderWindow* mWindow; // set up the render window mWindow = GraphicsManager::instance()->getRenderWindow(); mWindow->getCustomAttribute("WINDOW", &windowHnd); windowHndStr << windowHnd; pl.insert(std::make_pair(std::string("WINDOW"), windowHndStr.str())); // Set up the input thread _mInputManager = OIS::InputManager::createInputSystem(pl); // Set up the input devices _mKeyboard = static_cast<OIS::Keyboard*>(_mInputManager->createInputObject(OIS::OISKeyboard, true)); _mMouse = static_cast<OIS::Mouse*>(_mInputManager->createInputObject(OIS::OISMouse, true)); // Register for events _mMouse->setEventCallback(this); _mKeyboard->setEventCallback(this); // Set initial mouse clipping size windowResized(mWindow); // Register as a Window listener Ogre::WindowEventUtilities::addWindowEventListener(mWindow, this); }
INT WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { #else int main (int argc, char *argv[]) { #endif #define OGRE_STATIC_ParticleFX 1 Ogre::Root *ogre; Ogre::RenderWindow *window; Ogre::SceneManager *sceneMgr; Ogre::Camera *camera; // fire up an Ogre rendering window. Clearing the first two (of three) params will let us // specify plugins and resources in code instead of via text file ogre = new Ogre::Root("", ""); // This is a VERY minimal rendersystem loading example; we are hardcoding the OpenGL // renderer, instead of loading GL and D3D9. We will add renderer selection support in a // future article. // I separate the debug and release versions of my plugins using the same "_d" suffix that // the Ogre main libraries use; you may need to remove the "_d" in your code, depending on the // naming convention you use ogre->loadPlugin("RenderSystem_GL_d"); ogre->loadPlugin("Plugin_ParticleFX_d"); const Ogre::RenderSystemList &renderSystems = ogre->getAvailableRenderers(); Ogre::RenderSystemList::const_iterator r_it; // we do this step just to get an iterator that we can use with setRenderSystem. In a future article // we actually will iterate the list to display which renderers are available. // renderSystems = ogre->getAvailableRenderers(); r_it = renderSystems.begin(); ogre->setRenderSystem(*r_it); ogre->initialise(false); // load common plugins ogre->loadPlugin("Plugin_CgProgramManager_d"); ogre->loadPlugin("Plugin_OctreeSceneManager_d"); // setup main window; hardcode some defaults for the sake of presentation Ogre::NameValuePairList opts; opts["resolution"] = "1024x768"; opts["fullscreen"] = "false"; opts["vsync"] = "true"; // create a rendering window with the title "CDK" window = ogre->createRenderWindow("CDK", 1024, 768, false, &opts); // load the basic resource location(s) Ogre::ResourceGroupManager::getSingleton().addResourceLocation( "resource", "FileSystem", "General"); Ogre::ResourceGroupManager::getSingleton().addResourceLocation( "resource/gui.zip", "Zip", "GUI"); Ogre::ResourceGroupManager::getSingleton().addResourceLocation( "resource/textures", "FileSystem", "Textures"); Ogre::ResourceGroupManager::getSingleton().addResourceLocation( "resource/particles", "FileSystem", "Particles"); Ogre::ResourceGroupManager::getSingleton().addResourceLocation( "resource/materials", "FileSystem", "Materials"); #if defined(WIN32) Ogre::ResourceGroupManager::getSingleton().addResourceLocation( "c:\\windows\\fonts", "FileSystem", "GUI"); #endif //Must initialize resource groups after window if using particle effects. Ogre::ResourceGroupManager::getSingleton().initialiseResourceGroup("General"); Ogre::ResourceGroupManager::getSingleton().initialiseResourceGroup("GUI"); Ogre::ResourceGroupManager::getSingleton().initialiseResourceGroup("Textures"); Ogre::ResourceGroupManager::getSingleton().initialiseResourceGroup("Materials"); Ogre::ResourceGroupManager::getSingleton().initialiseResourceGroup("Particles"); // since this is basically a CEGUI app, we can use the ST_GENERIC scene manager for now; in a later article // we'll see how to change this sceneMgr = ogre->createSceneManager(Ogre::ST_GENERIC); camera = sceneMgr->createCamera("camera"); camera->setNearClipDistance(1); Ogre::Viewport* vp = window->addViewport(camera); vp->setBackgroundColour(Ogre::ColourValue(0,0,0)); // most examples get the viewport size to calculate this; for now, we'll just // set it to 4:3 the easy way camera->setAspectRatio((Ogre::Real)1.333333); // with a scene manager and window, we can create a the GUI renderer // new way to instantiate a CEGUIOgreRenderer (Ogre 1.7) Ogre::RenderTarget *mRenderTarget = window; CEGUI::OgreRenderer* pGUIRenderer = &CEGUI::OgreRenderer::bootstrapSystem(*mRenderTarget); // create the root CEGUI class CEGUI::System* pSystem = CEGUI::System::getSingletonPtr(); // tell us a lot about what is going on (see CEGUI.log in the working directory) CEGUI::Logger::getSingleton().setLoggingLevel(CEGUI::Informative); // use this CEGUI scheme definition (see CEGUI docs for more) CEGUI::SchemeManager::getSingleton().create((CEGUI::utf8*)"TaharezLookSkin.scheme", (CEGUI::utf8*)"GUI"); // show the CEGUI mouse cursor (defined in the look-n-feel) pSystem->setDefaultMouseCursor((CEGUI::utf8*)"TaharezLook", (CEGUI::utf8*)"MouseArrow"); // use this font for text in the UI CEGUI::FontManager::getSingleton().create("Tahoma-8.font", (CEGUI::utf8*)"GUI"); pSystem->setDefaultFont((CEGUI::utf8*)"Tahoma-8"); // load a layout from the XML layout file (you'll find this in resources/gui.zip), and // put it in the GUI resource group CEGUI::Window* pLayout = CEGUI::WindowManager::getSingleton().loadWindowLayout("katana.layout", "", "GUI"); // you need to tell CEGUI which layout to display. You can call this at any time to change the layout to // another loaded layout (i.e. moving from screen to screen or to load your HUD layout). Note that this takes // a CEGUI::Window instance -- you can use anything (any widget) that serves as a root window. pSystem->setGUISheet(pLayout); // this next bit is for the sake of the input handler unsigned long hWnd; // WINDOW is generic to all platforms now as of Eihort window->getCustomAttribute("WINDOW", &hWnd); // set up the input handlers Simulation *sim = new Simulation(); // since the input handler deals with pushing input to CEGUI, we need to give it a pointer // to the CEGUI System instance to use InputHandler *handler = new InputHandler(pSystem, sim, hWnd); // put us into our "main menu" state sim->requestStateChange(GUI); // make an instance of our GUI sheet handler class MainMenuDlg* pDlg = new MainMenuDlg(pSystem, pLayout, sim); //testing shit Ogre::SceneNode *systemNode = sceneMgr->getRootSceneNode()->createChildSceneNode(Ogre::Vector3(0,0,0)); SphereMesh *sphere = NULL; sphere->createSphere("sphereMesh", 80, 64, 64); /* // Now I can create several entities using that mesh Ogre::Entity *MoonEntity = sceneMgr->createEntity("Moon", planetMesh); // Now I attach it to a scenenode, so that it becomes present in the scene. Ogre::SceneNode *EarthOrbitNode = systemNode->createChildSceneNode("Earth Orbit", Ogre::Vector3(0,0,0)); Ogre::SceneNode *EarthNode = EarthOrbitNode->createChildSceneNode("Earth", Ogre::Vector3(200,0,0)); Ogre::SceneNode *MoonNode = EarthNode->createChildSceneNode("Moon", Ogre::Vector3(150,0,0)); MoonNode->attachObject(MoonEntity); MoonEntity->getParentNode()->scale(0.5,0.5,0.5); */ //Material Tests Ogre::MaterialManager& lMaterialManager = Ogre::MaterialManager::getSingleton(); Ogre::String lNameOfResourceGroup = "Mission 1 : Deliver Tom"; Ogre::ResourceGroupManager& lRgMgr = Ogre::ResourceGroupManager::getSingleton(); lRgMgr.createResourceGroup(lNameOfResourceGroup); { Ogre::MaterialPtr lMaterial = lMaterialManager.create("M_Lighting+OneTexture",lNameOfResourceGroup); Ogre::Technique* lFirstTechnique = lMaterial->getTechnique(0); Ogre::Pass* lFirstPass = lFirstTechnique->getPass(0); lFirstPass->setDiffuse(0.8f, 0.8f, 0.8f,1.0f); lFirstPass->setAmbient(0.3f, 0.3f, 0.3f); lFirstPass->setSpecular(1.0f, 1.0f, 1.0f, 1.0f); lFirstPass->setShininess(64.0f); lFirstPass->setSelfIllumination(0.1f, 0.1f, 0.1f); Ogre::TextureUnitState* lTextureUnit = lFirstPass->createTextureUnitState(); lTextureUnit->setTextureName("SimpleTexture.bmp", Ogre::TEX_TYPE_2D); lTextureUnit->setTextureCoordSet(0); } // 3/ Lighting color. // To have the feeling of '3D', the lighting is good feeling. // It often requires the object to have correct normals (see my manual object construction), // and some lights in the scene. { Ogre::MaterialPtr lMaterial = lMaterialManager.create("Sun",lNameOfResourceGroup); Ogre::Technique* lFirstTechnique = lMaterial->getTechnique(0); Ogre::Pass* lFirstPass = lFirstTechnique->getPass(0); // Lighting is allowed on this pass. lFirstPass->setLightingEnabled(true); // Emissive / self illumination is the color 'produced' by the object. // Color values vary between 0.0(minimum) to 1.0 (maximum). Ogre::ColourValue lSelfIllumnationColour(0.5f, 0.0f, 0.0f, 1.0f); lFirstPass->setSelfIllumination(lSelfIllumnationColour); // diffuse color is the traditionnal color of the lit object. Ogre::ColourValue lDiffuseColour(1.0f, 0.4f, 0.4f, 1.0f); lFirstPass->setDiffuse(lDiffuseColour); // ambient colour is linked to ambient lighting. // If there is no ambient lighting, then this has no influence. // It the ambient lighting is at 1, then this colour is fully added. // This is often use to change the general feeling of a whole scene. Ogre::ColourValue lAmbientColour(0.4f, 0.1f, 0.1f, 1.0f); lFirstPass->setAmbient(lAmbientColour); // specular colour, is the colour of the 'little light reflection' // that you can see on some object. For example, my bald head skin // reflect the sun. This make a 'round of specular lighting'. // Set this to black if you don't want to see it. Ogre::ColourValue lSpecularColour(1.0f, 1.0f, 1.0f, 1.0f); lFirstPass->setSpecular(lSpecularColour); // Shininess is the 'inverse of specular color splattering' coefficient. // If this is big (e.g : 64) you get a very tiny dot with a quite strong color (on round surface). // If this is 0, you get a simple color layer (the dot has become very wide). Ogre::Real lShininess = 64.0f; lFirstPass->setShininess(lShininess); } { Ogre::MaterialPtr lMaterial = lMaterialManager.create("mars",lNameOfResourceGroup); Ogre::Technique* lFirstTechnique = lMaterial->getTechnique(0); Ogre::Pass* lFirstPass = lFirstTechnique->getPass(0); // Lighting is allowed on this pass. lFirstPass->setLightingEnabled(true); // Emissive / self illumination is the color 'produced' by the object. // Color values vary between 0.0(minimum) to 1.0 (maximum). Ogre::ColourValue lSelfIllumnationColour(0.6f, 0.1f, 0.1f, 0.0f); lFirstPass->setSelfIllumination(lSelfIllumnationColour); // diffuse color is the traditionnal color of the lit object. Ogre::ColourValue lDiffuseColour(1.0f, 0.2f, 0.0f, 0.0f); lFirstPass->setDiffuse(lDiffuseColour); // ambient colour is linked to ambient lighting. // If there is no ambient lighting, then this has no influence. // It the ambient lighting is at 1, then this colour is fully added. // This is often use to change the general feeling of a whole scene. Ogre::ColourValue lAmbientColour(1.0f, 0.2f, 0.0f, 0.0f); lFirstPass->setAmbient(lAmbientColour); // specular colour, is the colour of the 'little light reflection' // that you can see on some object. For example, my bald head skin // reflect the sun. This make a 'round of specular lighting'. // Set this to black if you don't want to see it. Ogre::ColourValue lSpecularColour(1.0f, 0.3f, 0.3f, 0.3f); lFirstPass->setSpecular(lSpecularColour); // Shininess is the 'inverse of specular color splattering' coefficient. // If this is big (e.g : 64) you get a very tiny dot with a quite strong color (on round surface). // If this is 0, you get a simple color layer (the dot has become very wide). Ogre::Real lShininess = 34.0f; lFirstPass->setShininess(lShininess); } { Ogre::MaterialPtr lMaterial = lMaterialManager.create("gaia",lNameOfResourceGroup); Ogre::Technique* lFirstTechnique = lMaterial->getTechnique(0); Ogre::Pass* lFirstPass = lFirstTechnique->getPass(0); // Lighting is allowed on this pass. lFirstPass->setLightingEnabled(true); // Emissive / self illumination is the color 'produced' by the object. // Color values vary between 0.0(minimum) to 1.0 (maximum). Ogre::ColourValue lSelfIllumnationColour(0.0f, 0.0f, 0.1f, 0.3f); lFirstPass->setSelfIllumination(lSelfIllumnationColour); // diffuse color is the traditionnal color of the lit object. Ogre::ColourValue lDiffuseColour(0.1f, 0.2f, 0.8f, 1.0f); lFirstPass->setDiffuse(lDiffuseColour); // ambient colour is linked to ambient lighting. // If there is no ambient lighting, then this has no influence. // It the ambient lighting is at 1, then this colour is fully added. // This is often use to change the general feeling of a whole scene. Ogre::ColourValue lAmbientColour(0.0f, 0.1f, 0.4f, 1.0f); lFirstPass->setAmbient(lAmbientColour); // specular colour, is the colour of the 'little light reflection' // that you can see on some object. For example, my bald head skin // reflect the sun. This make a 'round of specular lighting'. // Set this to black if you don't want to see it. Ogre::ColourValue lSpecularColour(0.0f, 0.3f, 1.0f, 1.0f); lFirstPass->setSpecular(lSpecularColour); // Shininess is the 'inverse of specular color splattering' coefficient. // If this is big (e.g : 64) you get a very tiny dot with a quite strong color (on round surface). // If this is 0, you get a simple color layer (the dot has become very wide). Ogre::Real lShininess = 34.0f; lFirstPass->setShininess(lShininess); } { Ogre::MaterialPtr lMaterial = lMaterialManager.create("barren",lNameOfResourceGroup); Ogre::Technique* lFirstTechnique = lMaterial->getTechnique(0); Ogre::Pass* lFirstPass = lFirstTechnique->getPass(0); // Lighting is allowed on this pass. lFirstPass->setLightingEnabled(true); // Emissive / self illumination is the color 'produced' by the object. // Color values vary between 0.0(minimum) to 1.0 (maximum). Ogre::ColourValue lSelfIllumnationColour(0.1f, 0.1f, 0.1f, 0.1f); lFirstPass->setSelfIllumination(lSelfIllumnationColour); // diffuse color is the traditionnal color of the lit object. Ogre::ColourValue lDiffuseColour(0.3f, 0.3f, 0.3f, 0.3f); lFirstPass->setDiffuse(lDiffuseColour); // ambient colour is linked to ambient lighting. // If there is no ambient lighting, then this has no influence. // It the ambient lighting is at 1, then this colour is fully added. // This is often use to change the general feeling of a whole scene. Ogre::ColourValue lAmbientColour(0.3f, 0.3f, 0.3f, 0.3f); lFirstPass->setAmbient(lAmbientColour); // specular colour, is the colour of the 'little light reflection' // that you can see on some object. For example, my bald head skin // reflect the sun. This make a 'round of specular lighting'. // Set this to black if you don't want to see it. Ogre::ColourValue lSpecularColour(0.7f, 0.7f, 0.7f, 0.7f); lFirstPass->setSpecular(lSpecularColour); // Shininess is the 'inverse of specular color splattering' coefficient. // If this is big (e.g : 64) you get a very tiny dot with a quite strong color (on round surface). // If this is 0, you get a simple color layer (the dot has become very wide). Ogre::Real lShininess = 34.0f; lFirstPass->setShininess(lShininess); } { Ogre::MaterialPtr lMaterial = lMaterialManager.create("gasgiant",lNameOfResourceGroup); Ogre::Technique* lFirstTechnique = lMaterial->getTechnique(0); Ogre::Pass* lFirstPass = lFirstTechnique->getPass(0); // Lighting is allowed on this pass. lFirstPass->setLightingEnabled(true); // Emissive / self illumination is the color 'produced' by the object. // Color values vary between 0.0(minimum) to 1.0 (maximum). Ogre::ColourValue lSelfIllumnationColour(0.0f, 0.3f, 0.0f, 0.1f); lFirstPass->setSelfIllumination(lSelfIllumnationColour); // diffuse color is the traditionnal color of the lit object. Ogre::ColourValue lDiffuseColour(0.1f, 0.7f, 0.1f, 0.3f); lFirstPass->setDiffuse(lDiffuseColour); // ambient colour is linked to ambient lighting. // If there is no ambient lighting, then this has no influence. // It the ambient lighting is at 1, then this colour is fully added. // This is often use to change the general feeling of a whole scene. Ogre::ColourValue lAmbientColour(0.1f, 0.7f, 0.3f, 0.3f); lFirstPass->setAmbient(lAmbientColour); // specular colour, is the colour of the 'little light reflection' // that you can see on some object. For example, my bald head skin // reflect the sun. This make a 'round of specular lighting'. // Set this to black if you don't want to see it. Ogre::ColourValue lSpecularColour(0.2f, 1.0f, 0.6f, 0.6f); lFirstPass->setSpecular(lSpecularColour); // Shininess is the 'inverse of specular color splattering' coefficient. // If this is big (e.g : 64) you get a very tiny dot with a quite strong color (on round surface). // If this is 0, you get a simple color layer (the dot has become very wide). Ogre::Real lShininess = 34.0f; lFirstPass->setShininess(lShininess); } //end material tests //System Creator std::string systemDefinition[10] = {"15000,0,0,false,false,false,700000,0", "300,0,0,false,false,barren,2500,1", "300,x,y,false,co2,barren,6000,2", "300,x,y,h2o,n2/o2,gaia,6300,3", "300,x,y,false,co2,mars,3400,4", "300,x,y,false,h2/he,gasgiant,71000,5", "300,x,y,false,h2/he,gasgiant,60000,6", "300,x,y,false,h2/he,gasgiant,25001,7", "300,x,y,false,h2/he,gasgiant,25000,8", "300,x,y,false,n-ice,ice,1100,9"}; StarSystem sol = StarSystem::StarSystem(sceneMgr, systemDefinition); //Star Creator /* { int x = 0; int y = 0; int kelvin = 15000; CelestialBody newstar = CelestialBody::CelestialBody(kelvin, 100, systemNode, sceneMgr, x, y); } // Spectrum testing and multi star generation. int time = 200; int x = -500; int y = 500; for ( int count = 1; count <= time; count++){ int kelvin = count * (40000/time); Star newstar = Star::Star(kelvin, 100, systemNode, sceneMgr, x, y); x += 20; if (count % 10 == 0) { y -= 20; x = -500; } } */ // I move the SceneNode back 15 so that it is visible to the camera. float PositionOffset = 0.0; float distance = -2000.0; systemNode->translate(0, PositionOffset, distance); camera->lookAt(Ogre::Vector3(0,0,distance)); while (sim->getCurrentState() != SHUTDOWN) { sol.rotateOrbits(); handler->capture(); ogre->renderOneFrame(); // run the message pump (uncomment for Eihort) Ogre::WindowEventUtilities::messagePump(); } { window->removeAllViewports(); } { sceneMgr->destroyAllCameras(); sceneMgr->destroyAllManualObjects(); sceneMgr->destroyAllEntities(); sceneMgr->destroyAllLights(); systemNode->removeAndDestroyAllChildren(); } { Ogre::ResourceGroupManager& lRgMgr = Ogre::ResourceGroupManager::getSingleton(); lRgMgr.destroyResourceGroup(lNameOfResourceGroup); } // clean up after ourselves delete pDlg; delete handler; delete sim; delete ogre; return 0; }
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { #else int main (int argc, char *argv[]) { #endif Ogre::Root *ogre; Ogre::RenderWindow *window; Ogre::SceneManager *sceneMgr; Ogre::SceneManager *guiSceneMgr; Ogre::Camera *camera; Ogre::Camera *guiCamera; // fire up an Ogre rendering window. Clearing the first two (of three) params will let us // specify plugins and resources in code instead of via text file ogre = new Ogre::Root("", ""); #if defined(_DEBUG) ogre->loadPlugin("RenderSystem_GL_d"); #else ogre->loadPlugin("RenderSystem_GL"); #endif Ogre::RenderSystemList *renderSystems = NULL; Ogre::RenderSystemList::iterator r_it; renderSystems = ogre->getAvailableRenderers(); r_it = renderSystems->begin(); ogre->setRenderSystem(*r_it); ogre->initialise(false); // load common plugins #if defined(_DEBUG) //ogre->loadPlugin("Plugin_CgProgramManager_d"); ogre->loadPlugin("Plugin_OctreeSceneManager_d"); #else //ogre->loadPlugin("Plugin_CgProgramManager"); ogre->loadPlugin("Plugin_OctreeSceneManager"); #endif // load the basic resource location(s) Ogre::ResourceGroupManager::getSingleton().addResourceLocation("resource", "FileSystem", "General"); Ogre::ResourceGroupManager::getSingleton().addResourceLocation("resource/gui.zip", "Zip", "GUI"); Ogre::ResourceGroupManager::getSingleton().addResourceLocation("meshes", "FileSystem", "Meshes"); #if defined(WIN32) Ogre::ResourceGroupManager::getSingleton().addResourceLocation("c:\\windows\\fonts", "FileSystem", "GUI"); #endif Ogre::ResourceGroupManager::getSingleton().initialiseResourceGroup("General"); Ogre::ResourceGroupManager::getSingleton().initialiseResourceGroup("GUI"); Ogre::ResourceGroupManager::getSingleton().initialiseResourceGroup("Meshes"); // setup main window; hardcode some defaults for the sake of presentation Ogre::NameValuePairList opts; opts["resolution"] = "1024x768"; opts["fullscreen"] = "false"; opts["vsync"] = "false"; // create a rendering window with the title "CDK" window = ogre->createRenderWindow("Bouwgame Client v0.1", 1024, 768, false, &opts); // since this is basically a CEGUI app, we can use the ST_GENERIC scene manager for now; in a later article // we'll see how to change this sceneMgr = ogre->createSceneManager(Ogre::ST_GENERIC); guiSceneMgr = ogre->createSceneManager(Ogre::ST_GENERIC); guiCamera = guiSceneMgr->createCamera("GUICamera"); guiCamera->setNearClipDistance(5); camera = sceneMgr->createCamera("camera"); camera->setNearClipDistance(5); Ogre::Viewport* vp = window->addViewport(guiCamera); vp->setBackgroundColour(Ogre::ColourValue(0.2f,0.2f,0.8f)); /* ambient light */ sceneMgr->setAmbientLight(Ogre::ColourValue(0.8, 0.8, 0.8)); sceneMgr->setShadowTechnique(Ogre::SHADOWTYPE_STENCIL_ADDITIVE); /* meshes */ Ogre::Entity* ent = sceneMgr->createEntity( "BouwPlaatsEntity", "world.mesh" ); Ogre::SceneNode* node = sceneMgr->getRootSceneNode()->createChildSceneNode("BouwNode", Ogre::Vector3(0, 0, 0)); node->attachObject(ent); //node->setScale(Ogre::Vector3(0.7,0.7,0.7)); ent = sceneMgr->createEntity("plaats", "bouwplaats_step_00.mesh"); Ogre::Vector3 size = ent->getBoundingBox().getSize(); Ogre::LogManager::getSingletonPtr()->getDefaultLog()->logMessage(Ogre::String("Bouwplaats size: ") + Ogre::StringConverter::toString(size)); size = ent->getBoundingBox().getMaximum(); Ogre::LogManager::getSingletonPtr()->getDefaultLog()->logMessage(Ogre::String("Bouwplaats max: ") + Ogre::StringConverter::toString(size)); size = ent->getBoundingBox().getMinimum(); Ogre::LogManager::getSingletonPtr()->getDefaultLog()->logMessage(Ogre::String("Bouwplaats min: ") + Ogre::StringConverter::toString(size)); Ogre::Entity* ent1 = sceneMgr->createEntity( "KeetEntity", "keet.mesh" ); Ogre::SceneNode* scenenode = sceneMgr->getRootSceneNode()->createChildSceneNode("KeetNode", Ogre::Vector3(0, 0, 0)); scenenode->attachObject(ent1); Ogre::Entity* ent2 = sceneMgr->createEntity( "HekjeEntity", "hekje.mesh" ); Ogre::SceneNode* scenenode2 = sceneMgr->getRootSceneNode()->createChildSceneNode("HekjeNode", Ogre::Vector3(0, -100, 0)); scenenode2->attachObject(ent2); scenenode2->setScale(Ogre::Vector3(400,0,100)); // most examples get the viewport size to calculate this; for now, we'll just // set it to 4:3 the easy way camera->setAspectRatio((Ogre::Real)1.333333); camera->setPosition(Ogre::Vector3(40,100,10)); guiCamera->setPosition(0, 0, 300); guiCamera->lookAt(node->getPosition()); // this next bit is for the sake of the input handler unsigned long hWnd; window->getCustomAttribute("WINDOW", &hWnd); // set up the input handlers Simulation *sim = new Simulation(); InputHandler *handler = new InputHandler(sim, hWnd, camera); DataManager *dataManager = new DataManager(); GameAI* gameAI = new GameAI(dataManager); //Create Network Network * net = new Network(dataManager); //net->start(); sim->requestStateChange(GUI); gui = new GuiManager(); // networkshit while(!net->isConnected()) { Sleep(1000); } net->Send(GETGROUPS, "", "", NULL); net->Send(LOGIN, "gast", "gast", 1); gui->setSimulation(sim); gui->init("", ogre, guiSceneMgr, window); gui->activate("main"); handler->setWindowExtents(1024,768); SimulationState cState; Ogre::WindowEventUtilities::addWindowEventListener(window, handler); DWORD tFrameStart = 0x0; //in miliseconds signed long tFrameX = 0x0; float tDelta2 = 0.0f; //in seconds float m_fps = 60.0f; tFrameStart = GetTickCount(); float tDelta; //testAI->calculateNextPath(40,10); while ((cState = sim->getCurrentState()) != SHUTDOWN) { tFrameX = GetTickCount() - tFrameStart; tDelta2 = (float)tFrameX / 1000.0f; if (tDelta2 > 3600) // tDelta > 1 hour tDelta2 = 1.0f / m_fps; //< System tick count has highly likely overflowed, so get approximation tFrameStart = GetTickCount(); m_fps = (int)(1.0f / tDelta2); tDelta = tDelta2; handler->capture(); handler->update(tDelta); gui->update(tDelta); //if (sim->getCurrentState() == SIMULATION || sim->getCurrentState() == SIMULATION_MOUSELOOK) // testAI->update(tDelta); // run the message pump (Eihort) Ogre::WindowEventUtilities::messagePump(); ogre->renderOneFrame(); if (sim->getCurrentState() != cState) { handler->StateSwitched(cState, sim->getCurrentState()); switch (sim->getCurrentState()) { case GUI: window->getViewport(0)->setCamera(guiCamera); break; case SIMULATION: window->getViewport(0)->setCamera(camera); break; } } } // clean up after ourselves //delete testAI; delete sim; delete ogre; delete handler; delete gameAI; delete dataManager; 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); }
int initOgreAR(aruco::CameraParameters camParams, unsigned char* buffer, std::string resourcePath) { /// INIT OGRE FUNCTIONS #ifdef _WIN32 root = new Ogre::Root(resourcePath + "plugins_win.cfg", resourcePath + "ogre_win.cfg"); #elif __x86_64__ || __ppc64__ root = new Ogre::Root(resourcePath + "plugins_x64.cfg", resourcePath + "ogre.cfg"); #else root = new Ogre::Root(resourcePath + "plugins.cfg", resourcePath + "ogre.cfg"); #endif if (!root->showConfigDialog()) return -1; Ogre::SceneManager* smgr = root->createSceneManager(Ogre::ST_GENERIC); /// CREATE WINDOW, CAMERA AND VIEWPORT Ogre::RenderWindow* window = root->initialise(true); Ogre::Camera *camera; Ogre::SceneNode* cameraNode; camera = smgr->createCamera("camera"); camera->setNearClipDistance(0.01f); camera->setFarClipDistance(10.0f); camera->setProjectionType(Ogre::PT_ORTHOGRAPHIC); camera->setPosition(0, 0, 0); camera->lookAt(0, 0, 1); double pMatrix[16]; camParams.OgreGetProjectionMatrix(camParams.CamSize,camParams.CamSize, pMatrix, 0.05,10, false); Ogre::Matrix4 PM(pMatrix[0], pMatrix[1], pMatrix[2] , pMatrix[3], pMatrix[4], pMatrix[5], pMatrix[6] , pMatrix[7], pMatrix[8], pMatrix[9], pMatrix[10], pMatrix[11], pMatrix[12], pMatrix[13], pMatrix[14], pMatrix[15]); camera->setCustomProjectionMatrix(true, PM); camera->setCustomViewMatrix(true, Ogre::Matrix4::IDENTITY); window->addViewport(camera); cameraNode = smgr->getRootSceneNode()->createChildSceneNode("cameraNode"); cameraNode->attachObject(camera); /// CREATE BACKGROUND FROM CAMERA IMAGE int width = camParams.CamSize.width; int height = camParams.CamSize.height; // create background camera image mPixelBox = Ogre::PixelBox(width, height, 1, Ogre::PF_R8G8B8, buffer); // Create Texture mTexture = Ogre::TextureManager::getSingleton().createManual("CameraTexture",Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, Ogre::TEX_TYPE_2D,width,height,0,Ogre::PF_R8G8B8,Ogre::TU_DYNAMIC_WRITE_ONLY_DISCARDABLE); //Create Camera Material Ogre::MaterialPtr material = Ogre::MaterialManager::getSingleton().create("CameraMaterial", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME); Ogre::Technique *technique = material->createTechnique(); technique->createPass(); material->getTechnique(0)->getPass(0)->setLightingEnabled(false); material->getTechnique(0)->getPass(0)->setDepthWriteEnabled(false); material->getTechnique(0)->getPass(0)->createTextureUnitState("CameraTexture"); Ogre::Rectangle2D* rect = new Ogre::Rectangle2D(true); rect->setCorners(-1.0, 1.0, 1.0, -1.0); rect->setMaterial("CameraMaterial"); // Render the background before everything else rect->setRenderQueueGroup(Ogre::RENDER_QUEUE_BACKGROUND); // Hacky, but we need to set the bounding box to something big, use infinite AAB to always stay visible Ogre::AxisAlignedBox aabInf; aabInf.setInfinite(); rect->setBoundingBox(aabInf); // Attach background to the scene Ogre::SceneNode* node = smgr->getRootSceneNode()->createChildSceneNode("Background"); node->attachObject(rect); /// CREATE SIMPLE OGRE SCENE // add sinbad.mesh Ogre::ResourceGroupManager::getSingleton().addResourceLocation(resourcePath + "Sinbad.zip", "Zip", "Popular"); Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups(); for(int i=0; i<MAX_MARKERS; i++) { Ogre::String entityName = "Marker_" + Ogre::StringConverter::toString(i); Ogre::Entity* ogreEntity = smgr->createEntity(entityName, "Sinbad.mesh"); Ogre::Real offset = ogreEntity->getBoundingBox().getHalfSize().y; ogreNode[i] = smgr->getRootSceneNode()->createChildSceneNode(); // add entity to a child node to correct position (this way, entity axis is on feet of sinbad) Ogre::SceneNode *ogreNodeChild = ogreNode[i]->createChildSceneNode(); ogreNodeChild->attachObject(ogreEntity); // Sinbad is placed along Y axis, we need to rotate to put it along Z axis so it stands up over the marker // first rotate along X axis, then add offset in Z dir so it is over the marker and not in the middle of it ogreNodeChild->rotate(Ogre::Vector3(1,0,0), Ogre::Radian(Ogre::Degree(90))); ogreNodeChild->translate(0,0,offset,Ogre::Node::TS_PARENT); // mesh is too big, rescale! const float scale = 0.006675f; ogreNode[i]->setScale(scale, scale, scale); // Init animation ogreEntity->getSkeleton()->setBlendMode(Ogre::ANIMBLEND_CUMULATIVE); if(i==0) { baseAnim[i] = ogreEntity->getAnimationState("HandsClosed"); topAnim[i] = ogreEntity->getAnimationState("HandsRelaxed"); } else if(i==1) { baseAnim[i] = ogreEntity->getAnimationState("Dance"); topAnim[i] = ogreEntity->getAnimationState("Dance"); } else if(i==2) { baseAnim[i] = ogreEntity->getAnimationState("RunBase"); topAnim[i] = ogreEntity->getAnimationState("RunTop"); } else { baseAnim[i] = ogreEntity->getAnimationState("IdleBase"); topAnim[i] = ogreEntity->getAnimationState("IdleTop"); } baseAnim[i]->setLoop(true); topAnim[i]->setLoop(true); baseAnim[i]->setEnabled(true); topAnim[i]->setEnabled(true); } /// KEYBOARD INPUT READING size_t windowHnd = 0; window->getCustomAttribute("WINDOW", &windowHnd); im = OIS::InputManager::createInputSystem(windowHnd); keyboard = static_cast<OIS::Keyboard*>(im->createInputObject(OIS::OISKeyboard, true)); return 1; }