Mercurial > sdl-ios-xcode
annotate src/joystick/iphoneos/SDLUIAccelerationDelegate.m @ 2451:28286ecb3f15 gsoc2008_iphone
removed comment about NULL video driver ... it's not null anymore, it's the UIKit video driver.
author | Holmes Futrell <hfutrell@umail.ucsb.edu> |
---|---|
date | Sat, 16 Aug 2008 00:17:18 +0000 |
parents | 78bddf0c0fa2 |
children |
rev | line source |
---|---|
2439
78bddf0c0fa2
Cleaned up code, added comments.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
2427
diff
changeset
|
1 /* |
78bddf0c0fa2
Cleaned up code, added comments.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
2427
diff
changeset
|
2 SDL - Simple DirectMedia Layer |
78bddf0c0fa2
Cleaned up code, added comments.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
2427
diff
changeset
|
3 Copyright (C) 1997-2006 Sam Lantinga |
78bddf0c0fa2
Cleaned up code, added comments.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
2427
diff
changeset
|
4 |
78bddf0c0fa2
Cleaned up code, added comments.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
2427
diff
changeset
|
5 This library is free software; you can redistribute it and/or |
78bddf0c0fa2
Cleaned up code, added comments.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
2427
diff
changeset
|
6 modify it under the terms of the GNU Lesser General Public |
78bddf0c0fa2
Cleaned up code, added comments.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
2427
diff
changeset
|
7 License as published by the Free Software Foundation; either |
78bddf0c0fa2
Cleaned up code, added comments.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
2427
diff
changeset
|
8 version 2.1 of the License, or (at your option) any later version. |
78bddf0c0fa2
Cleaned up code, added comments.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
2427
diff
changeset
|
9 |
78bddf0c0fa2
Cleaned up code, added comments.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
2427
diff
changeset
|
10 This library is distributed in the hope that it will be useful, |
78bddf0c0fa2
Cleaned up code, added comments.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
2427
diff
changeset
|
11 but WITHOUT ANY WARRANTY; without even the implied warranty of |
78bddf0c0fa2
Cleaned up code, added comments.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
2427
diff
changeset
|
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
78bddf0c0fa2
Cleaned up code, added comments.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
2427
diff
changeset
|
13 Lesser General Public License for more details. |
78bddf0c0fa2
Cleaned up code, added comments.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
2427
diff
changeset
|
14 |
78bddf0c0fa2
Cleaned up code, added comments.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
2427
diff
changeset
|
15 You should have received a copy of the GNU Lesser General Public |
78bddf0c0fa2
Cleaned up code, added comments.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
2427
diff
changeset
|
16 License along with this library; if not, write to the Free Software |
78bddf0c0fa2
Cleaned up code, added comments.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
2427
diff
changeset
|
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
78bddf0c0fa2
Cleaned up code, added comments.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
2427
diff
changeset
|
18 |
78bddf0c0fa2
Cleaned up code, added comments.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
2427
diff
changeset
|
19 Sam Lantinga |
78bddf0c0fa2
Cleaned up code, added comments.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
2427
diff
changeset
|
20 slouken@libsdl.org |
78bddf0c0fa2
Cleaned up code, added comments.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
2427
diff
changeset
|
21 */ |
2362
44fc2537ff9e
These files contain the specification for a class which receives updates from the iPhone accelerometer. The class holds the accelerometer information, and is queried by SDL_sysjoystick.m.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff
changeset
|
22 |
44fc2537ff9e
These files contain the specification for a class which receives updates from the iPhone accelerometer. The class holds the accelerometer information, and is queried by SDL_sysjoystick.m.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff
changeset
|
23 #import "SDLUIAccelerationDelegate.h" |
2439
78bddf0c0fa2
Cleaned up code, added comments.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
2427
diff
changeset
|
24 /* needed for SDL_IPHONE_MAX_GFORCE macro */ |
2427
32b9909db651
changed macro MAX_G_FORCE to SDL_IPHONE_MAX_GFORCE and moved it to the SDL_config_iphoneos.h file. This should allow users to convert between the Sint16 returned by polling the joystick and units of g-force, which better describe what is going on with the iPhone (and are what the iPhone OS actually gives you). This conversion wouldn't be necessary except that we'd need floating point to store everything as g-force.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
2362
diff
changeset
|
25 #import "../../../include/SDL_config_iphoneos.h" |
2362
44fc2537ff9e
These files contain the specification for a class which receives updates from the iPhone accelerometer. The class holds the accelerometer information, and is queried by SDL_sysjoystick.m.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff
changeset
|
26 |
44fc2537ff9e
These files contain the specification for a class which receives updates from the iPhone accelerometer. The class holds the accelerometer information, and is queried by SDL_sysjoystick.m.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff
changeset
|
27 static SDLUIAccelerationDelegate *sharedDelegate=nil; |
44fc2537ff9e
These files contain the specification for a class which receives updates from the iPhone accelerometer. The class holds the accelerometer information, and is queried by SDL_sysjoystick.m.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff
changeset
|
28 |
44fc2537ff9e
These files contain the specification for a class which receives updates from the iPhone accelerometer. The class holds the accelerometer information, and is queried by SDL_sysjoystick.m.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff
changeset
|
29 @implementation SDLUIAccelerationDelegate |
44fc2537ff9e
These files contain the specification for a class which receives updates from the iPhone accelerometer. The class holds the accelerometer information, and is queried by SDL_sysjoystick.m.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff
changeset
|
30 |
2439
78bddf0c0fa2
Cleaned up code, added comments.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
2427
diff
changeset
|
31 /* |
78bddf0c0fa2
Cleaned up code, added comments.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
2427
diff
changeset
|
32 Returns a shared instance of the SDLUIAccelerationDelegate, creating the shared delegate if it doesn't exist yet. |
78bddf0c0fa2
Cleaned up code, added comments.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
2427
diff
changeset
|
33 */ |
2362
44fc2537ff9e
These files contain the specification for a class which receives updates from the iPhone accelerometer. The class holds the accelerometer information, and is queried by SDL_sysjoystick.m.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff
changeset
|
34 +(SDLUIAccelerationDelegate *)sharedDelegate { |
44fc2537ff9e
These files contain the specification for a class which receives updates from the iPhone accelerometer. The class holds the accelerometer information, and is queried by SDL_sysjoystick.m.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff
changeset
|
35 if (sharedDelegate == nil) { |
44fc2537ff9e
These files contain the specification for a class which receives updates from the iPhone accelerometer. The class holds the accelerometer information, and is queried by SDL_sysjoystick.m.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff
changeset
|
36 sharedDelegate = [[SDLUIAccelerationDelegate alloc] init]; |
44fc2537ff9e
These files contain the specification for a class which receives updates from the iPhone accelerometer. The class holds the accelerometer information, and is queried by SDL_sysjoystick.m.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff
changeset
|
37 } |
44fc2537ff9e
These files contain the specification for a class which receives updates from the iPhone accelerometer. The class holds the accelerometer information, and is queried by SDL_sysjoystick.m.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff
changeset
|
38 return sharedDelegate; |
44fc2537ff9e
These files contain the specification for a class which receives updates from the iPhone accelerometer. The class holds the accelerometer information, and is queried by SDL_sysjoystick.m.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff
changeset
|
39 } |
2439
78bddf0c0fa2
Cleaned up code, added comments.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
2427
diff
changeset
|
40 /* |
78bddf0c0fa2
Cleaned up code, added comments.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
2427
diff
changeset
|
41 UIAccelerometerDelegate delegate method. Invoked by the UIAccelerometer instance when it has new data for us. |
78bddf0c0fa2
Cleaned up code, added comments.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
2427
diff
changeset
|
42 We just take the data and mark that we have new data available so that the joystick system will pump it to the |
78bddf0c0fa2
Cleaned up code, added comments.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
2427
diff
changeset
|
43 events system when SDL_SYS_JoystickUpdate is called. |
78bddf0c0fa2
Cleaned up code, added comments.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
2427
diff
changeset
|
44 */ |
2362
44fc2537ff9e
These files contain the specification for a class which receives updates from the iPhone accelerometer. The class holds the accelerometer information, and is queried by SDL_sysjoystick.m.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff
changeset
|
45 -(void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration { |
44fc2537ff9e
These files contain the specification for a class which receives updates from the iPhone accelerometer. The class holds the accelerometer information, and is queried by SDL_sysjoystick.m.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff
changeset
|
46 |
44fc2537ff9e
These files contain the specification for a class which receives updates from the iPhone accelerometer. The class holds the accelerometer information, and is queried by SDL_sysjoystick.m.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff
changeset
|
47 x = acceleration.x; |
44fc2537ff9e
These files contain the specification for a class which receives updates from the iPhone accelerometer. The class holds the accelerometer information, and is queried by SDL_sysjoystick.m.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff
changeset
|
48 y = acceleration.y; |
44fc2537ff9e
These files contain the specification for a class which receives updates from the iPhone accelerometer. The class holds the accelerometer information, and is queried by SDL_sysjoystick.m.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff
changeset
|
49 z = acceleration.z; |
44fc2537ff9e
These files contain the specification for a class which receives updates from the iPhone accelerometer. The class holds the accelerometer information, and is queried by SDL_sysjoystick.m.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff
changeset
|
50 |
2439
78bddf0c0fa2
Cleaned up code, added comments.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
2427
diff
changeset
|
51 hasNewData = YES; |
2362
44fc2537ff9e
These files contain the specification for a class which receives updates from the iPhone accelerometer. The class holds the accelerometer information, and is queried by SDL_sysjoystick.m.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff
changeset
|
52 } |
2439
78bddf0c0fa2
Cleaned up code, added comments.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
2427
diff
changeset
|
53 /* |
78bddf0c0fa2
Cleaned up code, added comments.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
2427
diff
changeset
|
54 getLastOrientation -- put last obtained accelerometer data into Sint16 array |
78bddf0c0fa2
Cleaned up code, added comments.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
2427
diff
changeset
|
55 |
78bddf0c0fa2
Cleaned up code, added comments.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
2427
diff
changeset
|
56 Called from the joystick system when it needs the accelerometer data. |
78bddf0c0fa2
Cleaned up code, added comments.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
2427
diff
changeset
|
57 Function grabs the last data sent to the accelerometer and converts it |
78bddf0c0fa2
Cleaned up code, added comments.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
2427
diff
changeset
|
58 from floating point to Sint16, which is what the joystick system expects. |
78bddf0c0fa2
Cleaned up code, added comments.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
2427
diff
changeset
|
59 |
78bddf0c0fa2
Cleaned up code, added comments.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
2427
diff
changeset
|
60 To do the conversion, the data is first clamped onto the interval |
78bddf0c0fa2
Cleaned up code, added comments.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
2427
diff
changeset
|
61 [-SDL_IPHONE_MAX_G_FORCE, SDL_IPHONE_MAX_G_FORCE], then the data is multiplied |
78bddf0c0fa2
Cleaned up code, added comments.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
2427
diff
changeset
|
62 by MAX_SINT16 so that it is mapped to the full range of an Sint16. |
78bddf0c0fa2
Cleaned up code, added comments.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
2427
diff
changeset
|
63 |
78bddf0c0fa2
Cleaned up code, added comments.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
2427
diff
changeset
|
64 You can customize the clamped range of this function by modifying the |
78bddf0c0fa2
Cleaned up code, added comments.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
2427
diff
changeset
|
65 SDL_IPHONE_MAX_GFORCE macro in SDL_config_iphoneos.h. |
78bddf0c0fa2
Cleaned up code, added comments.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
2427
diff
changeset
|
66 |
78bddf0c0fa2
Cleaned up code, added comments.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
2427
diff
changeset
|
67 Once converted to Sint16, the accelerometer data no longer has coherent units. |
78bddf0c0fa2
Cleaned up code, added comments.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
2427
diff
changeset
|
68 You can convert the data back to units of g-force by multiplying it |
78bddf0c0fa2
Cleaned up code, added comments.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
2427
diff
changeset
|
69 in your application's code by SDL_IPHONE_MAX_GFORCE / 0x7FFF. |
78bddf0c0fa2
Cleaned up code, added comments.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
2427
diff
changeset
|
70 */ |
2362
44fc2537ff9e
These files contain the specification for a class which receives updates from the iPhone accelerometer. The class holds the accelerometer information, and is queried by SDL_sysjoystick.m.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff
changeset
|
71 -(void)getLastOrientation:(Sint16 *)data { |
44fc2537ff9e
These files contain the specification for a class which receives updates from the iPhone accelerometer. The class holds the accelerometer information, and is queried by SDL_sysjoystick.m.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff
changeset
|
72 |
2427
32b9909db651
changed macro MAX_G_FORCE to SDL_IPHONE_MAX_GFORCE and moved it to the SDL_config_iphoneos.h file. This should allow users to convert between the Sint16 returned by polling the joystick and units of g-force, which better describe what is going on with the iPhone (and are what the iPhone OS actually gives you). This conversion wouldn't be necessary except that we'd need floating point to store everything as g-force.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
2362
diff
changeset
|
73 #define MAX_SINT16 0x7FFF |
2362
44fc2537ff9e
These files contain the specification for a class which receives updates from the iPhone accelerometer. The class holds the accelerometer information, and is queried by SDL_sysjoystick.m.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff
changeset
|
74 |
2439
78bddf0c0fa2
Cleaned up code, added comments.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
2427
diff
changeset
|
75 /* clamp the data */ |
2427
32b9909db651
changed macro MAX_G_FORCE to SDL_IPHONE_MAX_GFORCE and moved it to the SDL_config_iphoneos.h file. This should allow users to convert between the Sint16 returned by polling the joystick and units of g-force, which better describe what is going on with the iPhone (and are what the iPhone OS actually gives you). This conversion wouldn't be necessary except that we'd need floating point to store everything as g-force.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
2362
diff
changeset
|
76 if (x > SDL_IPHONE_MAX_GFORCE) x = SDL_IPHONE_MAX_GFORCE; |
32b9909db651
changed macro MAX_G_FORCE to SDL_IPHONE_MAX_GFORCE and moved it to the SDL_config_iphoneos.h file. This should allow users to convert between the Sint16 returned by polling the joystick and units of g-force, which better describe what is going on with the iPhone (and are what the iPhone OS actually gives you). This conversion wouldn't be necessary except that we'd need floating point to store everything as g-force.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
2362
diff
changeset
|
77 else if (x < -SDL_IPHONE_MAX_GFORCE) x = -SDL_IPHONE_MAX_GFORCE; |
32b9909db651
changed macro MAX_G_FORCE to SDL_IPHONE_MAX_GFORCE and moved it to the SDL_config_iphoneos.h file. This should allow users to convert between the Sint16 returned by polling the joystick and units of g-force, which better describe what is going on with the iPhone (and are what the iPhone OS actually gives you). This conversion wouldn't be necessary except that we'd need floating point to store everything as g-force.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
2362
diff
changeset
|
78 if (y > SDL_IPHONE_MAX_GFORCE) y = SDL_IPHONE_MAX_GFORCE; |
32b9909db651
changed macro MAX_G_FORCE to SDL_IPHONE_MAX_GFORCE and moved it to the SDL_config_iphoneos.h file. This should allow users to convert between the Sint16 returned by polling the joystick and units of g-force, which better describe what is going on with the iPhone (and are what the iPhone OS actually gives you). This conversion wouldn't be necessary except that we'd need floating point to store everything as g-force.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
2362
diff
changeset
|
79 else if (y < -SDL_IPHONE_MAX_GFORCE) y = -SDL_IPHONE_MAX_GFORCE; |
32b9909db651
changed macro MAX_G_FORCE to SDL_IPHONE_MAX_GFORCE and moved it to the SDL_config_iphoneos.h file. This should allow users to convert between the Sint16 returned by polling the joystick and units of g-force, which better describe what is going on with the iPhone (and are what the iPhone OS actually gives you). This conversion wouldn't be necessary except that we'd need floating point to store everything as g-force.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
2362
diff
changeset
|
80 if (z > SDL_IPHONE_MAX_GFORCE) z = SDL_IPHONE_MAX_GFORCE; |
32b9909db651
changed macro MAX_G_FORCE to SDL_IPHONE_MAX_GFORCE and moved it to the SDL_config_iphoneos.h file. This should allow users to convert between the Sint16 returned by polling the joystick and units of g-force, which better describe what is going on with the iPhone (and are what the iPhone OS actually gives you). This conversion wouldn't be necessary except that we'd need floating point to store everything as g-force.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
2362
diff
changeset
|
81 else if (z < -SDL_IPHONE_MAX_GFORCE) z = -SDL_IPHONE_MAX_GFORCE; |
2362
44fc2537ff9e
These files contain the specification for a class which receives updates from the iPhone accelerometer. The class holds the accelerometer information, and is queried by SDL_sysjoystick.m.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff
changeset
|
82 |
2439
78bddf0c0fa2
Cleaned up code, added comments.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
2427
diff
changeset
|
83 /* pass in data mapped to range of SInt16 */ |
2427
32b9909db651
changed macro MAX_G_FORCE to SDL_IPHONE_MAX_GFORCE and moved it to the SDL_config_iphoneos.h file. This should allow users to convert between the Sint16 returned by polling the joystick and units of g-force, which better describe what is going on with the iPhone (and are what the iPhone OS actually gives you). This conversion wouldn't be necessary except that we'd need floating point to store everything as g-force.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
2362
diff
changeset
|
84 data[0] = (x / SDL_IPHONE_MAX_GFORCE) * MAX_SINT16; |
32b9909db651
changed macro MAX_G_FORCE to SDL_IPHONE_MAX_GFORCE and moved it to the SDL_config_iphoneos.h file. This should allow users to convert between the Sint16 returned by polling the joystick and units of g-force, which better describe what is going on with the iPhone (and are what the iPhone OS actually gives you). This conversion wouldn't be necessary except that we'd need floating point to store everything as g-force.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
2362
diff
changeset
|
85 data[1] = (y / SDL_IPHONE_MAX_GFORCE) * MAX_SINT16; |
32b9909db651
changed macro MAX_G_FORCE to SDL_IPHONE_MAX_GFORCE and moved it to the SDL_config_iphoneos.h file. This should allow users to convert between the Sint16 returned by polling the joystick and units of g-force, which better describe what is going on with the iPhone (and are what the iPhone OS actually gives you). This conversion wouldn't be necessary except that we'd need floating point to store everything as g-force.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
2362
diff
changeset
|
86 data[2] = (z / SDL_IPHONE_MAX_GFORCE) * MAX_SINT16; |
2362
44fc2537ff9e
These files contain the specification for a class which receives updates from the iPhone accelerometer. The class holds the accelerometer information, and is queried by SDL_sysjoystick.m.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff
changeset
|
87 |
44fc2537ff9e
These files contain the specification for a class which receives updates from the iPhone accelerometer. The class holds the accelerometer information, and is queried by SDL_sysjoystick.m.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff
changeset
|
88 } |
44fc2537ff9e
These files contain the specification for a class which receives updates from the iPhone accelerometer. The class holds the accelerometer information, and is queried by SDL_sysjoystick.m.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff
changeset
|
89 |
2439
78bddf0c0fa2
Cleaned up code, added comments.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
2427
diff
changeset
|
90 /* |
78bddf0c0fa2
Cleaned up code, added comments.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
2427
diff
changeset
|
91 Initialize SDLUIAccelerationDelegate. Since we don't have any data yet, |
78bddf0c0fa2
Cleaned up code, added comments.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
2427
diff
changeset
|
92 just set our last received data to zero, and indicate we don't have any; |
78bddf0c0fa2
Cleaned up code, added comments.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
2427
diff
changeset
|
93 */ |
2362
44fc2537ff9e
These files contain the specification for a class which receives updates from the iPhone accelerometer. The class holds the accelerometer information, and is queried by SDL_sysjoystick.m.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff
changeset
|
94 -(id)init { |
44fc2537ff9e
These files contain the specification for a class which receives updates from the iPhone accelerometer. The class holds the accelerometer information, and is queried by SDL_sysjoystick.m.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff
changeset
|
95 self = [super init]; |
44fc2537ff9e
These files contain the specification for a class which receives updates from the iPhone accelerometer. The class holds the accelerometer information, and is queried by SDL_sysjoystick.m.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff
changeset
|
96 x = y = z = 0.0; |
2439
78bddf0c0fa2
Cleaned up code, added comments.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
2427
diff
changeset
|
97 hasNewData = NO; |
2362
44fc2537ff9e
These files contain the specification for a class which receives updates from the iPhone accelerometer. The class holds the accelerometer information, and is queried by SDL_sysjoystick.m.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff
changeset
|
98 return self; |
44fc2537ff9e
These files contain the specification for a class which receives updates from the iPhone accelerometer. The class holds the accelerometer information, and is queried by SDL_sysjoystick.m.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff
changeset
|
99 } |
44fc2537ff9e
These files contain the specification for a class which receives updates from the iPhone accelerometer. The class holds the accelerometer information, and is queried by SDL_sysjoystick.m.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff
changeset
|
100 |
44fc2537ff9e
These files contain the specification for a class which receives updates from the iPhone accelerometer. The class holds the accelerometer information, and is queried by SDL_sysjoystick.m.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff
changeset
|
101 -(void)dealloc { |
44fc2537ff9e
These files contain the specification for a class which receives updates from the iPhone accelerometer. The class holds the accelerometer information, and is queried by SDL_sysjoystick.m.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff
changeset
|
102 sharedDelegate = nil; |
2439
78bddf0c0fa2
Cleaned up code, added comments.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
2427
diff
changeset
|
103 [self shutdown]; |
2362
44fc2537ff9e
These files contain the specification for a class which receives updates from the iPhone accelerometer. The class holds the accelerometer information, and is queried by SDL_sysjoystick.m.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff
changeset
|
104 [super dealloc]; |
44fc2537ff9e
These files contain the specification for a class which receives updates from the iPhone accelerometer. The class holds the accelerometer information, and is queried by SDL_sysjoystick.m.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff
changeset
|
105 } |
44fc2537ff9e
These files contain the specification for a class which receives updates from the iPhone accelerometer. The class holds the accelerometer information, and is queried by SDL_sysjoystick.m.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff
changeset
|
106 |
2439
78bddf0c0fa2
Cleaned up code, added comments.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
2427
diff
changeset
|
107 /* |
78bddf0c0fa2
Cleaned up code, added comments.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
2427
diff
changeset
|
108 Lets our delegate start receiving accelerometer updates. |
78bddf0c0fa2
Cleaned up code, added comments.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
2427
diff
changeset
|
109 */ |
2362
44fc2537ff9e
These files contain the specification for a class which receives updates from the iPhone accelerometer. The class holds the accelerometer information, and is queried by SDL_sysjoystick.m.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff
changeset
|
110 -(void)startup { |
44fc2537ff9e
These files contain the specification for a class which receives updates from the iPhone accelerometer. The class holds the accelerometer information, and is queried by SDL_sysjoystick.m.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff
changeset
|
111 [UIAccelerometer sharedAccelerometer].delegate = self; |
44fc2537ff9e
These files contain the specification for a class which receives updates from the iPhone accelerometer. The class holds the accelerometer information, and is queried by SDL_sysjoystick.m.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff
changeset
|
112 isRunning = YES; |
44fc2537ff9e
These files contain the specification for a class which receives updates from the iPhone accelerometer. The class holds the accelerometer information, and is queried by SDL_sysjoystick.m.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff
changeset
|
113 } |
2439
78bddf0c0fa2
Cleaned up code, added comments.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
2427
diff
changeset
|
114 /* |
78bddf0c0fa2
Cleaned up code, added comments.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
2427
diff
changeset
|
115 Stops our delegate from receiving accelerometer updates. |
78bddf0c0fa2
Cleaned up code, added comments.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
2427
diff
changeset
|
116 */ |
2362
44fc2537ff9e
These files contain the specification for a class which receives updates from the iPhone accelerometer. The class holds the accelerometer information, and is queried by SDL_sysjoystick.m.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff
changeset
|
117 -(void)shutdown { |
2439
78bddf0c0fa2
Cleaned up code, added comments.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
2427
diff
changeset
|
118 if ([UIAccelerometer sharedAccelerometer].delegate == self) { |
78bddf0c0fa2
Cleaned up code, added comments.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
2427
diff
changeset
|
119 [UIAccelerometer sharedAccelerometer].delegate = nil; |
78bddf0c0fa2
Cleaned up code, added comments.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
2427
diff
changeset
|
120 } |
2362
44fc2537ff9e
These files contain the specification for a class which receives updates from the iPhone accelerometer. The class holds the accelerometer information, and is queried by SDL_sysjoystick.m.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff
changeset
|
121 isRunning = NO; |
44fc2537ff9e
These files contain the specification for a class which receives updates from the iPhone accelerometer. The class holds the accelerometer information, and is queried by SDL_sysjoystick.m.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff
changeset
|
122 } |
2439
78bddf0c0fa2
Cleaned up code, added comments.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
2427
diff
changeset
|
123 /* |
78bddf0c0fa2
Cleaned up code, added comments.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
2427
diff
changeset
|
124 Our we currently receiving accelerometer updates? |
78bddf0c0fa2
Cleaned up code, added comments.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
2427
diff
changeset
|
125 */ |
2362
44fc2537ff9e
These files contain the specification for a class which receives updates from the iPhone accelerometer. The class holds the accelerometer information, and is queried by SDL_sysjoystick.m.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff
changeset
|
126 -(BOOL)isRunning { |
44fc2537ff9e
These files contain the specification for a class which receives updates from the iPhone accelerometer. The class holds the accelerometer information, and is queried by SDL_sysjoystick.m.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff
changeset
|
127 return isRunning; |
44fc2537ff9e
These files contain the specification for a class which receives updates from the iPhone accelerometer. The class holds the accelerometer information, and is queried by SDL_sysjoystick.m.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff
changeset
|
128 } |
2439
78bddf0c0fa2
Cleaned up code, added comments.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
2427
diff
changeset
|
129 /* |
78bddf0c0fa2
Cleaned up code, added comments.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
2427
diff
changeset
|
130 Do we have any data that hasn't been pumped into SDL's event system? |
78bddf0c0fa2
Cleaned up code, added comments.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
2427
diff
changeset
|
131 */ |
2362
44fc2537ff9e
These files contain the specification for a class which receives updates from the iPhone accelerometer. The class holds the accelerometer information, and is queried by SDL_sysjoystick.m.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff
changeset
|
132 -(BOOL)hasNewData { |
44fc2537ff9e
These files contain the specification for a class which receives updates from the iPhone accelerometer. The class holds the accelerometer information, and is queried by SDL_sysjoystick.m.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff
changeset
|
133 return hasNewData; |
44fc2537ff9e
These files contain the specification for a class which receives updates from the iPhone accelerometer. The class holds the accelerometer information, and is queried by SDL_sysjoystick.m.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff
changeset
|
134 } |
2439
78bddf0c0fa2
Cleaned up code, added comments.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
2427
diff
changeset
|
135 /* |
78bddf0c0fa2
Cleaned up code, added comments.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
2427
diff
changeset
|
136 When the joystick system grabs the new data, it sets this to NO. |
78bddf0c0fa2
Cleaned up code, added comments.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
2427
diff
changeset
|
137 */ |
2362
44fc2537ff9e
These files contain the specification for a class which receives updates from the iPhone accelerometer. The class holds the accelerometer information, and is queried by SDL_sysjoystick.m.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff
changeset
|
138 -(void)setHasNewData:(BOOL)value { |
44fc2537ff9e
These files contain the specification for a class which receives updates from the iPhone accelerometer. The class holds the accelerometer information, and is queried by SDL_sysjoystick.m.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff
changeset
|
139 hasNewData = value; |
44fc2537ff9e
These files contain the specification for a class which receives updates from the iPhone accelerometer. The class holds the accelerometer information, and is queried by SDL_sysjoystick.m.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff
changeset
|
140 } |
44fc2537ff9e
These files contain the specification for a class which receives updates from the iPhone accelerometer. The class holds the accelerometer information, and is queried by SDL_sysjoystick.m.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff
changeset
|
141 |
44fc2537ff9e
These files contain the specification for a class which receives updates from the iPhone accelerometer. The class holds the accelerometer information, and is queried by SDL_sysjoystick.m.
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff
changeset
|
142 @end |