3 weeks ago my computer failed. I'm behind on hard coding as I just finished setting up my computer when I got it back from my builder. I was attempting to set up a SQL database using a private network I had set up through "Lion Server" and SQL pro, but my bootfiles somehow got switched into my private network and my computer wouldn't turn on, my profile was lost and my harddrives became inaccessible.
Also when I updated to iOS 5.1 (4g service) I lost my keychain certificate which allows for developing and testing through the iphone. I can't test any hardware APIs (ex camcorder, gyroscope etc.) without getting my certifications back in order.
AR Spaceships Script Example:
Hello World Layer.m - Uses Cocos 2D API
#import "HelloWorldLayer.h"
#include <stdlib.h>
#import "SimpleAudioEngine.h"
// HelloWorldLayer implementation
@implementation HelloWorldLayer
@synthesize motionManager;
@synthesize enemyCount;
#define kXPositionMultiplier 15
#define kTimeToLive 100
+(CCScene *) scene
{
// 'scene' is an autorelease object.
CCScene *scene = [CCScene node];
// 'layer' is an autorelease object.
HelloWorldLayer *layer = [HelloWorldLayer node];
// add layer as a child to scene
[scene addChild: layer];
// return the scene
return scene;
}
// on "init" you need to initialize your instance
-(id) init {
if((self=[super init])) {
// add and position the labels
/*yawLabel = [CCLabelTTF labelWithString:@"Yaw: " fontName:@"Marker Felt" fontSize:12];
posIn360Label = [CCLabelTTF labelWithString:@"360Pos: " fontName:@"Marker Felt" fontSize:12];
yawLabel.position = ccp(50, 240);
posIn360Label.position = ccp(50, 300);
[self addChild: yawLabel];
[self addChild:posIn360Label];*/
self.motionManager = [[[CMMotionManager alloc] init] autorelease];
motionManager.deviceMotionUpdateInterval = 1.0/60.0;
if (motionManager.isDeviceMotionAvailable) {
[motionManager startDeviceMotionUpdates];
}
[self scheduleUpdate];
batchNode = [CCSpriteBatchNode batchNodeWithFile:@"Sprites.pvr.ccz"];
[self addChild:batchNode];
[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@"Sprites.plist"];
// Loop through 1 - 5 and add space ships
enemySprites = [[NSMutableArray alloc] init];
for(int i = 0; i < 5; ++i) {
EnemyShip *enemyShip = [self addEnemyShip:i];
[enemySprites addObject:enemyShip];
enemyCount += 1;
}
CCSprite *scope = [CCSprite spriteWithFile:@"scope.png"];
scope.position = ccp(240, 160);
[self addChild:scope z:15];
// Allow touches with the layer
[self registerWithTouchDispatcher];
[[SimpleAudioEngine sharedEngine] playBackgroundMusic:@"SpaceGame.caf" loop:YES];
[[SimpleAudioEngine sharedEngine] preloadEffect:@"explosion_large.caf"];
[[SimpleAudioEngine sharedEngine] preloadEffect:@"laser_ship.caf"];
}
return self;
}
-(void)update:(ccTime)delta {
CMDeviceMotion *currentDeviceMotion = motionManager.deviceMotion;
CMAttitude *currentAttitude = currentDeviceMotion.attitude;
// Convert the radians yaw value to degrees then round up/down
float yaw = roundf((float)(CC_RADIANS_TO_DEGREES(currentAttitude.yaw)));
// Convert the degrees value to float and use Math function to round the value
//[yawLabel setString:[NSString stringWithFormat:@"Yaw: %.0f", yaw]];
// Convert the yaw value to a value in the range of 0 to 360
int positionIn360 = yaw;
if (positionIn360 < 0) {
positionIn360 = 360 + positionIn360;
}
//[posIn360Label setString:[NSString stringWithFormat:@"360Pos: %d", positionIn360]];
for (EnemyShip *enemyShip in enemySprites) {
[self checkEnemyShipPosition:enemyShip withYaw:yaw];
}
for (EnemyShip *enemyShip in enemySprites) {
enemyShip.timeToLive--;
if (enemyShip.timeToLive == 0) {
int x = arc4random() % 360;
[enemyShip setPosition:ccp(5000, 160)];
enemyShip.yawPosition = x;
enemyShip.timeToLive = kTimeToLive;
}
}
}
-(EnemyShip *)addEnemyShip:(int)shipTag {
EnemyShip *enemyShip = [EnemyShip spriteWithSpriteFrameName:@"enemy_spaceship.png"];
// Set position of the space ship randomly
int x = arc4random() % 360;
enemyShip.yawPosition = x;
// Set the position of the space ship off the screen, but in the center of the y axis
// we will update it in another method
[enemyShip setPosition:ccp(5000, 160)];
// Set time to live on the space ship
enemyShip.timeToLive = kTimeToLive;
enemyShip.visible = true;
[batchNode addChild:enemyShip z:3 tag:shipTag];
return enemyShip;
}
-(void)checkEnemyShipPosition:(EnemyShip *)enemyShip withYaw:(float)yawPosition {
// Convert the yaw value to a value in the range of 0 to 360
int positionIn360 = yawPosition;
if (positionIn360 < 0) {
positionIn360 = 360 + positionIn360;
}
BOOL checkAlternateRange = false;
// Determine the minimum position for enemy ship
int rangeMin = positionIn360 - 23;
if (rangeMin < 0) {
rangeMin = 360 + rangeMin;
checkAlternateRange = true;
}
// Determine the maximum position for the enemy ship
int rangeMax = positionIn360 + 23;
if (rangeMax > 360) {
rangeMax = rangeMax - 360;
checkAlternateRange = true;
}
if (checkAlternateRange) {
if ((enemyShip.yawPosition < rangeMax || enemyShip.yawPosition > rangeMin ) || (enemyShip.yawPosition > rangeMin || enemyShip.yawPosition < rangeMax)) {
[self updateEnemyShipPosition:positionIn360 withEnemy:enemyShip];
}
} else {
if (enemyShip.yawPosition > rangeMin && enemyShip.yawPosition < rangeMax) {
[self updateEnemyShipPosition:positionIn360 withEnemy:enemyShip];
}
}
}
-(void)updateEnemyShipPosition:(int)positionIn360 withEnemy:(EnemyShip *)enemyShip {
int difference = 0;
if (positionIn360 < 23) {
// Run 1
if (enemyShip.yawPosition > 337) {
difference = (360 - enemyShip.yawPosition) + positionIn360;
int xPosition = 240 + (difference * kXPositionMultiplier);
[enemyShip setPosition:ccp(xPosition, enemyShip.position.y)];
} else {
// Run Standard Position Check
[self runStandardPositionCheck:positionIn360 withDiff:difference withEnemy:enemyShip];
}
} else if(positionIn360 > 337) {
// Run 2
if (enemyShip.yawPosition < 23) {
difference = enemyShip.yawPosition + (360 - positionIn360);
int xPosition = 240 - (difference * kXPositionMultiplier);
[enemyShip setPosition:ccp(xPosition, enemyShip.position.y)];
} else {
// Run Standard Position Check
[self runStandardPositionCheck:positionIn360 withDiff:difference withEnemy:enemyShip];
}
} else {
// Run Standard Position Check
[self runStandardPositionCheck:positionIn360 withDiff:difference withEnemy:enemyShip];
}
}
-(void)runStandardPositionCheck:(int)positionIn360 withDiff:(int)difference withEnemy:(EnemyShip *)enemyShip {
// This method checks if the enemyShip position is to the left or right of the
// device's positionIn360 when the positionIn360 fall within the range of 34 to 337
if (enemyShip.yawPosition > positionIn360) {
difference = enemyShip.yawPosition - positionIn360;
int xPosition = 240 - (difference * kXPositionMultiplier);
[enemyShip setPosition:ccp(xPosition, enemyShip.position.y)];
} else {
difference = positionIn360 - enemyShip.yawPosition;
int xPosition = 240 + (difference * kXPositionMultiplier);
[enemyShip setPosition:ccp(xPosition, enemyShip.position.y)];
}
}
- (BOOL) circle:(CGPoint) circlePoint withRadius:(float) radius collisionWithCircle:(CGPoint) circlePointTwo collisionCircleRadius:(float) radiusTwo {
float xdif = circlePoint.x - circlePointTwo.x;
float ydif = circlePoint.y - circlePointTwo.y;
float distance = sqrt(xdif*xdif+ydif*ydif);
if(distance <= radius+radiusTwo) return YES;
return NO;
}
-(void)ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
[[SimpleAudioEngine sharedEngine] playEffect:@"laser_ship.caf"];
CGPoint location = CGPointMake(240,160);
// 1
for (EnemyShip *enemyShip in enemySprites) {
if (enemyShip.timeToLive > 0) {
// Check to see if yaw position is in range
BOOL wasTouched = [self circle:location withRadius:50 collisionWithCircle:enemyShip.position collisionCircleRadius:50];
if (wasTouched) {
[[SimpleAudioEngine sharedEngine] playEffect:@"explosion_large.caf"];
enemyShip.timeToLive = 0;
enemyShip.visible = false;
enemyCount -= 1;
}
}
}
// 2
CCParticleSystemQuad *particle = [CCParticleSystemQuad particleWithFile:@"Explosion.plist"];
particle.position = ccp(240,160);
[self addChild:particle z:20];
particle.autoRemoveOnFinish = YES;
// 3
if (enemyCount == 0) {
// Show end game
CGSize winSize = [CCDirector sharedDirector].winSize;
CCLabelBMFont *label = [CCLabelBMFont labelWithString:@"You win!" fntFile:@"Arial.fnt"];
label.scale = 2.0;
label.position = ccp(winSize.width/2, winSize.height/2);
[self addChild:label z:30];
}
}
// on "dealloc" you need to release all your retained objects
- (void) dealloc
{
// in case you have something to dealloc, do it in this method
// in this particular example nothing needs to be released.
// cocos2d will automatically release all the children (Label)
[enemySprites release];
// don't forget to call "super dealloc"
[super dealloc];
}
@end
pARk. Ex. - 4D projection matrix with locked gps data
#import "ARView.h" |
#import "PlaceOfInterest.h" |
#import <AVFoundation/AVFoundation.h> |
#pragma mark - |
#pragma mark Math utilities declaration |
#define DEGREES_TO_RADIANS (M_PI/180.0) |
typedef float mat4f_t[16]; // 4x4 matrix in column major order |
typedef float vec4f_t[4]; // 4D vector |
// Creates a projection matrix using the given y-axis field-of-view, aspect ratio, and near and far clipping planes |
void createProjectionMatrix(mat4f_t mout, float fovy, float aspect, float zNear, float zFar); |
// Matrix-vector and matrix-matricx multiplication routines |
void multiplyMatrixAndVector(vec4f_t vout, const mat4f_t m, const vec4f_t v); |
void multiplyMatrixAndMatrix(mat4f_t c, const mat4f_t a, const mat4f_t b); |
// Initialize mout to be an affine transform corresponding to the same rotation specified by m |
void transformFromCMRotationMatrix(vec4f_t mout, const CMRotationMatrix *m); |
#pragma mark - |
#pragma mark Geodetic utilities declaration |
#define WGS84_A (6378137.0) // WGS 84 semi-major axis constant in meters |
#define WGS84_E (8.1819190842622e-2) // WGS 84 eccentricity |
// Converts latitude, longitude to ECEF coordinate system |
void latLonToEcef(double lat, double lon, double alt, double *x, double *y, double *z); |
// Coverts ECEF to ENU coordinates centered at given lat, lon |
void ecefToEnu(double lat, double lon, double x, double y, double z, double xr, double yr, double zr, double *e, double *n, double *u); |
#pragma mark - |
#pragma mark ARView extension |
@interface ARView () { |
UIView *captureView; |
AVCaptureSession *captureSession; |
AVCaptureVideoPreviewLayer *captureLayer; |
CADisplayLink *displayLink; |
CMMotionManager *motionManager; |
CLLocationManager *locationManager; |
CLLocation *location; |
NSArray *placesOfInterest; |
mat4f_t projectionTransform; |
mat4f_t cameraTransform; |
vec4f_t *placesOfInterestCoordinates; |
} |
- (void)initialize; |
- (void)startCameraPreview; |
- (void)stopCameraPreview; |
- (void)startLocation; |
- (void)stopLocation; |
- (void)startDeviceMotion; |
- (void)stopDeviceMotion; |
- (void)startDisplayLink; |
- (void)stopDisplayLink; |
- (void)updatePlacesOfInterestCoordinates; |
- (void)onDisplayLink:(id)sender; |
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation; |
@end |
#pragma mark - |
#pragma mark ARView implementation |
@implementation ARView |
@dynamic placesOfInterest; |
- (void)dealloc |
{ |
[self stop]; |
[placesOfInterest release]; |
[location release]; |
[captureView removeFromSuperview]; |
[captureView release]; |
if (placesOfInterestCoordinates != NULL) { |
free(placesOfInterestCoordinates); |
} |
[super dealloc]; |
} |
- (void)start |
{ |
[self startCameraPreview]; |
[self startLocation]; |
[self startDeviceMotion]; |
[self startDisplayLink]; |
} |
- (void)stop |
{ |
[self stopCameraPreview]; |
[self stopLocation]; |
[self stopDeviceMotion]; |
[self stopDisplayLink]; |
} |
- (void)setPlacesOfInterest:(NSArray *)pois |
{ |
for (PlaceOfInterest *poi in [placesOfInterest objectEnumerator]) { |
[poi.view removeFromSuperview]; |
} |
[placesOfInterest release]; |
placesOfInterest = [pois retain]; |
if (location != nil) { |
[self updatePlacesOfInterestCoordinates]; |
} |
} |
- (NSArray *)placesOfInterest |
{ |
return placesOfInterest; |
} |
- (void)initialize |
{ |
captureView = [[UIView alloc] initWithFrame:self.bounds]; |
captureView.bounds = self.bounds; |
[self addSubview:captureView]; |
[self sendSubviewToBack:captureView]; |
// Initialize projection matrix |
createProjectionMatrix(projectionTransform, 60.0f*DEGREES_TO_RADIANS, self.bounds.size.width*1.0f / self.bounds.size.height, 0.25f, 1000.0f); |
} |
- (void)startCameraPreview |
{ |
AVCaptureDevice* camera = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo]; |
if (camera == nil) { |
return; |
} |
captureSession = [[AVCaptureSession alloc] init]; |
AVCaptureDeviceInput *newVideoInput = [[[AVCaptureDeviceInput alloc] initWithDevice:camera error:nil] autorelease]; |
[captureSession addInput:newVideoInput]; |
captureLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:captureSession]; |
captureLayer.frame = captureView.bounds; |
[captureLayer setOrientation:AVCaptureVideoOrientationPortrait]; |
[captureLayer setVideoGravity:AVLayerVideoGravityResizeAspectFill]; |
[captureView.layer addSublayer:captureLayer]; |
// Start the session. This is done asychronously since -startRunning doesn't return until the session is running. |
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ |
[captureSession startRunning]; |
}); |
} |
- (void)stopCameraPreview |
{ |
[captureSession stopRunning]; |
[captureLayer removeFromSuperlayer]; |
[captureSession release]; |
[captureLayer release]; |
captureSession = nil; |
captureLayer = nil; |
} |
- (void)startLocation |
{ |
[locationManager release]; |
locationManager = [[CLLocationManager alloc] init]; |
locationManager.delegate = self; |
locationManager.distanceFilter = 100.0; |
[locationManager startUpdatingLocation]; |
} |
- (void)stopLocation |
{ |
[locationManager stopUpdatingLocation]; |
[locationManager release]; |
locationManager = nil; |
} |
- (void)startDeviceMotion |
{ |
motionManager = [[CMMotionManager alloc] init]; |
// Tell CoreMotion to show the compass calibration HUD when required to provide true north-referenced attitude |
motionManager.showsDeviceMovementDisplay = YES; |
motionManager.deviceMotionUpdateInterval = 1.0 / 60.0; |
// New in iOS 5.0: Attitude that is referenced to true north |
[motionManager startDeviceMotionUpdatesUsingReferenceFrame:CMAttitudeReferenceFrameXTrueNorthZVertical]; |
} |
- (void)stopDeviceMotion |
{ |
[motionManager stopDeviceMotionUpdates]; |
[motionManager release]; |
motionManager = nil; |
} |
- (void)startDisplayLink |
{ |
displayLink = [[CADisplayLink displayLinkWithTarget:self selector:@selector(onDisplayLink:)] retain]; |
[displayLink setFrameInterval:1]; |
[displayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode]; |
} |
- (void)stopDisplayLink |
{ |
[displayLink invalidate]; |
[displayLink release]; |
displayLink = nil; |
} |
- (void)updatePlacesOfInterestCoordinates |
{ |
if (placesOfInterestCoordinates != NULL) { |
free(placesOfInterestCoordinates); |
} |
placesOfInterestCoordinates = (vec4f_t *)malloc(sizeof(vec4f_t)*placesOfInterest.count); |
int i = 0; |
double myX, myY, myZ; |
latLonToEcef(location.coordinate.latitude, location.coordinate.longitude, 0.0, &myX, &myY, &myZ); |
// Array of NSData instances, each of which contains a struct with the distance to a POI and the |
// POI's index into placesOfInterest |
// Will be used to ensure proper Z-ordering of UIViews |
typedef struct { |
float distance; |
int index; |
} DistanceAndIndex; |
NSMutableArray *orderedDistances = [NSMutableArray arrayWithCapacity:placesOfInterest.count]; |
// Compute the world coordinates of each place-of-interest |
for (PlaceOfInterest *poi in [[self placesOfInterest] objectEnumerator]) { |
double poiX, poiY, poiZ, e, n, u; |
latLonToEcef(poi.location.coordinate.latitude, poi.location.coordinate.longitude, 0.0, &poiX, &poiY, &poiZ); |
ecefToEnu(location.coordinate.latitude, location.coordinate.longitude, myX, myY, myZ, poiX, poiY, poiZ, &e, &n, &u); |
placesOfInterestCoordinates[i][0] = (float)n; |
placesOfInterestCoordinates[i][1]= -(float)e; |
placesOfInterestCoordinates[i][2] = 0.0f; |
placesOfInterestCoordinates[i][3] = 1.0f; |
// Add struct containing distance and index to orderedDistances |
DistanceAndIndex distanceAndIndex; |
distanceAndIndex.distance = sqrtf(n*n + e*e); |
distanceAndIndex.index = i; |
[orderedDistances insertObject:[NSData dataWithBytes:&distanceAndIndex length:sizeof(distanceAndIndex)] atIndex:i++]; |
} |
// Sort orderedDistances in ascending order based on distance from the user |
[orderedDistances sortUsingComparator:(NSComparator)^(NSData *a, NSData *b) { |
const DistanceAndIndex *aData = (const DistanceAndIndex *)a.bytes; |
const DistanceAndIndex *bData = (const DistanceAndIndex *)b.bytes; |
if (aData->distance < bData->distance) { |
return NSOrderedAscending; |
} else if (aData->distance > bData->distance) { |
return NSOrderedDescending; |
} else { |
return NSOrderedSame; |
} |
}]; |
// Add subviews in descending Z-order so they overlap properly |
for (NSData *d in [orderedDistances reverseObjectEnumerator]) { |
const DistanceAndIndex *distanceAndIndex = (const DistanceAndIndex *)d.bytes; |
PlaceOfInterest *poi = (PlaceOfInterest *)[placesOfInterest objectAtIndex:distanceAndIndex->index]; |
[self addSubview:poi.view]; |
} |
} |
- (void)onDisplayLink:(id)sender |
{ |
CMDeviceMotion *d = motionManager.deviceMotion; |
if (d != nil) { |
CMRotationMatrix r = d.attitude.rotationMatrix; |
transformFromCMRotationMatrix(cameraTransform, &r); |
[self setNeedsDisplay]; |
} |
} |
- (void)drawRect:(CGRect)rect |
{ |
if (placesOfInterestCoordinates == nil) { |
return; |
} |
mat4f_t projectionCameraTransform; |
multiplyMatrixAndMatrix(projectionCameraTransform, projectionTransform, cameraTransform); |
int i = 0; |
for (PlaceOfInterest *poi in [placesOfInterest objectEnumerator]) { |
vec4f_t v; |
multiplyMatrixAndVector(v, projectionCameraTransform, placesOfInterestCoordinates[i]); |
float x = (v[0] / v[3] + 1.0f) * 0.5f; |
float y = (v[1] / v[3] + 1.0f) * 0.5f; |
if (v[2] < 0.0f) { |
poi.view.center = CGPointMake(x*self.bounds.size.width, self.bounds.size.height-y*self.bounds.size.height); |
poi.view.hidden = NO; |
} else { |
poi.view.hidden = YES; |
} |
i++; |
} |
} |
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation |
{ |
[location release]; |
location = [newLocation retain]; |
if (placesOfInterest != nil) { |
[self updatePlacesOfInterestCoordinates]; |
} |
} |
- (id)initWithFrame:(CGRect)frame |
{ |
self = [super initWithFrame:frame]; |
if (self) { |
[self initialize]; |
} |
return self; |
} |
- (id)initWithCoder:(NSCoder *)aDecoder |
{ |
self = [super initWithCoder:aDecoder]; |
if (self) { |
[self initialize]; |
} |
return self; |
} |
@end |
#pragma mark - |
#pragma mark Math utilities definition |
// Creates a projection matrix using the given y-axis field-of-view, aspect ratio, and near and far clipping planes |
void createProjectionMatrix(mat4f_t mout, float fovy, float aspect, float zNear, float zFar) |
{ |
float f = 1.0f / tanf(fovy/2.0f); |
mout[0] = f / aspect; |
mout[1] = 0.0f; |
mout[2] = 0.0f; |
mout[3] = 0.0f; |
mout[4] = 0.0f; |
mout[5] = f; |
mout[6] = 0.0f; |
mout[7] = 0.0f; |
mout[8] = 0.0f; |
mout[9] = 0.0f; |
mout[10] = (zFar+zNear) / (zNear-zFar); |
mout[11] = -1.0f; |
mout[12] = 0.0f; |
mout[13] = 0.0f; |
mout[14] = 2 * zFar * zNear / (zNear-zFar); |
mout[15] = 0.0f; |
} |
// Matrix-vector and matrix-matricx multiplication routines |
void multiplyMatrixAndVector(vec4f_t vout, const mat4f_t m, const vec4f_t v) |
{ |
vout[0] = m[0]*v[0] + m[4]*v[1] + m[8]*v[2] + m[12]*v[3]; |
vout[1] = m[1]*v[0] + m[5]*v[1] + m[9]*v[2] + m[13]*v[3]; |
vout[2] = m[2]*v[0] + m[6]*v[1] + m[10]*v[2] + m[14]*v[3]; |
vout[3] = m[3]*v[0] + m[7]*v[1] + m[11]*v[2] + m[15]*v[3]; |
} |
void multiplyMatrixAndMatrix(mat4f_t c, const mat4f_t a, const mat4f_t b) |
{ |
uint8_t col, row, i; |
memset(c, 0, 16*sizeof(float)); |
for (col = 0; col < 4; col++) { |
for (row = 0; row < 4; row++) { |
for (i = 0; i < 4; i++) { |
c[col*4+row] += a[i*4+row]*b[col*4+i]; |
} |
} |
} |
} |
// Initialize mout to be an affine transform corresponding to the same rotation specified by m |
void transformFromCMRotationMatrix(vec4f_t mout, const CMRotationMatrix *m) |
{ |
mout[0] = (float)m->m11; |
mout[1] = (float)m->m21; |
mout[2] = (float)m->m31; |
mout[3] = 0.0f; |
mout[4] = (float)m->m12; |
mout[5] = (float)m->m22; |
mout[6] = (float)m->m32; |
mout[7] = 0.0f; |
mout[8] = (float)m->m13; |
mout[9] = (float)m->m23; |
mout[10] = (float)m->m33; |
mout[11] = 0.0f; |
mout[12] = 0.0f; |
mout[13] = 0.0f; |
mout[14] = 0.0f; |
mout[15] = 1.0f; |
} |
#pragma mark - |
#pragma mark Geodetic utilities definition |
// References to ECEF and ECEF to ENU conversion may be found on the web. |
// Converts latitude, longitude to ECEF coordinate system |
void latLonToEcef(double lat, double lon, double alt, double *x, double *y, double *z) |
{ |
double clat = cos(lat * DEGREES_TO_RADIANS); |
double slat = sin(lat * DEGREES_TO_RADIANS); |
double clon = cos(lon * DEGREES_TO_RADIANS); |
double slon = sin(lon * DEGREES_TO_RADIANS); |
double N = WGS84_A / sqrt(1.0 - WGS84_E * WGS84_E * slat * slat); |
*x = (N + alt) * clat * clon; |
*y = (N + alt) * clat * slon; |
*z = (N * (1.0 - WGS84_E * WGS84_E) + alt) * slat; |
} |
// Coverts ECEF to ENU coordinates centered at given lat, lon |
void ecefToEnu(double lat, double lon, double x, double y, double z, double xr, double yr, double zr, double *e, double *n, double *u) |
{ |
double clat = cos(lat * DEGREES_TO_RADIANS); |
double slat = sin(lat * DEGREES_TO_RADIANS); |
double clon = cos(lon * DEGREES_TO_RADIANS); |
double slon = sin(lon * DEGREES_TO_RADIANS); |
double dx = x - xr; |
double dy = y - yr; |
double dz = z - zr; |
*e = -slon*dx + clon*dy; |
*n = -slat*clon*dx - slat*slon*dy + clat*dz; |
*u = clat*clon*dx + clat*slon*dy + slat*dz; |
} |
The New View
Combining the two codes together in a way which I can use the UI Actions and Animations with a GPS ([delta x,y,z] will be implemented later once I get a server to work). Instead of the spaceship which has no reference to augmented reality, I'm attaching a transparent square built in an Open GL ES 2.0 (3.0 will be dropping within the next couple months...) which shrinks and expands as one approaches its locked location or retreats. I'd maintain the same UI actions which exist in the cocos layer and apply them to the dynamic perspective square which will eventually be used to represent the wireframe of action area between player to player. I calculated that reality (ref point glasses frame) was 2:1 with the Augmented Frame while the ratio within the iphone viewfinder (even though there are 5 different lenses) decreases linearly. So at twice the distance away, the change of my reference point (a doorframe) decreased linearly by a factor of 2. So far I've broken down all of the variables and parallels between the two codes.
As well I've been writing an open GL ES code which dedicates the 3 variables of gyroscopic attitude (measured in radians) to a specific color spectrum, where all color channels overlap. As one manuevers the ipone around in space, the phone should display the dynamic changes in color spectrum as the attitude varies in space.
Red - Roll
Green - Pitch
Blue - Yaw
Understanding gyroscopic functions will be important when I begin designing methods of Wii style P2P interactions (think some Harry Potter style wand dueling interactions or something). I also intend on installing the iphone into a semi transparant icosohedrin (frosted plexi?) where if the dice is rolled, the attitude of the gyroscope in the phone relays not one the color into open glES view and into RGB leds within the platonic solid.
Here is the video of my roomate Martin Juarez's Light Instrumentation Cube in which I learned, troubleshot, and fixed his code so that it works. I also wrote equations for 4 out of the 5 animations.
No comments:
Post a Comment