Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Latest commit

 

History

History
88 lines (63 loc) · 1.78 KB

SDLUIAccelerationDelegate.m

File metadata and controls

88 lines (63 loc) · 1.78 KB
 
1
2
3
4
5
6
7
8
9
//
// SDLUIAccelerationDelegate.m
// iPodSDL
//
// Created by Holmes Futrell on 6/21/08.
// Copyright 2008 __MyCompanyName__. All rights reserved.
//
#import "SDLUIAccelerationDelegate.h"
Aug 15, 2008
Aug 15, 2008
10
#import "../../../include/SDL_config_iphoneos.h"
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
static SDLUIAccelerationDelegate *sharedDelegate=nil;
@implementation SDLUIAccelerationDelegate
+(SDLUIAccelerationDelegate *)sharedDelegate {
if (sharedDelegate == nil) {
sharedDelegate = [[SDLUIAccelerationDelegate alloc] init];
}
return sharedDelegate;
}
-(void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration {
x = acceleration.x;
y = acceleration.y;
z = acceleration.z;
hasNewData = YES;
//timestamp = acceleration.timestamp;
}
-(void)getLastOrientation:(Sint16 *)data {
Aug 15, 2008
Aug 15, 2008
36
#define MAX_SINT16 0x7FFF
Aug 15, 2008
Aug 15, 2008
38
39
if (x > SDL_IPHONE_MAX_GFORCE) x = SDL_IPHONE_MAX_GFORCE;
else if (x < -SDL_IPHONE_MAX_GFORCE) x = -SDL_IPHONE_MAX_GFORCE;
Aug 15, 2008
Aug 15, 2008
41
42
if (y > SDL_IPHONE_MAX_GFORCE) y = SDL_IPHONE_MAX_GFORCE;
else if (y < -SDL_IPHONE_MAX_GFORCE) y = -SDL_IPHONE_MAX_GFORCE;
Aug 15, 2008
Aug 15, 2008
44
45
if (z > SDL_IPHONE_MAX_GFORCE) z = SDL_IPHONE_MAX_GFORCE;
else if (z < -SDL_IPHONE_MAX_GFORCE) z = -SDL_IPHONE_MAX_GFORCE;
Aug 15, 2008
Aug 15, 2008
47
48
49
data[0] = (x / SDL_IPHONE_MAX_GFORCE) * MAX_SINT16;
data[1] = (y / SDL_IPHONE_MAX_GFORCE) * MAX_SINT16;
data[2] = (z / SDL_IPHONE_MAX_GFORCE) * MAX_SINT16;
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
}
-(id)init {
self = [super init];
x = y = z = 0.0;
return self;
}
-(void)dealloc {
sharedDelegate = nil;
[super dealloc];
}
-(void)startup {
[UIAccelerometer sharedAccelerometer].delegate = self;
isRunning = YES;
}
-(void)shutdown {
[UIAccelerometer sharedAccelerometer].delegate = nil;
isRunning = NO;
}
-(BOOL)isRunning {
return isRunning;
}
-(BOOL)hasNewData {
return hasNewData;
}
-(void)setHasNewData:(BOOL)value {
hasNewData = value;
}
@end