Skip to content

Commit

Permalink
Code reorganisation. Much cleaner that way.
Browse files Browse the repository at this point in the history
  • Loading branch information
kpmaalej committed Mar 23, 2011
1 parent 3895a1a commit 9e9e9b6
Show file tree
Hide file tree
Showing 17 changed files with 158 additions and 200 deletions.
4 changes: 0 additions & 4 deletions ARKit/ARCoordinate.h
Expand Up @@ -15,20 +15,16 @@
@class ARCoordinate;

@protocol ARPersistentItem

@property (nonatomic, readonly) ARCoordinate *arCoordinate;

@optional
// Title and subtitle for use by selection UI.
- (NSString *)title;
- (NSString *)subtitle;
@end

@protocol ARGeoPersistentItem

// Center latitude and longitude of the annotion view.
@property (nonatomic, readonly) CLLocationCoordinate2D coordinate;

@optional
// Title and subtitle for use by selection UI.
- (NSString *)title;
Expand Down
1 change: 0 additions & 1 deletion ARKit/ARGeoCoordinate.h
Expand Up @@ -16,7 +16,6 @@

@property (nonatomic, retain) CLLocation *geoLocation;

- (float)angleFromCoordinate:(CLLocationCoordinate2D)first toCoordinate:(CLLocationCoordinate2D)second;

+ (ARGeoCoordinate *)coordinateWithLocation:(CLLocation *)location locationTitle:(NSString*) titleOfLocation;
+ (ARGeoCoordinate *)coordinateWithLocation:(CLLocation *)location fromOrigin:(CLLocation *)origin;
Expand Down
61 changes: 37 additions & 24 deletions ARKit/ARGeoCoordinate.m
Expand Up @@ -8,26 +8,36 @@

#import "ARGeoCoordinate.h"

@interface ARGeoCoordinate (Private)
- (float)angleFromCoordinate:(CLLocationCoordinate2D)first toCoordinate:(CLLocationCoordinate2D)second;
@end

@implementation ARGeoCoordinate

@synthesize geoLocation;
#pragma mark -
#pragma mark Class methods

- (float)angleFromCoordinate:(CLLocationCoordinate2D)first toCoordinate:(CLLocationCoordinate2D)second {
float longitudinalDifference = second.longitude - first.longitude;
float latitudinalDifference = second.latitude - first.latitude;
float possibleAzimuth = (M_PI * .5f) - atan(latitudinalDifference / longitudinalDifference);
+ (ARGeoCoordinate *)coordinateWithLocation:(CLLocation *)location locationTitle:(NSString *) titleOfLocation {
ARGeoCoordinate *newCoordinate = [[ARGeoCoordinate alloc] init];
[newCoordinate setGeoLocation: location];
[newCoordinate setTitle: titleOfLocation];

if (longitudinalDifference > 0)
return possibleAzimuth;
else if (longitudinalDifference < 0)
return possibleAzimuth + M_PI;
else if (latitudinalDifference < 0)
return M_PI;
return [newCoordinate autorelease];
}

+ (ARGeoCoordinate *)coordinateWithLocation:(CLLocation *)location fromOrigin:(CLLocation *)origin {

return 0.0f;
ARGeoCoordinate *newCoordinate = [ARGeoCoordinate coordinateWithLocation:location locationTitle:@""];
[newCoordinate calibrateUsingOrigin:origin];
return newCoordinate;
}

#pragma mark -
#pragma mark Instance methods

@synthesize geoLocation;

- (void)calibrateUsingOrigin:(CLLocation *)origin {

if (![self geoLocation])
Expand All @@ -47,20 +57,23 @@ - (void)calibrateUsingOrigin:(CLLocation *)origin {
NSLog(@"distance is %f, angle is %f, azimuth is %f",baseDistance,angle,[self azimuth]);
}

+ (ARGeoCoordinate *)coordinateWithLocation:(CLLocation *)location locationTitle:(NSString *) titleOfLocation {
#pragma mark -
#pragma mark Private

ARGeoCoordinate *newCoordinate = [[ARGeoCoordinate alloc] init];
[newCoordinate setGeoLocation: location];
[newCoordinate setTitle: titleOfLocation];
- (float)angleFromCoordinate:(CLLocationCoordinate2D)first toCoordinate:(CLLocationCoordinate2D)second {

return [newCoordinate autorelease];
}

+ (ARGeoCoordinate *)coordinateWithLocation:(CLLocation *)location fromOrigin:(CLLocation *)origin {
float longitudinalDifference = second.longitude - first.longitude;
float latitudinalDifference = second.latitude - first.latitude;
float possibleAzimuth = (M_PI * .5f) - atan(latitudinalDifference / longitudinalDifference);

ARGeoCoordinate *newCoordinate = [ARGeoCoordinate coordinateWithLocation:location locationTitle:@""];
[newCoordinate calibrateUsingOrigin:origin];
return newCoordinate;
if (longitudinalDifference > 0)
return possibleAzimuth;
else if (longitudinalDifference < 0)
return possibleAzimuth + M_PI;
else if (latitudinalDifference < 0)
return M_PI;

return 0.0f;
}

@end
8 changes: 7 additions & 1 deletion ARKit/ARKit.h
Expand Up @@ -9,7 +9,13 @@
#import <Foundation/Foundation.h>

#import "ARViewController.h"
#import "ARLocationDelegate.h"
#import "ARGeoCoordinate.h"

@protocol ARLocationDataSource
- (NSMutableArray *)locations; //returns an array of ARGeoCoordinates
- (UIView *)viewForCoordinate:(ARCoordinate *)coordinate;
@end


@interface ARKit : NSObject {

Expand Down
1 change: 1 addition & 0 deletions ARKit/ARKit.m
Expand Up @@ -30,4 +30,5 @@ +(BOOL)deviceSupportsAR{

return YES;
}

@end
19 changes: 0 additions & 19 deletions ARKit/ARLocationDelegate.h

This file was deleted.

10 changes: 0 additions & 10 deletions ARKit/ARLocationDelegate.m

This file was deleted.

10 changes: 5 additions & 5 deletions ARKit/ARViewController.h
Expand Up @@ -7,20 +7,20 @@
//

#import <UIKit/UIKit.h>
#import "ARLocationDelegate.h"

#import "ARKit.h"

@class AugmentedRealityController;
@protocol ARLocationDataSource;

@interface ARViewController : UIViewController {
AugmentedRealityController *agController;
id<ARLocationDelegate> delegate;
id<ARLocationDataSource> dataSource;
}

@property (nonatomic, retain) AugmentedRealityController *agController;
@property (nonatomic, assign) id<ARLocationDelegate> delegate;
@property (nonatomic, assign) id<ARLocationDataSource> dataSource;

-(id)initWithDelegate:(id<ARLocationDelegate>) aDelegate;
-(id)initWithDataSource:(id<ARLocationDataSource>) aDataSource;

@end

66 changes: 15 additions & 51 deletions ARKit/ARViewController.m
Expand Up @@ -8,79 +8,43 @@

#import "ARViewController.h"
#import "AugmentedRealityController.h"
#import "GEOLocations.h"
#import "CoordinateView.h"

@implementation ARViewController

@synthesize agController;
@synthesize delegate;
@synthesize dataSource;

-(id)initWithDelegate:(id<ARLocationDelegate>) aDelegate {


self.delegate = aDelegate;

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

[self setWantsFullScreenLayout: YES];

-(id)initWithDataSource:(id<ARLocationDataSource>)aDataSource {
if ((self = [super init])) {
self.dataSource = aDataSource;
self.wantsFullScreenLayout = YES;
}
return self;
}

- (void)loadView {
[self setAgController:[[AugmentedRealityController alloc] initWithViewController:self]];
self.agController = [[AugmentedRealityController alloc] initWithViewController:self];

[agController setDebugMode:NO];
[agController setScaleViewsBasedOnDistance:YES];
[agController setMinimumScaleFactor:0.5];
[agController setRotateViewsBasedOnPerspective:YES];
self.agController.debugMode = NO;
self.agController.scaleViewsBasedOnDistance = YES;
self.agController.minimumScaleFactor = 0.5;
self.agController.rotateViewsBasedOnPerspective = YES;

GEOLocations* locations = [[GEOLocations alloc] initWithDelegate:delegate];

if ([[locations getLocations] count] > 0) {
for (ARCoordinate *coordinate in [locations getLocations]) {
CoordinateView *cv = [[CoordinateView alloc] initForCoordinate:coordinate];
[agController addCoordinate:coordinate augmentedView:cv animated:NO];
[cv release];
if ([dataSource.locations count] > 0) {
for (ARCoordinate *coordinate in dataSource.locations) {
UIView *coordinateView = [dataSource viewForCoordinate:coordinate];
[agController addCoordinate:coordinate augmentedView:coordinateView animated:NO];
}
}

[locations release];
}

- (void)viewDidAppear:(BOOL)animated {

[agController displayAR];
[super viewDidAppear:animated];
}

- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return YES;
}


- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];

// Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}


- (void)dealloc {
[super dealloc];
}


@end
1 change: 1 addition & 0 deletions ARKit/AugmentedRealityController.h
Expand Up @@ -79,4 +79,5 @@
@property double latestHeading;
@property float viewAngle;
@property (retain) NSMutableArray *coordinateViews;

@end
28 changes: 0 additions & 28 deletions ARKit/GEOLocations.h

This file was deleted.

36 changes: 0 additions & 36 deletions ARKit/GEOLocations.m

This file was deleted.

0 comments on commit 9e9e9b6

Please sign in to comment.