Fixed Y axis inversion on iOS; positive is up, negative is down.
authorSam Lantinga <slouken@libsdl.org>
Sun, 20 Oct 2013 22:23:09 -0700
changeset 786129d012c8f2a9
parent 7860 2b0bcdea3a79
child 7862 d20e37f08533
Fixed Y axis inversion on iOS; positive is up, negative is down.
Xcode-iOS/Demos/src/accelerometer.c
src/joystick/iphoneos/SDL_sysjoystick.m
     1.1 --- a/Xcode-iOS/Demos/src/accelerometer.c	Sun Oct 20 21:56:15 2013 -0700
     1.2 +++ b/Xcode-iOS/Demos/src/accelerometer.c	Sun Oct 20 22:23:09 2013 -0700
     1.3 @@ -31,19 +31,19 @@
     1.4  static SDL_Texture *space = 0;       /* texture for space (background */
     1.5  
     1.6  void
     1.7 -render(SDL_Renderer *renderer)
     1.8 +render(SDL_Renderer *renderer, int w, int h)
     1.9  {
    1.10  
    1.11  
    1.12      /* get joystick (accelerometer) axis values and normalize them */
    1.13      float ax = SDL_JoystickGetAxis(accelerometer, 0);
    1.14 -    float ay = -SDL_JoystickGetAxis(accelerometer, 1);
    1.15 +    float ay = SDL_JoystickGetAxis(accelerometer, 1);
    1.16  
    1.17      /* ship screen constraints */
    1.18      Uint32 minx = 0.0f;
    1.19 -    Uint32 maxx = SCREEN_WIDTH - shipData.rect.w;
    1.20 +    Uint32 maxx = w - shipData.rect.w;
    1.21      Uint32 miny = 0.0f;
    1.22 -    Uint32 maxy = SCREEN_HEIGHT - shipData.rect.h;
    1.23 +    Uint32 maxy = h - shipData.rect.h;
    1.24  
    1.25  #define SINT16_MAX ((float)(0x7FFF))
    1.26  
    1.27 @@ -162,8 +162,9 @@
    1.28      SDL_Renderer *renderer;
    1.29      Uint32 startFrame;          /* time frame began to process */
    1.30      Uint32 endFrame;            /* time frame ended processing */
    1.31 -    Uint32 delay;               /* time to pause waiting to draw next frame */
    1.32 +    Sint32 delay;               /* time to pause waiting to draw next frame */
    1.33      int done;                   /* should we clean up and exit? */
    1.34 +    int w, h;
    1.35  
    1.36      /* initialize SDL */
    1.37      if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK) < 0) {
    1.38 @@ -175,6 +176,8 @@
    1.39                                  SDL_WINDOW_OPENGL |
    1.40                                  SDL_WINDOW_BORDERLESS);
    1.41      renderer = SDL_CreateRenderer(window, 0, 0);
    1.42 +    
    1.43 +    SDL_GetWindowSize(window, &w, &h);
    1.44  
    1.45      /* print out some info about joysticks and try to open accelerometer for use */
    1.46      printf("There are %d joysticks available\n", SDL_NumJoysticks());
    1.47 @@ -196,8 +199,8 @@
    1.48      initializeTextures(renderer);
    1.49  
    1.50      /* setup ship */
    1.51 -    shipData.x = (SCREEN_WIDTH - shipData.rect.w) / 2;
    1.52 -    shipData.y = (SCREEN_HEIGHT - shipData.rect.h) / 2;
    1.53 +    shipData.x = (w - shipData.rect.w) / 2;
    1.54 +    shipData.y = (h - shipData.rect.h) / 2;
    1.55      shipData.vx = 0.0f;
    1.56      shipData.vy = 0.0f;
    1.57  
    1.58 @@ -211,7 +214,7 @@
    1.59                  done = 1;
    1.60              }
    1.61          }
    1.62 -        render(renderer);
    1.63 +        render(renderer, w, h);
    1.64          endFrame = SDL_GetTicks();
    1.65  
    1.66          /* figure out how much time we have left, and then sleep */
     2.1 --- a/src/joystick/iphoneos/SDL_sysjoystick.m	Sun Oct 20 21:56:15 2013 -0700
     2.2 +++ b/src/joystick/iphoneos/SDL_sysjoystick.m	Sun Oct 20 22:23:09 2013 -0700
     2.3 @@ -106,7 +106,7 @@
     2.4          [[SDLUIAccelerationDelegate sharedDelegate] setHasNewData: NO];
     2.5  
     2.6          SDL_PrivateJoystickAxis(joystick, 0, orientation[0]);
     2.7 -        SDL_PrivateJoystickAxis(joystick, 1, orientation[1]);
     2.8 +        SDL_PrivateJoystickAxis(joystick, 1, -orientation[1]);
     2.9          SDL_PrivateJoystickAxis(joystick, 2, orientation[2]);
    2.10  
    2.11      }