[solved] Viewport::getOrientationMode() always returns 0

Discussion of issues specific to mobile platforms such as iOS, Android, Symbian and Meego.
d000hg
Goblin
Posts: 257
Joined: Tue Sep 02, 2008 9:41 pm
x 1

[solved] Viewport::getOrientationMode() always returns 0

Post by d000hg »

I've built 1.8.1 for iOS with orientation support enabled. But getOrientationMode() always returns 0 as I rotate the display.

I'm not doing anything with the orientation in my code, letting Ogre do whatever it does... it is rotating the rendered output and I have all 4 orientations permitted in my plist file.
Last edited by d000hg on Mon Sep 17, 2012 8:41 pm, edited 1 time in total.
d000hg
Goblin
Posts: 257
Joined: Tue Sep 02, 2008 9:41 pm
x 1

Re: Viewport::getOrientationMode() always returns 0

Post by d000hg »

Bump. I must also be misunderstanding iOS rotations because using OIS, my X/Y coords are always switched - I want to only let my app run in landscape modes. Am I supposed to explicitly TELL my viewport about the current orientation... I'd assumed Ogre was somehow doing this but thinking about it that seems unlikely.
User avatar
masterfalcon
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 4270
Joined: Sun Feb 25, 2007 4:56 am
Location: Bloomington, MN
x 126

Re: Viewport::getOrientationMode() always returns 0

Post by masterfalcon »

That was kind of a hacky way of dealing with orientation. How about just doing this?

Code: Select all

[UIDevice currentDevice].orientation
d000hg
Goblin
Posts: 257
Joined: Tue Sep 02, 2008 9:41 pm
x 1

Re: Viewport::getOrientationMode() always returns 0

Post by d000hg »

I'm not hot on OBJ-C, is that effectively a line I can put anywhere to access a sort of global var? i.e. make sure the file is compiled as obj-c and put it between #ifdefs?
User avatar
masterfalcon
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 4270
Joined: Sun Feb 25, 2007 4:56 am
Location: Bloomington, MN
x 126

Re: Viewport::getOrientationMode() always returns 0

Post by masterfalcon »

Yeah I guess so
d000hg
Goblin
Posts: 257
Joined: Tue Sep 02, 2008 9:41 pm
x 1

Re: Viewport::getOrientationMode() always returns 0

Post by d000hg »

Oh I looked around and found some samples doing this kind of thing, that was a daft question.

But whatever I try to do with orientation makes things worse. All I did was base my code off the sample app but my mouse X/Y axes are swapped and trying to fix it just screws up the render orientation.

All I want is to force it in landscape mode and make the mouse work, I don't even need to support multiple rotations!
User avatar
masterfalcon
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 4270
Joined: Sun Feb 25, 2007 4:56 am
Location: Bloomington, MN
x 126

Re: Viewport::getOrientationMode() always returns 0

Post by masterfalcon »

Then all you need to do is change what orientations are supported in your app's Info.plist. Ogre reads those values and will limit rotation events appropriately.

From the sample browser, this is what you need for the input. It assumes you're using OIS but is easily adapted for any input system.

Code: Select all

    void transformInputState(OIS::MultiTouchState &state)
    {
        int w = mWindow->getViewport(0)->getActualWidth();
        int h = mWindow->getViewport(0)->getActualHeight();
        int absX = state.X.abs;
        int absY = state.Y.abs;
        int relX = state.X.rel;
        int relY = state.Y.rel;

        UIInterfaceOrientation interfaceOrientation = [UIApplication sharedApplication].statusBarOrientation;
        switch (interfaceOrientation)
        {
            case UIInterfaceOrientationPortrait:
                break;
            case UIInterfaceOrientationLandscapeLeft:
                state.X.abs = w - absY;
                state.Y.abs = absX;
                state.X.rel = -relY;
                state.Y.rel = relX;
                break;
            case UIInterfaceOrientationPortraitUpsideDown:
                state.X.abs = w - absX;
                state.Y.abs = h - absY;
                state.X.rel = -relX;
                state.Y.rel = -relY;
                break;
            case UIInterfaceOrientationLandscapeRight:
                state.X.abs = absY;
                state.Y.abs = h - absX;
                state.X.rel = relY;
                state.Y.rel = -relX;
                break;
        }
    }
d000hg
Goblin
Posts: 257
Joined: Tue Sep 02, 2008 9:41 pm
x 1

Re: Viewport::getOrientationMode() always returns 0

Post by d000hg »

That looks far too easy :)