Permalink
Browse files

Added "Fly to…" field, and refactoring

  • Loading branch information...
1 parent 77698d1 commit e6c8405cd19eb76ea123901ef9a53625a67209de Ross Anderson committed May 29, 2012
View
@@ -50,7 +50,6 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
switch( IMAGERY_DATASET ) {
case 1:
if ( [[UIScreen mainScreen] scale] > 1.5 ) {
- NSLog(@"Retina");
// Dancing Robots Streets Retina: https://tiles.mapbox.com/v3/dancingrobots.map-lqzbpv0l.jsonp
database.baseUrlStrings = [NSArray arrayWithObjects:
@"http://a.tiles.mapbox.com/v3/dancingrobots.map-lqzbpv0l/{z}/{x}/{y}.png",
@@ -143,14 +142,16 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
}
self.viewController.pager.terrainDatabase = database;
+#if 0
// add world tour
tourController = [RAWorldTour new];
tourController.manipulator = self.viewController.manipulator;
UITapGestureRecognizer * recognizer = [[UITapGestureRecognizer alloc] initWithTarget:tourController action:@selector(startOrStop:)];
[recognizer setNumberOfTapsRequired:4];
[self.viewController.view addGestureRecognizer:recognizer];
- //[tourController start: self];
+ [tourController start: self];
+#endif
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
@@ -9,6 +9,9 @@
/* Begin PBXBuildFile section */
9109E03C153D86100008286D /* star1.png in Resources */ = {isa = PBXBuildFile; fileRef = 9109E03B153D86100008286D /* star1.png */; };
9109E03E153D864F0008286D /* RASceneGraphController.m in Sources */ = {isa = PBXBuildFile; fileRef = 9109E03D153D864F0008286D /* RASceneGraphController.m */; };
+ 91483B351573FA8000FC195E /* CoreLocation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 91483B341573FA8000FC195E /* CoreLocation.framework */; };
+ 91483B39157463D200FC195E /* fly.png in Resources */ = {isa = PBXBuildFile; fileRef = 91483B37157463D200FC195E /* fly.png */; };
+ 91483B3A157463D200FC195E /* fly@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 91483B38157463D200FC195E /* fly@2x.png */; };
916EEB8D1552D4E800951ACC /* RAPageNode.m in Sources */ = {isa = PBXBuildFile; fileRef = 916EEB8C1552D4E800951ACC /* RAPageNode.m */; };
91B9BF1E15549FB100A7602E /* RAImageSampler.m in Sources */ = {isa = PBXBuildFile; fileRef = 91B9BF1D15549FB100A7602E /* RAImageSampler.m */; };
91C1D9BA15575D0C008717A9 /* RAWorldTour.m in Sources */ = {isa = PBXBuildFile; fileRef = 91C1D9B915575D0C008717A9 /* RAWorldTour.m */; };
@@ -55,6 +58,9 @@
/* Begin PBXFileReference section */
9109E03B153D86100008286D /* star1.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = star1.png; sourceTree = "<group>"; };
9109E03D153D864F0008286D /* RASceneGraphController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RASceneGraphController.m; sourceTree = "<group>"; };
+ 91483B341573FA8000FC195E /* CoreLocation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreLocation.framework; path = System/Library/Frameworks/CoreLocation.framework; sourceTree = SDKROOT; };
+ 91483B37157463D200FC195E /* fly.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = fly.png; sourceTree = "<group>"; };
+ 91483B38157463D200FC195E /* fly@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "fly@2x.png"; sourceTree = "<group>"; };
916EEB8B1552D4E800951ACC /* RAPageNode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RAPageNode.h; sourceTree = "<group>"; };
916EEB8C1552D4E800951ACC /* RAPageNode.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RAPageNode.m; sourceTree = "<group>"; };
91B9BF1C15549FB000A7602E /* RAImageSampler.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RAImageSampler.h; sourceTree = "<group>"; };
@@ -129,6 +135,7 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
+ 91483B351573FA8000FC195E /* CoreLocation.framework in Frameworks */,
91C1D9DE155B2CBC008717A9 /* CFNetwork.framework in Frameworks */,
91C1D9DF155B2CBC008717A9 /* Security.framework in Frameworks */,
91C1D9E0155B2CBC008717A9 /* SystemConfiguration.framework in Frameworks */,
@@ -182,6 +189,7 @@
91C1D9DB155B2CBC008717A9 /* CFNetwork.framework */,
91C1D9DC155B2CBC008717A9 /* Security.framework */,
91C1D9DD155B2CBC008717A9 /* SystemConfiguration.framework */,
+ 91483B341573FA8000FC195E /* CoreLocation.framework */,
);
name = Frameworks;
sourceTree = "<group>";
@@ -264,6 +272,8 @@
91F77E841539342A00F8AE05 /* Images */ = {
isa = PBXGroup;
children = (
+ 91483B37157463D200FC195E /* fly.png */,
+ 91483B38157463D200FC195E /* fly@2x.png */,
91F77E851539342A00F8AE05 /* clear256.png */,
91F77E871539342A00F8AE05 /* grid256.png */,
9109E03B153D86100008286D /* star1.png */,
@@ -339,6 +349,8 @@
91C9979E1549DBD400B69A8A /* Shader.vsh in Resources */,
91C997601548E21400B69A8A /* Icon144.png in Resources */,
91C997621548E22E00B69A8A /* Icon72.png in Resources */,
+ 91483B39157463D200FC195E /* fly.png in Resources */,
+ 91483B3A157463D200FC195E /* fly@2x.png in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
@@ -11,6 +11,8 @@
#import "RABoundingSphere.h"
+extern NSString * RACameraStateChangedNotification;
+
@interface RACamera : NSObject
@@ -23,4 +25,6 @@
- (void)calculateProjectionForBounds:(RABoundingSphere *)bound;
+- (void)followCamera:(RACamera *)primary;
+
@end
View
@@ -8,6 +8,9 @@
#import "RACamera.h"
+
+NSString * RACameraStateChangedNotification = @"RACameraStateChangedNotification";
+
@implementation RACamera
@synthesize modelViewMatrix=_modelViewMatrix;
@@ -25,6 +28,23 @@ - (id)init
return self;
}
+- (void)dealloc {
+ [[NSNotificationCenter defaultCenter] removeObserver:self];
+}
+
+- (void)stateUpdated {
+ [[NSNotificationCenter defaultCenter] postNotificationName:RACameraStateChangedNotification object:self];
+}
+
+- (GLKMatrix4)modelViewMatrix {
+ return _modelViewMatrix;
+}
+
+- (void)setModelViewMatrix:(GLKMatrix4)modelViewMatrix {
+ _modelViewMatrix = modelViewMatrix;
+ [self stateUpdated];
+}
+
- (void)calculateProjectionForBounds:(RABoundingSphere *)bound {
float aspect = fabsf(viewport.size.width / viewport.size.height);
@@ -38,4 +58,14 @@ - (void)calculateProjectionForBounds:(RABoundingSphere *)bound {
_tanThetaOverTwo = tan(GLKMathDegreesToRadians(self.fieldOfView)/2.);
}
+- (void)followCamera:(RACamera *)primary {
+ [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(followCameraFromNotification:) name:RACameraStateChangedNotification object:primary];
+}
+
+- (void)followCameraFromNotification:(NSNotification *)note {
+ RACamera * primary = note.object;
+
+ [self setModelViewMatrix:primary.modelViewMatrix];
+}
+
@end
View
@@ -9,12 +9,11 @@
#import <Foundation/Foundation.h>
#import <GLKit/GLKit.h>
+#import <CoreLocation/CoreLocation.h>
#import "RACamera.h"
#import "RAGeographicUtils.h"
-extern NSString * RAManipulatorStateChangedNotification;
-
@interface RAManipulator : NSObject <UIGestureRecognizerDelegate>
@@ -29,6 +28,8 @@ extern NSString * RAManipulatorStateChangedNotification;
- (void)addGesturesToView:(UIView *)view;
-- (GLKMatrix4)modelViewMatrix;
+//- (GLKMatrix4)modelViewMatrix;
+
+- (void)flyToRegion:(CLRegion *)region;
@end
View
@@ -18,8 +18,6 @@
static const CGFloat kAnimationDuration = 1.0f;
static const CGFloat kMinimumAnimatedAngle = 2.0f;
-NSString * RAManipulatorStateChangedNotification = @"RAManipulatorStateChangedNotification";
-
typedef struct {
double latitude; // all angles in degrees
@@ -79,10 +77,6 @@ - (void)addGesturesToView:(UIView *)view {
[view addGestureRecognizer:stopRecognizer];
}
-- (void)stateUpdated {
- [[NSNotificationCenter defaultCenter] postNotificationName:RAManipulatorStateChangedNotification object:self];
-}
-
- (double)latitude {
return _state.latitude;
}
@@ -91,7 +85,7 @@ - (void)setLatitude:(double)latitude {
NSAssert( !isnan(latitude), @"angle cannot be NAN" );
_state.latitude = NormalizeLatitude(latitude);
- [self stateUpdated];
+ [self updateCamera];
}
- (double)longitude {
@@ -102,7 +96,7 @@ - (void)setLongitude:(double)longitude {
NSAssert( !isnan(longitude), @"angle cannot be NAN" );
_state.longitude = NormalizeLongitude(longitude);
- [self stateUpdated];
+ [self updateCamera];
}
- (double)azimuth {
@@ -113,7 +107,7 @@ - (void)setAzimuth:(double)azimuth {
NSAssert( !isnan(azimuth), @"angle cannot be NAN" );
_state.azimuth = NormalizeLongitude(azimuth);
- [self stateUpdated];
+ [self updateCamera];
}
- (double)elevation {
@@ -126,7 +120,7 @@ - (void)setElevation:(double)elevation {
if ( elevation > 90. ) elevation = 90.;
_state.elevation = elevation;
- [self stateUpdated];
+ [self updateCamera];
}
- (double)distance {
@@ -139,7 +133,36 @@ - (void)setDistance:(double)distance {
if ( distance > 1.e7 ) distance = 1.e7;
_state.distance = distance;
- [self stateUpdated];
+ [self updateCamera];
+}
+
+- (void)flyToRegion:(CLRegion *)region {
+ const double duration = 4.0;
+
+ // determine the appropriate distance in order to see the entire region
+ double distance = region.radius / self.camera.tanThetaOverTwo;
+
+ // zoom in to that location
+ TPPropertyAnimation *anim = [TPPropertyAnimation propertyAnimationWithKeyPath:@"latitude"];
+ anim.duration = duration;
+ anim.fromValue = [NSNumber numberWithDouble:_state.latitude];
+ anim.toValue = [NSNumber numberWithDouble:region.center.latitude];
+ anim.timing = TPPropertyAnimationTimingEaseInEaseOut;
+ [anim beginWithTarget:self];
+
+ anim = [TPPropertyAnimation propertyAnimationWithKeyPath:@"longitude"];
+ anim.duration = duration;
+ anim.fromValue = [NSNumber numberWithDouble:_state.longitude];
+ anim.toValue = [NSNumber numberWithDouble:region.center.longitude];
+ anim.timing = TPPropertyAnimationTimingEaseInEaseOut;
+ [anim beginWithTarget:self];
+
+ anim = [TPPropertyAnimation propertyAnimationWithKeyPath:@"distance"];
+ anim.duration = duration;
+ anim.fromValue = [NSNumber numberWithDouble:_state.distance];
+ anim.toValue = [NSNumber numberWithDouble:distance];
+ anim.timing = TPPropertyAnimationTimingEaseInEaseOut;
+ [anim beginWithTarget:self];
}
- (GLKMatrix4)modelViewMatrixForState:(CameraState)aState {
@@ -154,8 +177,6 @@ - (GLKMatrix4)modelViewMatrixForState:(CameraState)aState {
perspective = GLKMatrix4Rotate(perspective, self.azimuth * (M_PI/180.), 0, 0, 1);
GLKMatrix4 modelView = GLKMatrix4Multiply(perspective, surfaceTransform);
- //NSLog(@"ModelView: %@", [self stringFromMatrix:renderVisitor.projectionMatrix], [self stringFromMatrix:modelView]);
-
return modelView;
}
@@ -184,8 +205,9 @@ - (BOOL)intersectPoint:(CGPoint)point atLatitude:(double*)lat atLongitude:(doubl
return NO;
}
-- (GLKMatrix4)modelViewMatrix {
- return [self modelViewMatrixForState:_state];
+- (void)updateCamera {
+ // !!! how do we collalesce calls to this?
+ self.camera.modelViewMatrix = [self modelViewMatrixForState:_state];
}
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
@@ -209,7 +231,7 @@ - (void)scale:(id)sender {
case UIGestureRecognizerStateCancelled:
case UIGestureRecognizerStateFailed:
_state = startState;
- [self stateUpdated];
+ [self updateCamera];
break;
case UIGestureRecognizerStateBegan:
[self stop:nil];
@@ -262,7 +284,7 @@ - (void)move:(id)sender {
case UIGestureRecognizerStateCancelled:
case UIGestureRecognizerStateFailed:
_state = startState;
- [self stateUpdated];
+ [self updateCamera];
break;
case UIGestureRecognizerStateBegan:
{
@@ -442,11 +464,12 @@ - (void)zoomToLocation:(id)sender {
double lat, lon;
// get the current touch position on the globe
- [self intersectPoint:pt atLatitude:&lat atLongitude:&lon withState:_state];
+ if ( [self intersectPoint:pt atLatitude:&lat atLongitude:&lon withState:_state] == NO )
+ return;
//printf("Zoom from %f %f to: %f %f\n", _state.latitude, _state.longitude, lat, lon);
- double duration = 1.0;
+ const double duration = 1.0;
// zoom in to that location
TPPropertyAnimation *anim = [TPPropertyAnimation propertyAnimationWithKeyPath:@"latitude"];
@@ -13,13 +13,17 @@
#import "RATilePager.h"
#import "RAManipulator.h"
-@interface RASceneGraphController : UIViewController <GLKViewDelegate>
+@interface RASceneGraphController : UIViewController <GLKViewDelegate, UITextFieldDelegate>
-@property (readonly) EAGLContext * context;
+@property (strong) EAGLContext * context;
+@property (strong, nonatomic) IBOutlet GLKView * glView;
+@property (strong, nonatomic) IBOutlet UITextField * flyToLocationField;
-@property (readonly, nonatomic) RANode * sceneRoot;
-@property (readonly, nonatomic) RACamera * camera;
-@property (readonly, nonatomic) RATilePager * pager;
-@property (readonly, nonatomic) RAManipulator * manipulator;
+@property (strong, nonatomic) RANode * sceneRoot;
+@property (strong, nonatomic) RACamera * camera;
+@property (strong, nonatomic) RATilePager * pager;
+@property (strong, nonatomic) RAManipulator * manipulator;
+
+- (IBAction)flyToLocationFrom:(id)sender;
@end
Oops, something went wrong.

0 comments on commit e6c8405

Please sign in to comment.