Skip to content

Commit

Permalink
Removing Properties for variables that are private
Browse files Browse the repository at this point in the history
Removed any property from the AugmentedRealityController that had a
private variable and should not be changed outside of the class.

Added pragma marks within the AugementedRealityController to organize
class.
  • Loading branch information
nielswh committed Nov 20, 2011
1 parent 4a41792 commit 663ea8a
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 107 deletions.
10 changes: 0 additions & 10 deletions ARKit/AugmentedRealityController.h
Expand Up @@ -66,16 +66,6 @@
@property double maximumScaleDistance;
@property double minimumScaleFactor;
@property double maximumRotationAngle;
@property double degreeRange;
@property double latestHeading;

@property float verticleDiff;
@property float prevHeading;
@property float viewAngle;

@property int totalDisplayed;
@property int prevTotalDisplayed;
@property int cameraOrientation;

@property CGPoint startPoint;
@property CGPoint endPoint;
Expand Down
196 changes: 99 additions & 97 deletions ARKit/AugmentedRealityController.m
Expand Up @@ -38,6 +38,11 @@ @implementation AugmentedRealityController
@synthesize locationManager;
@synthesize accelerometerManager;
@synthesize displayView;
@synthesize ARView;
@synthesize debugView;
@synthesize rootViewController;
@synthesize coordinateViews;

@synthesize centerCoordinate;
@synthesize scaleViewsBasedOnDistance;
@synthesize rotateViewsBasedOnPerspective;
Expand All @@ -47,30 +52,22 @@ @implementation AugmentedRealityController
@synthesize centerLocation;
@synthesize coordinates;
@synthesize debugMode;
@synthesize degreeRange;
@synthesize rootViewController;

@synthesize debugView;
@synthesize latestHeading;
@synthesize viewAngle;
@synthesize coordinateViews;
@synthesize captureSession;
@synthesize previewLayer;
@synthesize ARView;
@synthesize verticleDiff, prevHeading;

@synthesize startPoint, endPoint;
@synthesize totalDisplayed, prevTotalDisplayed;
@synthesize cameraOrientation;


- (id)initWithViewController:(ARViewController *)vc {

if (!(self = [super init]))
return nil;

[self setLatestHeading: -1.0f];
[self setVerticleDiff:0.0f];
[self setPrevHeading:-1.0f];

latestHeading = -1.0f;
verticleDiff = 0.0f;
prevHeading = -1.0f;

[self setRootViewController: vc];
[self setMaximumScaleDistance: 0.0];
[self setMinimumScaleFactor: 1.0];
Expand All @@ -85,21 +82,19 @@ - (id)initWithViewController:(ARViewController *)vc {

CGRect screenRect = [[UIScreen mainScreen] bounds];

if ([self cameraOrientation] == UIDeviceOrientationLandscapeLeft || [self cameraOrientation] == UIDeviceOrientationLandscapeRight) {
if (cameraOrientation == UIDeviceOrientationLandscapeLeft || cameraOrientation == UIDeviceOrientationLandscapeRight) {
screenRect.size.width = [[UIScreen mainScreen] bounds].size.height;
screenRect.size.height = [[UIScreen mainScreen] bounds].size.width;
}

UIView *arView = [[UIView alloc] initWithFrame: screenRect];

[self setDegreeRange:[arView bounds].size.width / ADJUST_BY];
degreeRange = [arView bounds].size.width / ADJUST_BY;

UIView *displayV= [[UIView alloc] initWithFrame: screenRect];

[vc setView:displayV];
[[vc view] insertSubview:arView atIndex:0];



#if !TARGET_IPHONE_SIMULATOR

Expand Down Expand Up @@ -128,7 +123,7 @@ - (id)initWithViewController:(ARViewController *)vc {
[newCaptureVideoPreviewLayer setFrame:bounds];

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

[newCaptureVideoPreviewLayer setVideoGravity:AVLayerVideoGravityResizeAspectFill];
Expand Down Expand Up @@ -181,12 +176,28 @@ -(void)unloadAV {
[self setPreviewLayer:nil];
}

- (void)dealloc {
[self unloadAV];
[[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications];
[ARView release];
locationManager.delegate = nil;
[UIAccelerometer sharedAccelerometer].delegate = nil;
[locationManager release];
[coordinateViews release];
[coordinates release];
[debugView release];
[super dealloc];
}


- (IBAction)closeButtonClicked:(id)sender {
[self stopListening];
[self unloadAV];
[[self rootViewController] dismissModalViewControllerAnimated:YES];
}

#pragma mark -
#pragma mark Location Manager methods
- (void)startListening {

// start our heading readings and our accelerometer readings.
Expand Down Expand Up @@ -246,35 +257,41 @@ - (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLoca
NSLog(@"Location of phone changed!");
}

-(void) setupDebugPostion {

if ([self debugMode]) {
[debugView sizeToFit];
CGRect displayRect = [[self displayView] bounds];

[debugView setFrame:CGRectMake(0, displayRect.size.height - [debugView bounds].size.height, displayRect.size.width, [debugView bounds].size.height)];
}
}

- (void)updateCenterCoordinate {

double adjustment = 0;

if ([self cameraOrientation] == UIDeviceOrientationLandscapeLeft)
if (cameraOrientation == UIDeviceOrientationLandscapeLeft)
adjustment = degreesToRadian(270);
else if ([self cameraOrientation] == UIDeviceOrientationLandscapeRight)
else if (cameraOrientation == UIDeviceOrientationLandscapeRight)
adjustment = degreesToRadian(90);
else if ([self cameraOrientation] == UIDeviceOrientationPortraitUpsideDown)
else if (cameraOrientation == UIDeviceOrientationPortraitUpsideDown)
adjustment = degreesToRadian(180);

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

[self updateLocations];
}

- (void)setCenterLocation:(CLLocation *)newLocation {
[centerLocation release];
centerLocation = [newLocation retain];

for (ARGeoCoordinate *geoLocation in [self coordinates]) {

if ([geoLocation isKindOfClass:[ARGeoCoordinate class]]) {
[geoLocation calibrateUsingOrigin:centerLocation];

if ([geoLocation radialDistance] > [self maximumScaleDistance])
[self setMaximumScaleDistance:[geoLocation radialDistance]];
}
}
}


- (void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration {

switch ([self cameraOrientation]) {
switch (cameraOrientation) {
case UIDeviceOrientationLandscapeLeft:
viewAngle = atan2(acceleration.x, acceleration.z);
break;
Expand All @@ -294,20 +311,8 @@ - (void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAccelera
// [self updateCenterCoordinate];
}

- (void)setCenterLocation:(CLLocation *)newLocation {
[centerLocation release];
centerLocation = [newLocation retain];

for (ARGeoCoordinate *geoLocation in [self coordinates]) {

if ([geoLocation isKindOfClass:[ARGeoCoordinate class]]) {
[geoLocation calibrateUsingOrigin:centerLocation];

if ([geoLocation radialDistance] > [self maximumScaleDistance])
[self setMaximumScaleDistance:[geoLocation radialDistance]];
}
}
}
#pragma mark -
#pragma mark Coordinate methods

- (void)addCoordinate:(ARCoordinate *)coordinate augmentedView:(UIView *)agView animated:(BOOL)animated {

Expand Down Expand Up @@ -338,6 +343,9 @@ - (void)removeCoordinates:(NSArray *)coordinateArray {
}
}

#pragma mark -
#pragma mark Location methods

-(double) findDeltaOfRadianCenter:(double*)centerAzimuth coordinateAzimuth:(double)pointAzimuth betweenNorth:(BOOL*) isBetweenNorth {

if (*centerAzimuth < 0.0)
Expand All @@ -350,11 +358,11 @@ -(double) findDeltaOfRadianCenter:(double*)centerAzimuth coordinateAzimuth:(doub
*isBetweenNorth = NO;

// If values are on either side of the Azimuth of North we need to adjust it. Only check the degree range
if (*centerAzimuth < degreesToRadian([self degreeRange]) && pointAzimuth > degreesToRadian(360-[self degreeRange])) {
if (*centerAzimuth < degreesToRadian(degreeRange) && pointAzimuth > degreesToRadian(360-degreeRange)) {
deltaAzimith = (*centerAzimuth + ((M_PI * 2.0) - pointAzimuth));
*isBetweenNorth = YES;
}
else if (pointAzimuth < degreesToRadian([self degreeRange]) && *centerAzimuth > degreesToRadian(360-[self degreeRange])) {
else if (pointAzimuth < degreesToRadian(degreeRange) && *centerAzimuth > degreesToRadian(360-degreeRange)) {
deltaAzimith = (pointAzimuth + ((M_PI * 2.0) - *centerAzimuth));
*isBetweenNorth = YES;
}
Expand All @@ -372,13 +380,31 @@ - (BOOL)viewportContainsView:(UIView *)viewToDraw forCoordinate:(ARCoordinate *

// NSLog(@"Current %f, Item %f, delta %f, range %f",currentAzimuth,pointAzimuth,deltaAzimith,degreesToRadian([self degreeRange]));


if (deltaAzimith <= degreesToRadian([self degreeRange]))
if (deltaAzimith <= degreesToRadian(degreeRange))
result = YES;

return result;
}

- (CGPoint)pointInView:(UIView *)realityView withView:(UIView *)viewToDraw forCoordinate:(ARCoordinate *)coordinate forIndex:(int)frameIndex {

CGPoint point;
CGRect realityBounds = [realityView bounds];
double currentAzimuth = [[self centerCoordinate] azimuth];
double pointAzimuth = [coordinate azimuth];
BOOL isBetweenNorth = NO;
double deltaAzimith = [self findDeltaOfRadianCenter: &currentAzimuth coordinateAzimuth:pointAzimuth betweenNorth:&isBetweenNorth];

if ((pointAzimuth > currentAzimuth && !isBetweenNorth) || (currentAzimuth > degreesToRadian(360- degreeRange) && pointAzimuth < degreesToRadian(degreeRange)))
point.x = (realityBounds.size.width / 2) + ((deltaAzimith / degreesToRadian(1)) * ADJUST_BY); // Right side of Azimuth
else
point.x = (realityBounds.size.width / 2) - ((deltaAzimith / degreesToRadian(1)) * ADJUST_BY); // Left side of Azimuth

point.y = (realityBounds.size.height / 2) + (radianToDegrees(M_PI_2 + viewAngle) * 2.0);

return point;
}

- (void)updateLocations {

if (!coordinateViews || [coordinateViews count] == 0)
Expand Down Expand Up @@ -450,25 +476,6 @@ - (void)updateLocations {
}
}

- (CGPoint)pointInView:(UIView *)realityView withView:(UIView *)viewToDraw forCoordinate:(ARCoordinate *)coordinate forIndex:(int)frameIndex {

CGPoint point;
CGRect realityBounds = [realityView bounds];
double currentAzimuth = [[self centerCoordinate] azimuth];
double pointAzimuth = [coordinate azimuth];
BOOL isBetweenNorth = NO;
double deltaAzimith = [self findDeltaOfRadianCenter: &currentAzimuth coordinateAzimuth:pointAzimuth betweenNorth:&isBetweenNorth];

if ((pointAzimuth > currentAzimuth && !isBetweenNorth) || (currentAzimuth > degreesToRadian(360-[self degreeRange]) && pointAzimuth < degreesToRadian([self degreeRange])))
point.x = (realityBounds.size.width / 2) + ((deltaAzimith / degreesToRadian(1)) * ADJUST_BY); // Right side of Azimuth
else
point.x = (realityBounds.size.width / 2) - ((deltaAzimith / degreesToRadian(1)) * ADJUST_BY); // Left side of Azimuth

point.y = (realityBounds.size.height / 2) + (radianToDegrees(M_PI_2 + viewAngle) * 2.0);

return point;
}

-(NSComparisonResult) LocationSortClosestFirst:(ARCoordinate *) s1 secondCoord:(ARCoordinate*) s2 {

if ([s1 radialDistance] < [s2 radialDistance])
Expand All @@ -479,19 +486,22 @@ -(NSComparisonResult) LocationSortClosestFirst:(ARCoordinate *) s1 secondCoord:(
return NSOrderedSame;
}

#pragma mark -
#pragma mark Device Orientation

- (void)currentDeviceOrientation {
UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];

if (orientation != UIDeviceOrientationUnknown && orientation != UIDeviceOrientationFaceUp && orientation != UIDeviceOrientationFaceDown) {
if (orientation == UIDeviceOrientationLandscapeLeft)
[self setCameraOrientation:AVCaptureVideoOrientationLandscapeRight];
cameraOrientation = AVCaptureVideoOrientationLandscapeRight;
else if (orientation == UIDeviceOrientationLandscapeRight)
[self setCameraOrientation:AVCaptureVideoOrientationLandscapeLeft];
cameraOrientation = AVCaptureVideoOrientationLandscapeLeft;
else if (orientation == UIDeviceOrientationPortraitUpsideDown)
[self setCameraOrientation:AVCaptureVideoOrientationPortraitUpsideDown];
cameraOrientation = AVCaptureVideoOrientationPortraitUpsideDown;

if (orientation == UIDeviceOrientationPortrait)
[self setCameraOrientation:AVCaptureVideoOrientationPortrait];
cameraOrientation = AVCaptureVideoOrientationPortrait;
}
}

Expand All @@ -514,38 +524,32 @@ - (void)deviceOrientationDidChange:(NSNotification *)notification {
transform = CGAffineTransformMakeRotation(degreesToRadian(90));
bounds.size.width = [[UIScreen mainScreen] bounds].size.height;
bounds.size.height = [[UIScreen mainScreen] bounds].size.width;
[self setCameraOrientation: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 setCameraOrientation:AVCaptureVideoOrientationLandscapeLeft];
}
else if (orientation == UIDeviceOrientationPortraitUpsideDown)
{
transform = CGAffineTransformMakeRotation(degreesToRadian(180));
[self setCameraOrientation:AVCaptureVideoOrientationPortraitUpsideDown];
}

if (orientation == UIDeviceOrientationPortrait) {
[self setCameraOrientation:AVCaptureVideoOrientationPortrait];
}

[[self ARView] setFrame:bounds];

[[self previewLayer] setOrientation:[self cameraOrientation]];
[[self previewLayer] setOrientation:cameraOrientation];
[[self previewLayer] setFrame:bounds];

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

[self setDegreeRange:[[self displayView] bounds].size.width / ADJUST_BY];
degreeRange = [self displayView].bounds.size.width / ADJUST_BY;
[self updateDebugMode:YES];
}

}

#pragma mark -
#pragma mark Debug features

- (void)updateDebugMode:(BOOL) flag {

if ([self debugMode] == flag) {
Expand All @@ -566,19 +570,17 @@ - (void)updateDebugMode:(BOOL) flag {

}

- (void)dealloc {
[self unloadAV];
[[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications];
[ARView release];
locationManager.delegate = nil;
[UIAccelerometer sharedAccelerometer].delegate = nil;
[locationManager release];
[coordinateViews release];
[coordinates release];
[debugView release];
[super dealloc];
-(void) setupDebugPostion {

if ([self debugMode]) {
[debugView sizeToFit];
CGRect displayRect = [[self displayView] bounds];

[debugView setFrame:CGRectMake(0, displayRect.size.height - [debugView bounds].size.height, displayRect.size.width, [debugView bounds].size.height)];
}
}


#pragma mark -
#pragma mark Touch events

Expand Down
Binary file not shown.

0 comments on commit 663ea8a

Please sign in to comment.