Skip to content

Commit

Permalink
Added AVFoundation to use for Camera viewing instead of UIImagePicker…
Browse files Browse the repository at this point in the history
…Controller

AVFoundation gives us greater control of the camera and will allow for
unlimited types of AR apps to be developed.
Gets rid of the Camera open animation
No longer loads as ModalViewController for the Camera view
Added another close button to show Peter how to close the new view and
the AR view.
  • Loading branch information
Niels Hansen committed Sep 14, 2011
1 parent 5223fab commit 27ac4d9
Show file tree
Hide file tree
Showing 13 changed files with 26,988 additions and 26,316 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -28,3 +28,5 @@ error.log
.Trashes

ARKitDemo/ARKitDemo.xcodeproj/project.xcworkspace/xcuserdata/nielswhansen.xcuserdatad/UserInterfaceState.xcuserstate

ARKitDemo/ARKitDemo.xcodeproj/project.xcworkspace/xcuserdata/nielswhansen.xcuserdatad/UserInterfaceState.xcuserstate
2 changes: 1 addition & 1 deletion ARKit/ARKit.h
Expand Up @@ -3,7 +3,7 @@
// ARKitDemo
//
// Created by Jared Crawford on 2/13/10.
// Copyright 2010 __MyCompanyName__. All rights reserved.
// Copyright 2011 Agilite Software. All rights reserved.
//

#import <Foundation/Foundation.h>
Expand Down
2 changes: 1 addition & 1 deletion ARKit/ARKit.m
Expand Up @@ -3,7 +3,7 @@
// ARKitDemo
//
// Created by Jared Crawford on 2/13/10.
// Copyright 201. All rights reserved.
// Copyright 2011 Agilite Software. All rights reserved.
//

#import "ARKit.h"
Expand Down
2 changes: 1 addition & 1 deletion ARKit/ARViewController.h
Expand Up @@ -3,7 +3,7 @@
// ARKitDemo
//
// Created by Niels W Hansen on 1/23/10.
// Copyright 2010 Agilite Software. All rights reserved.
// Copyright 2011 Agilite Software. All rights reserved.
//

#import <UIKit/UIKit.h>
Expand Down
5 changes: 5 additions & 0 deletions ARKit/AugmentedRealityController.h
Expand Up @@ -10,6 +10,7 @@
#import <CoreLocation/CoreLocation.h>
#import "ARViewController.h"
#import <UIKit/UIKit.h>
#import <AVFoundation/AVFoundation.h>

@class ARCoordinate;

Expand All @@ -33,6 +34,8 @@
UILabel *debugView;
UIButton *closeButton;
UIImagePickerController *cameraController;
AVCaptureSession *captureSession;
AVCaptureVideoPreviewLayer *previewLayer;

@private
double latestHeading;
Expand Down Expand Up @@ -62,6 +65,8 @@
@property (nonatomic, retain) UIImagePickerController *cameraController;
@property UIDeviceOrientation currentOrientation;
@property (readonly) NSArray *coordinates;
@property (nonatomic, retain) AVCaptureSession *captureSession;
@property (nonatomic, retain) AVCaptureVideoPreviewLayer *previewLayer;

- (id)initWithViewController:(UIViewController *)theView;

Expand Down
90 changes: 78 additions & 12 deletions ARKit/AugmentedRealityController.m
Expand Up @@ -11,6 +11,7 @@
#import "ARGeoCoordinate.h"
#import <MapKit/MapKit.h>
#import <QuartzCore/QuartzCore.h>
#import <AVFoundation/AVFoundation.h>

#define kFilteringFactor 0.05
#define degreesToRadian(x) (M_PI * (x) / 180.0)
Expand Down Expand Up @@ -46,6 +47,8 @@ @implementation AugmentedRealityController
@synthesize latestHeading;
@synthesize viewAngle;
@synthesize coordinateViews;
@synthesize captureSession;
@synthesize previewLayer;

@synthesize cameraController;

Expand All @@ -67,20 +70,69 @@ - (id)initWithViewController:(ARViewController *)vc {

CGRect screenRect = [[UIScreen mainScreen] bounds];

[self setDisplayView: [[UIView alloc] initWithFrame: screenRect]];
UIView *ARview = [[UIView alloc] initWithFrame: screenRect];
[self setCurrentOrientation:UIDeviceOrientationPortrait];
[self setDegreeRange:[ARview bounds].size.width / 12];

[self setDisplayView: [[UIView alloc] initWithFrame: screenRect]];
[self setCurrentOrientation:UIDeviceOrientationPortrait];
[self setDegreeRange:[[self displayView] bounds].size.width / 12];

[vc setView:displayView];

[[vc view] insertSubview:ARview atIndex:0];
/*
[self setCameraController: [[[UIImagePickerController alloc] init] autorelease]];
[[self cameraController] setSourceType: UIImagePickerControllerSourceTypeCamera];
[[self cameraController] setCameraViewTransform: CGAffineTransformScale([[self cameraController] cameraViewTransform], 1.13f, 1.13f)];
[[self cameraController] setShowsCameraControls:NO];
[[self cameraController] setNavigationBarHidden:YES];
[[self cameraController] setCameraOverlayView:displayView];

CLLocation *newCenter = [[CLLocation alloc] initWithLatitude:37.41711 longitude:-122.02528];
*/
#if !TARGET_IPHONE_SIMULATOR
captureSession = [[AVCaptureSession alloc] init];

AVCaptureDevice *videoCaptureDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];

NSError *error = nil;

AVCaptureDeviceInput *videoInput = [AVCaptureDeviceInput deviceInputWithDevice:videoCaptureDevice error:&error];

if (videoInput) {
[captureSession addInput:videoInput];
}
else {
// Handle the failure.
}

AVCaptureVideoPreviewLayer *newCaptureVideoPreviewLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:captureSession];
UIView *view = ARview;
CALayer *viewLayer = [view layer];
[viewLayer setMasksToBounds:YES];

CGRect bounds = [view bounds];
[newCaptureVideoPreviewLayer setFrame:bounds];

if ([newCaptureVideoPreviewLayer isOrientationSupported]) {
[newCaptureVideoPreviewLayer setOrientation:AVCaptureVideoOrientationPortrait];
}

[newCaptureVideoPreviewLayer setVideoGravity:AVLayerVideoGravityResizeAspectFill];

[viewLayer insertSublayer:newCaptureVideoPreviewLayer below:[[viewLayer sublayers] objectAtIndex:0]];

[self setPreviewLayer:newCaptureVideoPreviewLayer];
[newCaptureVideoPreviewLayer release];

[captureSession setSessionPreset:AVCaptureSessionPresetLow];

[captureSession startRunning];

#endif

[ARview release];

CLLocation *newCenter = [[CLLocation alloc] initWithLatitude:37.41711 longitude:-122.02528];

[self setCenterLocation: newCenter];
[newCenter release];
Expand Down Expand Up @@ -154,7 +206,7 @@ - (void)startListening {

if (![self accelerometerManager]) {
[self setAccelerometerManager: [UIAccelerometer sharedAccelerometer]];
[[self accelerometerManager] setUpdateInterval: 0.25];
[[self accelerometerManager] setUpdateInterval: 0.75];
[[self accelerometerManager] setDelegate: self];
}

Expand Down Expand Up @@ -214,6 +266,7 @@ - (void)updateCenterCoordinate {
adjustment = degreesToRadian(180);

[[self centerCoordinate] setAzimuth: latestHeading - adjustment];

[self updateLocations];
}

Expand Down Expand Up @@ -343,7 +396,7 @@ - (void)updateLocations {
CGFloat scaleFactor = 1.0;

if ([self scaleViewsBasedOnDistance])
scaleFactor = 1.0 - [self minimumScaleFactor] * ([item radialDistance] / [self maximumScaleDistance]);
scaleFactor = 1.0 - [self minimumScaleFactor]*([item radialDistance] / [self maximumScaleDistance]);

float width = [viewToDraw bounds].size.width * scaleFactor;
float height = [viewToDraw bounds].size.height * scaleFactor;
Expand All @@ -357,7 +410,7 @@ - (void)updateLocations {
// Set the scale if it needs it. Scale the perspective transform if we have one.
if ([self scaleViewsBasedOnDistance])
transform = CATransform3DScale(transform, scaleFactor, scaleFactor, scaleFactor);

if ([self rotateViewsBasedOnPerspective]) {
transform.m34 = 1.0 / 300.0;

Expand All @@ -371,19 +424,19 @@ - (void)updateLocations {
itemAzimuth += 2 * M_PI;

double angleDifference = itemAzimuth - centerAzimuth;
transform = CATransform3DRotate(transform, [self maximumRotationAngle] * angleDifference / 0.3696f , 0, 1, 0);
// transform = CATransform3DRotate(transform, [self maximumRotationAngle] * angleDifference / 0.3696f , 0, 1, 0);
}

[[viewToDraw layer] setTransform:transform];

//if we don't have a superview, set it up.
if (!([viewToDraw superview])) {
[[self displayView] addSubview:viewToDraw];
[[self displayView] sendSubviewToBack:viewToDraw];
[[self displayView] insertSubview:viewToDraw atIndex:1];

}
}
else
[viewToDraw removeFromSuperview];
if ([viewToDraw superview])
[viewToDraw removeFromSuperview];

index++;
}
Expand Down Expand Up @@ -427,24 +480,37 @@ - (void)deviceOrientationDidChange:(NSNotification *)notification {

CGAffineTransform transform = CGAffineTransformMakeRotation(degreesToRadian(0));
CGRect bounds = [[UIScreen mainScreen] bounds];



if (orientation == UIDeviceOrientationLandscapeLeft) {
transform = CGAffineTransformMakeRotation(degreesToRadian(90));
bounds.size.width = [[UIScreen mainScreen] bounds].size.height;
bounds.size.height = [[UIScreen mainScreen] bounds].size.width;
[[self previewLayer] setOrientation:AVCaptureVideoOrientationLandscapeRight];
}
else if (orientation == UIDeviceOrientationLandscapeRight) {
transform = CGAffineTransformMakeRotation(degreesToRadian(-90));
bounds.size.width = [[UIScreen mainScreen] bounds].size.height;
bounds.size.height = [[UIScreen mainScreen] bounds].size.width;
[[self previewLayer] setOrientation:AVCaptureVideoOrientationLandscapeLeft];
}
else if (orientation == UIDeviceOrientationPortraitUpsideDown)
{
transform = CGAffineTransformMakeRotation(degreesToRadian(180));
[[self previewLayer] setOrientation:AVCaptureVideoOrientationPortraitUpsideDown];
}

if (orientation == UIDeviceOrientationPortrait)
[[self previewLayer] setOrientation:AVCaptureVideoOrientationPortrait];

[displayView setTransform:CGAffineTransformIdentity];
[displayView setTransform: transform];
[displayView setBounds:bounds];

// [previewLayer setFrame:bounds];


[self setDegreeRange:[[self displayView] bounds].size.width / 12];
[self setDebugMode:YES];
}
Expand Down
2 changes: 1 addition & 1 deletion ARKit/GEOLocations.h
Expand Up @@ -3,7 +3,7 @@
// iPhoneAugmentedRealityLib
//
// Created by Niels W Hansen on 12/19/09.
// Copyright 2009 Agilite Software. All rights reserved.
// Copyright 2011 Agilite Software. All rights reserved.
//

#import <Foundation/Foundation.h>
Expand Down
8 changes: 8 additions & 0 deletions ARKitDemo/ARKitDemo.xcodeproj/project.pbxproj
Expand Up @@ -29,6 +29,8 @@
8C0F54F4141E66E5009D0D64 /* MainViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 8C0F54F2141E66E5009D0D64 /* MainViewController.xib */; };
8C564DDE141BDC3C0092E120 /* AR-logo-57.png in Resources */ = {isa = PBXBuildFile; fileRef = 8C564DDC141BDC3C0092E120 /* AR-logo-57.png */; };
8C564DDF141BDC3C0092E120 /* AR-logo-114.png in Resources */ = {isa = PBXBuildFile; fileRef = 8C564DDD141BDC3C0092E120 /* AR-logo-114.png */; };
8CD0EE40141FBA2100207B2F /* AVFoundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8CD0EE3F141FBA2100207B2F /* AVFoundation.framework */; };
8CD0EE4B141FBBCE00207B2F /* CoreMedia.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8CD0EE4A141FBBCE00207B2F /* CoreMedia.framework */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
Expand Down Expand Up @@ -67,6 +69,8 @@
8C0F54F6141E9D4D009D0D64 /* ARViewProtocol.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ARViewProtocol.h; sourceTree = "<group>"; };
8C564DDC141BDC3C0092E120 /* AR-logo-57.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "AR-logo-57.png"; sourceTree = "<group>"; };
8C564DDD141BDC3C0092E120 /* AR-logo-114.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "AR-logo-114.png"; sourceTree = "<group>"; };
8CD0EE3F141FBA2100207B2F /* AVFoundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AVFoundation.framework; path = System/Library/Frameworks/AVFoundation.framework; sourceTree = SDKROOT; };
8CD0EE4A141FBBCE00207B2F /* CoreMedia.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreMedia.framework; path = System/Library/Frameworks/CoreMedia.framework; sourceTree = SDKROOT; };
8D1107310486CEB800E47090 /* ARKitDemo-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "ARKitDemo-Info.plist"; plistStructureDefinitionIdentifier = "com.apple.xcode.plist.structure-definition.iphone.info-plist"; sourceTree = "<group>"; };
/* End PBXFileReference section */

Expand All @@ -75,6 +79,8 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
8CD0EE4B141FBBCE00207B2F /* CoreMedia.framework in Frameworks */,
8CD0EE40141FBA2100207B2F /* AVFoundation.framework in Frameworks */,
1D60589F0D05DD5A006BFB54 /* Foundation.framework in Frameworks */,
1DF5F4E00D08C38300B7A737 /* UIKit.framework in Frameworks */,
288765FD0DF74451002DB57D /* CoreGraphics.framework in Frameworks */,
Expand Down Expand Up @@ -110,6 +116,8 @@
29B97314FDCFA39411CA2CEA /* CustomTemplate */ = {
isa = PBXGroup;
children = (
8CD0EE4A141FBBCE00207B2F /* CoreMedia.framework */,
8CD0EE3F141FBA2100207B2F /* AVFoundation.framework */,
080E96DDFE201D6D7F000001 /* Classes */,
29B97315FDCFA39411CA2CEA /* Other Sources */,
29B97317FDCFA39411CA2CEA /* Resources */,
Expand Down

0 comments on commit 27ac4d9

Please sign in to comment.