Exemple #1
0
void
SDL_SYS_JoystickUpdate(SDL_Joystick * joystick)
{
    int i;
    Sint16 value;
    float values[3];
    SDL_joylist_item *item = SDL_joylist;

    while (item) {
        if (item->is_accelerometer) {
            if (item->joystick) {
                if (Android_JNI_GetAccelerometerValues(values)) {
                    for ( i = 0; i < 3; i++ ) {
                        if (values[i] > 1.0f) {
                            values[i] = 1.0f;
                        } else if (values[i] < -1.0f) {
                            values[i] = -1.0f;
                        }

                        value = (Sint16)(values[i] * 32767.0f);
                        SDL_PrivateJoystickAxis(item->joystick, i, value);
                    }
                }
            }
            break;
        }
        item = item->next;
    }
}
/* Function to update the state of a joystick - called as a device poll.
 * This function shouldn't update the joystick structure directly,
 * but instead should call SDL_PrivateJoystick*() to deliver events
 * and update joystick device state.
 */
void
SDL_SYS_JoystickUpdate(SDL_Joystick * joystick)
{
    int i;
    float values[3];

    Android_JNI_GetAccelerometerValues(values);

    for ( i = 0; i < 3; i++ ) {
        SDL_PrivateJoystickAxis(joystick, i, values[i]);
    }
}
/* Function to update the state of a joystick - called as a device poll.
 * This function shouldn't update the joystick structure directly,
 * but instead should call SDL_PrivateJoystick*() to deliver events
 * and update joystick device state.
 */
void
SDL_SYS_JoystickUpdate(SDL_Joystick * joystick)
{
    int i;
    Sint16 value;
    float values[3];

    if (Android_JNI_GetAccelerometerValues(values)) {
        for ( i = 0; i < 3; i++ ) {
            value = (Sint16)(values[i] * 32767.0f);
            SDL_PrivateJoystickAxis(joystick, i, value);
        }
    }
}