From 0ce7f0c4094fa8a6cc74c410aee37413034cb0b9 Mon Sep 17 00:00:00 2001 From: raysan5 Date: Mon, 17 Oct 2016 18:18:13 +0200 Subject: Some work on multiple inputs... - Corrected bug and tested new gamepad system - Reviewed Android key inputs system, unified with desktop - Reorganize mouse functions on core --- src/core.c | 199 +++++++++++++++++++++++++++++-------------------------------- 1 file changed, 94 insertions(+), 105 deletions(-) (limited to 'src/core.c') diff --git a/src/core.c b/src/core.c index 3bd85fdd..d044a66e 100644 --- a/src/core.c +++ b/src/core.c @@ -131,7 +131,7 @@ #endif #define MAX_GAMEPADS 4 // Max number of gamepads supported -#define MAX_GAMEPAD_BUTTONS 11 // Max bumber of buttons supported (per gamepad) +#define MAX_GAMEPAD_BUTTONS 32 // Max bumber of buttons supported (per gamepad) #define MAX_GAMEPAD_AXIS 8 // Max number of axis supported (per gamepad) #define RL_LOAD_DEFAULT_FONT // Load default font on window initialization (module: text) @@ -158,9 +158,6 @@ static const char *internalDataPath; // Android internal data path to static bool windowReady = false; // Used to detect display initialization static bool appEnabled = true; // Used to detec if app is active static bool contextRebindRequired = false; // Used to know context rebind required - -static int previousButtonState[128] = { 1 }; // Required to check if button pressed/released once -static int currentButtonState[128] = { 1 }; // Required to check if button pressed/released once #endif #if defined(PLATFORM_RPI) @@ -203,10 +200,6 @@ static Matrix downscaleView; // Matrix to downscale view (in case static const char *windowTitle; // Window text title... static bool cursorOnScreen = false; // Tracks if cursor is inside client area -// Register keyboard states -static char previousKeyState[512] = { 0 }; // Registers previous frame key state -static char currentKeyState[512] = { 0 }; // Registers current frame key state - // Register mouse states static char previousMouseState[3] = { 0 }; // Registers previous mouse button state static char currentMouseState[3] = { 0 }; // Registers current mouse button state @@ -221,11 +214,16 @@ static char currentGamepadState[MAX_GAMEPADS][MAX_GAMEPAD_BUTTONS] = { 0 }; // Keyboard configuration static int exitKey = KEY_ESCAPE; // Default exit key (ESC) -static int lastKeyPressed = -1; // Register last key pressed static bool cursorHidden; // Track if cursor is hidden #endif +// Register keyboard states +static char previousKeyState[512] = { 0 }; // Registers previous frame key state +static char currentKeyState[512] = { 0 }; // Registers current frame key state + +static int lastKeyPressed = -1; // Register last key pressed + static Vector2 mousePosition; // Mouse position on screen static Vector2 touchPosition[MAX_TOUCH_POINTS]; // Touch position on screen @@ -526,6 +524,63 @@ int GetScreenHeight(void) return screenHeight; } +// Show mouse cursor +void ShowCursor() +{ +#if defined(PLATFORM_DESKTOP) + #ifdef __linux + XUndefineCursor(glfwGetX11Display(), glfwGetX11Window(window)); + #else + glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_NORMAL); + #endif +#endif + cursorHidden = false; +} + +// Hide mouse cursor +void HideCursor() +{ +#if defined(PLATFORM_DESKTOP) + #ifdef __linux + XColor Col; + const char Nil[] = {0}; + + Pixmap Pix = XCreateBitmapFromData(glfwGetX11Display(), glfwGetX11Window(window), Nil, 1, 1); + Cursor Cur = XCreatePixmapCursor(glfwGetX11Display(), Pix, Pix, &Col, &Col, 0, 0); + + XDefineCursor(glfwGetX11Display(), glfwGetX11Window(window), Cur); + XFreeCursor(glfwGetX11Display(), Cur); + #else + glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_HIDDEN); + #endif +#endif + cursorHidden = true; +} + +// Check if mouse cursor is hidden +bool IsCursorHidden() +{ + return cursorHidden; +} + +// Enable mouse cursor +void EnableCursor() +{ +#if defined(PLATFORM_DESKTOP) + glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_NORMAL); +#endif + cursorHidden = false; +} + +// Disable mouse cursor +void DisableCursor() +{ +#if defined(PLATFORM_DESKTOP) + glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_DISABLED); +#endif + cursorHidden = true; +} + // Sets Background Color void ClearBackground(Color color) { @@ -1050,8 +1105,13 @@ bool IsKeyPressed(int key) { bool pressed = false; +#if defined(PLATFORM_ANDROID) + if ((currentButtonState[key] != previousButtonState[key]) && (currentButtonState[key] == 0)) pressed = true; + else pressed = false; +#else if ((currentKeyState[key] != previousKeyState[key]) && (currentKeyState[key] == 1)) pressed = true; else pressed = false; +#endif return pressed; } @@ -1067,9 +1127,14 @@ bool IsKeyDown(int key) bool IsKeyReleased(int key) { bool released = false; - + +#if defined(PLATFORM_ANDROID) + if ((currentButtonState[button] != previousButtonState[button]) && (currentButtonState[button] == 1)) released = true; + else released = false; +#else if ((currentKeyState[key] != previousKeyState[key]) && (currentKeyState[key] == 0)) released = true; else released = false; +#endif return released; } @@ -1091,64 +1156,9 @@ int GetKeyPressed(void) // NOTE: default exitKey is ESCAPE void SetExitKey(int key) { +#if !defined(PLATFORM_ANDROID) exitKey = key; -} - -// Hide mouse cursor -void HideCursor() -{ -#if defined(PLATFORM_DESKTOP) - #ifdef __linux - XColor Col; - const char Nil[] = {0}; - - Pixmap Pix = XCreateBitmapFromData(glfwGetX11Display(), glfwGetX11Window(window), Nil, 1, 1); - Cursor Cur = XCreatePixmapCursor(glfwGetX11Display(), Pix, Pix, &Col, &Col, 0, 0); - - XDefineCursor(glfwGetX11Display(), glfwGetX11Window(window), Cur); - XFreeCursor(glfwGetX11Display(), Cur); - #else - glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_HIDDEN); - #endif #endif - cursorHidden = true; -} - -// Show mouse cursor -void ShowCursor() -{ -#if defined(PLATFORM_DESKTOP) - #ifdef __linux - XUndefineCursor(glfwGetX11Display(), glfwGetX11Window(window)); - #else - glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_NORMAL); - #endif -#endif - cursorHidden = false; -} - -// Disable mouse cursor -void DisableCursor() -{ -#if defined(PLATFORM_DESKTOP) - glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_DISABLED); -#endif - cursorHidden = true; -} - -// Enable mouse cursor -void EnableCursor() -{ -#if defined(PLATFORM_DESKTOP) - glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_NORMAL); -#endif - cursorHidden = false; -} - -// Check if mouse cursor is hidden -bool IsCursorHidden() -{ - return cursorHidden; } // NOTE: Gamepad support not implemented in emscripten GLFW3 (PLATFORM_WEB) @@ -1204,7 +1214,7 @@ bool IsGamepadButtonDown(int gamepad, int button) { bool result = false; - if ((gamepad < MAX_GAMEPADS) && gamepadReady[gamepad] && (button < MAX_GAMEPAD_BUTTONS) && + if ((gamepad < MAX_GAMEPADS) && gamepadReady[gamepad] && (button < MAX_GAMEPAD_BUTTONS) && (currentGamepadState[gamepad][button] == 1)) result = true; return result; @@ -1387,37 +1397,6 @@ Vector2 GetTouchPosition(int index) return position; } -#if defined(PLATFORM_ANDROID) -// Detect if a button has been pressed once -bool IsButtonPressed(int button) -{ - bool pressed = false; - - if ((currentButtonState[button] != previousButtonState[button]) && (currentButtonState[button] == 0)) pressed = true; - else pressed = false; - - return pressed; -} - -// Detect if a button is being pressed (button held down) -bool IsButtonDown(int button) -{ - if (currentButtonState[button] == 0) return true; - else return false; -} - -// Detect if a button has been released once -bool IsButtonReleased(int button) -{ - bool released = false; - - if ((currentButtonState[button] != previousButtonState[button]) && (currentButtonState[button] == 1)) released = true; - else released = false; - - return released; -} -#endif - //---------------------------------------------------------------------------------- // Module specific Functions Definition //---------------------------------------------------------------------------------- @@ -1900,8 +1879,9 @@ static bool GetKeyStatus(int key) #if defined(PLATFORM_DESKTOP) || defined(PLATFORM_WEB) return glfwGetKey(window, key); #elif defined(PLATFORM_ANDROID) - // TODO: Check for virtual keyboard - return false; + // NOTE: Android supports up to 260 keys + if (key < 0 || key > 260) return false; + else return currentKeyState[key]; #elif defined(PLATFORM_RPI) // NOTE: Keys states are filled in PollInputEvents() if (key < 0 || key > 511) return false; @@ -1929,6 +1909,9 @@ static void PollInputEvents(void) // NOTE: Gestures update must be called every frame to reset gestures correctly // because ProcessGestureEvent() is just called on an event, not every frame UpdateGestures(); + + // Reset last key pressed registered + lastKeyPressed = -1; #if defined(PLATFORM_DESKTOP) || defined(PLATFORM_WEB) // Mouse input polling @@ -1939,9 +1922,8 @@ static void PollInputEvents(void) mousePosition.x = (float)mouseX; mousePosition.y = (float)mouseY; - + // Keyboard input polling (automatically managed by GLFW3 through callback) - lastKeyPressed = -1; // Register previous keys states for (int i = 0; i < 512; i++) previousKeyState[i] = currentKeyState[i]; @@ -1971,7 +1953,7 @@ static void PollInputEvents(void) for (int k = 0; (buttons != NULL) && (k < buttonsCount) && (buttonsCount < MAX_GAMEPAD_BUTTONS); k++) { - if (buttons[i] == GLFW_PRESS) currentGamepadState[i][k] = 1; + if (buttons[k] == GLFW_PRESS) currentGamepadState[i][k] = 1; else currentGamepadState[i][k] = 0; } @@ -1994,7 +1976,8 @@ static void PollInputEvents(void) #if defined(PLATFORM_ANDROID) // Register previous keys states - for (int i = 0; i < 128; i++) previousButtonState[i] = currentButtonState[i]; + // NOTE: Android supports up to 260 keys + for (int i = 0; i < 260; i++) previousKeyState[i] = currentKeyState[i]; // Poll Events (registered events) // NOTE: Activity is paused if not enabled (appEnabled) @@ -2371,7 +2354,13 @@ static int32_t AndroidInputCallback(struct android_app *app, AInputEvent *event) //int32_t AKeyEvent_getMetaState(event); // Save current button and its state - currentButtonState[keycode] = AKeyEvent_getAction(event); // Down = 0, Up = 1 + // NOTE: Android key action is 0 for down and 1 for up + if (AKeyEvent_getAction(event) == 0) + { + currentKeyState[keycode] = 1; // Key down + lastKeyPressed = keycode; + } + else currentKeyState[keycode] = 0; // Key up if (keycode == AKEYCODE_POWER) { -- cgit v1.2.3 From b8ce6805117bcd28f80ae92f7faa14abdcb2f741 Mon Sep 17 00:00:00 2001 From: Ray Date: Tue, 18 Oct 2016 00:15:23 +0200 Subject: Improved Android support --- src/core.c | 21 ++++++--------------- src/raylib.h | 8 +++----- 2 files changed, 9 insertions(+), 20 deletions(-) (limited to 'src/core.c') diff --git a/src/core.c b/src/core.c index d044a66e..b8a8ac05 100644 --- a/src/core.c +++ b/src/core.c @@ -79,8 +79,7 @@ #endif #if defined(PLATFORM_ANDROID) - #include // Java native interface - #include // Android sensors functions + //#include // Android sensors functions (accelerometer, gyroscope, light...) #include // Defines AWINDOW_FLAG_FULLSCREEN and others #include // Defines basic app state struct and manages activity @@ -361,7 +360,7 @@ void InitWindow(int width, int height, const char *title) #if defined(PLATFORM_ANDROID) // Android activity initialization -void InitWindow(int width, int height, struct android_app *state) +void InitWindow(int width, int height, void *state) { TraceLog(INFO, "Initializing raylib (v1.6.0)"); @@ -370,7 +369,7 @@ void InitWindow(int width, int height, struct android_app *state) screenWidth = width; screenHeight = height; - app = state; + app = (struct android_app *)state; internalDataPath = app->activity->internalDataPath; // Set desired windows flags before initializing anything @@ -524,6 +523,7 @@ int GetScreenHeight(void) return screenHeight; } +#if !defined(PLATFORM_ANDROID) // Show mouse cursor void ShowCursor() { @@ -580,6 +580,7 @@ void DisableCursor() #endif cursorHidden = true; } +#endif // !defined(PLATFORM_ANDROID) // Sets Background Color void ClearBackground(Color color) @@ -1099,19 +1100,13 @@ Matrix GetCameraMatrix(Camera camera) //---------------------------------------------------------------------------------- // Module Functions Definition - Input (Keyboard, Mouse, Gamepad) Functions //---------------------------------------------------------------------------------- -#if defined(PLATFORM_DESKTOP) || defined(PLATFORM_RPI) || defined(PLATFORM_WEB) // Detect if a key has been pressed once bool IsKeyPressed(int key) { bool pressed = false; -#if defined(PLATFORM_ANDROID) - if ((currentButtonState[key] != previousButtonState[key]) && (currentButtonState[key] == 0)) pressed = true; - else pressed = false; -#else if ((currentKeyState[key] != previousKeyState[key]) && (currentKeyState[key] == 1)) pressed = true; else pressed = false; -#endif return pressed; } @@ -1128,13 +1123,8 @@ bool IsKeyReleased(int key) { bool released = false; -#if defined(PLATFORM_ANDROID) - if ((currentButtonState[button] != previousButtonState[button]) && (currentButtonState[button] == 1)) released = true; - else released = false; -#else if ((currentKeyState[key] != previousKeyState[key]) && (currentKeyState[key] == 0)) released = true; else released = false; -#endif return released; } @@ -1161,6 +1151,7 @@ void SetExitKey(int key) #endif } +#if defined(PLATFORM_DESKTOP) || defined(PLATFORM_RPI) || defined(PLATFORM_WEB) // NOTE: Gamepad support not implemented in emscripten GLFW3 (PLATFORM_WEB) // Detect if a gamepad is available diff --git a/src/raylib.h b/src/raylib.h index c1ac2416..efb9a71c 100644 --- a/src/raylib.h +++ b/src/raylib.h @@ -77,10 +77,6 @@ #define PLATFORM_DESKTOP #endif -#if defined(PLATFORM_ANDROID) - typedef struct android_app; // Define android_app struct (android_native_app_glue.h) -#endif - #if defined(_WIN32) && defined(BUILDING_DLL) #define RLAPI __declspec(dllexport) // We are building raylib as a Win32 DLL #elif defined(_WIN32) && defined(RAYLIB_DLL) @@ -591,7 +587,7 @@ extern "C" { // Prevents name mangling of functions // Window and Graphics Device Functions (Module: core) //------------------------------------------------------------------------------------ #if defined(PLATFORM_ANDROID) -RLAPI void InitWindow(int width, int height, struct android_app *state); // Init Android Activity and OpenGL Graphics +RLAPI void InitWindow(int width, int height, void *state); // Init Android Activity and OpenGL Graphics (struct android_app) #elif defined(PLATFORM_DESKTOP) || defined(PLATFORM_RPI) || defined(PLATFORM_WEB) RLAPI void InitWindow(int width, int height, const char *title); // Initialize Window and OpenGL Graphics #endif @@ -603,11 +599,13 @@ RLAPI void ToggleFullscreen(void); // Fullscreen RLAPI int GetScreenWidth(void); // Get current screen width RLAPI int GetScreenHeight(void); // Get current screen height +#if !defined(PLATFORM_ANDROID) RLAPI void ShowCursor(void); // Shows cursor RLAPI void HideCursor(void); // Hides cursor RLAPI bool IsCursorHidden(void); // Returns true if cursor is not visible RLAPI void EnableCursor(void); // Enables cursor RLAPI void DisableCursor(void); // Disables cursor +#endif RLAPI void ClearBackground(Color color); // Sets Background Color RLAPI void BeginDrawing(void); // Setup drawing canvas to start drawing -- cgit v1.2.3 From 1142d4edae645f9e5b235c2c3278a8d16a1f97cf Mon Sep 17 00:00:00 2001 From: raysan5 Date: Mon, 24 Oct 2016 19:08:23 +0200 Subject: Force threads to finish on CloseWindow() --- src/core.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/core.c') diff --git a/src/core.c b/src/core.c index b8a8ac05..dd005836 100644 --- a/src/core.c +++ b/src/core.c @@ -463,6 +463,9 @@ void CloseWindow(void) // Wait for mouse and gamepad threads to finish before closing // NOTE: Those threads should already have finished at this point // because they are controlled by windowShouldClose variable + + windowShouldClose = true; // Added to force threads to exit when the close window is called + pthread_join(mouseThreadId, NULL); pthread_join(gamepadThreadId, NULL); #endif -- cgit v1.2.3 From 02842a3e2fefe122baaf40da1bcae5548239d570 Mon Sep 17 00:00:00 2001 From: raysan5 Date: Thu, 27 Oct 2016 13:41:43 +0200 Subject: Review gamepad inputs Added funtion: GetGamepadButtonPressed() - This function can be useful for custom gamepad configuration --- src/core.c | 19 ++++++++++++++++++- src/raylib.h | 61 ++++++++++++++++++++++++++++++++++++++++++------------------ 2 files changed, 61 insertions(+), 19 deletions(-) (limited to 'src/core.c') diff --git a/src/core.c b/src/core.c index dd005836..8646bf8f 100644 --- a/src/core.c +++ b/src/core.c @@ -222,6 +222,7 @@ static char previousKeyState[512] = { 0 }; // Registers previous frame key stat static char currentKeyState[512] = { 0 }; // Registers current frame key state static int lastKeyPressed = -1; // Register last key pressed +static int lastGamepadButtonPressed = -1; // Register last gamepad button pressed static Vector2 mousePosition; // Mouse position on screen static Vector2 touchPosition[MAX_TOUCH_POINTS]; // Touch position on screen @@ -1236,6 +1237,13 @@ bool IsGamepadButtonUp(int gamepad, int button) return result; } + +// Get the last gamepad button pressed +int GetGamepadButtonPressed(void) +{ + return lastGamepadButtonPressed; +} + #endif //defined(PLATFORM_DESKTOP) || defined(PLATFORM_RPI) || defined(PLATFORM_WEB) @@ -1906,6 +1914,9 @@ static void PollInputEvents(void) // Reset last key pressed registered lastKeyPressed = -1; + + // Reset last gamepad button pressed registered + lastGamepadButtonPressed = -1; #if defined(PLATFORM_DESKTOP) || defined(PLATFORM_WEB) // Mouse input polling @@ -1947,7 +1958,11 @@ static void PollInputEvents(void) for (int k = 0; (buttons != NULL) && (k < buttonsCount) && (buttonsCount < MAX_GAMEPAD_BUTTONS); k++) { - if (buttons[k] == GLFW_PRESS) currentGamepadState[i][k] = 1; + if (buttons[k] == GLFW_PRESS) + { + currentGamepadState[i][k] = 1; + lastGamepadButtonPressed = k; + } else currentGamepadState[i][k] = 0; } @@ -2801,6 +2816,8 @@ static void *GamepadThread(void *arg) { // 1 - button pressed, 0 - button released currentGamepadState[i][gamepadEvent.number] = (int)gamepadEvent.value; + + if ((int)gamepadEvent.value == 1) lastGamepadButtonPressed = gamepadEvent.number; } } else if (gamepadEvent.type == JS_EVENT_AXIS) diff --git a/src/raylib.h b/src/raylib.h index efb9a71c..491923dc 100644 --- a/src/raylib.h +++ b/src/raylib.h @@ -192,21 +192,32 @@ #define GAMEPAD_PLAYER3 2 #define GAMEPAD_PLAYER4 3 -// Gamepad Buttons +// Gamepad Buttons/Axis -// PS3 USB Controller -#define GAMEPAD_PS3_BUTTON_A 2 -#define GAMEPAD_PS3_BUTTON_B 1 -#define GAMEPAD_PS3_BUTTON_X 3 -#define GAMEPAD_PS3_BUTTON_Y 4 +// PS3 USB Controller Buttons +#define GAMEPAD_PS3_BUTTON_TRIANGLE 0 +#define GAMEPAD_PS3_BUTTON_CIRCLE 1 +#define GAMEPAD_PS3_BUTTON_CROSS 2 +#define GAMEPAD_PS3_BUTTON_SQUARE 3 +#define GAMEPAD_PS3_BUTTON_L1 6 #define GAMEPAD_PS3_BUTTON_R1 7 +#define GAMEPAD_PS3_BUTTON_L2 4 #define GAMEPAD_PS3_BUTTON_R2 5 -#define GAMEPAD_PS3_BUTTON_L1 6 -#define GAMEPAD_PS3_BUTTON_L2 8 +#define GAMEPAD_PS3_BUTTON_START 8 #define GAMEPAD_PS3_BUTTON_SELECT 9 -#define GAMEPAD_PS3_BUTTON_START 10 - -// TODO: Add PS3 d-pad axis +#define GAMEPAD_PS3_BUTTON_UP 24 +#define GAMEPAD_PS3_BUTTON_RIGHT 25 +#define GAMEPAD_PS3_BUTTON_DOWN 26 +#define GAMEPAD_PS3_BUTTON_LEFT 27 +#define GAMEPAD_PS3_BUTTON_PS 12 + +// PS3 USB Controller Axis +#define GAMEPAD_PS3_AXIS_LEFT_X 0 +#define GAMEPAD_PS3_AXIS_LEFT_Y 1 +#define GAMEPAD_PS3_AXIS_RIGHT_X 2 +#define GAMEPAD_PS3_AXIS_RIGHT_Y 5 +#define GAMEPAD_PS3_AXIS_L2 3 // 1.0(not pressed) --> -1.0(completely pressed) +#define GAMEPAD_PS3_AXIS_R2 4 // 1.0(not pressed) --> -1.0(completely pressed) // Xbox360 USB Controller Buttons #define GAMEPAD_XBOX_BUTTON_A 0 @@ -221,22 +232,27 @@ #define GAMEPAD_XBOX_BUTTON_RIGHT 11 #define GAMEPAD_XBOX_BUTTON_DOWN 12 #define GAMEPAD_XBOX_BUTTON_LEFT 13 +#define GAMEPAD_XBOX_BUTTON_HOME 9 +// Xbox360 USB Controller Axis #define GAMEPAD_XBOX_AXIS_LEFT_X 0 #define GAMEPAD_XBOX_AXIS_LEFT_Y 1 +#define GAMEPAD_XBOX_AXIS_RIGHT_X 2 +#define GAMEPAD_XBOX_AXIS_RIGHT_Y 3 +#define GAMEPAD_XBOX_AXIS_LT 4 // -1.0(not pressed) --> 1.0(completely pressed) +#define GAMEPAD_XBOX_AXIS_RT 5 // -1.0(not pressed) --> 1.0(completely pressed) +/* +// NOTE: For Raspberry Pi, axis must be reconfigured #if defined(PLATFORM_RPI) - #define GAMEPAD_XBOX_AXIS_DPAD_X 7 - #define GAMEPAD_XBOX_AXIS_DPAD_Y 6 + #define GAMEPAD_XBOX_AXIS_LEFT_X 7 + #define GAMEPAD_XBOX_AXIS_LEFT_Y 6 #define GAMEPAD_XBOX_AXIS_RIGHT_X 3 #define GAMEPAD_XBOX_AXIS_RIGHT_Y 4 #define GAMEPAD_XBOX_AXIS_LT 2 #define GAMEPAD_XBOX_AXIS_RT 5 -#else - #define GAMEPAD_XBOX_AXIS_RIGHT_X 4 - #define GAMEPAD_XBOX_AXIS_RIGHT_Y 3 - #define GAMEPAD_XBOX_AXIS_LT_RT 2 #endif +*/ // NOTE: MSC C++ compiler does not support compound literals (C99 feature) // Plain structures in C++ (without constructors) can be initialized from { } initializers. @@ -533,6 +549,12 @@ typedef enum { COMPRESSED_ASTC_8x8_RGBA // 2 bpp } TextureFormat; +// Texture parameters: filter mode +typedef enum { FILTER_POINT = 0, FILTER_BILINEAR, FILTER_TRILINEAR } TextureFilterMode; + +// Texture parameters: wrap mode +typedef enum { WRAP_REPEAT = 0, WRAP_CLAMP, WRAP_MIRROR } TextureWrapMode; + // Color blending modes (pre-defined) typedef enum { BLEND_ALPHA = 0, BLEND_ADDITIVE, BLEND_MULTIPLIED } BlendMode; @@ -663,6 +685,7 @@ RLAPI bool IsGamepadButtonPressed(int gamepad, int button); // Detect if a gam RLAPI bool IsGamepadButtonDown(int gamepad, int button); // Detect if a gamepad button is being pressed RLAPI bool IsGamepadButtonReleased(int gamepad, int button); // Detect if a gamepad button has been released once RLAPI bool IsGamepadButtonUp(int gamepad, int button); // Detect if a gamepad button is NOT being pressed +RLAPI int GetGamepadButtonPressed(void); // Get the last gamepad button pressed #endif RLAPI bool IsMouseButtonPressed(int button); // Detect if a mouse button has been pressed once @@ -752,6 +775,7 @@ RLAPI void UnloadTexture(Texture2D texture); RLAPI void UnloadRenderTexture(RenderTexture2D target); // Unload render texture from GPU memory RLAPI Color *GetImageData(Image image); // Get pixel data from image as a Color struct array RLAPI Image GetTextureData(Texture2D texture); // Get pixel data from GPU texture and return an Image +RLAPI void UpdateTexture(Texture2D texture, void *pixels); // Update GPU texture with new data RLAPI void ImageToPOT(Image *image, Color fillColor); // Convert image to POT (power-of-two) RLAPI void ImageFormat(Image *image, int newFormat); // Convert image data to desired format RLAPI void ImageAlphaMask(Image *image, Image alphaMask); // Apply alpha mask to image @@ -773,7 +797,8 @@ RLAPI void ImageColorGrayscale(Image *image); RLAPI void ImageColorContrast(Image *image, float contrast); // Modify image color: contrast (-100 to 100) RLAPI void ImageColorBrightness(Image *image, int brightness); // Modify image color: brightness (-255 to 255) RLAPI void GenTextureMipmaps(Texture2D texture); // Generate GPU mipmaps for a texture -RLAPI void UpdateTexture(Texture2D texture, void *pixels); // Update GPU texture with new data +RLAPI void SetTextureFilter(Texture2D texture, int filterMode); +RLAPI void SetTextureWrap(Texture2D texture, int wrapMode); RLAPI void DrawTexture(Texture2D texture, int posX, int posY, Color tint); // Draw a Texture2D RLAPI void DrawTextureV(Texture2D texture, Vector2 position, Color tint); // Draw a Texture2D with position defined as Vector2 -- cgit v1.2.3 From 43fd9ffe08025a82b79ce41c22c6ae82feb2c9aa Mon Sep 17 00:00:00 2001 From: raysan5 Date: Sat, 29 Oct 2016 22:16:54 +0200 Subject: Tweak to avoid warnings --- src/core.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/core.c') diff --git a/src/core.c b/src/core.c index 8646bf8f..b8574f0a 100644 --- a/src/core.c +++ b/src/core.c @@ -208,8 +208,8 @@ static int currentMouseWheelY = 0; // Registers current mouse wheel var // Register gamepads states static bool gamepadReady[MAX_GAMEPADS] = { false }; // Flag to know if gamepad is ready static float gamepadAxisState[MAX_GAMEPADS][MAX_GAMEPAD_AXIS]; // Gamepad axis state -static char previousGamepadState[MAX_GAMEPADS][MAX_GAMEPAD_BUTTONS] = { 0 }; -static char currentGamepadState[MAX_GAMEPADS][MAX_GAMEPAD_BUTTONS] = { 0 }; +static char previousGamepadState[MAX_GAMEPADS][MAX_GAMEPAD_BUTTONS]; // Previous gamepad buttons state +static char currentGamepadState[MAX_GAMEPADS][MAX_GAMEPAD_BUTTONS]; // Current gamepad buttons state // Keyboard configuration static int exitKey = KEY_ESCAPE; // Default exit key (ESC) -- cgit v1.2.3 From 16101ce3d8c601447f935056b09a36ea3afefe7d Mon Sep 17 00:00:00 2001 From: raysan5 Date: Mon, 31 Oct 2016 13:56:57 +0100 Subject: Reorganize defines check --- src/core.c | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) (limited to 'src/core.c') diff --git a/src/core.c b/src/core.c index b8574f0a..9bb7b8cf 100644 --- a/src/core.c +++ b/src/core.c @@ -198,6 +198,7 @@ static Matrix downscaleView; // Matrix to downscale view (in case #if defined(PLATFORM_DESKTOP) || defined(PLATFORM_RPI) || defined(PLATFORM_WEB) static const char *windowTitle; // Window text title... static bool cursorOnScreen = false; // Tracks if cursor is inside client area +static bool cursorHidden = false; // Track if cursor is hidden // Register mouse states static char previousMouseState[3] = { 0 }; // Registers previous mouse button state @@ -213,8 +214,6 @@ static char currentGamepadState[MAX_GAMEPADS][MAX_GAMEPAD_BUTTONS]; // Curre // Keyboard configuration static int exitKey = KEY_ESCAPE; // Default exit key (ESC) - -static bool cursorHidden; // Track if cursor is hidden #endif // Register keyboard states @@ -1155,15 +1154,16 @@ void SetExitKey(int key) #endif } -#if defined(PLATFORM_DESKTOP) || defined(PLATFORM_RPI) || defined(PLATFORM_WEB) // NOTE: Gamepad support not implemented in emscripten GLFW3 (PLATFORM_WEB) // Detect if a gamepad is available bool IsGamepadAvailable(int gamepad) { bool result = false; - + +#if !defined(PLATFORM_ANDROID) if ((gamepad < MAX_GAMEPADS) && gamepadReady[gamepad]) result = true; +#endif return result; } @@ -1183,11 +1183,10 @@ const char *GetGamepadName(int gamepad) float GetGamepadAxisMovement(int gamepad, int axis) { float value = 0; - - if ((gamepad < MAX_GAMEPADS) && gamepadReady[gamepad] && (axis < MAX_GAMEPAD_AXIS)) - { - value = gamepadAxisState[gamepad][axis]; - } + +#if !defined(PLATFORM_ANDROID) + if ((gamepad < MAX_GAMEPADS) && gamepadReady[gamepad] && (axis < MAX_GAMEPAD_AXIS)) value = gamepadAxisState[gamepad][axis]; +#endif return value; } @@ -1196,10 +1195,12 @@ float GetGamepadAxisMovement(int gamepad, int axis) bool IsGamepadButtonPressed(int gamepad, int button) { bool pressed = false; - + +#if !defined(PLATFORM_ANDROID) if ((gamepad < MAX_GAMEPADS) && gamepadReady[gamepad] && (button < MAX_GAMEPAD_BUTTONS) && (currentGamepadState[gamepad][button] != previousGamepadState[gamepad][button]) && (currentGamepadState[gamepad][button] == 1)) pressed = true; +#endif return pressed; } @@ -1209,8 +1210,10 @@ bool IsGamepadButtonDown(int gamepad, int button) { bool result = false; +#if !defined(PLATFORM_ANDROID) if ((gamepad < MAX_GAMEPADS) && gamepadReady[gamepad] && (button < MAX_GAMEPAD_BUTTONS) && (currentGamepadState[gamepad][button] == 1)) result = true; +#endif return result; } @@ -1220,9 +1223,11 @@ bool IsGamepadButtonReleased(int gamepad, int button) { bool released = false; +#if !defined(PLATFORM_ANDROID) if ((gamepad < MAX_GAMEPADS) && gamepadReady[gamepad] && (button < MAX_GAMEPAD_BUTTONS) && (currentGamepadState[gamepad][button] != previousGamepadState[gamepad][button]) && (currentGamepadState[gamepad][button] == 0)) released = true; +#endif return released; } @@ -1232,8 +1237,10 @@ bool IsGamepadButtonUp(int gamepad, int button) { bool result = false; +#if !defined(PLATFORM_ANDROID) if ((gamepad < MAX_GAMEPADS) && gamepadReady[gamepad] && (button < MAX_GAMEPAD_BUTTONS) && (currentGamepadState[gamepad][button] == 0)) result = true; +#endif return result; } @@ -1244,9 +1251,6 @@ int GetGamepadButtonPressed(void) return lastGamepadButtonPressed; } -#endif //defined(PLATFORM_DESKTOP) || defined(PLATFORM_RPI) || defined(PLATFORM_WEB) - - // Detect if a mouse button has been pressed once bool IsMouseButtonPressed(int button) { -- cgit v1.2.3 From 673dcf94364d37f3d52285ac27c88707ae567872 Mon Sep 17 00:00:00 2001 From: raysan5 Date: Mon, 31 Oct 2016 20:39:03 +0100 Subject: Comments tweaks --- src/core.c | 2 +- src/models.c | 2 +- src/rlgl.c | 2 +- src/shapes.c | 15 +++++++-------- src/textures.c | 4 ++-- src/utils.c | 2 +- 6 files changed, 13 insertions(+), 14 deletions(-) (limited to 'src/core.c') diff --git a/src/core.c b/src/core.c index 9bb7b8cf..8850eefa 100644 --- a/src/core.c +++ b/src/core.c @@ -22,7 +22,7 @@ * * RL_LOAD_DEFAULT_FONT - Use external module functions to load default raylib font (module: text) * -* Copyright (c) 2014 Ramon Santamaria (@raysan5) +* Copyright (c) 2014-2016 Ramon Santamaria (@raysan5) * * This software is provided "as-is", without any express or implied warranty. In no event * will the authors be held liable for any damages arising from the use of this software. diff --git a/src/models.c b/src/models.c index 55ac7893..c0f04387 100644 --- a/src/models.c +++ b/src/models.c @@ -4,7 +4,7 @@ * * Basic functions to draw 3d shapes and load/draw 3d models (.OBJ) * -* Copyright (c) 2014 Ramon Santamaria (@raysan5) +* Copyright (c) 2014-2016 Ramon Santamaria (@raysan5) * * This software is provided "as-is", without any express or implied warranty. In no event * will the authors be held liable for any damages arising from the use of this software. diff --git a/src/rlgl.c b/src/rlgl.c index 492ca3a6..e2804e9c 100644 --- a/src/rlgl.c +++ b/src/rlgl.c @@ -35,7 +35,7 @@ #include // Required for: atan2() #ifndef RLGL_STANDALONE - #include "raymath.h" // Required for Vector3 and Matrix functions + #include "raymath.h" // Required for: Vector3 and Matrix functions #endif #if defined(GRAPHICS_API_OPENGL_11) diff --git a/src/shapes.c b/src/shapes.c index 62076b2c..79cf567a 100644 --- a/src/shapes.c +++ b/src/shapes.c @@ -4,7 +4,7 @@ * * Basic functions to draw 2d Shapes and check collisions * -* Copyright (c) 2014 Ramon Santamaria (@raysan5) +* Copyright (c) 2014-2016 Ramon Santamaria (@raysan5) * * This software is provided "as-is", without any express or implied warranty. In no event * will the authors be held liable for any damages arising from the use of this software. @@ -25,9 +25,8 @@ #include "raylib.h" -#include // Required for abs() function -#include // Math related functions, sin() and cos() used on DrawCircle* - // sqrt() and pow() and abs() used on CheckCollision* +#include // Required for: abs() +#include // Required for: sinf(), cosf(), sqrtf() #include "rlgl.h" // raylib OpenGL abstraction layer to OpenGL 1.1, 3.3+ or ES2 @@ -331,8 +330,8 @@ void DrawPoly(Vector2 center, int sides, float radius, float rotation, Color col rlColor4ub(color.r, color.g, color.b, color.a); rlVertex2f(0, 0); - rlVertex2f(sin(DEG2RAD*i)*radius, cos(DEG2RAD*i)*radius); - rlVertex2f(sin(DEG2RAD*(i + 360/sides))*radius, cos(DEG2RAD*(i + 360/sides))*radius); + rlVertex2f(sinf(DEG2RAD*i)*radius, cosf(DEG2RAD*i)*radius); + rlVertex2f(sinf(DEG2RAD*(i + 360/sides))*radius, cosf(DEG2RAD*(i + 360/sides))*radius); } rlEnd(); rlPopMatrix(); @@ -434,7 +433,7 @@ bool CheckCollisionCircles(Vector2 center1, float radius1, Vector2 center2, floa float dx = center2.x - center1.x; // X distance between centers float dy = center2.y - center1.y; // Y distance between centers - float distance = sqrt(dx*dx + dy*dy); // Distance between centers + float distance = sqrtf(dx*dx + dy*dy); // Distance between centers if (distance <= (radius1 + radius2)) collision = true; @@ -457,7 +456,7 @@ bool CheckCollisionCircleRec(Vector2 center, float radius, Rectangle rec) if (dx <= (rec.width/2)) { return true; } if (dy <= (rec.height/2)) { return true; } - float cornerDistanceSq = pow(dx - rec.width/2, 2) + pow(dy - rec.height/2, 2); + float cornerDistanceSq = (dx - rec.width/2)*(dx - rec.width/2) + (dy - rec.height/2)*(dy - rec.height/2); return (cornerDistanceSq <= (radius*radius)); } diff --git a/src/textures.c b/src/textures.c index 729756a5..5354a74f 100644 --- a/src/textures.c +++ b/src/textures.c @@ -8,7 +8,7 @@ * stb_image - Multiple formats image loading (JPEG, PNG, BMP, TGA, PSD, GIF, PIC) * NOTE: stb_image has been slightly modified, original library: https://github.com/nothings/stb * -* Copyright (c) 2014 Ramon Santamaria (@raysan5) +* Copyright (c) 2014-2016 Ramon Santamaria (@raysan5) * * This software is provided "as-is", without any express or implied warranty. In no event * will the authors be held liable for any damages arising from the use of this software. @@ -1241,7 +1241,7 @@ Image ImageTextEx(SpriteFont font, const char *text, float fontSize, int spacing // NOTE: GetTextureData() not available in OpenGL ES Image imFont = GetTextureData(font.texture); - ImageFormat(&imFont, UNCOMPRESSED_R8G8B8A8); // Required for color tint + ImageFormat(&imFont, UNCOMPRESSED_R8G8B8A8); // Convert to 32 bit for color tint ImageColorTint(&imFont, tint); // Apply color tint to font Color *fontPixels = GetImageData(imFont); diff --git a/src/utils.c b/src/utils.c index 36b06f0f..b96e2c70 100644 --- a/src/utils.c +++ b/src/utils.c @@ -8,7 +8,7 @@ * tinfl - zlib DEFLATE algorithm decompression lib * stb_image_write - PNG writting functions * -* Copyright (c) 2014 Ramon Santamaria (@raysan5) +* Copyright (c) 2014-2016 Ramon Santamaria (@raysan5) * * This software is provided "as-is", without any express or implied warranty. In no event * will the authors be held liable for any damages arising from the use of this software. -- cgit v1.2.3 From 64f67f6e9f414a54dfc3fb519b892ecd5517f2cf Mon Sep 17 00:00:00 2001 From: raysan5 Date: Tue, 1 Nov 2016 14:39:57 +0100 Subject: Improved gamepad support new function: GetGamepadAxisCount() new function: IsGamepadName() --- src/core.c | 50 +++++++++++++++++++++++++++++++++++++++----------- src/raylib.h | 4 +++- 2 files changed, 42 insertions(+), 12 deletions(-) (limited to 'src/core.c') diff --git a/src/core.c b/src/core.c index 8850eefa..3bade07b 100644 --- a/src/core.c +++ b/src/core.c @@ -58,12 +58,12 @@ #endif #include // Standard input / output lib -#include // Declares malloc() and free() for memory management, rand(), atexit() -#include // Required for typedef unsigned long long int uint64_t, used by hi-res timer -#include // Useful to initialize random seed - Android/RPI hi-res timer (NOTE: Linux only!) -#include // Math related functions, tan() used to set perspective -#include // String function definitions, memset() -#include // Macros for reporting and retrieving error conditions through error codes +#include // Required for: malloc(), free(), rand(), atexit() +#include // Required for: typedef unsigned long long int uint64_t, used by hi-res timer +#include // Required for: time() - Android/RPI hi-res timer (NOTE: Linux only!) +#include // Required for: tan() [Used in Begin3dMode() to set perspective] +#include // Required for: strcmp() +//#include // Macros for reporting and retrieving error conditions through error codes #if defined(PLATFORM_DESKTOP) || defined(PLATFORM_WEB) //#define GLFW_INCLUDE_NONE // Disable the standard OpenGL header inclusion on GLFW3 @@ -222,6 +222,7 @@ static char currentKeyState[512] = { 0 }; // Registers current frame key state static int lastKeyPressed = -1; // Register last key pressed static int lastGamepadButtonPressed = -1; // Register last gamepad button pressed +static int gamepadAxisCount = 0; // Register number of available gamepad axis static Vector2 mousePosition; // Mouse position on screen static Vector2 touchPosition[MAX_TOUCH_POINTS]; // Touch position on screen @@ -1168,17 +1169,36 @@ bool IsGamepadAvailable(int gamepad) return result; } +// Check gamepad name (if available) +bool IsGamepadName(int gamepad, const char *name) +{ + bool result = false; + const char *gamepadName = NULL; + + if (gamepadReady[gamepad]) gamepadName = GetGamepadName(gamepad); + + if ((name != NULL) && (gamepadName != NULL)) result = (strcmp(name, gamepadName) == 0); + + return result; +} + // Return gamepad internal name id const char *GetGamepadName(int gamepad) { #if defined(PLATFORM_DESKTOP) - if (glfwJoystickPresent(gamepad) == 1) return glfwGetJoystickName(gamepad); + if (gamepadReady[gamepad]) return glfwGetJoystickName(gamepad); else return NULL; #else return NULL; #endif } +// Return gamepad axis count +int GetGamepadAxisCount(int gamepad) +{ + return gamepadAxisCount; +} + // Return axis movement vector for a gamepad float GetGamepadAxisMovement(int gamepad, int axis) { @@ -1921,6 +1941,7 @@ static void PollInputEvents(void) // Reset last gamepad button pressed registered lastGamepadButtonPressed = -1; + gamepadAxisCount = 0; #if defined(PLATFORM_DESKTOP) || defined(PLATFORM_WEB) // Mouse input polling @@ -1943,13 +1964,19 @@ static void PollInputEvents(void) previousMouseWheelY = currentMouseWheelY; currentMouseWheelY = 0; + // Check if gamepads are ready + // NOTE: We do it here in case of disconection + for (int i = 0; i < MAX_GAMEPADS; i++) + { + if (glfwJoystickPresent(i)) gamepadReady[i] = true; + else gamepadReady[i] = false; + } + // Register gamepads buttons events for (int i = 0; i < MAX_GAMEPADS; i++) { - if (glfwJoystickPresent(i)) // Check if gamepad is available + if (gamepadReady[i]) // Check if gamepad is available { - gamepadReady[i] = true; - // Register previous gamepad states for (int k = 0; k < MAX_GAMEPAD_BUTTONS; k++) previousGamepadState[i][k] = currentGamepadState[i][k]; @@ -1980,8 +2007,9 @@ static void PollInputEvents(void) { gamepadAxisState[i][k] = axes[k]; } + + gamepadAxisCount = axisCount; } - else gamepadReady[i] = false; } glfwPollEvents(); // Register keyboard/mouse events (callbacks)... and window events! diff --git a/src/raylib.h b/src/raylib.h index 4996bb2b..58037770 100644 --- a/src/raylib.h +++ b/src/raylib.h @@ -687,13 +687,15 @@ RLAPI int GetKeyPressed(void); // Get latest key RLAPI void SetExitKey(int key); // Set a custom key to exit program (default is ESC) RLAPI bool IsGamepadAvailable(int gamepad); // Detect if a gamepad is available +RLAPI bool IsGamepadName(int gamepad, const char *name); // Check gamepad name (if available) RLAPI const char *GetGamepadName(int gamepad); // Return gamepad internal name id -RLAPI float GetGamepadAxisMovement(int gamepad, int axis); // Return axis movement value for a gamepad axis RLAPI bool IsGamepadButtonPressed(int gamepad, int button); // Detect if a gamepad button has been pressed once RLAPI bool IsGamepadButtonDown(int gamepad, int button); // Detect if a gamepad button is being pressed RLAPI bool IsGamepadButtonReleased(int gamepad, int button); // Detect if a gamepad button has been released once RLAPI bool IsGamepadButtonUp(int gamepad, int button); // Detect if a gamepad button is NOT being pressed RLAPI int GetGamepadButtonPressed(void); // Get the last gamepad button pressed +RLAPI int GetGamepadAxisCount(int gamepad); // Return gamepad axis count for a gamepad +RLAPI float GetGamepadAxisMovement(int gamepad, int axis); // Return axis movement value for a gamepad axis RLAPI bool IsMouseButtonPressed(int button); // Detect if a mouse button has been pressed once RLAPI bool IsMouseButtonDown(int button); // Detect if a mouse button is being pressed -- cgit v1.2.3 From f2d61d4d432ff302c57d0869d75e72c6462658f5 Mon Sep 17 00:00:00 2001 From: raysan5 Date: Wed, 2 Nov 2016 13:39:48 +0100 Subject: Improved gamepad support on Raspberry Pi --- src/core.c | 19 ++++++++++++++++--- src/raylib.h | 34 ++++++++++++++++------------------ 2 files changed, 32 insertions(+), 21 deletions(-) (limited to 'src/core.c') diff --git a/src/core.c b/src/core.c index 3bade07b..8e15eb96 100644 --- a/src/core.c +++ b/src/core.c @@ -96,8 +96,8 @@ #include // UNIX System call for device-specific input/output operations - ioctl() #include // Linux: KDSKBMODE, K_MEDIUMRAM constants definition #include // Linux: Keycodes constants definition (KEY_A, ...) - #include - + #include // Linux: Joystick support library + #include "bcm_host.h" // Raspberry Pi VideoCore IV access functions #include "EGL/egl.h" // Khronos EGL library - Native platform display device control functions @@ -175,6 +175,7 @@ static pthread_t mouseThreadId; // Mouse reading thread id // Gamepad input variables static int gamepadStream[MAX_GAMEPADS] = { -1 };// Gamepad device file descriptor static pthread_t gamepadThreadId; // Gamepad reading thread id +static char gamepadName[64]; // Gamepad name holder #endif #if defined(PLATFORM_ANDROID) || defined(PLATFORM_RPI) @@ -1188,6 +1189,10 @@ const char *GetGamepadName(int gamepad) #if defined(PLATFORM_DESKTOP) if (gamepadReady[gamepad]) return glfwGetJoystickName(gamepad); else return NULL; +#elif defined(PLATFORM_RPI) + if (gamepadReady[gamepad]) ioctl(gamepadStream[gamepad], JSIOCGNAME(64), &gamepadName); + + return gamepadName; #else return NULL; #endif @@ -1196,6 +1201,11 @@ const char *GetGamepadName(int gamepad) // Return gamepad axis count int GetGamepadAxisCount(int gamepad) { +#if defined(PLATFORM_RPI) + int axisCount = 0; + if (gamepadReady[gamepad]) ioctl(gamepadStream[gamepad], JSIOCGAXES, &axisCount); + gamepadAxisCount = axisCount; +#endif return gamepadAxisCount; } @@ -1939,9 +1949,11 @@ static void PollInputEvents(void) // Reset last key pressed registered lastKeyPressed = -1; - // Reset last gamepad button pressed registered +#if !defined(PLATFORM_RPI) + // Reset last gamepad button/axis registered state lastGamepadButtonPressed = -1; gamepadAxisCount = 0; +#endif #if defined(PLATFORM_DESKTOP) || defined(PLATFORM_WEB) // Mouse input polling @@ -2850,6 +2862,7 @@ static void *GamepadThread(void *arg) currentGamepadState[i][gamepadEvent.number] = (int)gamepadEvent.value; if ((int)gamepadEvent.value == 1) lastGamepadButtonPressed = gamepadEvent.number; + else lastGamepadButtonPressed = -1; } } else if (gamepadEvent.type == JS_EVENT_AXIS) diff --git a/src/raylib.h b/src/raylib.h index 58037770..08acafdd 100644 --- a/src/raylib.h +++ b/src/raylib.h @@ -216,8 +216,8 @@ #define GAMEPAD_PS3_AXIS_LEFT_Y 1 #define GAMEPAD_PS3_AXIS_RIGHT_X 2 #define GAMEPAD_PS3_AXIS_RIGHT_Y 5 -#define GAMEPAD_PS3_AXIS_L2 3 // 1.0(not pressed) --> -1.0(completely pressed) -#define GAMEPAD_PS3_AXIS_R2 4 // 1.0(not pressed) --> -1.0(completely pressed) +#define GAMEPAD_PS3_AXIS_L2 3 // [1..-1] (pressure-level) +#define GAMEPAD_PS3_AXIS_R2 4 // [1..-1] (pressure-level) // Xbox360 USB Controller Buttons #define GAMEPAD_XBOX_BUTTON_A 0 @@ -232,27 +232,25 @@ #define GAMEPAD_XBOX_BUTTON_RIGHT 11 #define GAMEPAD_XBOX_BUTTON_DOWN 12 #define GAMEPAD_XBOX_BUTTON_LEFT 13 -#define GAMEPAD_XBOX_BUTTON_HOME 9 +#define GAMEPAD_XBOX_BUTTON_HOME 8 // Xbox360 USB Controller Axis -#define GAMEPAD_XBOX_AXIS_LEFT_X 0 -#define GAMEPAD_XBOX_AXIS_LEFT_Y 1 -#define GAMEPAD_XBOX_AXIS_RIGHT_X 2 -#define GAMEPAD_XBOX_AXIS_RIGHT_Y 3 -#define GAMEPAD_XBOX_AXIS_LT 4 // -1.0(not pressed) --> 1.0(completely pressed) -#define GAMEPAD_XBOX_AXIS_RT 5 // -1.0(not pressed) --> 1.0(completely pressed) - -/* +#define GAMEPAD_XBOX_AXIS_LEFT_X 0 // [-1..1] (left->right) +#define GAMEPAD_XBOX_AXIS_LEFT_Y 1 // [1..-1] (up->down) +#define GAMEPAD_XBOX_AXIS_RIGHT_X 2 // [-1..1] (left->right) +#define GAMEPAD_XBOX_AXIS_RIGHT_Y 3 // [1..-1] (up->down) +#define GAMEPAD_XBOX_AXIS_LT 4 // [-1..1] (pressure-level) +#define GAMEPAD_XBOX_AXIS_RT 5 // [-1..1] (pressure-level) + // NOTE: For Raspberry Pi, axis must be reconfigured #if defined(PLATFORM_RPI) - #define GAMEPAD_XBOX_AXIS_LEFT_X 7 - #define GAMEPAD_XBOX_AXIS_LEFT_Y 6 - #define GAMEPAD_XBOX_AXIS_RIGHT_X 3 - #define GAMEPAD_XBOX_AXIS_RIGHT_Y 4 - #define GAMEPAD_XBOX_AXIS_LT 2 - #define GAMEPAD_XBOX_AXIS_RT 5 + #define GAMEPAD_XBOX_AXIS_LEFT_X 0 // [-1..1] (left->right) + #define GAMEPAD_XBOX_AXIS_LEFT_Y 1 // [-1..1] (up->down) + #define GAMEPAD_XBOX_AXIS_RIGHT_X 3 // [-1..1] (left->right) + #define GAMEPAD_XBOX_AXIS_RIGHT_Y 4 // [-1..1] (up->down) + #define GAMEPAD_XBOX_AXIS_LT 2 // [-1..1] (pressure-level) + #define GAMEPAD_XBOX_AXIS_RT 5 // [-1..1] (pressure-level) #endif -*/ // NOTE: MSC C++ compiler does not support compound literals (C99 feature) // Plain structures in C++ (without constructors) can be initialized from { } initializers. -- cgit v1.2.3