In this blog I briefly explain how to use it. This guide assumes that you are using the modified BaseApplication from my git repository which I tweaked to give it an option that disables OIS. You may have set up your project according to the prerequisite guide. However, you can always use your own framework.
I don't point out every detail because I believe that you, as a seasoned programmer, can handle any easy chores entailed in this process.
- Let's add the base class constructor BaseApplication(false) to your own BaseApplication-derived class' initialization list.
The 'false' argument disables OIS. This is not in the original framework code. I added that option by myself. - Let's add a native window handle as instance(member) variable to your own BaseApplication-derived class.
We need to prevent OGRE from creating its own window and give it our own native window which we create by ourself. This variable is used to pass the handle over. Initialize this variable through a parameter of your own BaseApplication-derived class's constructor.
This variable should be of int type. - Let's override BaseApplication::configure() as following.
bool YourOwnBaseApplicationDerivedClass::configure() { mRoot->initialise( false ) ; mWindow = OgreAssistKit::CreateRenderWindowWithNative( mRoot, m_iNativeWindowHandle ) ; return true ; }
- Let's inherit the interface class OgreAssistKit::TouchListener.
Implement each of the methods in your own BaseApplication-derived class. - Let's add the native window handle as instance(member) variable to the app delegate objective-C class.
This variable should be of pointer type to class OgreAssistKit_UIWindow. I also assumes that you already have the pointer to your own BaseApplication-derived class instance in this class' @interface portion. For example,@interface YourAppDelegate : UIResponder <UIApplicationDelegate> { OgreAssistKit_UIWindow* m_oNativeWindow ; YourOwnBaseApplicationDerivedClass* m_pYourOwnBaseApplicationDerivedClassInstance ; }
-
Let's create our own native window and pass it over.
Add the following code to application:didFinishLaunchingWithOptions: method before creating your own BaseApplication-derived class instance.m_oNativeWindow = [ [OgreAssistKit_UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds ] ;
Then pass it as an argument to your own BaseApplication-derived class' constructor through reinterpret_cast while creating the instance.
After being created, it needs to be known to the native window through the interface OgreAssistKit::TouchListener as following.m_oNativeWindow->m_pTouchInput->SetListener( m_pYourOwnBaseApplicationDerivedClassInstance ) ;
- Let's sense orientation changes.
Add the next code at the end of application:didFinishLaunchingWithOptions: method.[ [NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationDidChange:) name:UIDeviceOrientationDidChangeNotification object:nil ] ; [ [UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications ] ;
Then add orientationDidChange: method into the app delegate class' @implementation portion as following.-(void) orientationDidChange:(NSNotification*)a_oNotif { UIDeviceOrientation ort = [UIDevice currentDevice].orientation ; m_oNativeWindow->m_pTouchInput->set_Orientation( OgreAssistKit::ToOgre(ort) ) ; }
- Let's clean up on termination.
In applicationWillTerminate: method, call UIDevice's [endGeneratingDeviceOrientationNotifications], NSNotificationCenter's [removeObserve:] and OgreAssistKit_UIWindow_CleanUp().
Do not forget to release the native window, either.
No comments:
Post a Comment