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

Commit

Permalink
changed macro MAX_G_FORCE to SDL_IPHONE_MAX_GFORCE and moved it to th…
Browse files Browse the repository at this point in the history
…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 79f2737
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions src/joystick/iphoneos/SDLUIAccelerationDelegate.m
Expand Up @@ -7,6 +7,7 @@
//

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

static SDLUIAccelerationDelegate *sharedDelegate=nil;

Expand All @@ -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;

}

Expand Down

0 comments on commit 79f2737

Please sign in to comment.