void ServerGraphics::setupResources (void)
{
    // Load resource paths from config file
    Ogre::ConfigFile cf;
    cf.load(mResourcesCfg);

    // Go through all sections & settings in the file
    Ogre::ConfigFile::SectionIterator seci = cf.getSectionIterator();

    Ogre::String secName, typeName, archName;
    while (seci.hasMoreElements())
    {
        secName = seci.peekNextKey();
        Ogre::ConfigFile::SettingsMultiMap *settings = seci.getNext();
        Ogre::ConfigFile::SettingsMultiMap::iterator i;
        for (i = settings->begin(); i != settings->end(); ++i)
        {
            typeName = i->first;
            archName = i->second;
            Ogre::ResourceGroupManager::getSingleton().addResourceLocation(archName, typeName, secName);
        }
    }
}
예제 #2
0
void GraphicsOgre::defineRessources()
{
	Ogre::String secName, typeName, archName;
	Ogre::ConfigFile cf;
	Ogre::String resource_path = "./";
	cf.load(resource_path + "resources.cfg");

	Ogre::ConfigFile::SectionIterator seci = cf.getSectionIterator();
	while (seci.hasMoreElements())
	{
		secName = seci.peekNextKey();
		Ogre::ConfigFile::SettingsMultiMap *settings = seci.getNext();
		Ogre::ConfigFile::SettingsMultiMap::iterator i;
		for (i = settings->begin(); i != settings->end(); ++i)
		{
			typeName = i->first;
			archName = i->second;
			Ogre::ResourceGroupManager::getSingleton().addResourceLocation(archName, typeName, secName);
		}
	}
	Ogre::TextureManager::getSingleton().setDefaultNumMipmaps(5);
	Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups();
}
예제 #3
0
void RenderPump::setupResources()
{
    Ogre::ConfigFile cf;
#if OGRE_DEBUG_MODE
    cf.load("resources_d.cfg");
#else
    cf.load("resources.cfg");
#endif
    Ogre::ConfigFile::SectionIterator secIter = cf.getSectionIterator();
    Ogre::String secName, typeName, archName;
    while(secIter.hasMoreElements())
    {
        secName = secIter.peekNextKey();
        Ogre::ConfigFile::SettingsMultiMap *settings = secIter.getNext();
        Ogre::ConfigFile::SettingsMultiMap::iterator i;
        for(i=settings->begin(); i!=settings->end(); i++)
        {
            typeName = i->first;
            archName = i->second;
            Ogre::ResourceGroupManager::getSingleton().addResourceLocation(
                archName, typeName, secName);
        }
    }
}
예제 #4
0
	//This function is based on code from the Ogre ExampleApplication.
	//It is not constrained by the Ogre licence (free for any use).
	void Application::loadResourcePathsFromConfigFile(const QString& filename)
    {
        // Load resource paths from config file
		Ogre::ConfigFile cf;
		cf.load(filename.toStdString());

        // Go through all sections & settings in the file
        Ogre::ConfigFile::SectionIterator seci = cf.getSectionIterator();

        Ogre::String secName, typeName, archName;
        while (seci.hasMoreElements())
        {
            secName = seci.peekNextKey();
            Ogre::ConfigFile::SettingsMultiMap *settings = seci.getNext();
            Ogre::ConfigFile::SettingsMultiMap::iterator i;
            for (i = settings->begin(); i != settings->end(); ++i)
            {
                typeName = i->first;
                archName = i->second;
                Ogre::ResourceGroupManager::getSingleton().addResourceLocation(
                    archName, typeName, secName);
            }
        }
    }
예제 #5
0
void QtOgre::loadResources()
{
    // Load resource paths from config file
#ifdef _DEBUG
    mResourcesCfg = "resources_d.cfg";
    mPluginsCfg = "plugins_d.cfg";
#else
    mResourcesCfg = "resources.cfg";
    mPluginsCfg = "plugins.cfg";
#endif
    Ogre::ConfigFile cf;
    cf.load(mResourcesCfg);
    // Go through all sections & settings in the file
    Ogre::ConfigFile::SectionIterator seci = cf.getSectionIterator();
    Ogre::String secName, typeName, archName;
    while (seci.hasMoreElements()) {
        secName = seci.peekNextKey();
        Ogre::ConfigFile::SettingsMultiMap *settings = seci.getNext();
        Ogre::ConfigFile::SettingsMultiMap::iterator i;
        for (i = settings->begin(); i != settings->end(); ++i) {
            typeName = i->first;
            archName = i->second;
#if OGRE_PLATFORM == OGRE_PLATFORM_APPLE
            // OS X does not set the working directory relative to the app,
            // In order to make things portable on OS X we need to provide
            // the loading with it's own bundle path location
            Ogre::ResourceGroupManager::getSingleton().addResourceLocation(
                Ogre::String(macBundlePath() + "/" + archName), typeName, secName);
#else
            Ogre::ResourceGroupManager::getSingleton().addResourceLocation(archName, typeName, secName);
#endif
        }
    }
    // Initialise, parse scripts etc
    Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups();
}
예제 #6
0
void OgreView::setupResources()
{	
	mRoot = new Ogre::Root();	

	Ogre::ConfigFile cf;
	cf.load("resources.cfg");

	Ogre::ConfigFile::SectionIterator seci = cf.getSectionIterator();
	Ogre::String secName, typeName, archName;
	while(seci.hasMoreElements())
	{
		secName = seci.peekNextKey();
		Ogre::ConfigFile::SettingsMultiMap* settings = seci.getNext();
		Ogre::ConfigFile::SettingsMultiMap::iterator i;
		for(i=settings->begin(); i!=settings->end(); ++i){
			typeName = i->first;
			archName = i->second;
			Ogre::ResourceGroupManager::getSingleton().addResourceLocation(archName, typeName, secName);
		}
	}

	mRoot->restoreConfig();
	mRoot->initialise(false);
}
예제 #7
0
	/**
	* @internal
	* @brief Initializes the Resource Manager, which makes ogre aware of all resources directories
	* @note This method does not actually load the resources, each subsystem of the library is in charche
	* of loading the actual resources that they need.
	* @note Ogre Root object is created here (to acces the resources management features), so this manager should be
	* initialized before the rest of Ogre related managers
	*/
	void ResourceManager::init()
	{
		// Obtain the user execution directory
		extractUserAppPath();

		// Init Ogre Root
		LOG( "Creating Ogre Root. Plugins path: %s", (resourcesPathInBundle + pluginsPath).c_str() );
		new Ogre::Root( resourcesPathInBundle + pluginsPath );

		 // Store user data path in globals
		dataFolder = userDataPath;
		LOG("User Data Folder: %s", dataFolder.c_str() );

		// Load Cing Config file
		XMLElement xml;
		xml.load( "CingConfig.xml" );

		// Get cing data folder (the root is CingConfig)
		if ( xml.isValid() )
		{
			XMLElement cingDataFolderXMLElement = xml.getChild("Cing_Data_Folder");
			cingDataFolder = cingDataFolderXMLElement.getStringAttribute("relativePath");
		}
		else
			LOG_ERROR( "CingConfig.xml not found in data folder -> using default paths" );
		
		// Get Cing data path
		LOG( "Cing Data Folder: %s", cingDataFolder.c_str());
		if ( cingDataFolder != "" )
		{
			libDataPath = cingDataFolder;
		}
		else
			LOG_ERROR( "Cing Data Folder is empty: libDataPath will use default value: %s",  libDataPath.c_str() );
		
		// Load resource paths from config file
		Ogre::ConfigFile  cf;
		std::string resourcesFileAbsPath = libDataPath + resourcesFileName ;
		LOG( "Trying to load Ogre Resources file (resources.cfg) at: %s", resourcesFileAbsPath.c_str() ); 
		cf.load( resourcesFileAbsPath.c_str() );

		// Go through all sections & settings in the file to add all library resource locations
		Ogre::String secName, typeName, archName;
		Ogre::ConfigFile::SectionIterator seci = cf.getSectionIterator();
		while (seci.hasMoreElements())
		{
			// Get section name and data
			secName = seci.peekNextKey();
			Ogre::ConfigFile::SettingsMultiMap *settings = seci.getNext();

			// Iterate through section elements
			Ogre::ConfigFile::SettingsMultiMap::iterator i;
			for (i = settings->begin(); i != settings->end(); ++i)
			{
				typeName = i->first;
				archName = i->second;

				// Add the resource location to the manager
				Ogre::ResourceGroupManager::getSingleton().addResourceLocation( libDataPath + archName, typeName, secName );
			}
		}

		m_bIsValid = true;
	}
예제 #8
0
int main(int argc, char **argv)
#endif
{
	try
	{
		//Iniciem el nostre carregador de classes
		ClassLoader::init();
		
		//Iniciem OGRE
		#ifdef NO_LOGS
			Ogre::Root *lRoot = new Ogre::Root("", "", "");
		#else
			Ogre::Root *lRoot = new Ogre::Root("", "", "skbl.log");
		#endif
		lRoot->loadPlugin("Plugin_OctreeSceneManager");
		
		//provem de carregar els plugins de DirectX o OpenGL
		#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
			try
			{
				lRoot->loadPlugin("RenderSystem_Direct3D9");
			}catch (Ogre::Exception &e)
			{
				MessageBox( NULL, "Get it in our web page",
					"Couldn't find shared library \"RenderSystem_Direct3D9\"\n",
						MB_OK | MB_ICONERROR | MB_TASKMODAL);
			}
		#else //Win32
			try
			{
				lRoot->loadPlugin("RenderSystem_GL");
			}catch (Ogre::Exception &ee)
			{
					std::cerr << "Couldn't find shared library \"RenderSystem_GL\". Get it in our web page\n" << std::endl;
			}
		#endif //Win32
		
		
		//ara seleccionem un render system d'entre els disponibles
		const Ogre::RenderSystemList& lRenderSystemList = lRoot->getAvailableRenderers();
		for(unsigned int i=0; i<lRenderSystemList.size(); i++)
		{
			Ogre::String rsysnm = lRenderSystemList[i]->getName();
			//l'ordre d'ifs es el de preferencia
			if(rsysnm=="Direct3D9 Rendering Subsystem")
			{
				lRoot->setRenderSystem(lRenderSystemList[i]);
				break;
			}
			if(rsysnm=="OpenGL Rendering Subsystem")
			{
				lRoot->setRenderSystem(lRenderSystemList[i]);
				break;
			}
		}
		
		//Inicialitzem Root sense crear finestra
		lRoot->initialise(false);
		
		//TODO: Llegir fitxer de configuracio
		Ogre::RenderWindow *lWindow;
		Ogre::NameValuePairList lParams;
		lParams["vsync"] = "true";
		lWindow = lRoot->createRenderWindow("De-geso~~~", 1280, 720, false, &lParams);
		

    // Load resource paths from config file
		Ogre::ConfigFile cf;
    cf.load("configScripts/resources.cfg");

    // Go through all sections & settings in the file
    Ogre::ConfigFile::SectionIterator seci = cf.getSectionIterator();

    Ogre::String secName, typeName, archName;
    while (seci.hasMoreElements())
    {
        secName = seci.peekNextKey();
        Ogre::ConfigFile::SettingsMultiMap *settings = seci.getNext();
        Ogre::ConfigFile::SettingsMultiMap::iterator i;
        for (i = settings->begin(); i != settings->end(); ++i)
        {
            typeName = i->first;
            archName = i->second;
#if OGRE_PLATFORM == OGRE_PLATFORM_APPLE
            // OS X does not set the working directory relative to the app,
            // In order to make things portable on OS X we need to provide
            // the loading with it's own bundle path location
            if (!Ogre::StringUtil::startsWith(archName, "/", false)) // only adjust relative dirs
                archName = Ogre::String(Ogre::macBundlePath() + archName);
#endif
            Ogre::ResourceGroupManager::getSingleton().addResourceLocation(
                archName, typeName, secName);
        }
    }
		//Creem un GameSetup --provisional
		GameSetup *lGameSetup = ClassLoader::makeGameSetupLocalProva(lRoot, lWindow, "pl_Boxejador", "lv_Prova");
		delete lGameSetup;
		
		ClassLoader::unloadGameSetupLocalProva();
		
		#ifndef NO_LOGS
			Ogre::LogManager::getSingletonPtr()->logMessage("Fi del programa");
		#endif
		delete lRoot;
	
	}catch(Ogre::Exception &e)
	{
		#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
            MessageBox( NULL, e.getFullDescription().c_str(), "An exception has occured!", MB_OK | MB_ICONERROR | MB_TASKMODAL);
		#else
            std::cerr << "An exception has occured: " <<
                e.getFullDescription().c_str() << std::endl;
		#endif
	}
	return 0;
}
예제 #9
0
void App::initOgre()
{
	// Config file class is an utility that parses and stores values from a .cfg file
	Ogre::ConfigFile cf;
	std::string configFilePathPrefix = "cfg/";			// configuration files default location when app is installed
#ifdef _DEBUG
	std::string pluginsFileName = "plugins_d.cfg";		// plugins config file name (Debug mode)
#else
	std::string pluginsFileName = "plugins.cfg";		// plugins config file name (Release mode)
#endif
	std::string resourcesFileName = "resources.cfg";	// resources config file name (Debug/Release mode)


	// LOAD OGRE PLUGINS
	// Try to load load up a valid config file (and don't start the program if none is found)
	try
	{
		//This will work ONLY when application is installed (only Release application)!
		cf.load(configFilePathPrefix + pluginsFileName);
	}
	catch (Ogre::FileNotFoundException &e)
	{
		try
		{
			// if no existing config, or could not restore it, try to load from a different location
			configFilePathPrefix = "../cfg/";

			//This will work ONLY when application is in development (Debug/Release configuration)
			cf.load(configFilePathPrefix + pluginsFileName);			
		}
		catch (Ogre::FileNotFoundException &e)
		{
			// launch exception if no valid config file is found! - PROGRAM WON'T START!
			throw e;
		}
	}


	// INSTANCIATE OGRE ROOT (IT INSTANCIATES ALSO ALL OTHER OGRE COMPONENTS)
	// In Ogre, the singletons are instanciated explicitly (with new) the first time,
	// then it can be accessed with Ogre::Root::getSingleton()
	// Plugins are passed as argument to the "Root" constructor
	mRoot = new Ogre::Root(configFilePathPrefix + pluginsFileName, configFilePathPrefix + "ogre.cfg", "ogre.log");
	// No Ogre::FileNotFoundException is thrown by this, that's why we tried to open it first with ConfigFile::load()

	
	// LOAD OGRE RESOURCES
	// Load up resources according to resources.cfg ("cf" variable is reused)
	try
	{
		//This will work ONLY when application is installed!
		cf.load("cfg/resources.cfg");
	}
	catch (Ogre::FileNotFoundException &e)	// It works, no need to change anything
	{
		try
		{
			//This will work ONLY when application is in development (Debug/Release configuration)
			cf.load("../cfg/resources.cfg");
		}
		catch (Ogre::FileNotFoundException &e)
		{
			// launch exception if no valid config file is found! - PROGRAM WON'T START!
			throw e;
		}
	}

    // Go through all sections & settings in the file
    Ogre::ConfigFile::SectionIterator seci = cf.getSectionIterator();
    Ogre::String secName, typeName, archName;
    while (seci.hasMoreElements())
    {
        secName = seci.peekNextKey(); Ogre::ConfigFile::SettingsMultiMap *settings = seci.getNext();
        Ogre::ConfigFile::SettingsMultiMap::iterator i;
        for (i = settings->begin(); i != settings->end(); ++i)
        {
            typeName = i->first;
            archName = i->second;
			//For each section/key-value, add a resource to ResourceGroupManager
            Ogre::ResourceGroupManager::getSingleton().addResourceLocation(
                archName, typeName, secName);
        }
	}


	// Then setup THIS CLASS INSTANCE as a frame listener
	// This means that Ogre will call frameStarted(), frameRenderingQueued() and frameEnded()
	// automatically and periodically if defined in this class
	mRoot->addFrameListener(this);


	// SELECT AND CUSTOMIZE OGRE RENDERING (OpenGL)
	// Get a reference of the RenderSystem in Ogre that I want to customize
	Ogre::RenderSystem* pRS = mRoot->getRenderSystemByName("OpenGL Rendering Subsystem");
	// Get current config RenderSystem options in a ConfigOptionMap
	Ogre::ConfigOptionMap cfgMap = pRS->getConfigOptions();
	// Modify them
	cfgMap["Full Screen"].currentValue = "No";
	cfgMap["VSync"].currentValue = "Yes";
	#ifdef _DEBUG
		cfgMap["FSAA"].currentValue = "0";
	#else
		cfgMap["FSAA"].currentValue = "8";
	#endif
	cfgMap["Video Mode"].currentValue = "1200 x 800";
	// Set them back into the RenderSystem
	for(Ogre::ConfigOptionMap::iterator iter = cfgMap.begin(); iter != cfgMap.end(); iter++) pRS->setConfigOption(iter->first, iter->second.currentValue);
	// Set this RenderSystem as the one I want to use
	mRoot->setRenderSystem(pRS);
	// Initialize it: "false" is DO NOT CREATE A WINDOW FOR ME
	mRoot->initialise(false, "Oculus Rift Visualization");


	// CREATE WINDOWS
	/* REMOVED: Rift class creates the window if no null is passed to its constructor
	// Options for Window 1 (rendering window)
	Ogre::NameValuePairList miscParams;
	if( NO_RIFT )
		miscParams["monitorIndex"] = Ogre::StringConverter::toString(0);
	else
		miscParams["monitorIndex"] = Ogre::StringConverter::toString(1);
	miscParams["border "] = "none";
	*/

	/*
	// Create Window 1
	if( !ROTATE_VIEW )
	mWindow = mRoot->createRenderWindow("Oculus Rift Liver Visualization", 1280, 800, true, &miscParams);
	//mWindow = mRoot->createRenderWindow("Oculus Rift Liver Visualization", 1920*0.5, 1080*0.5, false, &miscParams);
	else
	mWindow = mRoot->createRenderWindow("Oculus Rift Liver Visualization", 1080, 1920, true, &miscParams);
	*/

	// Options for Window 2 (debug window)
	// This window will simply show what the two cameras see in two different viewports
	Ogre::NameValuePairList miscParamsSmall;
	miscParamsSmall["monitorIndex"] = Ogre::StringConverter::toString(0);

	// Create Window 2
	if( DEBUG_WINDOW )
		mSmallWindow = mRoot->createRenderWindow("DEBUG Oculus Rift Liver Visualization", 1920*debugWindowSize, 1080*debugWindowSize, false, &miscParamsSmall);   

	Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups();
}
예제 #10
0
bool BasicWindow::go(void) {

	// 1. define the root object:
	
	mRoot = new Ogre::Root(mPluginsFileName);

	// 2. define the resources that ogre will use:

	Ogre::ConfigFile configFile;
	configFile.load(mResourcesFileName);
	Ogre::ConfigFile::SectionIterator sectionsIter = configFile.getSectionIterator();
	Ogre::ConfigFile::SettingsMultiMap::iterator settingsIter;
	Ogre::ConfigFile::SettingsMultiMap* settings;
	Ogre::String secName, typeName, archName;

	while(sectionsIter.hasMoreElements()) {
		secName  = sectionsIter.peekNextKey();
		settings = sectionsIter.getNext();
		for (settingsIter=settings->begin(); settingsIter!=settings->end(); ++settingsIter) {
			typeName = settingsIter->first;
			archName = settingsIter->second;
			Ogre::ResourceGroupManager::getSingleton().addResourceLocation(archName, typeName, secName);
		}
	}

	// 3. choose and setup the render system:

	if (!(mRoot->restoreConfig() || mRoot->showConfigDialog())) {
		return false;
	}

	// 4. create the render window:

	mWindow = mRoot->initialise(true, "Testing");

	// 5. initialise the required resources:

	Ogre::TextureManager::getSingleton().setDefaultNumMipmaps(5);
	Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups();

	// 6. setup scene:

	mSceneMgr = mRoot->createSceneManager("DefaultSceneManager");
	
	mCamera   = mSceneMgr->createCamera("mCamera");
	mCamera->setNearClipDistance(1);
	//mCamera->setFarClipDistance(10000);

	mCameraMan = new OgreBites::SdkCameraMan(mCamera);

	Ogre::Viewport* vp = mWindow->addViewport(mCamera);
	//vp->setBackgroundColour(Ogre::ColourValue(1, 1, 1));
	mCamera->setAspectRatio(Ogre::Real(vp->getActualWidth()) / Ogre::Real(vp->getActualHeight()));

	mCameraNode = mSceneMgr->getRootSceneNode()->createChildSceneNode("cameraNode");
	mCameraNode->attachObject(mCamera);

	createGUI();
	createScene();

	// 7. setup 3rd party libraries and plugins:

	Utils::log("*** Initialising OIS ***");
	OIS::ParamList paramList;
	size_t windowHandle = 0;
	std::ostringstream windowHandleString;
	mWindow->getCustomAttribute("WINDOW", &windowHandle);
	windowHandleString << windowHandle;
	paramList.insert(std::make_pair(std::string("WINDOW"), windowHandleString.str()));

	mInputManager = OIS::InputManager::createInputSystem(paramList);
	mKeyboard     = static_cast<OIS::Keyboard*>(mInputManager->createInputObject(OIS::OISKeyboard, true));
	mMouse        = static_cast<OIS::Mouse*>(mInputManager->createInputObject(OIS::OISMouse, true));

	windowResized(mWindow);  //<- sets mouse clipping size

	// 8. add listeners and callbacks:

	Ogre::WindowEventUtilities::addWindowEventListener(mWindow, this);
	mRoot->addFrameListener(this);
	mMouse->setEventCallback(this);
	mKeyboard->setEventCallback(this);

	// 9. start the render loop

	mRoot->startRendering();

	return true;
}
예제 #11
0
bool OgreFramework::initOgre(Ogre::String wndTitle, OIS::KeyListener *pKeyListener, OIS::MouseListener *pMouseListener)
{
	// PTR TuanNA [Create and initiate the Log- 10/7/2016]
    Ogre::LogManager* logMgr = new Ogre::LogManager();

    m_pLog = Ogre::LogManager::getSingleton().createLog("OgreLogfile.log", true, true, false);
    m_pLog->setDebugOutputEnabled(true);

	// PTR TuanNA [Create an Ogre Root- 10/7/2016]
    m_pRoot = new Ogre::Root();
//PTR TuanNA begin comment
//[Add icon to app- 10/7/2016]
    if(m_pRoot->showConfigDialog())
	{
		// If returned true, user clicked OK so initialise
		// Here we choose to let the system create a default rendering window by passing 'true'
		m_pRenderWnd = m_pRoot->initialise(true, "OgreFramework Render Window");

		// Let's add a nice window icon
#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
		HWND hwnd;
		m_pRenderWnd->getCustomAttribute("WINDOW", (void*)&hwnd);
		LONG iconID   = (LONG)LoadIcon( GetModuleHandle(0), MAKEINTRESOURCE(IDI_APPICON) );
		SetClassLong( hwnd, GCL_HICON, iconID );
#endif
//PTR TuanNA end comment
		// PTR TuanNA [Remove CM m_pRenderWnd- 10/7/2016] m_pRenderWnd = m_pRoot->initialise(true, wndTitle);

		// PTR TuanNA [Add a viewport the to Render window- 11/7/2016]
		m_pViewport = m_pRenderWnd->addViewport(0);
		m_pViewport->setBackgroundColour(ColourValue(0.5f, 0.5f, 0.5f, 1.0f));

		m_pViewport->setCamera(0);

		//PTR TuanNA- Init Ogre Render Window... [16:37:20 4/9/2016 by TNA]
		size_t hWnd = 0;
		OIS::ParamList paramList;
		m_pRenderWnd->getCustomAttribute("WINDOW", &hWnd);

		paramList.insert(OIS::ParamList::value_type("WINDOW", Ogre::StringConverter::toString(hWnd)));

		// PTR TuanNA [Create Input System- 11/7/2016]
		m_pInputMgr = OIS::InputManager::createInputSystem(paramList);

		m_pKeyboard = static_cast<OIS::Keyboard*>(m_pInputMgr->createInputObject(OIS::OISKeyboard, true));
		m_pMouse = static_cast<OIS::Mouse*>(m_pInputMgr->createInputObject(OIS::OISMouse, true));

		m_pMouse->getMouseState().height = m_pRenderWnd->getHeight();
		m_pMouse->getMouseState().width	 = m_pRenderWnd->getWidth();

		if(pKeyListener == 0)
			m_pKeyboard->setEventCallback(this);
		else
			m_pKeyboard->setEventCallback(pKeyListener);

		if(pMouseListener == 0)
			m_pMouse->setEventCallback(this);
		else
			m_pMouse->setEventCallback(pMouseListener);

		Ogre::String secName, typeName, archName;
		Ogre::ConfigFile cf;
#ifdef _DEBUG
		cf.load("resources_d.cfg");
#else
		cf.load("resources.cfg");
#endif

		Ogre::ConfigFile::SectionIterator seci = cf.getSectionIterator();
		while (seci.hasMoreElements())
		{
			secName = seci.peekNextKey();
			Ogre::ConfigFile::SettingsMultiMap *settings = seci.getNext();
			Ogre::ConfigFile::SettingsMultiMap::iterator i;
			for (i = settings->begin(); i != settings->end(); ++i)
			{
				typeName = i->first;
				archName = i->second;
				Ogre::ResourceGroupManager::getSingleton().addResourceLocation(archName, typeName, secName);
			}
		}

		// PTR TuanNA [Configure the amount of MipMaps per texture(to avoid aliasing).- 11/7/2016]
		Ogre::TextureManager::getSingleton().setDefaultNumMipmaps(5);
		Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups();

		/*
		//PTR TuanNA begin comment
		////Load cursor resources
			Ogre::ResourceGroupManager::getSingleton().createResourceGroup("Cursor");
			Ogre::ResourceGroupManager::getSingleton().addResourceLocation("../Media/Cursor.zip","Zip","Cursor");
			Ogre::ResourceGroupManager::getSingleton().initialiseResourceGroup("Cursor");
		
			//Create the GUI handler
			mpGui = new GuiHandler(mpRenderWnd);
		
		#ifdef DEBUG
			loadDebugResources();
			mpGui->initDebugGui();
		#endif
			
			//Link the log to the Settings singleton
			Settings::getSingletonPtr()->setLog(mpLog);	
		
			//Initiate the sound.
			mpSound = new SoundManager();
		//[16:43:54 4/9/2016 by TNA]
		//PTR TuanNA end comment
		*/

		m_pTrayMgr = new OgreBites::SdkTrayManager("AOFTrayMgr", m_pRenderWnd, m_pMouse, 0);
		
		// PTR TuanNA [Initiate the Timer- 11/7/2016]
		m_pTimer = new Ogre::Timer();
		m_pTimer->reset();

		m_pRenderWnd->setActive(true);
		return true;
	}
	else
	{
		return false;
	}
}  
예제 #12
0
bool MinimalOgre::go(void)
{
#ifdef _DEBUG
    mResourcesCfg = "resources_d.cfg";
    mPluginsCfg = "plugins_d.cfg";
#else
    mResourcesCfg = "resources.cfg";
    mPluginsCfg = "plugins.cfg";
#endif
 
    // construct Ogre::Root
    mRoot = new Ogre::Root(mPluginsCfg);
 
//-------------------------------------------------------------------------------------
    // setup resources
    // Load resource paths from config file
    Ogre::ConfigFile cf;
    cf.load(mResourcesCfg);
 
    // Go through all sections & settings in the file
    Ogre::ConfigFile::SectionIterator seci = cf.getSectionIterator();
 
    Ogre::String secName, typeName, archName;
    while (seci.hasMoreElements())
    {
        secName = seci.peekNextKey();
        Ogre::ConfigFile::SettingsMultiMap *settings = seci.getNext();
        Ogre::ConfigFile::SettingsMultiMap::iterator i;
        for (i = settings->begin(); i != settings->end(); ++i)
        {
            typeName = i->first;
            archName = i->second;
            Ogre::ResourceGroupManager::getSingleton().addResourceLocation(
                archName, typeName, secName);
        }
    }
//-------------------------------------------------------------------------------------
    // configure
    // Show the configuration dialog and initialise the system
    // You can skip this and use root.restoreConfig() to load configuration
    // settings if you were sure there are valid ones saved in ogre.cfg
    if(mRoot->restoreConfig() || mRoot->showConfigDialog())
    {
        // If returned true, user clicked OK so initialise
        // Here we choose to let the system create a default rendering window by passing 'true'
        mWindow = mRoot->initialise(true, "MinimalOgre Render Window");
    }
    else
    {
        return false;
    }
    
    //new addition to 1.9, needs to be created for singleton instance.
    overlaySystem = new Ogre::OverlaySystem();
//-------------------------------------------------------------------------------------
    // choose scenemanager
    // Get the SceneManager, in this case a generic one
    mSceneMgr = mRoot->createSceneManager(Ogre::ST_GENERIC);
    mSceneMgr->addRenderQueueListener(overlaySystem);

//-------------------------------------------------------------------------------------
    // create camera
    // Create the camera
    mCamera = mSceneMgr->createCamera("PlayerCam");
 
    // Position it at 500 in Z direction
    mCamera->setPosition(Ogre::Vector3(0,0,80));
    // Look back along -Z
    mCamera->lookAt(Ogre::Vector3(0,0,-300));
    mCamera->setNearClipDistance(5);
 
    mCameraMan = new OgreBites::SdkCameraMan(mCamera);   // create a default camera controller
//-------------------------------------------------------------------------------------
    // create viewports
    // Create one viewport, entire window
    Ogre::Viewport* vp = mWindow->addViewport(mCamera);
    vp->setBackgroundColour(Ogre::ColourValue(0,0,0));
 
    // Alter the camera aspect ratio to match the viewport
    mCamera->setAspectRatio(
        Ogre::Real(vp->getActualWidth()) / Ogre::Real(vp->getActualHeight()));
//-------------------------------------------------------------------------------------
    // Set default mipmap level (NB some APIs ignore this)
    Ogre::TextureManager::getSingleton().setDefaultNumMipmaps(5);
//-------------------------------------------------------------------------------------
    // Create any resource listeners (for loading screens)
    //createResourceListener();
//-------------------------------------------------------------------------------------
    // load resources
    Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups();
//-------------------------------------------------------------------------------------
    // Create the scene
    Ogre::Entity* ogreHead = mSceneMgr->createEntity("Head", "cube.mesh");
 
    //Ogre::SceneNode* headNode = mSceneMgr->getRootSceneNode()->createChildSceneNode();
    //headNode->attachObject(ogreHead);
 
    // Set ambient light
    mSceneMgr->setAmbientLight(Ogre::ColourValue(0.5, 0.5, 0.5));
 
    // Create a light
    Ogre::Light* l = mSceneMgr->createLight("MainLight");
    l->setPosition(20,80,50);
//-------------------------------------------------------------------------------------
    //create FrameListener
    Ogre::LogManager::getSingletonPtr()->logMessage("*** Initializing OIS ***");
    OIS::ParamList pl;
    size_t windowHnd = 0;
    std::ostringstream windowHndStr;
    mWindow->getCustomAttribute("WINDOW", &windowHnd);
    windowHndStr << windowHnd;
    pl.insert(std::make_pair(std::string("WINDOW"), windowHndStr.str()));
    //allow debugging in linux
    pl.insert(std::make_pair("x11_keyboard_grab", "false"));
    pl.insert(std::make_pair("x11_mouse_grab", "false"));
 
    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 ));
 
    mMouse->setEventCallback(this);
    mKeyboard->setEventCallback(this);
    
    OgreBites::InputContext input_context;
    input_context.mKeyboard = mKeyboard;
    input_context.mMouse= mMouse;

    //Set initial mouse clipping size
    windowResized(mWindow);
 
    //Register as a Window listener
    Ogre::WindowEventUtilities::addWindowEventListener(mWindow, this);
 
    mTrayMgr = new OgreBites::SdkTrayManager("InterfaceName", mWindow, input_context, this);
    mTrayMgr->showFrameStats(OgreBites::TL_BOTTOMLEFT);
    mTrayMgr->showLogo(OgreBites::TL_BOTTOMRIGHT);
    //mTrayMgr->hideCursor();
 
    // create a params panel for displaying sample details
    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");
 
    mDetailsPanel = mTrayMgr->createParamsPanel(OgreBites::TL_NONE, "DetailsPanel", 200, items);
    mDetailsPanel->setParamValue(9, "Bilinear");
    mDetailsPanel->setParamValue(10, "Solid");
    mDetailsPanel->hide();
 
    mRoot->addFrameListener(this);
    Voxelizor *v = new Voxelizor();
    //v->fill();
    v->make_wall();
    v->to_ogre_mesh(*mSceneMgr);
//-------------------------------------------------------------------------------------
    mRoot->startRendering();
 
    
    return true;
}
예제 #13
0
파일: main.cpp 프로젝트: chenbk85/3dlearn
BOOL InitOgre()
{
	using namespace Ogre;

#ifdef _DEBUG
	mOgreRoot = new Ogre::Root("plugins_d.cfg", "OgreMFC.cfg", "OgreMFC.log"); 
#else
	mOgreRoot = new Ogre::Root("plugins.cfg", "OgreMFC.cfg", "OgreMFC.log"); 
#endif

	//
	// Setup paths to all resources
	//

	Ogre::ConfigFile cf;
	cf.load("resources_d.cfg");

	// Go through all sections & settings in the file
	Ogre::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);
		}
	}

	const RenderSystemList& render =  mOgreRoot->getAvailableRenderers();

	RenderSystemList::const_iterator pRend = render.begin();

	while (pRend != render.end())
	{
		Ogre::String rName = (*pRend)->getName();
		//if (rName == "OpenGL Rendering Subsystem") //
		if (rName == "Direct3D9 Rendering Subsystem") //Direct3D9 Rendering Subsystem
			break;
		pRend++;
	}

	if (pRend == render.end())
	{
		// Unrecognised render system
		//MessageBox("Unable to locate OpenGL rendering system.  Application is terminating");
		return FALSE;
	}

	Ogre::RenderSystem *rsys = *pRend;
	rsys->setConfigOption("Full Screen", "No");
	rsys->setConfigOption("VSync", "Yes");

	// Set the rendering system.
	mOgreRoot->setRenderSystem(rsys);

	//
	// Initialize the system, but don't create a render window.
	//
	mOgreRoot->initialise(false);

	return TRUE;
}
예제 #14
0
bool OgreSmartBody::go(void)
{
#ifdef _DEBUG
    mResourcesCfg = "resources_d.cfg";
	mPluginsCfg = "plugins_d.cfg";
#else
    mResourcesCfg = "resources.cfg";
    mPluginsCfg = "plugins.cfg";
#endif
 
    // construct Ogre::Root
    mRoot = new Ogre::Root(mPluginsCfg);
 
    // setup resources
    // Load resource paths from config file
    Ogre::ConfigFile cf;
    cf.load(mResourcesCfg);
 
    // Go through all sections & settings in the file
    Ogre::ConfigFile::SectionIterator seci = cf.getSectionIterator();
 
    Ogre::String secName, typeName, archName;
    while (seci.hasMoreElements())
    {
        secName = seci.peekNextKey();
        Ogre::ConfigFile::SettingsMultiMap *settings = seci.getNext();
        Ogre::ConfigFile::SettingsMultiMap::iterator i;
        for (i = settings->begin(); i != settings->end(); ++i)
        {
            typeName = i->first;
            archName = i->second;
            Ogre::ResourceGroupManager::getSingleton().addResourceLocation(
                archName, typeName, secName);
        }
    }
    // configure
    // Show the configuration dialog and initialise the system
    if(!(mRoot->restoreConfig() || mRoot->showConfigDialog()))
    {
        return false;
    }
 
    mWindow = mRoot->initialise(true, "OgreSmartBody Render Window");
 
    // Set default mipmap level (NB some APIs ignore this)
    Ogre::TextureManager::getSingleton().setDefaultNumMipmaps(5);
    // initialise all resource groups
    Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups();
 
    // Create the SceneManager, in this case a generic one
    mSceneMgr = mRoot->createSceneManager("DefaultSceneManager");
 
    // Create the camera
    mCamera = mSceneMgr->createCamera("PlayerCam");
 
    // Position it at 500 in Z direction
    mCamera->setPosition(Ogre::Vector3(0,10,60));
    // Look back along -Z
    mCamera->lookAt(Ogre::Vector3(0,0,-300));
    mCamera->setNearClipDistance(5);
 
    // Create one viewport, entire window
    Ogre::Viewport* vp = mWindow->addViewport(mCamera);
    vp->setBackgroundColour(Ogre::ColourValue(0,0,0));
 
    // Alter the camera aspect ratio to match the viewport
    mCamera->setAspectRatio(
        Ogre::Real(vp->getActualWidth()) / Ogre::Real(vp->getActualHeight()));

	// create a floor for better visualization
		//adding plane entity to the scene
	Ogre::Plane plane;
	plane.normal = Ogre::Vector3::UNIT_Y;
	plane.d = 0;
	Ogre::MeshManager::getSingleton().createPlane( "Myplane", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, plane, 1500, 1500, 20, 20, true, 1, 60, 60, Ogre::Vector3::UNIT_Z );
	Ogre::Entity * pPlaneEnt = mSceneMgr->createEntity( "plane", "Myplane" );
	//pPlaneEnt->setMaterialName( "Examples/Rockwall" );
	pPlaneEnt->setMaterialName( "Rockwall" );
	pPlaneEnt->setCastShadows( false );
	mSceneMgr->getRootSceneNode()->createChildSceneNode("plane_node", Ogre::Vector3( 0, 0, 0 ) )->attachObject( pPlaneEnt );
	mSceneMgr->getSceneNode("plane_node")->setVisible(true);

	// shadows
	mSceneMgr->setShadowTechnique( Ogre::SHADOWTYPE_TEXTURE_MODULATIVE );
	mSceneMgr->setShadowTextureSize( 4048 );
	mSceneMgr->setShadowColour( Ogre::ColourValue( 0.3f, 0.3f, 0.3f ) );
  
    // Set ambient light
    mSceneMgr->setAmbientLight(Ogre::ColourValue(0.5, 0.5, 0.5));
 
    // Create a light
    Ogre::Light* l = mSceneMgr->createLight("MainLight");
    l->setPosition(20,80,50);
 
    Ogre::LogManager::getSingletonPtr()->logMessage("*** Initializing OIS ***");
    OIS::ParamList pl;
    size_t windowHnd = 0;
    std::ostringstream windowHndStr;
 
    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 ));
    mMouse = static_cast<OIS::Mouse*>(mInputManager->createInputObject( OIS::OISMouse, false ));
 
    //Set initial mouse clipping size
    windowResized(mWindow);
 
    //Register as a Window listener
    Ogre::WindowEventUtilities::addWindowEventListener(mWindow, this);
 
    mRoot->addFrameListener(this);

	// smartbody
	// the root path to SmartBody: change this to your own path
	std::string smartbodyRoot = "..";
	// set the following to the location of the Python libraries. 
	// if you downloaded SmartBody, it will be in core/smartbody/Python26/Lib
#ifdef WIN32
	initPython(smartbodyRoot + "/Python27/lib");
#else
	initPython("/usr/lib/python2.7");
#endif
	m_pScene = SmartBody::SBScene::getScene();

	m_pScene->startFileLogging("smartbody.log");
	OgreSmartBodyListener* listener = new OgreSmartBodyListener(this);
	m_pScene->addSceneListener(listener);
	m_pScene->start();

	// sets the media path, or root of all the data to be used
	// other paths will be relative to the media path
	m_pScene->setMediaPath(smartbodyRoot + "/data");
	m_pScene->addAssetPath("script", ".");
	// the file 'OgreSmartBody.py' needs to be placed in the media path directory
	m_pScene->runScript("ogresmartbody.py");

	mStartTime = Ogre::Root::getSingleton().getTimer()->getMilliseconds() / 1000.0f;
	mRoot->startRendering();
 
    return true;
}
예제 #15
0
bool OgreFramework::initOgre(Ogre::String wndTitle, OIS::KeyListener *pKeyListener, OIS::MouseListener *pMouseListener)
#endif
{
    new Ogre::LogManager();

	m_pLog = Ogre::LogManager::getSingleton().createLog("OgreLogfile.log", true, true, false);
	m_pLog->setDebugOutputEnabled(true);
    
    String pluginsPath;
    // only use plugins.cfg if not static
#ifndef OGRE_STATIC_LIB
    pluginsPath = m_ResourcePath + "plugins.cfg";
#endif
    
    m_pRoot = new Ogre::Root(pluginsPath, Ogre::macBundlePath() + "/ogre.cfg");
    
#ifdef OGRE_STATIC_LIB
    m_StaticPluginLoader.load();
#endif
    
	if(!m_pRoot->showConfigDialog())
		return false;
	m_pRenderWnd = m_pRoot->initialise(true, wndTitle);
    
	m_pSceneMgr = m_pRoot->createSceneManager(ST_GENERIC, "SceneManager");
	m_pSceneMgr->setAmbientLight(Ogre::ColourValue(0.7f, 0.7f, 0.7f));
	
	m_pCamera = m_pSceneMgr->createCamera("Camera");
	m_pCamera->setPosition(Vector3(0, 60, 60));
	m_pCamera->lookAt(Vector3(0, 0, 0));
	m_pCamera->setNearClipDistance(1);
    
	m_pViewport = m_pRenderWnd->addViewport(m_pCamera);
	m_pViewport->setBackgroundColour(ColourValue(0.8f, 0.7f, 0.6f, 1.0f));
    
	m_pCamera->setAspectRatio(Real(m_pViewport->getActualWidth()) / Real(m_pViewport->getActualHeight()));
	
	m_pViewport->setCamera(m_pCamera);
    
	unsigned long hWnd = 0;
    OIS::ParamList paramList;
    m_pRenderWnd->getCustomAttribute("WINDOW", &hWnd);
    
	paramList.insert(OIS::ParamList::value_type("WINDOW", Ogre::StringConverter::toString(hWnd)));
    
	m_pInputMgr = OIS::InputManager::createInputSystem(paramList);
    
#if !defined(OGRE_IS_IOS)
    m_pKeyboard = static_cast<OIS::Keyboard*>(m_pInputMgr->createInputObject(OIS::OISKeyboard, true));
	m_pMouse = static_cast<OIS::Mouse*>(m_pInputMgr->createInputObject(OIS::OISMouse, true));
    
	m_pMouse->getMouseState().height = m_pRenderWnd->getHeight();
	m_pMouse->getMouseState().width	 = m_pRenderWnd->getWidth();
#else
	m_pMouse = static_cast<OIS::MultiTouch*>(m_pInputMgr->createInputObject(OIS::OISMultiTouch, true));
#endif
    
#if !defined(OGRE_IS_IOS)
	if(pKeyListener == 0)
		m_pKeyboard->setEventCallback(this);
	else
		m_pKeyboard->setEventCallback(pKeyListener);
#endif
    
	if(pMouseListener == 0)
		m_pMouse->setEventCallback(this);
	else
		m_pMouse->setEventCallback(pMouseListener);
    
	Ogre::String secName, typeName, archName;
	Ogre::ConfigFile cf;
    cf.load(m_ResourcePath + "resources.cfg");
    
	Ogre::ConfigFile::SectionIterator seci = cf.getSectionIterator();
    while (seci.hasMoreElements())
    {
        secName = seci.peekNextKey();
		Ogre::ConfigFile::SettingsMultiMap *settings = seci.getNext();
        Ogre::ConfigFile::SettingsMultiMap::iterator i;
        for (i = settings->begin(); i != settings->end(); ++i)
        {
            typeName = i->first;
            archName = i->second;
#if OGRE_PLATFORM == OGRE_PLATFORM_APPLE || defined(OGRE_IS_IOS)
            // OS X does not set the working directory relative to the app,
            // In order to make things portable on OS X we need to provide
            // the loading with it's own bundle path location
            if (!Ogre::StringUtil::startsWith(archName, "/", false)) // only adjust relative dirs
                archName = Ogre::String(m_ResourcePath + archName);
#endif
            Ogre::ResourceGroupManager::getSingleton().addResourceLocation(archName, typeName, secName);
        }
    }
	Ogre::TextureManager::getSingleton().setDefaultNumMipmaps(5);
	Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups();
    
	m_pTimer = OGRE_NEW Ogre::Timer();
	m_pTimer->reset();
	
    /*
	m_pTrayMgr = new OgreBites::SdkTrayManager("TrayMgr", m_pRenderWnd, m_pMouse, this);
    m_pTrayMgr->showFrameStats(OgreBites::TL_BOTTOMLEFT);
    m_pTrayMgr->showLogo(OgreBites::TL_BOTTOMRIGHT);
    m_pTrayMgr->hideCursor();
    */
	m_pRenderWnd->setActive(true);
    
    mGame = new Game(m_pSceneMgr, m_pRenderWnd, m_pCamera);
    
	return true;
}
예제 #16
0
bool OgreFramework::initOgre(OIS::KeyListener *pKeyListener, OIS::MouseListener *pMouseListener, Ogre::RenderTargetListener *pRenderTargetListener)
#endif
{
    new Ogre::LogManager();
    
	m_pLog = Ogre::LogManager::getSingleton().createLog("OgreLogfile.log", true, true, false);
	m_pLog->setDebugOutputEnabled(true);
    
    String pluginsPath;
    // only use plugins.cfg if not static
#ifndef OGRE_STATIC_LIB
    pluginsPath = m_ResourcePath + "plugins.cfg";
#endif
    m_pRoot = new Ogre::Root(pluginsPath, Ogre::macBundlePath() + "/ogre.cfg");
    
#ifdef OGRE_STATIC_LIB
    m_StaticPluginLoader.load();
#endif
    if(m_pRoot->restoreConfig() || m_pRoot->showConfigDialog())
        m_pRenderWnd = m_pRoot->initialise(true, "");
    else
        return false;
    m_pRenderWnd->resize(600, 800);
    m_pRenderWnd->windowMovedOrResized();
    //m_pRenderWnd->setFullscreen(true, 800, 600);
    globals.screenWidth = m_pRenderWnd->getWidth();
    globals.screenHeight = m_pRenderWnd->getHeight();
    globals.set();
    
    /*
     Ogre::NameValuePairList paramsWnd;
     paramsWnd["border"] = "fixed";
     m_pRenderWnd = m_pRoot->createRenderWindow(wndTitle, Util::SCREEN_WIDTH, Util::SCREEN_HEIGHT, false, &paramsWnd);
     */
	m_pSceneMgrMain = m_pRoot->createSceneManager(ST_GENERIC, "SceneManagerMain");
	//m_pSceneMgrSide = m_pRoot->createSceneManager(ST_GENERIC, "SceneManagerSide");
	m_pSceneMgrMain->setAmbientLight(Ogre::ColourValue(0.5, 0.5, 0.5));
	//m_pSceneMgrSide->setAmbientLight(Ogre::ColourValue(0.5, 0.5, 0.5));
    
	m_pCameraMain = m_pSceneMgrMain->createCamera("CameraMain");
	m_pCameraMain->setPosition(Vector3(0, 0, 50));
	m_pCameraMain->lookAt(Vector3(0, 0, 0));
	m_pCameraMain->setNearClipDistance(0.1);
//    m_pCameraMain->setFOVy(Degree(45));
    //m_pCameraMain->setFarClipDistance(500.0);
	m_pViewportMain = m_pRenderWnd->addViewport(m_pCameraMain, 1,
                                                0.0,
                                                0.0,
                                                float(globals.viewportMainWidth_modeNone) / globals.screenWidth,
                                                float(globals.viewportMainHeight_modeNone) / globals.screenHeight);
	m_pCameraMain->setAspectRatio(Real(m_pViewportMain->getActualWidth()) / Real(m_pViewportMain->getActualHeight()));
	m_pViewportMain->setCamera(m_pCameraMain);
    m_pViewportMain->getTarget()->addListener(pRenderTargetListener);
    /*
     m_pCameraSide = m_pSceneMgrSide->createCamera("CameraSide");
     m_pCameraSide->setPosition(Vector3(0, 0, 30));
     m_pCameraSide->lookAt(Vector3(0, 0, 0));
     m_pCameraSide->setNearClipDistance(1);
     m_pCameraSide->setOrthoWindow(10.0, 25.0);
     m_pCameraSide->setProjectionType(Ogre::PT_ORTHOGRAPHIC);
     m_pViewportSide = m_pRenderWnd->addViewport(m_pCameraSide, 0,
     float(globals.viewportMainWidth_modeNone) / globals.screenWidth,
     0.0,
     float(globals.viewportSideWidth_modeNone) / globals.screenWidth,
     float(globals.viewportSideHeight_modeNone) / globals.screenHeight);
     m_pViewportSide->setBackgroundColour(ColourValue(0.0f, 0.0f, 0.0f, 1.0f));
     m_pCameraSide->setAspectRatio(Real(m_pViewportSide->getActualWidth()) / Real(m_pViewportSide->getActualHeight()));
     m_pViewportSide->setCamera(m_pCameraSide);
     m_pViewportSide->getTarget()->addListener(pRenderTargetListener);
     */
	unsigned long hWnd = 0;
    OIS::ParamList paramList;
    m_pRenderWnd->getCustomAttribute("WINDOW", &hWnd);
    
	paramList.insert(OIS::ParamList::value_type("WINDOW", Ogre::StringConverter::toString(hWnd)));
    
	m_pInputMgr = OIS::InputManager::createInputSystem(paramList);
    
#if !defined(OGRE_IS_IOS)
    m_pKeyboard = static_cast<OIS::Keyboard*>(m_pInputMgr->createInputObject(OIS::OISKeyboard, true));
	m_pMouse = static_cast<OIS::Mouse*>(m_pInputMgr->createInputObject(OIS::OISMouse, true));
    
	m_pMouse->getMouseState().height = m_pRenderWnd->getHeight();
	m_pMouse->getMouseState().width	 = m_pRenderWnd->getWidth();
    
	if(pKeyListener == 0)
		m_pKeyboard->setEventCallback(this);
	else
		m_pKeyboard->setEventCallback(pKeyListener);
    
	if(pMouseListener == 0)
		m_pMouse->setEventCallback(this);
	else
		m_pMouse->setEventCallback(pMouseListener);
#else
    //	m_pMouse = static_cast<OIS::MultiTouch*>(m_pInputMgr->createInputObject(OIS::OISMultiTouch, true));
	//if(pMouseListener == 0)
	//	m_pMouse->setEventCallback(this);
	//else
	//	m_pMouse->setEventCallback(pMouseListener);
#endif
    
    
	Ogre::String secName, typeName, archName;
	Ogre::ConfigFile cf;
    
    cf.load(m_ResourcePath + "resources.cfg");
    
    m_pResourceGroupMgr = Ogre::ResourceGroupManager::getSingletonPtr();
    m_pOverlayMgr = Ogre::OverlayManager::getSingletonPtr();
    m_pFontMgr = Ogre::FontManager::getSingletonPtr();
    m_pMeshMgr = Ogre::MeshManager::getSingletonPtr();
    m_pMaterialMgr = Ogre::MaterialManager::getSingletonPtr();
    m_pTextureMgr = Ogre::TextureManager::getSingletonPtr();
    m_pCompositeMgr = CompositorManager::getSingletonPtr();
    
	Ogre::ConfigFile::SectionIterator seci = cf.getSectionIterator();
    while (seci.hasMoreElements())
    {
        secName = seci.peekNextKey();
		Ogre::ConfigFile::SettingsMultiMap *settings = seci.getNext();
        Ogre::ConfigFile::SettingsMultiMap::iterator i;
        for (i = settings->begin(); i != settings->end(); ++i)
        {
            typeName = i->first;
            archName = i->second;
#if OGRE_PLATFORM == OGRE_PLATFORM_APPLE || defined(OGRE_IS_IOS)
            // OS X does not set the working directory relative to the app,
            // In order to make things portable on OS X we need to provide
            // the loading with it's own bundle path location
            if (!Ogre::StringUtil::startsWith(archName, "/", false)) // only adjust relative dirs
                archName = Ogre::String(m_ResourcePath + archName);
#endif
            m_pResourceGroupMgr->addResourceLocation(archName, typeName, secName);
        }
    }
    
    Ogre::ResourceGroupManager::getSingleton().initialiseResourceGroup("Bootstrap");
    
	m_pTrayMgr = new OgreBites::SdkTrayManager("TrayMgr", m_pRenderWnd, m_pMouse, this);
    //m_pTrayMgr->showFrameStats(OgreBites::TL_BOTTOMLEFT);
    //m_pTrayMgr->showLogo(OgreBites::TL_BOTTOMRIGHT);
    m_pTrayMgr->hideCursor();
    m_pTrayMgr->setListener(this);
    m_pTrayMgr->setTrayPadding(10.0);
    
    Ogre::FontManager::getSingleton().getByName("SdkTrays/Caption")->load();
    //  m_quitButton = OgreFramework::getSingletonPtr()->m_pTrayMgr->createButton(OgreBites::TL_BOTTOMLEFT, "sdkQuitButton", "QUIT", 250);
    
    m_pSoundMgr = OgreOggSound::OgreOggSoundManager::getSingletonPtr();
    m_pSoundMgr->init();
    m_pSoundMgr->createSound("Music1", "pianomusic2.ogg", false, true, true);
    m_pSoundMgr->createSound("Music4", "pianomusic5.ogg", false, true, true);
    m_pSoundMgr->createSound("Music5", "pianomusic.ogg", false, true, true);
    //m_pSoundMgr->createSound("SoundGreatFeedback", "GoodFeedback.wav", false, false, true);
    m_pSoundMgr->createSound("SoundGreatFeedback", "ding3up3.wav", false, false, true);
    m_pSoundMgr->createSound("SoundGoodFeedback", "energyup.wav", false, false, true);
    m_pSoundMgr->createSound("SoundBadFeedback", "BadFeedback.wav", false, false, true);
    m_pSoundMgr->createSound("SoundCollision", "wrong_answer_feedback.wav", false, false, true);
    m_pSoundMgr->createSound("SoundPod1", "pod4.wav", false, false, true);           // Rose
    m_pSoundMgr->createSound("SoundPod2", "pod3.wav", false, false, true);            // Iris
    m_pSoundMgr->createSound("SoundPod3", "bubbleSound.wav", false, false, true);    // Bubble Flower
    m_pSoundMgr->createSound("SoundPod4", "pod2.wav", false, false, true);            // Daisy
    m_pSoundMgr->createSound("SoundStartup", "beeTakeoff.wav", false, false, true);
    
	Ogre::TextureManager::getSingleton().setDefaultNumMipmaps(5);
	Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups();
    
	Ogre::TextureManager::getSingleton().setDefaultNumMipmaps(5);
	Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups();
    
	m_pTimer = OGRE_NEW Ogre::Timer();
	m_pTimer->reset();
    
	m_pRenderWnd->setActive(true);
    
	return true;
}
예제 #17
0
int Landusemap::loadConfig(Ogre::String filename)
{
	Vector3 mapsize = gEnv->terrainManager->getMaxTerrainSize();
	std::map<unsigned int, String> usemap;
	String textureFilename = "";

	LOG("Parsing landuse config: '"+filename+"'");

	String group = "";
	try
	{
		group = ResourceGroupManager::getSingleton().findGroupContainingResource(filename);
	}catch(...)
	{
		// we wont catch anything, since the path could be absolute as well, then the group is not found
	}

	Ogre::ConfigFile cfg;
	try
	{
		// try to load directly otherwise via resource group
		if (group == "")
			cfg.loadDirect(filename);
		else
			cfg.loadFromResourceSystem(filename, group, "\x09:=", true);
	} catch(Ogre::Exception& e)
	{
		ErrorUtils::ShowError(_L("Error while loading landuse config"), e.getFullDescription());
		return 1;
	}

	Ogre::ConfigFile::SectionIterator seci = cfg.getSectionIterator();
	Ogre::String secName, kname, kvalue;
	while (seci.hasMoreElements())
	{
		secName = seci.peekNextKey();
		Ogre::ConfigFile::SettingsMultiMap *settings = seci.getNext();
		Ogre::ConfigFile::SettingsMultiMap::iterator i;
		for (i = settings->begin(); i != settings->end(); ++i)
		{
			kname = i->first;
			kvalue = i->second;
			// we got all the data available now, processing now
			if (secName == "general" || secName == "config")
			{
				// set some class properties accoring to the information in this section
				if (kname == "texture")
					textureFilename = kvalue;
				else if (kname == "frictionconfig" || kname == "loadGroundModelsConfig")
					gEnv->collisions->loadGroundModelsConfigFile(kvalue);
				else if (kname == "defaultuse")
					default_ground_model = gEnv->collisions->getGroundModelByString(kvalue);

			} else if (secName == "use-map")
			{
				if (kname.size() != 10)
				{
					LOG("invalid color in landuse line in " + filename);
					continue;
				}
				char *ptr; //not used
				unsigned int color = strtoul(kname.c_str(), &ptr, 16);
				usemap[color] = kvalue;
			}
		}
	}

#ifdef USE_PAGED
	// process the config data and load the buffers finally
	try
	{
		Forests::ColorMap *colourMap = Forests::ColorMap::load(textureFilename, Forests::CHANNEL_COLOR);
		colourMap->setFilter(Forests::MAPFILTER_NONE);

		/*
		// debug things below
		printf("found ground use definitions:\n");
		for (std::map < uint32, String >::iterator it=usemap.begin(); it!=usemap.end(); it++)
		{
			printf(" 0x%Lx : %s\n", it->first, it->second.c_str());
		}
		*/

		bool bgr = colourMap->getPixelBox().format == PF_A8B8G8R8;

		Ogre::TRect<Ogre::Real> bounds = Forests::TBounds(0, 0, mapsize.x, mapsize.z);

		// now allocate the data buffer to hold pointers to ground models
		data = new ground_model_t*[(int)(mapsize.x * mapsize.z)];
		ground_model_t **ptr = data;
		//std::map < String, int > counters;
		for (int z=0; z<mapsize.z; z++)
		{
			for (int x=0; x<mapsize.x; x++)
			{
				unsigned int col = colourMap->getColorAt(x, z, bounds);
				if (bgr)
				{
					// Swap red and blue values
					unsigned int cols = col & 0xFF00FF00;
					cols |= (col & 0xFF) << 16;
					cols |= (col & 0xFF0000) >> 16;
					col = cols;
				}
				String use = usemap[col];
				//if (use!="")
				//	counters[use]++;

				// store the pointer to the ground model in the data slot
				*ptr = gEnv->collisions->getGroundModelByString(use);
				ptr++;
			}
		}
	} catch (...)
	{
		Log("Landuse: Failed to load texture: " + textureFilename);
	}	
#endif // USE_PAGED

	return 0;
}
예제 #18
0
bool OgreFramework::initOgre(OIS::KeyListener *pKeyListener, OIS::MouseListener *pMouseListener)
#endif
{
    new Ogre::LogManager();
    
	m_pLog = Ogre::LogManager::getSingleton().createLog("OgreLogfile.log", true, true, false);
	m_pLog->setDebugOutputEnabled(true);
    
    String pluginsPath;
    // only use plugins.cfg if not static
#ifndef OGRE_STATIC_LIB
    pluginsPath = m_ResourcePath + "plugins.cfg";
#endif
    m_pRoot = new Ogre::Root(pluginsPath, Ogre::macBundlePath() + "/ogre.cfg");
    
#ifdef OGRE_STATIC_LIB
    m_StaticPluginLoader.load();
#endif
    
    m_pRoot->initialise(false, "");
    
    Ogre::NameValuePairList params;
    
    params["externalWindowHandle"] = Ogre::StringConverter::toString((unsigned long)uiWindow);
    params["externalViewHandle"] = Ogre::StringConverter::toString((unsigned long)uiView);
    params["contentScalingFactor"] = Ogre::StringConverter::toString((unsigned long)getScalingFactor()); // 2 for non-retina
    
    m_pRenderWnd = m_pRoot->createRenderWindow("", width, height, false, &params);
    
    m_pSceneMgrMain = m_pRoot->createSceneManager(ST_GENERIC, "SceneManagerMain");
    m_pSceneMgrMain->setAmbientLight(Ogre::ColourValue(0.0, 0.0, 0.0));
    
    m_pCameraMain = m_pSceneMgrMain->createCamera("CameraMain");
    m_pCameraMain->setPosition(Vector3(0, 0, 50));
    m_pCameraMain->lookAt(Vector3(0, 0, 0));
    m_pCameraMain->setNearClipDistance(0.1);
    m_pCameraMain->setProjectionType(Ogre::PT_ORTHOGRAPHIC);
    m_pCameraMain->setOrthoWindow(25.0, 25.0);
    m_pViewportMain = m_pRenderWnd->addViewport(m_pCameraMain, 1,
                                                0.0,
                                                0.0,
                                                1.0,
                                                1.0);
    m_pViewportMain->setCamera(m_pCameraMain);
    
    Ogre::OverlaySystem* m_pOverlaySystem = new Ogre::OverlaySystem();
    m_pSceneMgrMain->addRenderQueueListener(m_pOverlaySystem);
    
	Ogre::String secName, typeName, archName;
	Ogre::ConfigFile cf;
    
    cf.load(m_ResourcePath + "resources.cfg");
    
    m_pResourceGroupMgr = Ogre::ResourceGroupManager::getSingletonPtr();
    m_pOverlayMgr = Ogre::OverlayManager::getSingletonPtr();
    m_pFontMgr = Ogre::FontManager::getSingletonPtr();
    m_pMeshMgr = Ogre::MeshManager::getSingletonPtr();
    m_pMaterialMgr = Ogre::MaterialManager::getSingletonPtr();
    m_pTextureMgr = Ogre::TextureManager::getSingletonPtr();
    m_pCompositeMgr = CompositorManager::getSingletonPtr();
    
	Ogre::ConfigFile::SectionIterator seci = cf.getSectionIterator();
    while (seci.hasMoreElements())
    {
        secName = seci.peekNextKey();
		Ogre::ConfigFile::SettingsMultiMap *settings = seci.getNext();
        Ogre::ConfigFile::SettingsMultiMap::iterator i;
        for (i = settings->begin(); i != settings->end(); ++i)
        {
            typeName = i->first;
            archName = i->second;
#if OGRE_PLATFORM == OGRE_PLATFORM_APPLE || defined(OGRE_IS_IOS)
            // OS X does not set the working directory relative to the app,
            // In order to make things portable on OS X we need to provide
            // the loading with it's own bundle path location
            if (!Ogre::StringUtil::startsWith(archName, "/", false)) // only adjust relative dirs
                archName = Ogre::String(m_ResourcePath + archName);
#endif
            m_pResourceGroupMgr->addResourceLocation(archName, typeName, secName);
        }
    }
    
    Ogre::ResourceGroupManager::getSingleton().initialiseResourceGroup("Bootstrap");

    m_pSoundMgr = OgreOggSound::OgreOggSoundManager::getSingletonPtr();
    m_pSoundMgr->init();
    
    m_pSoundMgr->createSound("SoundGreatFeedback", "ding3up2fast.wav", false, false, true);
    m_pSoundMgr->createSound("SoundBadFeedback", "negativebeep.wav", false, false, true);

    
	Ogre::TextureManager::getSingleton().setDefaultNumMipmaps(5);
	Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups();
    
	m_pTimer = OGRE_NEW Ogre::Timer();
	m_pTimer->reset();
    
    requestResize();
	m_pRenderWnd->setActive(true);
    
	return true;
}
예제 #19
0
bool OgreFramework::initOgre(OIS::KeyListener *pKeyListener, OIS::MouseListener *pMouseListener)
#endif
{
    new Ogre::LogManager();
    
	m_pLog = Ogre::LogManager::getSingleton().createLog("OgreLogfile.log", true, true, false);
	m_pLog->setDebugOutputEnabled(true);
    
    String pluginsPath;
    // only use plugins.cfg if not static
#ifndef OGRE_STATIC_LIB
    pluginsPath = m_ResourcePath + "plugins.cfg";
#endif
    m_pRoot = new Ogre::Root(pluginsPath, Ogre::macBundlePath() + "/ogre.cfg");
    
    // OgreOggSound is still a dynamic library (dylib)
    // OgreOggSound::OgreOggSoundPlugin* mOgreOggSoundPlugin = OGRE_NEW OgreOggSound::OgreOggSoundPlugin();
    // m_pRoot->installPlugin(mOgreOggSoundPlugin);
#ifdef OGRE_STATIC_LIB
    m_StaticPluginLoader.load();
#endif

    if(m_pRoot->restoreConfig() || m_pRoot->showConfigDialog())
        m_pRenderWnd = m_pRoot->initialise(true, "");
    else
        return false;
    //m_pRenderWnd->resize(800, 600);
    //m_pRenderWnd->setFullscreen(true, 1024, 800);
    globals.screenWidth = m_pRenderWnd->getWidth();
    globals.screenHeight = m_pRenderWnd->getHeight();
    globals.set();
    
	m_pSceneMgrMain = m_pRoot->createSceneManager(ST_GENERIC, "SceneManagerMain");
    m_pSceneMgrMain->setAmbientLight(Ogre::ColourValue(0.5, 0.5, 0.5));
    
	m_pCameraMain = m_pSceneMgrMain->createCamera("CameraMain");
	m_pCameraMain->setPosition(Vector3(0, 0, 50));
	m_pCameraMain->lookAt(Vector3(0, 0, 0));
	m_pCameraMain->setNearClipDistance(0.1);
	m_pViewportMain = m_pRenderWnd->addViewport(m_pCameraMain);
	m_pViewportMain->setCamera(m_pCameraMain);
    
    Ogre::OverlaySystem* m_pOverlaySystem = new Ogre::OverlaySystem();
    m_pSceneMgrMain->addRenderQueueListener(m_pOverlaySystem);
    
	unsigned long hWnd = 0;
    OIS::ParamList paramList;
    m_pRenderWnd->getCustomAttribute("WINDOW", &hWnd);
    
	paramList.insert(OIS::ParamList::value_type("WINDOW", Ogre::StringConverter::toString(hWnd)));
    
	m_pInputMgr = OIS::InputManager::createInputSystem(paramList);
    
#if !defined(OGRE_IS_IOS)
    m_pKeyboard = static_cast<OIS::Keyboard*>(m_pInputMgr->createInputObject(OIS::OISKeyboard, true));
	m_pMouse = static_cast<OIS::Mouse*>(m_pInputMgr->createInputObject(OIS::OISMouse, true));
    
	m_pMouse->getMouseState().height = m_pRenderWnd->getHeight();
	m_pMouse->getMouseState().width	 = m_pRenderWnd->getWidth();
    
	if(pKeyListener == 0)
		m_pKeyboard->setEventCallback(this);
	else
		m_pKeyboard->setEventCallback(pKeyListener);
    
	if(pMouseListener == 0)
		m_pMouse->setEventCallback(this);
	else
		m_pMouse->setEventCallback(pMouseListener);
#endif
    
    
	Ogre::String secName, typeName, archName;
	Ogre::ConfigFile cf;
    
    cf.load(m_ResourcePath + "resources.cfg");
    
    m_pResourceGroupMgr = Ogre::ResourceGroupManager::getSingletonPtr();
    m_pOverlayMgr = Ogre::OverlayManager::getSingletonPtr();
    m_pFontMgr = Ogre::FontManager::getSingletonPtr();
    m_pMeshMgr = Ogre::MeshManager::getSingletonPtr();
    m_pMaterialMgr = Ogre::MaterialManager::getSingletonPtr();
    m_pTextureMgr = Ogre::TextureManager::getSingletonPtr();
    m_pCompositeMgr = CompositorManager::getSingletonPtr();
    
	Ogre::ConfigFile::SectionIterator seci = cf.getSectionIterator();
    while (seci.hasMoreElements())
    {
        secName = seci.peekNextKey();
		Ogre::ConfigFile::SettingsMultiMap *settings = seci.getNext();
        Ogre::ConfigFile::SettingsMultiMap::iterator i;
        for (i = settings->begin(); i != settings->end(); ++i)
        {
            typeName = i->first;
            archName = i->second;
#if OGRE_PLATFORM == OGRE_PLATFORM_APPLE || defined(OGRE_IS_IOS)
            // OS X does not set the working directory relative to the app,
            // In order to make things portable on OS X we need to provide
            // the loading with it's own bundle path location
            if (!Ogre::StringUtil::startsWith(archName, "/", false)) // only adjust relative dirs
                archName = Ogre::String(m_ResourcePath + archName);
#endif
            m_pResourceGroupMgr->addResourceLocation(archName, typeName, secName);
        }
    }
    
    Ogre::ResourceGroupManager::getSingleton().initialiseResourceGroup("Bootstrap");

    m_pSoundMgr = OgreOggSound::OgreOggSoundManager::getSingletonPtr();
    m_pSoundMgr->init();
    
    m_pSoundMgr->createSound("SoundGreatFeedback", "ding3up3.wav", false, false, true);
    m_pSoundMgr->createSound("SoundGoodFeedback", "energyup.wav", false, false, true);
    m_pSoundMgr->createSound("SoundBadFeedback", "wrongtriangle.wav", false, false, true);
    m_pSoundMgr->createSound("SoundMissFeedback", "misstriangle.wav", false, false, true);
    m_pSoundMgr->createSound("SoundCollision", "laser.wav", false, false, true);
    m_pSoundMgr->createSound("SoundStartup", "shipstartup.wav", false, false, true);
    m_pSoundMgr->createSound("SoundBoost", "ExhaustSound.wav", false, true, true);
    m_pSoundMgr->createSound("SoundButtonPress", "menuButton.wav", false, false, true);
    m_pSoundMgr->createSound("SoundFirework", "distantboom.wav", false, false, true);
    m_pSoundMgr->createSound("SoundDing", "positiveding.wav", false, false, true);
    
    m_pSoundMgr->createSound("GateOpen", "gateopen.wav", false, false, true);
    m_pSoundMgr->createSound("GateClose", "gateclose.wav", false, false, true);
    
    m_pSoundMgr->createSound("LevelFail", "down.wav", false, false, true);
    m_pSoundMgr->createSound("LevelPass", "LevelPass.wav", false, false, true);
    
	Ogre::TextureManager::getSingleton().setDefaultNumMipmaps(5);
	Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups();
    
	m_pTimer = OGRE_NEW Ogre::Timer();
	m_pTimer->reset();
    
    OgreBites::InputContext inputContext;
    inputContext.mMouse = m_pMouse;
    inputContext.mKeyboard = m_pKeyboard;
    m_pTrayMgr = new OgreBites::SdkTrayManager("TrayMgr", m_pRenderWnd, inputContext, this);
    //m_pTrayMgr->showFrameStats(OgreBites::TL_BOTTOMLEFT);
    //m_pTrayMgr->showLogo(OgreBites::TL_BOTTOMRIGHT);
    //m_pTrayMgr->hideCursor();
    
	m_pRenderWnd->setActive(true);
    
	return true;
}
예제 #20
0
//-----------------------------------------------------------------------
void WarModeTwo::initEmemyFormat()
{

	Ogre::DataStreamPtr pDataStream=Ogre::ResourceGroupManager::getSingleton().openResource("EnemyFormatMode2.cfg","General");


	if(pDataStream.isNull())
	{
		OGRE_EXCEPT(0,"can't find warmode1 enemyFormat file","WarModeOne::initEmemyFormat()");
	}



	m_EnemyFormatCollect.clear();


	Ogre::ConfigFile cf;
    
	cf.load(pDataStream);



	///循环取出所有的队列和位置信息
	Ogre::ConfigFile::SectionIterator seci = cf.getSectionIterator();
	Ogre::String sec, type, arch;

	//获取所有阵型
	while (seci.hasMoreElements())
	{
		sec = seci.peekNextKey();

		Ogre::ConfigFile::SettingsMultiMap* settings = seci.getNext();
		Ogre::ConfigFile::SettingsMultiMap::iterator i;
		if(settings->empty())
			continue;

		if(sec.find("Format")!=Ogre::String::npos)
		{
			EnemyFormat enemyFormat;
			m_EnemyFormatCollect.push_back(enemyFormat);

		}
	
		for (i = settings->begin(); i != settings->end(); i++)
		{
			type = i->first;
			arch = i->second;


			///如果是设置范围大小的
			if(sec=="Enemylimits")
			{
				if(type=="Minx")
				{
					m_Minx=Ogre::StringConverter::parseReal(arch);
				}else if(type=="Maxx")
				{
					m_Maxx=Ogre::StringConverter::parseReal(arch);
				}else if(type=="Miny")
				{
					m_Miny=Ogre::StringConverter::parseReal(arch);
				}else if(type=="Maxy")
				{
					m_Maxy=Ogre::StringConverter::parseReal(arch);
				}else if(type=="Minz")
				{
					m_Minz=Ogre::StringConverter::parseReal(arch);
				}else if(type=="Maxz")
				{
					m_Maxz=Ogre::StringConverter::parseReal(arch);
				}else if(type=="LeftTime")
				{
					m_EnemyLeftTime=Ogre::StringConverter::parseReal(arch);
				}



			}else
			{


				Ogre::Vector3 Pos=Ogre::StringConverter::parseVector3(arch);
				if(type=="Enemy")
				{	
					m_EnemyFormatCollect.back().m_EnemyCollect.push_back(Pos);
				}else if(type=="Friend")
				{
					m_EnemyFormatCollect.back().m_FriendCollect.push_back(Pos);
				}

			}
		}


	}





	return ;

}
예제 #21
0
CEngine::CEngine(void)
	: m_Root(NULL)
{
	TCHAR szPath[MAX_PATH];

	CString ApplicationName = "SceneEditor.exe";

	GetModuleFileName(NULL, szPath, MAX_PATH);
    Ogre::ConfigFile OgreConfigFile;
	CString ApplicationPath(szPath);

	ApplicationPath = ApplicationPath.Left(ApplicationPath.GetLength() - ApplicationName.GetLength());

	m_Root = new Ogre::Root("", "", Ogre::String(ApplicationPath + "SceneEditor.log")); 

	OgreConfigFile.load(Ogre::String(ApplicationPath + "ogre.cfg"), "\t:=", false);

	Ogre::String RenderSystemName;
	RenderSystemName = OgreConfigFile.getSetting("Render System");

		if (RenderSystemName == "Direct3D9 Rendering Subsystem")
		{
#ifdef _DEBUG
			m_Root->loadPlugin("RenderSystem_Direct3D9_d");
#else
		    m_Root->loadPlugin("RenderSystem_Direct3D9");
#endif
		}
		else			
		if(RenderSystemName == "OpenGL Rendering Subsystem")
		{
#ifdef _DEBUG
			m_Root->loadPlugin("RenderSystem_GL_d");
#else
		    m_Root->loadPlugin("RenderSystem_GL");
#endif
		}
		else
		{
#ifdef _DEBUG		 
			m_Root->loadPlugin("RenderSystem_Direct3D9_d");
#else
			m_Root->loadPlugin("RenderSystem_Direct3D9");
#endif
		}

#ifdef _DEBUG
		m_Root->loadPlugin("Plugin_ParticleFX_d");
#else
        m_Root->loadPlugin("Plugin_ParticleFX");
#endif

		Ogre::RenderSystemList RendersList = m_Root->getAvailableRenderers();
		m_Root->setRenderSystem(RendersList[0]);

    //
    // Initialize the system, but don't create a render window.
    //

		// Load resource paths from config file
        Ogre::ConfigFile cf;
		Ogre::String ResourcePath = ApplicationPath + "resources_d.cfg";
        cf.load(ResourcePath);

        // Go through all sections & settings in the file
        Ogre::ConfigFile::SectionIterator seci = cf.getSectionIterator();

        Ogre::String secName, typeName, archName;

		while (seci.hasMoreElements())
        {
            secName = seci.peekNextKey();
            Ogre::ConfigFile::SettingsMultiMap *settings = seci.getNext();
            Ogre::ConfigFile::SettingsMultiMap::iterator i;

			for (i = settings->begin(); i != settings->end(); ++i)
            {
                typeName = i->first;
                archName = i->second;
				archName = Ogre::String(ApplicationPath) + archName;
                Ogre::ResourceGroupManager::getSingleton().addResourceLocation(archName, typeName, secName);
            }
        }

    m_Root->initialise(false);
}
예제 #22
0
파일: WebUIApp.cpp 프로젝트: vizcount/work
//-------------------------------------------------------------------------------------
void WebUIApp::go(void)
{
    mResourcesCfg = "resources.cfg";

#ifdef _DEBUG
    mPluginsCfg = "plugins_d.cfg";
#else
    mPluginsCfg = "plugins.cfg";
#endif

    // construct Ogre::Root
    mRoot = OGRE_NEW Ogre::Root(mPluginsCfg);

    mWebPanelFactory = OGRE_NEW WebPanelOverlayElementFactory();
    Ogre::OverlayManager::getSingleton().addOverlayElementFactory(mWebPanelFactory);

    //-------------------------------------------------------------------------------------
    // setup resources
    // Load resource paths from config file
    Ogre::ConfigFile cf;
    cf.load(mResourcesCfg);
 
    // Go through all sections & settings in the file
    Ogre::ConfigFile::SectionIterator seci = cf.getSectionIterator();
 
    Ogre::String secName, typeName, archName;
    while (seci.hasMoreElements())
    {
        secName = seci.peekNextKey();
        Ogre::ConfigFile::SettingsMultiMap *settings = seci.getNext();
        Ogre::ConfigFile::SettingsMultiMap::iterator i;
        for (i = settings->begin(); i != settings->end(); ++i)
        {
            typeName = i->first;
            archName = i->second;
            Ogre::ResourceGroupManager::getSingleton().addResourceLocation(
                archName, typeName, secName, true);
        }
    }

    //-------------------------------------------------------------------------------------
    // configure
    // Show the configuration dialog and initialise the system
    // You can skip this and use root.restoreConfig() to load configuration
    // settings if you were sure there are valid ones saved in ogre.cfg
    if(mRoot->showConfigDialog())
    {
        ///WebKit does not support single-precision float
        Ogre::ConfigOptionMap& options = mRoot->getRenderSystem()->getConfigOptions();
        options["Floating-point mode"].currentValue = "Consistent";

        int w = atoi(options["Video Mode"].currentValue.c_str());
        if (w < 1024)
        {
            if (strchr(options["Video Mode"].currentValue.c_str(), '@'))
                options["Video Mode"].currentValue = "1024 x 768 @ 32-bit colour";
            else
                options["Video Mode"].currentValue = "1024 x 768";
        }
        
        // If returned true, user clicked OK so initialise
        // Here we choose to let the system create a default rendering window by passing 'true'
        mWindow = mRoot->initialise(true, "OgreWebKit");
        if (!mRoot)
            return;
    }
    else
    {
        return;
    }
    //-------------------------------------------------------------------------------------
    // choose scenemanager
    // Get the SceneManager, in this case a generic one
    mSceneMgr = mRoot->createSceneManager(Ogre::ST_GENERIC);
    //-------------------------------------------------------------------------------------
    // create camera
    // Create the camera
    mCamera = mSceneMgr->createCamera("PlayerCam");
    
    // Position it at 500 in Z direction
    mCamera->setPosition(Ogre::Vector3(0,0,80));
    // Look back along -Z
    mCamera->lookAt(Ogre::Vector3(0,0,-300));
    mCamera->setNearClipDistance(5);

    mCameraMan = new OgreBites::SdkCameraMan(mCamera);
    //-------------------------------------------------------------------------------------
    // create viewports
    // Create one viewport, entire window
    Ogre::Viewport* vp = mWindow->addViewport(mCamera);
    vp->setBackgroundColour(Ogre::ColourValue(0,0,0));
 
    // Alter the camera aspect ratio to match the viewport
    mCamera->setAspectRatio(
        Ogre::Real(vp->getActualWidth()) / Ogre::Real(vp->getActualHeight()));
    //-------------------------------------------------------------------------------------
    // Set default mipmap level (NB some APIs ignore this)
    Ogre::TextureManager::getSingleton().setDefaultNumMipmaps(5);
    //-------------------------------------------------------------------------------------
    // load resources
    Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups();

    mSceneMgr->setSkyBox(true, "Examples/EveningSkyBox");

    // dim orange ambient and two bright orange lights to match the skybox
    mSceneMgr->setAmbientLight(Ogre::ColourValue(0.3f, 0.2f, 0));
    Ogre::Light* light = mSceneMgr->createLight();
    light->setPosition(2000, 1000, -1000);
    light->setDiffuseColour(1, 0.5f, 0);
    light = mSceneMgr->createLight();
    light->setPosition(-2000, 1000, 1000);
    light->setDiffuseColour(1, 0.5, 0);

    mPivot = mSceneMgr->getRootSceneNode()->createChildSceneNode();  // create a pivot node

    // create a child node and attach an ogre head and some smoke to it
    Ogre::SceneNode* headNode = mPivot->createChildSceneNode(Ogre::Vector3(100, 0, 0));
    headNode->attachObject(mSceneMgr->createEntity("Head", "ogrehead.mesh"));
    headNode->attachObject(mSceneMgr->createParticleSystem("Smoke", "Examples/Smoke"));

    mCamera->setPosition(0, 30, 350);

    //-------------------------------------------------------------------------------------
    //create FrameListener
    Ogre::LogManager::getSingletonPtr()->logMessage("*** Initializing OIS ***");
    OIS::ParamList pl;
    size_t windowHnd = 0;
    std::ostringstream windowHndStr;
 
    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 ));

    mMouse->setEventCallback(this);
    mKeyboard->setEventCallback(this);

    //Register as a Window listener
    Ogre::WindowEventUtilities::addWindowEventListener(mWindow, this);

    mWebBrowser = getWebBrowser();
    mWebBrowser->show();

    mAddressBar = getAddressBar();
    mAddressBar->loadFile("html/addressbar.html");
    
    mWebView = getWebView();
    mWebView->setWebTransparent(true);
    mWebView->loadFile("html/mac-osx-lion.html");

    clientHandler.onTitleChanged = onTitleChanged;
    clientHandler.onURLChanged = onURLChanged;
    mWebView->setClientHandler(&clientHandler);

    //Set initial mouse clipping size
    windowResized(mWindow);

    mRoot->addFrameListener(this);
    mRoot->startRendering();
}
예제 #23
0
파일: OgreSetup.cpp 프로젝트: Tombana/NNYv3
// This function will set up everything required by Ogre
// and it will ask the user for display settings
// At the end of this function Ogre is ready to render.
// This function is mostly taken from tutorials and sample programs.
int CUIMain::SetupOgre(void)
{
	//=================
	//Ogre defaultly logs to console
	// To prevent this the LogManager has to be created
	// before the Root object.
	//=================
	Ogre::LogManager* logMgr = OGRE_NEW Ogre::LogManager;
	logMgr->createLog("Ogre.log", true, false, false);

	//=================
	//Create the Ogre root object
	// It's possible to specify as parameters the paths to the:
	// plugin file (what render systems it has to load), config file (screen resolution etc) and log file
	//=================
	if( !mRoot ) mRoot = OGRE_NEW Ogre::Root();

	//=================
	// Tell Ogre where all the needed resources are (rendersystems and so on)
	//=================
	Ogre::ConfigFile cf;
	cf.load("resources.cfg");
	
	Ogre::String secName, typeName, archName;
	Ogre::ConfigFile::SectionIterator seci = cf.getSectionIterator();
	while (seci.hasMoreElements()){
		secName = seci.peekNextKey();
		Ogre::ConfigFile::SettingsMultiMap *settings = seci.getNext();
		Ogre::ConfigFile::SettingsMultiMap::iterator i;
		
		for (i = settings->begin(); i != settings->end(); ++i)
		{
			typeName = i->first;
			archName = i->second;
			Ogre::ResourceGroupManager::getSingleton().addResourceLocation(archName, typeName, secName);
		}
	}

	//=================
	// Set up the render system.
	// Ogre will ask the user for display settings
	//=================
	if( !mRoot->showConfigDialog() )
		return 0; //The user probably clicked cancel

	mWindow = mRoot->initialise(true, "NNYv3");

	//=================
	// Load all the resources. For now, just load all resources at once. The following is from a tutorial:
	// In a very large game or application, we may have hundreds or even thousands of resources
	// that our game uses - everything from meshes to textures to scripts. At any given time though,
	// we probably will only be using a small subset of these resources. To keep down memory requirements,
	// we can load only the resources that our application is using. We do this by dividing the resources
	// into sections and only initializing them as we go. 
	//=================
	Ogre::TextureManager::getSingleton().setDefaultNumMipmaps(5);
	Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups();

	//=================
	// Preparing the scene
	//=================
	mSceneMgr = mRoot->createSceneManager(Ogre::ST_EXTERIOR_CLOSE); //ST_EXTERIOR_CLOSE allows rendering terrain

	mCamera.Initialize(mSceneMgr);

	Ogre::Viewport* vp = mWindow->addViewport(mCamera.GetCamera());
	vp->setBackgroundColour(Ogre::ColourValue(0.9,0.9,0.9));
	//Fog will not work with sky ;)
	//mSceneMgr->setFog(Ogre::FOG_LINEAR, Ogre::ColourValue(0.9,0.9,0.9), 0.0, 50, 500);

	mCamera.GetCamera()->setAspectRatio(Ogre::Real(vp->getActualWidth()) / Ogre::Real(vp->getActualHeight()));
	
	//Set a moving cloud texture as background
	mSceneMgr->setSkyDome(true, "CloudySky", 5, 8);

	//Get a RaySceneQuery object. A SceneQuery object is a class that can query all
	//objects in a region or scene. RaySceneQuery has it as a base class. RaySceneQuery
	//can get all objects that intersect a ray.
	mQueryMouseMovement = mSceneMgr->createRayQuery(Ogre::Ray(), QUERY_MASK_MOUSE_MOVEMENT);
	mQueryMouseSelection = mSceneMgr->createRayQuery(Ogre::Ray(), QUERY_MASK_MOUSE_SELECTING);

	LoadWorld();

	//=================
	// Set up the CEGUI system
	//=================
	mGUIHandler = new CGUIHandler(mWindow, mSceneMgr);

	//=================
	// Create the input handler
	//=================
	mInputHandler = new CInputHandler(mWorld, mCamera, mWindow, mSceneMgr);
	mRoot->addFrameListener(mInputHandler);
	mRoot->addFrameListener(this);

	//=================
	// Create the console overlay
	//=================
	mConsoleOverlay = new ConsoleOverlay();

	return 1;
}
예제 #24
0
bool OgreFramework::initOgre(Ogre::String wndTitle, HWND hwnd)
{
    if (!hwnd)
    {
        return false;
    }

    _hWnd = hwnd;

#if _DEBUG
    m_pRoot = new Ogre::Root("plugins_d.cfg", "Ogre.cfg");
#else
    m_pRoot = new Ogre::Root("plugins.cfg", "Ogre.cfg");
#endif

//#if _DEBUG
//
//	m_pRoot->loadPlugin("RenderSystem_Direct3D9_d");
//	m_pRoot->loadPlugin("Plugin_ParticleFX_d");
//	//m_pRoot->loadPlugin("Plugin_CgProgramManager_d");
//
//#else
//
//	m_pRoot->loadPlugin("RenderSystem_Direct3D9");
//	m_pRoot->loadPlugin("Plugin_ParticleFX");
//	//m_pRoot->loadPlugin("Plugin_CgProgramManager");
//
//#endif

    if (!m_pRoot->restoreConfig())
    {
        //m_pRoot->showConfigDialog();

        RenderSystemList rList = m_pRoot->getAvailableRenderers();
        if (rList.size() == 0)
            return false;

        m_pRoot->setRenderSystem( *(rList.begin()) );

        try
        {
            m_pRoot->saveConfig();	//crash on windows vista or above if no administrator right
        }
        catch (...)
        {

        }
    }

    m_pRenderWnd = m_pRoot->initialise(false, wndTitle);

    Ogre::ConfigOptionMap	optionMap = m_pRoot->getRenderSystem()->getConfigOptions();
    if (optionMap.find("FSAA") != optionMap.end())
    {
        _strFSAA = optionMap["FSAA"].currentValue;
    }

    NameValuePairList opts;
    opts["externalWindowHandle"] = StringConverter::toString((Ogre::uint)_hWnd);
    //opts["vsync"]	= "true";
    opts["FSAA"]	= _strFSAA;

    m_pRenderWnd = m_pRoot->createRenderWindow(
                       wndTitle,
                       800, 600,
                       false, &opts
                   );


    m_pSceneMgr = m_pRoot->createSceneManager(ST_GENERIC, "SceneManager");
    m_pSceneMgr->setAmbientLight(Ogre::ColourValue(0.7f, 0.7f, 0.7f));


    m_pCamera = m_pSceneMgr->createCamera("Camera");
    m_pCamera->setPosition(Vector3(0, 120, 120));
    m_pCamera->lookAt(Vector3(0, 0, 0));
    m_pCamera->setNearClipDistance(1);

    _pCameraController = new CameraController(m_pCamera);


    m_pViewport = m_pRenderWnd->addViewport(m_pCamera);
    m_pViewport->setBackgroundColour(ColourValue(0.0f, 0.0f, 0.0f, 1.0f));
    m_pCamera->setAspectRatio(Real(m_pViewport->getActualWidth()) / Real(m_pViewport->getActualHeight()));
    m_pViewport->setCamera(m_pCamera);


    OIS::ParamList paramList;
    unsigned long hWnd = (unsigned long)AfxGetMainWnd()->GetSafeHwnd();
    //m_pRenderWnd->getCustomAttribute("WINDOW", &hWnd);
    paramList.insert(OIS::ParamList::value_type("WINDOW", Ogre::StringConverter::toString(hWnd)));
    paramList.insert(OIS::ParamList::value_type("w32_mouse", "DISCL_FOREGROUND"));
    paramList.insert(OIS::ParamList::value_type("w32_mouse", "DISCL_NONEXCLUSIVE"));
    paramList.insert(OIS::ParamList::value_type("w32_keyboard", "DISCL_FOREGROUND"));
    paramList.insert(OIS::ParamList::value_type("w32_keyboard", "DISCL_NONEXCLUSIVE"));
    m_pInputMgr = OIS::InputManager::createInputSystem(paramList);


    m_pKeyboard = static_cast<OIS::Keyboard*>(m_pInputMgr->createInputObject(OIS::OISKeyboard, true));
    m_pKeyboard->setEventCallback(this);

    m_pMouse	= static_cast<OIS::Mouse*>(m_pInputMgr->createInputObject(OIS::OISMouse, true));
    m_pMouse->setEventCallback(this);

    m_pMouse->getMouseState().height = m_pRenderWnd->getHeight();
    m_pMouse->getMouseState().width	 = m_pRenderWnd->getWidth();

    Ogre::String secName, typeName, archName;
    Ogre::ConfigFile cf;
    cf.load("resources.cfg");

    Ogre::ConfigFile::SectionIterator seci = cf.getSectionIterator();
    while (seci.hasMoreElements())
    {
        secName = seci.peekNextKey();
        Ogre::ConfigFile::SettingsMultiMap *settings = seci.getNext();
        Ogre::ConfigFile::SettingsMultiMap::iterator i;
        for (i = settings->begin(); i != settings->end(); ++i)
        {
            typeName = i->first;
            archName = i->second;
            Ogre::ResourceGroupManager::getSingleton().addResourceLocation(archName, typeName, secName);
        }
    }
    Ogre::TextureManager::getSingleton().setDefaultNumMipmaps(5);
    Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups();

    m_pTimer = new Ogre::Timer();
    m_pTimer->reset();

    m_pTrayMgr = new OgreBites::SdkTrayManager("TrayMgr", m_pRenderWnd, m_pMouse, this);
    //m_pTrayMgr->showFrameStats(OgreBites::TL_BOTTOMLEFT);
    //m_pTrayMgr->showLogo(OgreBites::TL_BOTTOMRIGHT);
    m_pTrayMgr->hideCursor();

    m_pRenderWnd->setActive(true);


    /*
    BaseProperty *pProp = GetClassRTTI()->GetPropertyByName("FSAA");
    Ogre::ConfigOptionMap	optionMap = m_pRoot->getRenderSystem()->getConfigOptions();
    Ogre::StringVector		fsaaVector = optionMap["FSAA"].possibleValues;
    Ogre::String			strOpts;
    for (size_t t = 0; t < fsaaVector.size(); ++t)
    {
    	strOpts += fsaaVector[t];

    	if (t != fsaaVector.size() - 1)
    	{
    		strOpts += ";";
    	}
    }
    pProp->SetValueSpecify(eValueList, strOpts);
    */


    return true;
}
예제 #25
0
bool
AppDemarrage::start(const Ogre::String& pluginFile, const Ogre::String& ogreFile,
                         const Ogre::String& logFile, const Ogre::String& resourceFile)
{
    mRoot = OGRE_NEW Ogre::Root(pluginFile, ogreFile, logFile);
    Ogre::ConfigFile configFile;
    configFile.load(resourceFile);

    Ogre::ConfigFile::SectionIterator seci = configFile.getSectionIterator();
    Ogre::String secName, typeName, archName;
    while (seci.hasMoreElements())
    {
        secName = seci.peekNextKey();


            Ogre::ConfigFile::SettingsMultiMap *settings = seci.getNext();
            Ogre::ConfigFile::SettingsMultiMap::iterator i;
            for (i = settings->begin(); i != settings->end(); ++i)
            {
                typeName = i->first;
                archName = i->second;

                if(secName == "TileResourceID")
                {
                    resourceIdMapper[Ogre::StringConverter::parseInt(typeName)] = archName;
                }else
                {
                    Ogre::ResourceGroupManager::getSingleton().addResourceLocation(
                    archName, typeName, secName);
                }

            }

    }

    //if(!(mRoot->restoreConfig() || mRoot->showConfigDialog()))
    if(!mRoot->showConfigDialog())
    {
        return false;
    }

    mWindow = mRoot->initialise(true, APP_WIN_NAME);

    Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups();

    mSceneMgr = mRoot->createSceneManager("DefaultSceneManager", "Mon Scene Manager");
    mSceneMgr->setAmbientLight(Ogre::ColourValue(0.0f, 0.0f, 0.0f));
    mSceneMgr->setShadowTechnique(Ogre::SHADOWTYPE_STENCIL_ADDITIVE);


//    Ogre::Light* pointLight = mSceneMgr->createLight("pointLight");
//    pointLight->setType(Ogre::Light::LT_POINT);
//    pointLight->setPosition(Ogre::Vector3(10*1.5f, 1*1.5f, 10*1.5f));
//    pointLight->setDiffuseColour(0.7, 0.7, 0.7);
//    pointLight->setSpecularColour(0.7, 0.7, 0.7);

    mCamera = mSceneMgr->createCamera(APP_MAIN_CAM_NAME);
    #define MYTILESIZE 1.5f
    mCamera->setPosition(5*MYTILESIZE,8,10*MYTILESIZE);
    //mCamera->setDirection(Ogre::Vector3::)
    //mCamera->setOrientation();
    mCamera->lookAt(5*MYTILESIZE,0,10*MYTILESIZE);
    mCamera->setDirection(0,0,0);

    mCamera->setProjectionType(Ogre::PT_ORTHOGRAPHIC);
    mCamera->setNearClipDistance(0.5);
    mCamera->setFarClipDistance(15);

    mCamera->setOrthoWindow(20 * MYTILESIZE, 20 * MYTILESIZE / 2.7f);


    //mCamera->setOrthoWindow(15.f, 6.f);//50 * 20

    Ogre::Viewport* vp = mWindow->addViewport(mCamera);
    vp->setBackgroundColour(Ogre::ColourValue(0,0,0));



    //mCamera->setAspectRatio(Ogre::Real(vp->getActualWidth()) / Ogre::Real(vp->getActualHeight()));
    //mCamera->setAspectRatio(Ogre::Real(vp->getActualWidth()) / Ogre::Real(vp->getActualHeight()));

    std::cout << "vp->getActualWidth(): " << vp->getActualWidth() << "\n";
    std::cout << "vp->getActualHeight(): " << vp->getActualHeight() << std::endl;
    //mCamera->setOrthoWindow(Ogre::Real(vp->getActualWidth()), Ogre::Real(vp->getActualHeight()));

    //mCamera->setPolygonMode(Ogre::PM_WIREFRAME);

    //m_battleground = new Battleground("plop", mSceneMgr, &resourceIdMapper);
    //m_battleground->load("battlegnd.png");

    //m_battleground Battleground(const xml_node &xmlBattlefieldNode, Ogre::SceneManager* mSceneMgr, std::map<int, Ogre::String>* resourceIdMapper);

    mFrameListener= new InputListener(mSceneMgr, &resourceIdMapper, m_battleground);
    mRoot->addFrameListener(mFrameListener);

    mWindow->setDeactivateOnFocusChange(false);


    while(true)
    {
        Ogre::WindowEventUtilities::messagePump();

        if(mWindow->isClosed())
        {
            return false;
        }

        if(!mRoot->renderOneFrame())
        {
            return false;
        }
    }

    return true;
}
예제 #26
0
//---------------------------------------------------------------------
bool OgreInit::startOgre(Ogre::String wndTitle, OIS::KeyListener *pKeyListener , OIS::MouseListener *pMouseListener)
{
    // Initialisation du monde virtuel utilisé par Bullet
    m_broadphase = new btDbvtBroadphase();
    m_collisionConfiguration = new btDefaultCollisionConfiguration();
    m_dispatcher = new btCollisionDispatcher(m_collisionConfiguration);
    m_solver = new btSequentialImpulseConstraintSolver;
    m_world = new btDiscreteDynamicsWorld(m_dispatcher, m_broadphase, m_solver, m_collisionConfiguration);
    m_world->setGravity(btVector3(0,-25,0));

    pLogMgr = new Ogre::LogManager();
    pLog = pLogMgr->createLog("LogFile.log", true, true, false);
    pLog->setDebugOutputEnabled(true);

    pRoot = new Ogre::Root();
    if(!pRoot->showConfigDialog()) return false;

    pRenderWnd = pRoot->initialise(true, wndTitle);
    //Initialisation du SceneManager
    pSceneMgr = pRoot->createSceneManager(ST_GENERIC, "SceneManager");
    pSceneMgr->setAmbientLight(Ogre::ColourValue(0.3f, 0.3f, 0.4f));

    //Initialisation de la camera
    pCamera=pSceneMgr->createCamera("MainCamera");
    pCamera->setPosition(Vector3(0,60,120));
    pCamera->lookAt(Vector3(0,0,0));
    pCamera->setNearClipDistance(1);
    //Initialisation du viewport
    pViewport=pRenderWnd->addViewport(pCamera);
    pViewport->setBackgroundColour(ColourValue(0.0f,0.0f,0.0f,1.0f));
    pCamera->setAspectRatio(Real(pViewport->getActualWidth()) / Real(pViewport->getActualHeight()));
    pViewport->setCamera(pCamera);
    //Initialisation de OIS
    unsigned long hwnd=0;
    OIS::ParamList paramList;
    pRenderWnd->getCustomAttribute("WINDOW",&hwnd);
    paramList.insert(OIS::ParamList::value_type("WINDOW",Ogre::StringConverter::toString(hwnd)));

    pInputMgr=OIS::InputManager::createInputSystem(paramList);
    pKeyboard=static_cast<OIS::Keyboard*>(pInputMgr->createInputObject(OIS::OISKeyboard,true));
    pMouse=static_cast<OIS::Mouse*>(pInputMgr->createInputObject(OIS::OISMouse, true));
    pMouse->getMouseState().height = pRenderWnd->getHeight();
    pMouse->getMouseState().width = pRenderWnd->getWidth();

    if(pKeyListener == 0)
        pKeyboard->setEventCallback(this);
    else
        pKeyboard->setEventCallback(pKeyListener);

    if(pMouseListener == 0)
        pMouse->setEventCallback(this);
    else
        pMouse->setEventCallback(pMouseListener);

    //Definition des ressources
    Ogre::String secName, typeName, archName;
    Ogre::ConfigFile cf;
    cf.load("resources.cfg");

    Ogre::ConfigFile::SectionIterator seci = cf.getSectionIterator();
    while (seci.hasMoreElements())
    {
        secName=seci.peekNextKey();
        Ogre::ConfigFile::SettingsMultiMap *settings = seci.getNext();
        Ogre::ConfigFile::SettingsMultiMap::iterator i;
        for(i=settings->begin(); i!=settings->end(); i++)
        {
            typeName=i->first;
            archName=i->second;
            Ogre::ResourceGroupManager::getSingleton().addResourceLocation(archName, typeName, secName);
        }
    }

    Ogre::TextureManager::getSingleton().setDefaultNumMipmaps(5);
    Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups();

    pTimer = new Ogre::Timer();
    pTimer->reset();

    pTrayMgr = new OgreBites::SdkTrayManager("InterfaceName", pRenderWnd , pMouse, this);
    pTrayMgr->hideLogo();
    pTrayMgr->hideFrameStats();
    pTrayMgr->hideCursor();

    pRenderWnd->setActive(true);
    return true;
}//startOgre
bool OgreFramework::initOgre(Ogre::String wndTitle, OIS::KeyListener *pKeyListener, OIS::MouseListener *pMouseListener)
{
	Ogre::LogManager* logMgr = new Ogre::LogManager();

	m_pLog = Ogre::LogManager::getSingleton().createLog("OgreLogfile.log", true, true, false);
	m_pLog->setDebugOutputEnabled(true);

	m_pRoot = new Ogre::Root();

	if(!m_pRoot->showConfigDialog())
		return false;
	m_pRenderWnd = m_pRoot->initialise(true, wndTitle);

	m_pViewport = m_pRenderWnd->addViewport(0);
	m_pViewport->setBackgroundColour(ColourValue(0.5f, 0.5f, 0.5f, 1.0f));
	
	m_pViewport->setCamera(0);

	size_t hWnd = 0;
	OIS::ParamList paramList;
	m_pRenderWnd->getCustomAttribute("WINDOW", &hWnd);

	paramList.insert(OIS::ParamList::value_type("WINDOW", Ogre::StringConverter::toString(hWnd)));

	m_pInputMgr = OIS::InputManager::createInputSystem(paramList);

	m_pKeyboard = static_cast<OIS::Keyboard*>(m_pInputMgr->createInputObject(OIS::OISKeyboard, true));
	m_pMouse = static_cast<OIS::Mouse*>(m_pInputMgr->createInputObject(OIS::OISMouse, true));

	m_pMouse->getMouseState().height = m_pRenderWnd->getHeight();
	m_pMouse->getMouseState().width  = m_pRenderWnd->getWidth();

	if(pKeyListener == 0)
		m_pKeyboard->setEventCallback(this);
	else
		m_pKeyboard->setEventCallback(pKeyListener);

	if(pMouseListener == 0)
		m_pMouse->setEventCallback(this);
	else
		m_pMouse->setEventCallback(pMouseListener);

	Ogre::String secName, typeName, archName;
	Ogre::ConfigFile cf;
	cf.load("resources.cfg");

	Ogre::ConfigFile::SectionIterator seci = cf.getSectionIterator();
	while (seci.hasMoreElements())
	{
		secName = seci.peekNextKey();
		Ogre::ConfigFile::SettingsMultiMap *settings = seci.getNext();
		Ogre::ConfigFile::SettingsMultiMap::iterator i;
		for (i = settings->begin(); i != settings->end(); ++i)
		{
			typeName = i->first;
			archName = i->second;
			Ogre::ResourceGroupManager::getSingleton().addResourceLocation(archName, typeName, secName);
		}
	}
	Ogre::TextureManager::getSingleton().setDefaultNumMipmaps(5);
	Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups();

	m_pTrayMgr = new OgreBites::SdkTrayManager("AOFTrayMgr", m_pRenderWnd, m_pMouse, 0);

	m_pTimer = new Ogre::Timer();
	m_pTimer->reset();

	m_pRenderWnd->setActive(true);

	return true;
}
예제 #28
0
/// <summary>
/// Inits the ogre framework.
/// 1.Instantiates the log manager class
/// 2. Creates a new Ogre root
/// 3. Creates the scene manager and set some ambient light
/// 4. Creates the camera and sets its position and clip planes
/// 5. Creates the viewport and sets the background color
/// 6. Creates the input devices
/// 7. Loads the resources
/// 8. Creates the timer
/// 9. Creates the debug overlay
/// 10. Sets the render window active
/// </summary>
/// <param name="wndTitle">The WND title.</param>
/// <param name="pKeyListener">The p key listener.</param>
/// <param name="pMouseListener">The p mouse listener.</param>
/// <returns></returns>
bool OgreFramework::initOgre(Ogre::String wndTitle, Ogre::SceneType sceneType, OIS::KeyListener *pKeyListener,  OIS::MouseListener *pMouseListener )
{
	Ogre::LogManager* logMgr = new Ogre::LogManager();
 
	m_pLog = Ogre::LogManager::getSingleton().createLog("OgreLogfile.log", true, true, false);
	m_pLog->setDebugOutputEnabled(true);
 
	m_pRoot = new Ogre::Root("plugins.cfg");
 
	if(!m_pRoot->showConfigDialog())
		return false;
	m_pRenderWnd = m_pRoot->initialise(true, wndTitle);
 
	m_pSceneMgr = m_pRoot->createSceneManager(sceneType, "SceneManager");
	
	Ogre::Vector3 lightdir(0.55, -0.3, 0.75);
    lightdir.normalise();


	m_light = m_pSceneMgr->createLight("tstLight");
    m_light->setType(Ogre::Light::LT_DIRECTIONAL);
    m_light->setDirection(lightdir);
    m_light->setDiffuseColour(Ogre::ColourValue::White);
    m_light->setSpecularColour(Ogre::ColourValue(0.4, 0.4, 0.4));
	
	
	m_pSceneMgr->setAmbientLight(Ogre::ColourValue(0.7f, 0.7f, 0.7f));

	m_cameraNode = m_pSceneMgr->getRootSceneNode()->createChildSceneNode("CameraNode");
	m_cameraNode->setPosition(Vector3(0, 60, 60));

	m_pCamera = m_pSceneMgr->createCamera("Camera");
	m_pCamera->setNearClipDistance(1);
 
	m_pViewport = m_pRenderWnd->addViewport(m_pCamera);
    m_pViewport->setBackgroundColour(Ogre::ColourValue::Blue);
 
	m_pCamera->setAspectRatio(Real(m_pViewport->getActualWidth()) / Real(m_pViewport->getActualHeight()));
 
	m_pViewport->setCamera(m_pCamera);
 
	m_cameraNode->attachObject(m_pCamera);

	size_t hWnd = 0;
	m_pRenderWnd->getCustomAttribute("WINDOW", &hWnd);
	m_pInputMgr = OIS::InputManager::createInputSystem(hWnd);

 
    m_pKeyboard = static_cast<OIS::Keyboard*>(m_pInputMgr->createInputObject(OIS::OISKeyboard, true));
	m_pMouse = static_cast<OIS::Mouse*>(m_pInputMgr->createInputObject(OIS::OISMouse, true));
 
	m_pMouse->getMouseState().height = m_pRenderWnd->getHeight();
	m_pMouse->getMouseState().width	 = m_pRenderWnd->getWidth();
 
	if(pKeyListener == 0)
		m_pKeyboard->setEventCallback(this);
	else
		m_pKeyboard->setEventCallback(pKeyListener);
 
	if(pMouseListener == 0)
		m_pMouse->setEventCallback(this);
	else
		m_pMouse->setEventCallback(pMouseListener);
 
	Ogre::String secName, typeName, archName;
	Ogre::ConfigFile cf;
    cf.load("resources.cfg");
 
	Ogre::ConfigFile::SectionIterator seci = cf.getSectionIterator();
        while (seci.hasMoreElements())
        {
            secName = seci.peekNextKey();
		Ogre::ConfigFile::SettingsMultiMap *settings = seci.getNext();
            Ogre::ConfigFile::SettingsMultiMap::iterator i;
            for (i = settings->begin(); i != settings->end(); ++i)
            {
                typeName = i->first;
                archName = i->second;
                Ogre::ResourceGroupManager::getSingleton().addResourceLocation(archName, typeName, secName);
            }
        }
	Ogre::TextureManager::getSingleton().setDefaultNumMipmaps(5);
	Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups();
 
	m_pTimer = new Ogre::Timer();
	m_pTimer->reset();
 
	OgreBites::InputContext inputContext = OgreBites::InputContext::InputContext();
	inputContext.mMouse = m_pMouse;


     /*

	m_pTrayMgr = new OgreBites::SdkTrayManager("TrayMgr", m_pRenderWnd, inputContext, this);
        m_pTrayMgr->showFrameStats(OgreBites::TL_BOTTOMLEFT);
        m_pTrayMgr->showLogo(OgreBites::TL_BOTTOMRIGHT);
        m_pTrayMgr->hideCursor();
		*/
	m_pRenderWnd->setActive(true);
 
	return true;
}
예제 #29
0
void
InitializeOgreBase( const Ogre::String& name )
{
    Ogre::LogManager* log_manager = new Ogre::LogManager();
    log_manager->createLog( "q-gears.log", true, true );
    log_manager->getDefaultLog()->setLogDetail( ( Ogre::LoggingLevel )3 );

    Ogre::String ressource_cfg("");
    Ogre::String plugins_cfg("");
    Ogre::String dyn_lib_ext("");
    Ogre::String render_system("");

#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
    dyn_lib_ext = ".dll";
#else // Assume Linux for now
    dyn_lib_ext = ".so";
#endif

#ifdef NDEBUG
    ressource_cfg = "resources.cfg";
    plugins_cfg = "plugins.cfg";
    render_system = "./RenderSystem_GL" + dyn_lib_ext;
#else
    ressource_cfg = "resources_d.cfg";
    plugins_cfg = "plugins_d.cfg";
    render_system = "./RenderSystem_GL_d" + dyn_lib_ext;
#endif

    // init root early
    root = new Ogre::Root( plugins_cfg );

    // set up resources
    // Load resource paths from config file
    Ogre::ConfigFile cf;
    cf.load( ressource_cfg );

    // Go through all sections & settings in the file
    Ogre::ConfigFile::SectionIterator seci = cf.getSectionIterator();

    Ogre::String secName, typeName, archName;
    Ogre::ResourceGroupManager &res_gm( Ogre::ResourceGroupManager::getSingleton() );
    while (seci.hasMoreElements())
    {
        secName = seci.peekNextKey();
        Ogre::ConfigFile::SettingsMultiMap *settings = seci.getNext();
        Ogre::ConfigFile::SettingsMultiMap::iterator i;
        for (i = settings->begin(); i != settings->end(); ++i)
        {
            typeName = i->first;
            archName = i->second;
            res_gm.addResourceLocation( archName, typeName, secName, true );
        }
    }

    // configure
    // Show the configuration dialog and initialise the system
    // You can skip this and use root.restoreConfig() to load configuration
    // settings if you were sure there are valid ones saved in ogre.cfg
    if( !root->restoreConfig() && !root->showConfigDialog() )
    {
        root->setRenderSystem( root->getAvailableRenderers()[ 0 ] );
    }

    root->initialise( false );
    Ogre::NameValuePairList misc;
    misc[ "title" ] = name;
    window = root->createRenderWindow( "QGearsWindow", 800, 600, false, &misc );


    // initialize resource
    Ogre::ResourceGroupManager::getSingleton().addResourceLocation( "./", "FileSystem", "General" );
    Ogre::ResourceGroupManager::getSingleton().addResourceLocation( "./exported", "FileSystem", "General" );
    Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups();

    Ogre::SceneManager* scene_manager;
    Ogre::Viewport*     viewport;

    Ogre::FontManager* fmgr = new Ogre::FontManager;
    Ogre::OverlayManager* overlay = new Ogre::OverlayManager();

    frame_listener = new DisplayFrameListener( window );
    root->addFrameListener( frame_listener );

    scene_manager = root->createSceneManager( Ogre::ST_GENERIC, "Scene" );
    scene_manager->clearScene();
    scene_manager->setAmbientLight( Ogre::ColourValue( 0.5, 0.5, 0.5 ) );
    Ogre::Light* directionalLight = scene_manager->createLight("directionalLight");
    directionalLight->setType( Ogre::Light::LT_DIRECTIONAL );
    directionalLight->setDiffuseColour( Ogre::ColourValue( 0.5, 0.5, 0.5) );
    directionalLight->setSpecularColour( Ogre::ColourValue( 0.5, 0.5, 0.5) );
    directionalLight->setDirection( Ogre::Vector3( 0, 0, -1 ) );

    camera = scene_manager->createCamera( "Camera" );
    camera->setNearClipDistance( 0.01f );
    camera->setPosition( 0, 5, 10 );
    camera->lookAt( 0, 0, 0 );

    viewport = window->addViewport( camera );
    viewport->setBackgroundColour( Ogre::ColourValue( 0.0f, 0.4f, 0.0f ) );
    camera->setAspectRatio( Ogre::Real( viewport->getActualWidth() ) / Ogre::Real( viewport->getActualHeight() ) );

    LOGGER = new Logger( "game.log" );
}
예제 #30
0
MainApplication::MainApplication()
{
    // create root node
    #ifdef _DEBUG
    rootNode = new Ogre::Root("Resources/plugins_d.cfg", "Resources/graphics_d.cfg", "log_d.txt");
    #else
    rootNode = new Ogre::Root("Resources/plugins.cfg", "Resources/graphics.cfg", "log.txt");
    #endif

    // load config file
    Ogre::ConfigFile configFile;
    #ifdef _DEBUG
    configFile.load("Resources/resources_d.cfg");
    #else
    configFile.load("Resources/resources.cfg");
    #endif

    // load resource files
    Ogre::ConfigFile::SectionIterator it = configFile.getSectionIterator();
    while(it.hasMoreElements())
    {
        Ogre::String sectionName = it.peekNextKey();
        Ogre::ConfigFile::SettingsMultiMap* settings = it.getNext();
        Ogre::ConfigFile::SettingsMultiMap::iterator i;
        for(i = settings->begin(); i != settings->end(); ++i)
        {
            Ogre::ResourceGroupManager::getSingleton().addResourceLocation(i->second, i->first, sectionName);
        }
    }

    // try to initialize window with settings from config file
    if(!(rootNode->restoreConfig()))
    {
    	throw Ogre::Exception(Ogre::Exception::ERR_INVALID_STATE, "Could not read graphics configuration", "MainApplication::go");
    }
	renderWindow = rootNode->initialise(true, "Driving Simulator - Test 5");

	// initialize resources
	Ogre::TextureManager::getSingleton().setDefaultNumMipmaps(5);
	Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups();

	// create scene manager
	sceneManager = rootNode->createSceneManager("DefaultSceneManager");

	// create camera
	camera = sceneManager->createCamera("PlayerCam");
	camera->setAutoAspectRatio(true);
	camera->setNearClipDistance(5);

	// add viewport
	Ogre::Viewport* viewPort = renderWindow->addViewport(camera);
	viewPort->setBackgroundColour(Ogre::ColourValue(0, 0, 0));

	// initialize OIS
	OIS::ParamList pList;
	size_t windowHandler = 0;
	std::ostringstream windowHandlerStr;
	renderWindow->getCustomAttribute("WINDOW", &windowHandler);
	windowHandlerStr << windowHandler;
	pList.insert(std::make_pair(std::string("WINDOW"), windowHandlerStr.str()));

	// prevent mouse pointer from disappearing under windows
	#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
	pList.insert(std::make_pair(std::string("w32_mouse"), std::string("DISCL_FOREGROUND" )));
	pList.insert(std::make_pair(std::string("w32_mouse"), std::string("DISCL_NONEXCLUSIVE")));
	pList.insert(std::make_pair(std::string("w32_keyboard"), std::string("DISCL_FOREGROUND")));
	pList.insert(std::make_pair(std::string("w32_keyboard"), std::string("DISCL_NONEXCLUSIVE")));
	#endif

	inputManager = OIS::InputManager::createInputSystem(pList);

	// create keyboard and mouse objects
	keyboard = static_cast<OIS::Keyboard*>(inputManager->createInputObject(OIS::OISKeyboard, false));
	mouse = static_cast<OIS::Mouse*>(inputManager->createInputObject(OIS::OISMouse, false));

	// initialize mouse clipping area by calling windowResized
	windowResized(renderWindow);

	// register as window event listener
	Ogre::WindowEventUtilities::addWindowEventListener(renderWindow, this);
}