[iOS] Coordinates & orientations screw up on iPad retina
Posted: Tue Jan 08, 2013 6:28 pm
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:
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?
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;
}