[iOS] Coordinates & orientations screw up on iPad retina

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

[iOS] Coordinates & orientations screw up on iPad retina

Post by d000hg »

When you run an iPad2 app (1024x768) on a retina display, the touch coordinates are still based on the retina resolution even though the window/view report as having dimensions 1024x768. So the standard code I borrowed from the sample app and forum threads fails:

Code: Select all

OIS::MouseState ConvertMultiTouch(const OIS::MultiTouchState &in)
{
    Ogre::Viewport *vp = GET_APP().getRenderWindow().getViewport(0);
    OIS::MultiTouchState state = in;
    
    int w = vp->getActualWidth();
    int h = vp->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;
    }
    OIS::MouseState s;
    s.X = state.X;
    s.Y = state.Y;
	s.buttons = 1 << OIS::MB_Left;
    return s;
}
As a side question, why doesn't the iPad retina provide a native resolution of 2048x1536, I would have thought the physical device resolution would be used unless you specified otherwise but it seems iOS 'thinks' in 1024x768 unless you explicitly tell it not to?
User avatar
masterfalcon
OGRE Team Member
OGRE Team Member
Posts: 4270
Joined: Sun Feb 25, 2007 4:56 am
Location: Bloomington, MN
x 126
Contact:

Re: [iOS] Coordinates & orientations screw up on iPad retina

Post by masterfalcon »

You should read the retina programming guide. The window is actually 1024x768, but the backing graphics context is double that.

Also, why don't you just use the native device resolution?
d000hg
Goblin
Posts: 257
Joined: Tue Sep 02, 2008 9:41 pm
x 1

Re: [iOS] Coordinates & orientations screw up on iPad retina

Post by d000hg »

masterfalcon wrote:Also, why don't you just use the native device resolution?
I'm not sure what you mean by this, do you mean "why don't you render at 2048x1536"?


But my concern/confusion is that if I build my app for iPad non-retina and install in the simulator, and later switch the simulator to retina mode, my app doesn't work right. That seems totally contradictory with what I heard... iPad1/2 apps are supposed to work on iPad3 without any modification, the developer can choose to supply newer artwork but they don't need to. So why is my app behaving in this strange way?
User avatar
masterfalcon
OGRE Team Member
OGRE Team Member
Posts: 4270
Joined: Sun Feb 25, 2007 4:56 am
Location: Bloomington, MN
x 126
Contact:

Re: [iOS] Coordinates & orientations screw up on iPad retina

Post by masterfalcon »

That's true, and they will. The resolution that you're seeing is saved out after the first launch. Which means that you'll never have the same config on an iPad 2 and an iPad 3. The simulator however is a different situation. The save data is shared between virtual devices, which is why you're seeing that problem. To resolve it, delete the app, switch modes, then reinstall and launch it.
d000hg
Goblin
Posts: 257
Joined: Tue Sep 02, 2008 9:41 pm
x 1

Re: [iOS] Coordinates & orientations screw up on iPad retina

Post by d000hg »

When you talk about saved state do you mean the Ogre.cfg or something else, because I already stopped my app saving updated Ogre.cfg. Either way, I just totally wiped the simulator, set XCode->Edit Scheme->Options->iPad SimulatorDisplay = Retina, and did a total clean build. Still it is weird.

So I have:

Code: Select all

Render System=OpenGL ES 2.x Rendering Subsystem

[OpenGL ES 2.x Rendering Subsystem]
Content Scaling Factor=1
FSAA=0
Full Screen=Yes
RTT Preferred Mode=FBO
GLES2RenderSystem::_createRenderWindow "test", 768x1024 fullscreen miscParams: FSAA=0 contentScalingFactor=1 displayFrequency=0 Hz
iOS: Window created 768 x 1024 with backing store size 1024 x 768 using content scaling factor 1.0
The simulator (6.0) is in landscape mode so I click close to the top right and get:
touchPressed (1520,2006)
So something isn't right - am I doing something wrong based on my description?
User avatar
masterfalcon
OGRE Team Member
OGRE Team Member
Posts: 4270
Joined: Sun Feb 25, 2007 4:56 am
Location: Bloomington, MN
x 126
Contact:

Re: [iOS] Coordinates & orientations screw up on iPad retina

Post by masterfalcon »

This may be a bug in OIS. I'm not sure. You'll probably save yourself a lot of hassle by creating your own view to receive touch events and handling them yourself. There are several examples on the forums and wiki on how to do this.
d000hg
Goblin
Posts: 257
Joined: Tue Sep 02, 2008 9:41 pm
x 1

Re: [iOS] Coordinates & orientations screw up on iPad retina

Post by d000hg »

I'll double-check the source but I don't think OIS can be blamed... I'm pretty sure OIS simply registers for touch events and passes the exact data received from iOS back to my listener. When I looked last at the OIS source, it basically looked the same as all the example code about how to add your own touch event handler... because that's all OIS is doing itself!
Post Reply