[SOLVED] Incorrect aspect ratio (Patch needed?)

Discussion of issues specific to mobile platforms such as iOS, Android, Symbian and Meego.
Ologon
Halfling
Posts: 70
Joined: Sun Dec 02, 2007 11:10 am
Location: Italy
x 2

[SOLVED] Incorrect aspect ratio (Patch needed?)

Post by Ologon »

I'm having a little problem with Ogre 1.8 and the iPhone. My project works in portait mode (In the XCode proj preferences, only portrait is enabled) so nothing happens when i roteate the device in landscape postion.

However when i open an UIView modal to the one created by Ogre while the device is held in landscape position (For example Game Center leaderboards or iAds full screen advertisements), Ogre automatically sets the aspect ratio to landscape (and it shouldn't) but it keeps the view orientation to portrait.

The result is that the whole scene is "streched out"! If these modal windows are opened while the device is being held in portrait position everything works fine.
I believe there's something to be fixed in the way Ogre handles the UIView.

Any hint about where is the pertinent code located and what could be causing this issue?
Last edited by Ologon on Sat Oct 27, 2012 10:39 am, edited 1 time in total.
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: [Bug?] Incorrect aspect ratio

Post by masterfalcon »

That's interesting. I'd check in the ViewController to see if it's receiving some events and making changes for some reason.
Ologon
Halfling
Posts: 70
Joined: Sun Dec 02, 2007 11:10 am
Location: Italy
x 2

Re: [Bug?] Incorrect aspect ratio

Post by Ologon »

My ViewController doesn't do anything suspicious, it just listens to touch events. My application never switches orientation and/or aspect ratio either... The most plausible cause I can think is that ogre is receiving an event informing that the device switched to landscape mode (even if it didn't), which would cause it to set the wrong aspect ratio (640/320 instead of 320/640), the orientation is kept to portrait because landscape is disable in Xcode, which causes the stretched view :/
Ologon
Halfling
Posts: 70
Joined: Sun Dec 02, 2007 11:10 am
Location: Italy
x 2

Re: [SOLVED] Incorrect aspect ratio (Patch needed?)

Post by Ologon »

Okay, I've solved this bug.

Basically what caused the issue is the "layoutSubviews" method in OgreEAGLView.mm
This method resizes the window (and adjusts the aspect ratio) but doesn't check if the rotation is actually supported before doing that. So the fix was to simply add this check to the method:

Code: Select all

    //Check if orientation is supported
    NSString *rotateToOrientation = @"";
    if(deviceOrientation == UIInterfaceOrientationPortrait)
        rotateToOrientation = @"UIInterfaceOrientationPortrait";
    else if(deviceOrientation == UIInterfaceOrientationPortraitUpsideDown)
        rotateToOrientation = @"UIInterfaceOrientationPortraitUpsideDown";
    else if(deviceOrientation == UIInterfaceOrientationLandscapeLeft)
        rotateToOrientation = @"UIInterfaceOrientationLandscapeLeft";
    else if(deviceOrientation == UIInterfaceOrientationLandscapeRight)
        rotateToOrientation = @"UIInterfaceOrientationLandscapeRight";
    
    NSArray *supportedOrientations = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"UISupportedInterfaceOrientations"];
    
    BOOL supported = [supportedOrientations containsObject:rotateToOrientation];
    
    if (!supported)
        return;
I put it right after:

Code: Select all

    // Return if the orientation is not a valid interface orientation(face up, face down)
    if(!UIDeviceOrientationIsValidInterfaceOrientation(deviceOrientation))
        return;

I don't know if a patch should be submitted for this? Btw, I'm still using Ogre 1.8.0, as 1.8.1 strangely hangs at startup sometimes.
User avatar
DanielSefton
Ogre Magi
Posts: 1235
Joined: Fri Oct 26, 2007 12:36 am
Location: Mountain View, CA
x 10

Re: [SOLVED] Incorrect aspect ratio (Patch needed?)

Post by DanielSefton »

+1 to this. I have to make that change every time I rebuild Ogre.
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: [SOLVED] Incorrect aspect ratio (Patch needed?)

Post by masterfalcon »

Don't worry about it. I'll apply it to the 1.8 branch this weekend.
User avatar
DanielSefton
Ogre Magi
Posts: 1235
Joined: Fri Oct 26, 2007 12:36 am
Location: Mountain View, CA
x 10

Re: [SOLVED] Incorrect aspect ratio (Patch needed?)

Post by DanielSefton »

Hey David, did you get chance to apply this yet? :)
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: [SOLVED] Incorrect aspect ratio (Patch needed?)

Post by masterfalcon »

I have not yet. But i'll check it out tonight.