zenilib  0.5.3.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
SDLUIAccelerationDelegate.m
Go to the documentation of this file.
1 /*
2  Simple DirectMedia Layer
3  Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
4 
5  This software is provided 'as-is', without any express or implied
6  warranty. In no event will the authors be held liable for any damages
7  arising from the use of this software.
8 
9  Permission is granted to anyone to use this software for any purpose,
10  including commercial applications, and to alter it and redistribute it
11  freely, subject to the following restrictions:
12 
13  1. The origin of this software must not be misrepresented; you must not
14  claim that you wrote the original software. If you use this software
15  in a product, an acknowledgment in the product documentation would be
16  appreciated but is not required.
17  2. Altered source versions must be plainly marked as such, and must not be
18  misrepresented as being the original software.
19  3. This notice may not be removed or altered from any source distribution.
20 */
21 
23 /* needed for SDL_IPHONE_MAX_GFORCE macro */
24 #import "../../../include/SDL_config_iphoneos.h"
25 
27 
28 @implementation SDLUIAccelerationDelegate
29 
30 /*
31  Returns a shared instance of the SDLUIAccelerationDelegate, creating the shared delegate if it doesn't exist yet.
32 */
33 +(SDLUIAccelerationDelegate *)sharedDelegate {
34  if (sharedDelegate == nil) {
35  sharedDelegate = [[SDLUIAccelerationDelegate alloc] init];
36  }
37  return sharedDelegate;
38 }
39 /*
40  UIAccelerometerDelegate delegate method. Invoked by the UIAccelerometer instance when it has new data for us.
41  We just take the data and mark that we have new data available so that the joystick system will pump it to the
42  events system when SDL_SYS_JoystickUpdate is called.
43 */
44 -(void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration {
45 
46  x = acceleration.x;
47  y = acceleration.y;
48  z = acceleration.z;
49 
50  hasNewData = YES;
51 }
52 /*
53  getLastOrientation -- put last obtained accelerometer data into Sint16 array
54 
55  Called from the joystick system when it needs the accelerometer data.
56  Function grabs the last data sent to the accelerometer and converts it
57  from floating point to Sint16, which is what the joystick system expects.
58 
59  To do the conversion, the data is first clamped onto the interval
60  [-SDL_IPHONE_MAX_G_FORCE, SDL_IPHONE_MAX_G_FORCE], then the data is multiplied
61  by MAX_SINT16 so that it is mapped to the full range of an Sint16.
62 
63  You can customize the clamped range of this function by modifying the
64  SDL_IPHONE_MAX_GFORCE macro in SDL_config_iphoneos.h.
65 
66  Once converted to Sint16, the accelerometer data no longer has coherent units.
67  You can convert the data back to units of g-force by multiplying it
68  in your application's code by SDL_IPHONE_MAX_GFORCE / 0x7FFF.
69  */
70 -(void)getLastOrientation:(Sint16 *)data {
71 
72  #define MAX_SINT16 0x7FFF
73 
74  /* clamp the data */
81 
82  /* pass in data mapped to range of SInt16 */
86 
87 }
88 
89 /*
90  Initialize SDLUIAccelerationDelegate. Since we don't have any data yet,
91  just set our last received data to zero, and indicate we don't have any;
92 */
93 -(id)init {
94  self = [super init];
95  x = y = z = 0.0;
96  hasNewData = NO;
97  return self;
98 }
99 
100 -(void)dealloc {
101  sharedDelegate = nil;
102  [self shutdown];
103  [super dealloc];
104 }
105 
106 /*
107  Lets our delegate start receiving accelerometer updates.
108 */
110  [UIAccelerometer sharedAccelerometer].delegate = self;
111  isRunning = YES;
112 }
113 /*
114  Stops our delegate from receiving accelerometer updates.
115 */
117  if ([UIAccelerometer sharedAccelerometer].delegate == self) {
118  [UIAccelerometer sharedAccelerometer].delegate = nil;
119  }
120  isRunning = NO;
121 }
122 /*
123  Our we currently receiving accelerometer updates?
124 */
126  return isRunning;
127 }
128 /*
129  Do we have any data that hasn't been pumped into SDL's event system?
130 */
132  return hasNewData;
133 }
134 /*
135  When the joystick system grabs the new data, it sets this to NO.
136 */
137 -(void)setHasNewData:(BOOL)value {
138  hasNewData = value;
139 }
140 
141 @end
GLvoid **typedef void(GLAPIENTRY *PFNGLGETVERTEXATTRIBDVPROC)(GLuint
Definition: glew.h:1824
EGLSurface EGLint x
Definition: eglext.h:293
static void init(struct bs2b *bs2b)
Definition: bs2b.c:46
#define MAX_SINT16
GLuint id
Definition: gl2ext.h:1142
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl2ext.h:848
static SDLUIAccelerationDelegate * sharedDelegate
#define SDL_IPHONE_MAX_GFORCE
EGLSurface EGLint EGLint y
Definition: eglext.h:293
EGLSurface EGLint void ** value
Definition: eglext.h:301
int16_t Sint16
A signed 16-bit integer type.
Definition: SDL_stdinc.h:133
GLint GLint GLint GLint z
Definition: gl2ext.h:1214
SDLUIAccelerationDelegate * sharedDelegate()
typedef BOOL(WINAPI *PFNWGLSETSTEREOEMITTERSTATE3DLPROC)(HDC hDC