Augmented reality: a physics engine for mobile - part 1

by James Diacono 19. January 2011 06:01

TheFARM has recently been working intensively on an AR (augmented reality) app for the iPhone.  We were tasked with overlaying geopoints on the phone’s screen, like all these apps do.

So, given a geolocation x (containing a latitude, longitude and altitude), how does that end up on the screen in the right place?  This is how we did it:

1. Given x and the phone’s current geoposition, compute the vector x, which describes x’s position relative to the phone.  x consists of a heading, an elevation and a distance.

RelativePosition


2. Find the orientation of the phone’s camera, c, which consists of a heading, an elevation and a rotation (this rotation being what makes a photo portrait or landscape).

CameraOrientation


3. Find the screen vector s, which is the deviation of x’s direction relative to cs consists of a deviation (the angle between x and c) and a rotation (x’s rotation around c).  This allows you to deal with positions on the screen in a very natural way, leaving pixels to the last moment.

ScreenVector


4. Render x on the screen using x, c and s.

FieldOfView'


I’m going to be writing this up in Objective-C (the language of iOS/iPhone and OSX) but its very general stuff.

So! First things first. 

1. Type definitions

typedef struct {
double heading;
double elevation;
double distance;
} RelativePosition;

typedef struct {
double heading;
double elevation;
double rotation;
} CameraOrientation;

typedef struct {
double rotation;
double deviation;
} ScreenVector;

2. Interface

@interface Utilities : NSObject

+ (RelativePosition) getRelativePositionOfB:(CLLocation *)b
toA:(CLLocation *)a;

+ (CameraOrientation) getCameraOrientationFromMotion:(CMMotionManager *)motionManager
andHeading:(CLHeading *)heading;

+ (ScreenVector) getScreenVectorOfPosition:(RelativePosition)position
fromCamera:(CameraOrientation)camera;

+ (void) renderView:(UIView *)view
inFrame:(CGRect)frame
fromRelativePosition:(RelativePosition)position
andCameraOrientation:(CameraOrientation)camera
andScreenVector:(ScreenVector)screenVector;


@end

 
3. Implementation
…That’s part 2.  Still, having this structure makes things a breeze.  Happy augmenting!
Categories: iPhone

Comments

6/2/2011 8:26:09 AM #

Hi, is the part 2 to this on the way? I am very much looking forward to it.

Agaton United Kingdom