I believe you have done through to the 6th task in the prerequisite guide for setting up the environment of XCode 4.3. This guide works through by fixing compiler errors in that environment. The 6th task has added the official Ogre Tutorial Framework files to your new project you are currently working on. There should be no include errors. If so, you have to check your include paths.
Green lines of code mean you have to add them. Struck red lines of code mean you have to remove them from the original code.
-
Let's include necessary header files.
For a start, open BaseApplication.h. Define the constant OGRE_STATIC_GLES and include the three headers: OgreStaticPluginLoader.h, OISMultiTouch.h, macUtils.h as following.#ifndef __BaseApplication_h_ #define __BaseApplication_h_ #define OGRE_STATIC_GLES 1 #include <OgreCamera.h> #include <OgreEntity.h> #include <OgreLogManager.h> #include <OgreRoot.h> #include <OgreViewport.h> #include <OgreSceneManager.h> #include <OgreRenderWindow.h> #include <OgreConfigFile.h> #include <OgreStaticPluginLoader.h> #include <OISEvents.h> #include <OISInputManager.h> #include <OISKeyboard.h>
#include <OISMouse.h>#include <OISMultiTouch.h> #include <SdkTrays.h> #include <SdkCameraMan.h> #include <macUtils.h> - Clear out the code inside the body of BaseApplication::windowResized() and remove main() in TutorialApplication.cpp.
-
Let's deal with multitouch code.
We are going to use [Find and Replace in Workspace...] in the main menu Edit-Find. Don't ignore case. Make sure you search only in this project.
- Replace OISMouse with OISMultiTouch.
- Replace MouseEvent with MultiTouchEvent.
- Replace MouseListener with MultiTouchListener.
- Change the method names mouseMoved(), mousePressed(), mouseReleased() in class BaseApplication respectively to touchMoved(), touchPressed(), touchReleased() and remove the last parameter OIS::MouseButtonID id from touchPressed(), touchReleased(). We should accordingly modify both the declarations and the implementations. The calls to injectMouseDown() and injectMouseUp() also require removal of the 'id' parameters.
-
Add touchCancelled() to class BaseApplication.
virtual bool touchCancelled( const OIS::MultiTouchEvent& evt ) { return true ; }
- Replace OIS::Mouse with OIS::MultiTouch.
- At this point in the simulator mode you get to see only link errors. If you don't like them, set up the linking libraries by doing the 7th task of the prerequisite guide. but you can keep going with this guide.
-
Let's remove the code related with the keyboard.
Comment out the variable mKeyboard in class BaseApplication and handle the entailed compiler errors by commenting them out. -
Let's revise the code of starting-up and cleaning-up.
To begin with, add the next variable to class BaseApplication.Ogre::StaticPluginLoader m_StaticPluginLoader ;
Now modify go(), setup(), the destructor of class BaseApplication as following.void BaseApplication::go(void) {
#ifdef _DEBUG mResourcesCfg = "resources_d.cfg"; mPluginsCfg = "plugins_d.cfg"; #else mResourcesCfg = "resources.cfg"; mPluginsCfg = "plugins.cfg"; #endifif (!setup()) return; mRoot->startRendering(); // clean up destroyScene(); }
bool BaseApplication::setup(void) { mResourcesCfg = Ogre::macBundlePath() + "/resources.cfg"; mPluginsCfg = "plugins.cfg"; mRoot = new Ogre::Root(mPluginsCfg); m_StaticPluginLoader.load() ; setupResources(); ...
BaseApplication::~BaseApplication(void) { if (mTrayMgr) delete mTrayMgr; if (mCameraMan) delete mCameraMan; //Remove ourself as a Window listener Ogre::WindowEventUtilities::removeWindowEventListener(mWindow, this); windowClosed(mWindow); delete mRoot; m_StaticPluginLoader.unload(); }
- Let's modify BaseApplication::setupResource()
Relative paths don't work in iOS. So we attach the bundle path as prefix to them. Don't miss the second addition 'bunPath +'
void BaseApplication::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 bunPath = Ogre::macBundlePath() + "/" ; 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 = bunPath + i->second; Ogre::ResourceGroupManager::getSingleton().addResourceLocation( archName, typeName, secName); } } }
-
Let's modify accessibility to class BaseApplication.
Make setup() and destroyScene() public and add an inline function get_Root() which allows access to Ogre's root object.... virtual ~BaseApplication(void); virtual void go(void);
protected:virtual bool setup(); virtual void destroyScene(void); Ogre::Root* get_pRoot() const { return mRoot ; } protected: virtual bool configure(void); virtual void chooseSceneManager(void); virtual void createCamera(void); virtual void createFrameListener(void); virtual void createScene(void) = 0; // Override me!virtual void destroyScene(void);virtual void createViewports(void); ... -
This is optional but this will make the camera naturally move along a touch on the screen.
Add the next line to the end of BaseApplication::createCamera() method.mCameraMan->setStyle( OgreBites::CS_ORBIT ) ;
The camera will orbit the origin point (0,0,0). Don't forget that this camera movement is really restricted. Later you can set a different style like CS_MANUAL for maximum freedom.
You forgot that the calls to injectMouseDown and injectMouseUp require the removal of the id parameter.
ReplyDeleteApart from that.... excellent. Just what I needed to get me started
You ended up figuring that out. That part was the most tangled to describe. I added your advice. Thanks.
DeletemResourcesCfg = Ogre::macBundlePath() + "/resources.cfg";
ReplyDeletemPluginsCfg = "plugins.cfg";
you made an error there.
mResourcesCfg = Ogre::macBundlePath() + "/resources.cfg";
mPluginsCfg = Ogre::macBundlePath() + "/plugins.cfg";
now I got an error that says Could not load dynamic library RenderSystem_GLES.
Also there are a couple of more errors to point out in a bit =) just to help with fixes, I found installing this and setting up for ios to be a major headache you thankfully helped me out quite a bit.