OpenGL Scene - Iphone - iphone

Question: why would an OpenGL scene render upside down in portrait mode but right-side up in landscape and visa-versa?
If I create a view matrix with UPx = 0, UPy = 0, UPz = 1 I get my viewport upside down in portrait mode and right-side up in landscape.
If I create a view matrix with UPx = 0, UPy = 0, UPz = -1 I get my viewport right-side up in portrait mode and upside down in landscape.
Should I be looking at other functions other than where I create my LookAt and Perspective matrices?

Got it - my FOVY angle was in degrees for Android - but GLKit for IOS requires radians. Dohhh.

Related

How do I rotate a AVAsset to portrait mode?

I import a video from the iPhone library and I apply some effects to that video. The problem is that the video has a wrong orientation (landscape). How can I rotate the video to portrait mode?
Have you tried a transform on the AVPlayerLayer?
self.videoLayer = [AVPlayerLayer playerLayerWithPlayer:self.videoPlayer];
self.videoLayer.transform = CATransform3DMakeRotation(M_PI / 2.0f, 0, 0, 1);

How to get coordinates of a view according to the coordinates of the uiimage on which it is placed in ios sdk?

I have an app where user takes a picture from camera and it is placed on a full screen image view. Now user can dear rectangular /square views on it and send the coordinates/size of the overlayed view to the server. The problem is i am getting the coordinates of the view according to the screen size but i want that the size should be according to the image on the imageview because normally image from the camera would be of larger resolution than the screen .
Please provide me a way to get the the size of the overlayed view according to the uiimage and not the screen
EDIT : For example :If user draw a view on a human face in the image and send the coordinates of the crop view to the server . Then it will be difficult to synchronize the coordinates with the real image if the coordinates are according to the screen and not according to the uiimage itself
The answer is simple:
You have the frame of your UIImageView, and the frame of your drew square (both relative to the self.view)
You only need to find the origin of your square, relative to the UIImageView.
Just subtract:
//get the frame of the square
CGRect *correctFrame = square.frame;
//edit square's origin
correctFrame.origin.x -= imageView.frame.origin.x;
correctFrame.origin.y -= imageView.frame.origin.y;
Now correctFrame is the frame of your square relative to the imageView, while square.frame is still relative to self.view (as we didn't change it)
To get the frame accordingly to the image resolution, do exact the same as above, then:
float xCoefficient = imageResolutionWidth / imageView.frame.size.width;
float yCoefficient = imageResolutionHeight / imageView.frame.size.height;
correctFrame.origin.x *= xCoefficient;
correctFrame.origin.y *= yCoefficient;
correctFrame.size.width *= xCoefficient;
correctFrame.size.height *= yCoefficient;
Why: the image resolution is much grater than the imageView.frame, so you gotta calculate a coefficient that will adjust your square.
That's all!

PDF-Scrollview - show PDF - document in landscape format

I'm using Apple's example «PDFScrollView» to display PDFs on an iPad. This works fine, as long as the PDF-document is in Portrait-Mode.
When the document is in Landscape-mode, though, the document is always shown rotated by 90 degrees.
I found this How to detect the orientation of a PDF document in iPhone SDK - but when I try to get the dimensions of the PDF, the height is always bigger than the width, no matter what orientation the PDF has...
Any ideas?
As mentionend in, the CGPDFPageGetBoxRect(page, kCGPDFMediaBox) always returns the same size for a PDF, no matter what orientation the PDF has.
But the rotation of the page is returned correctly.
So I get the rotation using this code:
rotate = CGPDFPageGetRotationAngle(page);
And then use the code below which I found here: http://ipdfdev.com/2011/03/23/display-a-pdf-page-on-the-iphone-and-ipad/
switch (rotate) {
case 0:
// Translate the origin of the coordinate system at the
// bottom left corner of the page rectangle.
CGContextTranslateCTM(context, 0, cropBox.size.height);
// Reverse the Y axis to grow from bottom to top.
CGContextScaleCTM(context, 1, -1);
break;
case 90:
// Reverse the Y axis to grow from bottom to top.
CGContextScaleCTM(context, 1, -1);
// Rotate the coordinate system.
CGContextRotateCTM(context, -M_PI / 2);
break;
case 180:
case -180:
// Reverse the Y axis to grow from bottom to top.
CGContextScaleCTM(context, 1, -1);
// Translate the origin of the coordinate system at the
// top right corner of the page rectangle.
CGContextTranslateCTM(context, cropBox.size.width, 0);
// Rotate the coordinate system with 180 degrees.
CGContextRotateCTM(context, M_PI);
break;
case 270:
case -90:
// Translate the origin of the coordinate system at the
// bottom right corner of the page rectangle.
CGContextTranslateCTM(context, cropBox.size.height, cropBox.size.width);
// Rotate the coordinate system.
CGContextRotateCTM(context, M_PI / 2);
// Reverse the X axis.
CGContextScaleCTM(context, -1, 1);
break;
}
Et voilà - the PDF is displayed in the right orientation
I am writing this with assumption that your problem is about rotating document when user rotates device....
For that you have to redraw document in view. TO achieve that do following....
change frame of the view in which document is drawn, and CALayer(OR CATiledLayer) being used in that view in following method.
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
Call setNeedsDisplay method of CATiledLayer after changing frame.
Then return YES in
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation.
Above steps will redraw the document in new frame of you View accordingly so it will appear properly.
->IF your view is in full screen or then only step 2 ans 3 will be enough.
Post here if any further assistance is required....
Is there a particular reason you are drawing PDFs yourself? You could use QLPreviewController on iOS 4.0 or later, and UIDocumentInteractionController for previous versions.

xcode animation ball iphone problem landscape mode

Hi everyone I'm french so scuse me for my english. My problem is that I'm animating a ball on the screen in portrait mode, but now I want do to the same thing in landscape mode. Everything work but when the ball hit a side of the iphone it go throught it. this code doesn't work I think that the problem is about x and y.
if (ball1.center.x > 480 ||ball1.center.x < 0){
ajout.x = -ajout.x;
}
if (ball1.center.y > 320 ||ball1.center.y < 0){
ajout.y = -ajout.y;
Yes your problem is with the x and y. In portrait mode that is correct with x being 480 and y being 320. However in landscape the two values are reversed.
Try this code instead;
CGRect _frame = [[UIScreen mainScreen] bounds];
if (ball1.center.x > _frame.size.width || ball1.center.x < 0)
ajout.x = -ajout.x;
if (ball1.center.y > _frame.size.height || ball1.center.y < 0)
ajout.y = -ajout.y;
This should return the propery bounds of your screen (320x480 in portrait, 480x320 in landscape) and check against those values.
Cheers.

UIWebView - Rotating Causes Non-Interactable Areas

I'm having a strange problem with UIWebView. I have to set it's orientation manually by rotating and sizing it. But after i've done that there are areas of the web content that aren't usable.
The iPad is in Portrait, but the web content is built in Landscape. So what I do is rotate the container by 90 degrees, set the bounds of the container, and resize the container and webframe.
Here's the code I use for this:
//rotate
CGRect contentRect;
CGAffineTransform transform;
transform = CGAffineTransformMakeRotation(-3.14159/2);
contentRect = CGRectMake(0,0,1024,768);
//set container bounds and transform
[_container setBounds:contentRect];
[_container setTransform:transform];
//set frame
containerFrame = CGRectMake(0,0,768,1024);
webViewFrame = CGRectMake(0,0,768,1024);
[_webview setFrame:webViewFrame];
[_container setFrame:containerFrame];
So after this rotation happens, the ipad is still in Portrait, the web content is displayed correctly on the screen (rotated). But content below 768 pixels is not interactable.
I'm not sure what's going on. This has stumped me for a while now. Any ideas?