Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

changed macro MAX_G_FORCE to SDL_IPHONE_MAX_GFORCE and moved it to th…

…e 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.
  • Loading branch information
Holmes Futrell committed Aug 15, 2008
1 parent baaaa5d commit 79f2737cdf6388c5bdb059f62fed1632666e6c45
Showing with 11 additions and 11 deletions.
  1. +11 −11 src/joystick/iphoneos/SDLUIAccelerationDelegate.m
@@ -7,6 +7,7 @@
//

#import "SDLUIAccelerationDelegate.h"
#import "../../../include/SDL_config_iphoneos.h"

static SDLUIAccelerationDelegate *sharedDelegate=nil;

@@ -32,21 +33,20 @@ -(void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAccelerat

-(void)getLastOrientation:(Sint16 *)data {

#define MAX_G_FORCE 5.0
#define MAX_SINT16 0x7FFF
#define MAX_SINT16 0x7FFF

if (x > MAX_G_FORCE) x = MAX_G_FORCE;
else if (x < -MAX_G_FORCE) x = -MAX_G_FORCE;
if (x > SDL_IPHONE_MAX_GFORCE) x = SDL_IPHONE_MAX_GFORCE;
else if (x < -SDL_IPHONE_MAX_GFORCE) x = -SDL_IPHONE_MAX_GFORCE;

if (y > MAX_G_FORCE) y = MAX_G_FORCE;
else if (y < -MAX_G_FORCE) y = -MAX_G_FORCE;
if (y > SDL_IPHONE_MAX_GFORCE) y = SDL_IPHONE_MAX_GFORCE;
else if (y < -SDL_IPHONE_MAX_GFORCE) y = -SDL_IPHONE_MAX_GFORCE;

if (z > MAX_G_FORCE) z = MAX_G_FORCE;
else if (z < -MAX_G_FORCE) z = -MAX_G_FORCE;
if (z > SDL_IPHONE_MAX_GFORCE) z = SDL_IPHONE_MAX_GFORCE;
else if (z < -SDL_IPHONE_MAX_GFORCE) z = -SDL_IPHONE_MAX_GFORCE;

data[0] = (x / MAX_G_FORCE) * MAX_SINT16;
data[1] = (y / MAX_G_FORCE) * MAX_SINT16;
data[2] = (z / MAX_G_FORCE) * MAX_SINT16;
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;

}

0 comments on commit 79f2737

Please sign in to comment.