See full sphere augmented reality in action - ©ompass360° is available in the iPhone App Store

3Dcompass© (augmented reality) 0.8.5 - fit camera preview to fullscreen

There were little trick to do during the scaling of the camera preview mentioned in the previous post. The only way to transform the camera preview is to assign a CGAffineTransform to the UIImagePickerController's cameraViewTransform property.

Knowing that the camera view (320x427) gets scaled from its center as a pivot point, it needs to be adjusted vertically since it is aligned top initially (its frame is 0,0,320,427). Thus we have to do a scale, and a translate in one step (must define it in one single CGAffineTransform matrix).

How to fit camera preview to fullscreen
As I realized the camera preview has to be scaled to 480/427 and shifted down by (480-427)/2 to fit the entire screen (with a slight 6% crop by each side).

As I read the CGAffineTransform description carefully, and planned the transformation carefully above, creating the matrix wasn't a big deal (thanks for OpenGL to introducing me the idea of matrices). As the device/camera has fixed dimensions, we can calculate the constants to work with, the code goes below.

#define kCameraScale 1.12412178 //= 480 / 427
#define kCameraOffset 26.5 //= (480 - 427) / 2
	
//Make camera view full screen.
picker.wantsFullScreenLayout = YES;
picker.cameraViewTransform = CGAffineTransformMake(kCameraScale, 0.0f,
                                                   0.0f,         kCameraScale,
                                                   0.0f,         kCameraOffset);

It gives a pretty fullscreen camera preview with only a 12% zoom and without any distortion. It crops only 6% on each side, and there is no offset relative to the OpenGL overlay now.

Tomorrow I'm gonna do some interface/design/marketing stuff. As the app 3Dcompass© will be completed soon it needs a coherent identy.

Comments

Not commented yet.

Say something

HTML tags not allowed, URL-s underlined automatically. An e-mail is minimum required (it wont appear on the page).If you have a freeblog account, may log in here.





Under construction



Youtube

Twitter
Free promo codes


Facebook likebox
Bookmark blog