diff --git a/examples-switch/Makefile b/examples-switch/Makefile index 0d5f70a53..23b31d6a0 100644 --- a/examples-switch/Makefile +++ b/examples-switch/Makefile @@ -413,6 +413,7 @@ CORE = \ core/core_input_mouse \ core/core_input_mouse_wheel \ core/core_input_gamepad \ + core/core_input_multi_gamepad \ core/core_input_multitouch \ core/core_input_gestures \ core/core_2d_camera \ diff --git a/examples-switch/core/core_2d_camera.c b/examples-switch/core/core_2d_camera.c index 27ed99fce..8a51777be 100644 --- a/examples-switch/core/core_2d_camera.c +++ b/examples-switch/core/core_2d_camera.c @@ -60,15 +60,15 @@ int main(void) // Update //---------------------------------------------------------------------------------- // Player movement - if (IsKeyDown(KEY_RIGHT)) player.x += 2; - else if (IsKeyDown(KEY_LEFT)) player.x -= 2; + if (GetGamepadAxisMovement(0, GAMEPAD_AXIS_LEFT_X) > 0) player.x += 2; + else if (GetGamepadAxisMovement(0, GAMEPAD_AXIS_LEFT_X) < 0) player.x -= 2; // Camera target follows player camera.target = (Vector2){ player.x + 20, player.y + 20 }; // Camera rotation controls - if (IsKeyDown(KEY_A)) camera.rotation--; - else if (IsKeyDown(KEY_S)) camera.rotation++; + if (GetGamepadAxisMovement(0, GAMEPAD_AXIS_RIGHT_X) > 0) camera.rotation--; + else if (GetGamepadAxisMovement(0, GAMEPAD_AXIS_RIGHT_X) < 0) camera.rotation++; // Limit camera rotation to 80 degrees (-40 to 40) if (camera.rotation > 40) camera.rotation = 40; @@ -119,9 +119,9 @@ int main(void) DrawText("Free 2d camera controls:", 20, 20, 10, BLACK); DrawText("- Right/Left to move Offset", 40, 40, 10, DARKGRAY); - DrawText("- Mouse Wheel to Zoom in-out", 40, 60, 10, DARKGRAY); - DrawText("- A / S to Rotate", 40, 80, 10, DARKGRAY); - DrawText("- R to reset Zoom and Rotation", 40, 100, 10, DARKGRAY); + DrawText("- R/L bumpers to Zoom in-out", 40, 60, 10, DARKGRAY); + DrawText("- Right thumbstick X-axis to Rotate", 40, 80, 10, DARKGRAY); + DrawText("- X button to reset Zoom and Rotation", 40, 100, 10, DARKGRAY); EndDrawing(); //---------------------------------------------------------------------------------- diff --git a/examples-switch/core/core_2d_camera_platformer.c b/examples-switch/core/core_2d_camera_platformer.c index cf134591e..42a109326 100644 --- a/examples-switch/core/core_2d_camera_platformer.c +++ b/examples-switch/core/core_2d_camera_platformer.c @@ -106,7 +106,14 @@ int main(void) UpdatePlayer(&player, envItems, envItemsLength, deltaTime); - camera.zoom += ((float)GetMouseWheelMove()*0.05f); + if (IsGamepadButtonDown(0, GAMEPAD_BUTTON_RIGHT_TRIGGER_1)) + { + camera.zoom += 0.05f; + } + else if (IsGamepadButtonDown(0, GAMEPAD_BUTTON_LEFT_TRIGGER_1)) + { + camera.zoom -= 0.05f; + } if (camera.zoom > 3.0f) camera.zoom = 3.0f; else if (camera.zoom < 0.25f) camera.zoom = 0.25f; @@ -117,7 +124,7 @@ int main(void) player.position = (Vector2){ 400, 280 }; } - if (IsKeyPressed(KEY_C)) cameraOption = (cameraOption + 1)%cameraUpdatersLength; + if (IsGamepadButtonReleased(0, GAMEPAD_BUTTON_RIGHT_FACE_LEFT)) cameraOption = (cameraOption + 1)%cameraUpdatersLength; // Call update camera function by its pointer cameraUpdaters[cameraOption](&camera, &player, envItems, envItemsLength, deltaTime, screenWidth, screenHeight); @@ -139,10 +146,10 @@ int main(void) EndMode2D(); DrawText("Controls:", 20, 20, 10, BLACK); - DrawText("- Right/Left to move", 40, 40, 10, DARKGRAY); - DrawText("- Space to jump", 40, 60, 10, DARKGRAY); - DrawText("- Mouse Wheel to Zoom in-out, R to reset zoom", 40, 80, 10, DARKGRAY); - DrawText("- C to change camera mode", 40, 100, 10, DARKGRAY); + DrawText("- Right/Left thumbstick to move", 40, 40, 10, DARKGRAY); + DrawText("- A button to jump", 40, 60, 10, DARKGRAY); + DrawText("- R/L buttons to Zoom in-out, X to reset zoom", 40, 80, 10, DARKGRAY); + DrawText("- Y button to change camera mode", 40, 100, 10, DARKGRAY); DrawText("Current camera mode:", 20, 120, 10, BLACK); DrawText(cameraDescriptions[cameraOption], 40, 140, 10, DARKGRAY); @@ -160,9 +167,9 @@ int main(void) void UpdatePlayer(Player *player, EnvItem *envItems, int envItemsLength, float delta) { - if (IsKeyDown(KEY_LEFT)) player->position.x -= PLAYER_HOR_SPD*delta; - if (IsKeyDown(KEY_RIGHT)) player->position.x += PLAYER_HOR_SPD*delta; - if (IsKeyDown(KEY_SPACE) && player->canJump) + if (GetGamepadAxisMovement(0, 0) < 0) player->position.x -= PLAYER_HOR_SPD*delta; + if (GetGamepadAxisMovement(0, 0) > 0) player->position.x += PLAYER_HOR_SPD*delta; + if (IsGamepadButtonPressed(0, GAMEPAD_BUTTON_RIGHT_FACE_RIGHT) && player->canJump) { player->speed = -PLAYER_JUMP_SPD; player->canJump = false; diff --git a/examples-switch/core/core_3d_camera_first_person.c b/examples-switch/core/core_3d_camera_first_person.c index 8d674b53f..2f8ae2415 100644 --- a/examples-switch/core/core_3d_camera_first_person.c +++ b/examples-switch/core/core_3d_camera_first_person.c @@ -14,6 +14,8 @@ #include "raylib.h" #define MAX_COLUMNS 20 +#define CAMERA_INVERTED_Y_TRUE -1.0f +#define CAMERA_INVERTED_Y_FALSE 1.0f //------------------------------------------------------------------------------------ // Program main entry point @@ -48,6 +50,7 @@ int main(void) } SetCameraMode(camera, CAMERA_FIRST_PERSON); // Set a first person camera mode + SetGamepadYAxisInverted(0, CAMERA_INVERTED_Y_FALSE); SetTargetFPS(60); // Set our game to run at 60 frames-per-second //-------------------------------------------------------------------------------------- @@ -57,7 +60,11 @@ int main(void) { // Update //---------------------------------------------------------------------------------- - UpdateCamera(&camera); + UpdateCameraGamepad(&camera, 0); + if (IsGamepadButtonPressed(0, GAMEPAD_BUTTON_RIGHT_TRIGGER_1)) + { + SetGamepadYAxisInverted(0, -GetGamepadYAxisInverted(0)); + } //---------------------------------------------------------------------------------- // Draw @@ -82,12 +89,13 @@ int main(void) EndMode3D(); - DrawRectangle( 10, 10, 220, 70, Fade(SKYBLUE, 0.5f)); - DrawRectangleLines( 10, 10, 220, 70, BLUE); + DrawRectangle( 10, 10, 220, 90, Fade(SKYBLUE, 0.5f)); + DrawRectangleLines( 10, 10, 220, 90, BLUE); DrawText("First person camera default controls:", 20, 20, 10, BLACK); - DrawText("- Move with keys: W, A, S, D", 40, 40, 10, DARKGRAY); - DrawText("- Mouse move to look around", 40, 60, 10, DARKGRAY); + DrawText("- Move with Left Thumbstick", 40, 40, 10, DARKGRAY); + DrawText("- Look around with Right Thumbstick", 40, 60, 10, DARKGRAY); + DrawText("- Press R to invert Look Y-Axis", 40, 80, 10, DARKGRAY); EndDrawing(); //---------------------------------------------------------------------------------- diff --git a/examples-switch/core/core_3d_camera_free.c b/examples-switch/core/core_3d_camera_free.c index c8ba7af56..8ac87a2e4 100644 --- a/examples-switch/core/core_3d_camera_free.c +++ b/examples-switch/core/core_3d_camera_free.c @@ -45,9 +45,9 @@ int main(void) { // Update //---------------------------------------------------------------------------------- - UpdateCamera(&camera); + UpdateCameraGamepad(&camera, 0); - if (IsKeyDown('Z')) camera.target = (Vector3){ 0.0f, 0.0f, 0.0f }; + if (IsGamepadButtonDown(0, GAMEPAD_BUTTON_RIGHT_FACE_UP)) camera.target = (Vector3){ 0.0f, 0.0f, 0.0f }; //---------------------------------------------------------------------------------- // Draw @@ -69,11 +69,11 @@ int main(void) DrawRectangleLines( 10, 10, 320, 133, BLUE); DrawText("Free camera default controls:", 20, 20, 10, BLACK); - DrawText("- Mouse Wheel to Zoom in-out", 40, 40, 10, DARKGRAY); - DrawText("- Mouse Wheel Pressed to Pan", 40, 60, 10, DARKGRAY); - DrawText("- Alt + Mouse Wheel Pressed to Rotate", 40, 80, 10, DARKGRAY); - DrawText("- Alt + Ctrl + Mouse Wheel Pressed for Smooth Zoom", 40, 100, 10, DARKGRAY); - DrawText("- Z to zoom to (0, 0, 0)", 40, 120, 10, DARKGRAY); + DrawText("- R/L Bumpers to Zoom", 40, 40, 10, DARKGRAY); + DrawText("- Left Thumbstick to Pan", 40, 60, 10, DARKGRAY); + DrawText("- Right Thumbstick to Rotate", 40, 80, 10, DARKGRAY); + DrawText("- Hold button A for Smooth Zoom with Left Thumbstick", 40, 100, 10, DARKGRAY); + DrawText("- Press X button to zoom to (0, 0, 0)", 40, 120, 10, DARKGRAY); EndDrawing(); //---------------------------------------------------------------------------------- diff --git a/examples-switch/core/core_3d_picking.c b/examples-switch/core/core_3d_picking.c index 00cc77828..707d3589f 100644 --- a/examples-switch/core/core_3d_picking.c +++ b/examples-switch/core/core_3d_picking.c @@ -50,14 +50,13 @@ int main(void) { // Update //---------------------------------------------------------------------------------- - UpdateCamera(&camera); + UpdateCameraGamepad(&camera, 0); - if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT)) + if (GetTouchPointCount() > 0) { if (!collision.hit) { - ray = GetMouseRay(GetMousePosition(), camera); - + ray = GetMouseRay(GetTouchPosition(0), camera); // Check collision between ray and box collision = GetRayCollisionBox(ray, (BoundingBox){(Vector3){ cubePosition.x - cubeSize.x/2, cubePosition.y - cubeSize.y/2, cubePosition.z - cubeSize.z/2 }, @@ -93,7 +92,7 @@ int main(void) EndMode3D(); - DrawText("Try selecting the box with mouse!", 240, 10, 20, DARKGRAY); + DrawText("Try selecting the box by touching it!", 240, 10, 20, DARKGRAY); if (collision.hit) DrawText("BOX SELECTED", (screenWidth - MeasureText("BOX SELECTED", 30)) / 2, (int)(screenHeight * 0.1f), 30, GREEN); diff --git a/examples-switch/core/core_basic_screen_manager.c b/examples-switch/core/core_basic_screen_manager.c index 6fc4791dd..9a6ea4f3c 100644 --- a/examples-switch/core/core_basic_screen_manager.c +++ b/examples-switch/core/core_basic_screen_manager.c @@ -15,6 +15,7 @@ #include "raylib.h" +#define START_BUTTON GAMEPAD_BUTTON_MIDDLE_RIGHT //------------------------------------------------------------------------------------------ // Types and Structures Definition //------------------------------------------------------------------------------------------ @@ -41,11 +42,16 @@ int main(void) SetTargetFPS(60); // Set desired framerate (frames-per-second) //-------------------------------------------------------------------------------------- + // Gesture detection for TAP + bool hasScreenBeenTouched = false; + // Main game loop while (!WindowShouldClose()) // Detect window close button or ESC key { // Update //---------------------------------------------------------------------------------- + bool isNextButtonPressed = IsGamepadButtonPressed(0, START_BUTTON); + switch(currentScreen) { case LOGO: @@ -65,33 +71,38 @@ int main(void) // TODO: Update TITLE screen variables here! // Press enter to change to GAMEPLAY screen - if (IsKeyPressed(KEY_ENTER) || IsGestureDetected(GESTURE_TAP)) + if (isNextButtonPressed || (!hasScreenBeenTouched && GetTouchPointCount() > 0)) { currentScreen = GAMEPLAY; + hasScreenBeenTouched = true; } } break; case GAMEPLAY: { // TODO: Update GAMEPLAY screen variables here! - // Press enter to change to ENDING screen - if (IsKeyPressed(KEY_ENTER) || IsGestureDetected(GESTURE_TAP)) + if (isNextButtonPressed || (!hasScreenBeenTouched && GetTouchPointCount() > 0)) { currentScreen = ENDING; + hasScreenBeenTouched = true; } } break; case ENDING: { // TODO: Update ENDING screen variables here! - // Press enter to return to TITLE screen - if (IsKeyPressed(KEY_ENTER) || IsGestureDetected(GESTURE_TAP)) + if (isNextButtonPressed || (!hasScreenBeenTouched && GetTouchPointCount() > 0)) { currentScreen = TITLE; + hasScreenBeenTouched = true; } } break; default: break; } + + // Reset TAP gesture + hasScreenBeenTouched = GetTouchPointCount() > 0; + //---------------------------------------------------------------------------------- // Draw @@ -99,6 +110,8 @@ int main(void) BeginDrawing(); ClearBackground(RAYWHITE); + const int horizontalCenter = screenHeight / 2; + int touchCount = GetTouchPointCount(); switch(currentScreen) { @@ -114,7 +127,7 @@ int main(void) // TODO: Draw TITLE screen here! DrawRectangle(0, 0, screenWidth, screenHeight, GREEN); DrawText("TITLE SCREEN", 20, 20, 40, DARKGREEN); - DrawText("PRESS ENTER or TAP to JUMP to GAMEPLAY SCREEN", 120, 220, 20, DARKGREEN); + DrawText("PRESS START or TAP to JUMP to GAMEPLAY SCREEN", 120, horizontalCenter, 20, DARKGREEN); } break; case GAMEPLAY: @@ -122,7 +135,7 @@ int main(void) // TODO: Draw GAMEPLAY screen here! DrawRectangle(0, 0, screenWidth, screenHeight, PURPLE); DrawText("GAMEPLAY SCREEN", 20, 20, 40, MAROON); - DrawText("PRESS ENTER or TAP to JUMP to ENDING SCREEN", 130, 220, 20, MAROON); + DrawText("PRESS START or TAP to JUMP to ENDING SCREEN", 130, horizontalCenter, 20, MAROON); } break; case ENDING: @@ -130,12 +143,17 @@ int main(void) // TODO: Draw ENDING screen here! DrawRectangle(0, 0, screenWidth, screenHeight, BLUE); DrawText("ENDING SCREEN", 20, 20, 40, DARKBLUE); - DrawText("PRESS ENTER or TAP to RETURN to TITLE SCREEN", 120, 220, 20, DARKBLUE); + DrawText("PRESS START or TAP to RETURN to TITLE SCREEN", 120, horizontalCenter, 20, DARKBLUE); } break; default: break; } - + for (int i = 0; i < touchCount; i++) + { + Vector2 touchPosition = GetTouchPosition(i); + DrawCircle(touchPosition.x, touchPosition.y, 75, RED); + } + EndDrawing(); //---------------------------------------------------------------------------------- } diff --git a/examples-switch/core/core_input_gamepad.c b/examples-switch/core/core_input_gamepad.c index 61451aced..1bd56f1c1 100644 --- a/examples-switch/core/core_input_gamepad.c +++ b/examples-switch/core/core_input_gamepad.c @@ -18,6 +18,7 @@ ********************************************************************************************/ #include "raylib.h" +#include // NOTE: Gamepad name ID depends on drivers and OS #define XBOX360_LEGACY_NAME_ID "Xbox Controller" @@ -38,13 +39,15 @@ int main(void) //-------------------------------------------------------------------------------------- const int screenWidth = 1280; const int screenHeight = 720; - + + romfsInit(); SetConfigFlags(FLAG_MSAA_4X_HINT); // Set MSAA 4X hint before windows creation InitWindow(screenWidth, screenHeight, "raylib [core] example - gamepad input"); - Texture2D texPs3Pad = LoadTexture("resources/ps3.png"); - Texture2D texXboxPad = LoadTexture("resources/xbox.png"); + Texture2D texPs3Pad = LoadTexture("romfs:/resources/ps3.png"); + Texture2D texXboxPad = LoadTexture("romfs:/resources/xbox.png"); + Texture2D texNinProPad = LoadTexture("romfs:/resources/switch_pro.png"); SetTargetFPS(60); // Set our game to run at 60 frames-per-second //-------------------------------------------------------------------------------------- @@ -66,7 +69,6 @@ int main(void) if (IsGamepadAvailable(0)) { DrawText(TextFormat("GP1: %s", GetGamepadName(0)), 10, 10, 10, BLACK); - if (TextIsEqual(GetGamepadName(0), XBOX360_NAME_ID) || TextIsEqual(GetGamepadName(0), XBOX360_LEGACY_NAME_ID)) { DrawTexture(texXboxPad, 0, 0, DARKGRAY); @@ -98,13 +100,13 @@ int main(void) DrawCircle(259, 152, 39, BLACK); DrawCircle(259, 152, 34, LIGHTGRAY); DrawCircle(259 + (int)(GetGamepadAxisMovement(0, GAMEPAD_AXIS_LEFT_X)*20), - 152 + (int)(GetGamepadAxisMovement(0, GAMEPAD_AXIS_LEFT_Y)*20), 25, BLACK); + 152 + (int)(GetGamepadAxisMovement(0, GAMEPAD_AXIS_LEFT_Y)*20), 25, BLACK); // Draw axis: right joystick - DrawCircle(461, 237, 38, BLACK); - DrawCircle(461, 237, 33, LIGHTGRAY); - DrawCircle(461 + (int)(GetGamepadAxisMovement(0, GAMEPAD_AXIS_RIGHT_X)*20), - 237 + (int)(GetGamepadAxisMovement(0, GAMEPAD_AXIS_RIGHT_Y)*20), 25, BLACK); + DrawCircle(450, 240, 60, BLACK); + DrawCircle(450, 240, 33, LIGHTGRAY); + DrawCircle(450 + (int)(GetGamepadAxisMovement(0, GAMEPAD_AXIS_RIGHT_X)*20), + 240 + (int)(GetGamepadAxisMovement(0, GAMEPAD_AXIS_RIGHT_Y)*20), 25, BLACK); // Draw axis: left-right triggers DrawRectangle(170, 30, 15, 70, GRAY); @@ -146,13 +148,13 @@ int main(void) DrawCircle(319, 255, 35, BLACK); DrawCircle(319, 255, 31, LIGHTGRAY); DrawCircle(319 + (int)(GetGamepadAxisMovement(0, GAMEPAD_AXIS_LEFT_X) * 20), - 255 + (int)(GetGamepadAxisMovement(0, GAMEPAD_AXIS_LEFT_Y) * 20), 25, BLACK); + 255 + (int)(GetGamepadAxisMovement(0, GAMEPAD_AXIS_LEFT_Y) * 20), 25, BLACK); // Draw axis: right joystick DrawCircle(475, 255, 35, BLACK); DrawCircle(475, 255, 31, LIGHTGRAY); DrawCircle(475 + (int)(GetGamepadAxisMovement(0, GAMEPAD_AXIS_RIGHT_X) * 20), - 255 + (int)(GetGamepadAxisMovement(0, GAMEPAD_AXIS_RIGHT_Y) * 20), 25, BLACK); + 255 + (int)(GetGamepadAxisMovement(0, GAMEPAD_AXIS_RIGHT_Y) * 20), 25, BLACK); // Draw axis: left-right triggers DrawRectangle(169, 48, 15, 70, GRAY); @@ -160,6 +162,59 @@ int main(void) DrawRectangle(169, 48, 15, (int)(((1 - GetGamepadAxisMovement(0, GAMEPAD_AXIS_LEFT_TRIGGER)) / 2) * 70), RED); DrawRectangle(611, 48, 15, (int)(((1 - GetGamepadAxisMovement(0, GAMEPAD_AXIS_RIGHT_TRIGGER)) / 2) * 70), RED); } + else if (TextIsEqual(GetGamepadName(0), "Nintendo Switch Pro Controller")) + { + DrawTexture(texNinProPad, screenWidth/2 - 400, screenHeight/2 - 352, DARKGRAY); + + // Draw buttons: basic + if (IsGamepadButtonDown(0, GAMEPAD_BUTTON_MIDDLE_RIGHT)) DrawCircle(screenWidth/2 + 92, 192, 15, RED); + if (IsGamepadButtonDown(0, GAMEPAD_BUTTON_MIDDLE_LEFT)) DrawCircle(screenWidth/2 - 99, 192, 15, RED); + if (IsGamepadButtonDown(0, GAMEPAD_BUTTON_RIGHT_FACE_LEFT)) DrawCircle(screenWidth/2 + 143, 252, 25, GREEN); + if (IsGamepadButtonDown(0, GAMEPAD_BUTTON_RIGHT_FACE_DOWN)) DrawCircle(screenWidth/2 + 205, 308, 25, YELLOW); + if (IsGamepadButtonDown(0, GAMEPAD_BUTTON_RIGHT_FACE_RIGHT)) DrawCircle(screenWidth/2 + 267, 252, 25, RED); + if (IsGamepadButtonDown(0, GAMEPAD_BUTTON_RIGHT_FACE_UP)) DrawCircle(screenWidth/2 + 205, 196, 25, BLUE); + + // Draw buttons: d-pad + // DrawRectangle(317, 202, 19, 71, BLACK); + // DrawRectangle(293, 228, 69, 19, BLACK); + DrawRectangle(499, 305, 40, 115, GRAY); + DrawRectangle(460, 346, 115, 40, GRAY); + if (IsGamepadButtonDown(0, GAMEPAD_BUTTON_LEFT_FACE_UP)) DrawRectangle(499, 305, 40, 30, RED); + if (IsGamepadButtonDown(0, GAMEPAD_BUTTON_LEFT_FACE_DOWN)) DrawRectangle(499, 396, 40, 30, RED); + if (IsGamepadButtonDown(0, GAMEPAD_BUTTON_LEFT_FACE_LEFT)) DrawRectangle(459, 346, 25, 40, RED); + if (IsGamepadButtonDown(0, GAMEPAD_BUTTON_LEFT_FACE_RIGHT)) DrawRectangle(550, 346, 26, 40, RED); + + // Draw buttons: left-right back + if (IsGamepadButtonDown(0, GAMEPAD_BUTTON_LEFT_TRIGGER_1)) DrawCircle(259 + 230, 61, 20, RED); + if (IsGamepadButtonDown(0, GAMEPAD_BUTTON_RIGHT_TRIGGER_1)) DrawCircle(536 + 230, 61, 20, RED); + + // Draw axis: left joystick + DrawCircle(421, 251, 70, BLACK); + DrawCircle(421, 251, 65, LIGHTGRAY); + DrawCircle(421 + (int)(GetGamepadAxisMovement(0, GAMEPAD_AXIS_LEFT_X)*20), + 251 + (int)(GetGamepadAxisMovement(0, GAMEPAD_AXIS_LEFT_Y)*-20), 35, BLACK); + + // Draw axis: right joystick + DrawCircle(screenWidth/2 + 103, 360, 70, BLACK); + DrawCircle(screenWidth/2 + 103, 360, 65, LIGHTGRAY); + DrawCircle(screenWidth/2 + 103 + (int)(GetGamepadAxisMovement(0, GAMEPAD_AXIS_RIGHT_X)*20), + 360 + (int)(GetGamepadAxisMovement(0, GAMEPAD_AXIS_RIGHT_Y)*-20), 35, BLACK); + + // joystick down press + if(IsGamepadButtonDown(0, GAMEPAD_BUTTON_LEFT_THUMB)) DrawCircle(421 + (int)(GetGamepadAxisMovement(0, GAMEPAD_AXIS_LEFT_X)*20), + 251 + (int)(GetGamepadAxisMovement(0, GAMEPAD_AXIS_LEFT_Y)*-20), 35, RED); + if(IsGamepadButtonDown(0, GAMEPAD_BUTTON_RIGHT_THUMB)) DrawCircle(screenWidth/2 + 103 + (int)(GetGamepadAxisMovement(0, GAMEPAD_AXIS_RIGHT_X)*20), + 360 + (int)(GetGamepadAxisMovement(0, GAMEPAD_AXIS_RIGHT_Y)*-20), 35, RED); + + // Draw axis: left-right triggers + DrawRectangle(170 + 230, 30, 15, 70, GRAY); + DrawRectangle(604 + 230, 30, 15, 70, GRAY); + DrawRectangle(170 + 230, 30, 15, (int)(((1 + GetGamepadAxisMovement(0, GAMEPAD_AXIS_LEFT_TRIGGER))/2)*70), RED); + DrawRectangle(604 + 230, 30, 15, (int)(((1 + GetGamepadAxisMovement(0, GAMEPAD_AXIS_RIGHT_TRIGGER))/2)*70), RED); + + //DrawText(TextFormat("Xbox axis LT: %02.02f", GetGamepadAxisMovement(0, GAMEPAD_AXIS_LEFT_TRIGGER)), 10, 40, 10, BLACK); + //DrawText(TextFormat("Xbox axis RT: %02.02f", GetGamepadAxisMovement(0, GAMEPAD_AXIS_RIGHT_TRIGGER)), 10, 60, 10, BLACK); + } else { DrawText("- GENERIC GAMEPAD -", 280, 180, 20, GRAY); @@ -192,9 +247,11 @@ int main(void) //-------------------------------------------------------------------------------------- UnloadTexture(texPs3Pad); UnloadTexture(texXboxPad); + UnloadTexture(texNinProPad); CloseWindow(); // Close window and OpenGL context //-------------------------------------------------------------------------------------- + romfsExit(); return 0; } diff --git a/examples-switch/core/core_input_multi_gamepad.c b/examples-switch/core/core_input_multi_gamepad.c new file mode 100644 index 000000000..955d7c14f --- /dev/null +++ b/examples-switch/core/core_input_multi_gamepad.c @@ -0,0 +1,96 @@ +/******************************************************************************************* +* +* raylib [core] example - Gamepad input +* +* NOTE: This example requires a Gamepad connected to the system +* raylib is configured to work with the following gamepads: +* - Xbox 360 Controller (Xbox 360, Xbox One) +* - PLAYSTATION(R)3 Controller +* Check raylib.h for buttons configuration +* +* Example originally created with raylib 1.1, last time updated with raylib 4.2 +* +* Example licensed under an unmodified zlib/libpng license, which is an OSI-certified, +* BSD-like license that allows static linking with closed source software +* +* Copyright (c) 2013-2022 Ramon Santamaria (@raysan5) +* +********************************************************************************************/ + +#include "raylib.h" +#include + +// NOTE: Gamepad name ID depends on drivers and OS +#define XBOX360_LEGACY_NAME_ID "Xbox Controller" +#if defined(PLATFORM_RPI) + #define XBOX360_NAME_ID "Microsoft X-Box 360 pad" + #define PS3_NAME_ID "PLAYSTATION(R)3 Controller" +#else + #define XBOX360_NAME_ID "Xbox 360 Controller" + #define PS3_NAME_ID "PLAYSTATION(R)3 Controller" +#endif +#define MAX_GAMEPADS 4 + +//------------------------------------------------------------------------------------ +// Program main entry point +//------------------------------------------------------------------------------------ +int main(void) +{ + // Initialization + //-------------------------------------------------------------------------------------- + const int screenWidth = 1280; + const int screenHeight = 720; + + SetConfigFlags(FLAG_MSAA_4X_HINT); // Set MSAA 4X hint before windows creation + + InitWindow(screenWidth, screenHeight, "raylib [core] example - gamepad input"); + + SetTargetFPS(60); // Set our game to run at 60 frames-per-second + //-------------------------------------------------------------------------------------- + + // Main game loop + while (!WindowShouldClose()) // Detect window close button or ESC key + { + // Update + //---------------------------------------------------------------------------------- + // ... + //---------------------------------------------------------------------------------- + + // Draw + //---------------------------------------------------------------------------------- + BeginDrawing(); + + ClearBackground(DARKGRAY); + + for(int i = 0; i< MAX_GAMEPADS; i++) { + int height = 75 * (i + 3); + if(IsGamepadAvailable(i)) + { + if (IsGamepadButtonDown(i, GAMEPAD_BUTTON_RIGHT_FACE_RIGHT)) + { + DrawRectangle(0, height - 22, 1280, 75, LIGHTGRAY); + DrawText(TextFormat("Controller %i", i+1), 300, height, 30, DARKGRAY); + DrawText(TextFormat("%s", GetGamepadName(i)), 600, height, 30, DARKGRAY); + } else { + DrawText(TextFormat("Controller %i", i+1), 300, height, 30, LIGHTGRAY); + DrawText(TextFormat("%s", GetGamepadName(i)), 600, height, 30, LIGHTGRAY); + } + } else { + DrawText(TextFormat("Controller %i", i+1), 300, height, 30, LIGHTGRAY); + DrawText(TextFormat("Not Connected"), 600, height, 30, LIGHTGRAY); + } + } + DrawText("Press", 1110, 670, 20, GRAY); + DrawCircle(1200, 680, 20, GRAY); + DrawCircle(1200, 680, 18, DARKGRAY); + DrawText("A", 1194, 671, 20, GRAY); + + EndDrawing(); + //---------------------------------------------------------------------------------- + } + + CloseWindow(); // Close window and OpenGL context + //-------------------------------------------------------------------------------------- + + return 0; +} diff --git a/examples-switch/core/core_input_multitouch.c b/examples-switch/core/core_input_multitouch.c index d1eb44590..5d178f108 100644 --- a/examples-switch/core/core_input_multitouch.c +++ b/examples-switch/core/core_input_multitouch.c @@ -56,7 +56,7 @@ int main(void) { // Draw circle and touch index number DrawCircleV(touchPositions[i], 34, ORANGE); - DrawText(TextFormat("%d", i), (int)touchPositions[i].x - 10, (int)touchPositions[i].y - 70, 40, BLACK); + DrawText(TextFormat("%d", GetTouchPointId(i)), (int)touchPositions[i].x - 10, (int)touchPositions[i].y - 70, 40, BLACK); } } diff --git a/examples-switch/core/core_split_screen.c b/examples-switch/core/core_split_screen.c index 5b9868a49..8211c878b 100644 --- a/examples-switch/core/core_split_screen.c +++ b/examples-switch/core/core_split_screen.c @@ -59,6 +59,7 @@ int main(void) cameraPlayer1.target.y = 1.0f; cameraPlayer1.position.z = -3.0f; cameraPlayer1.position.y = 1.0f; + cameraPlayer1.projection = CAMERA_PERSPECTIVE; RenderTexture screenPlayer1 = LoadRenderTexture(screenWidth/2, screenHeight); @@ -68,9 +69,13 @@ int main(void) cameraPlayer2.target.y = 3.0f; cameraPlayer2.position.x = -3.0f; cameraPlayer2.position.y = 3.0f; + cameraPlayer2.projection = CAMERA_PERSPECTIVE; RenderTexture screenPlayer2 = LoadRenderTexture(screenWidth / 2, screenHeight); + SetCameraMode(cameraPlayer1, CAMERA_FIRST_PERSON); + SetCameraMode(cameraPlayer2, CAMERA_FIRST_PERSON); + // Build a flipped rectangle the size of the split view to use for drawing later Rectangle splitScreenRect = { 0.0f, 0.0f, (float)screenPlayer1.texture.width, (float)-screenPlayer1.texture.height }; @@ -84,31 +89,10 @@ int main(void) //---------------------------------------------------------------------------------- // If anyone moves this frame, how far will they move based on the time since the last frame // this moves thigns at 10 world units per second, regardless of the actual FPS - float offsetThisFrame = 10.0f*GetFrameTime(); + // float offsetThisFrame = 10.0f*GetFrameTime(); - // Move Player1 forward and backwards (no turning) - if (IsKeyDown(KEY_W)) - { - cameraPlayer1.position.z += offsetThisFrame; - cameraPlayer1.target.z += offsetThisFrame; - } - else if (IsKeyDown(KEY_S)) - { - cameraPlayer1.position.z -= offsetThisFrame; - cameraPlayer1.target.z -= offsetThisFrame; - } - - // Move Player2 forward and backwards (no turning) - if (IsKeyDown(KEY_UP)) - { - cameraPlayer2.position.x += offsetThisFrame; - cameraPlayer2.target.x += offsetThisFrame; - } - else if (IsKeyDown(KEY_DOWN)) - { - cameraPlayer2.position.x -= offsetThisFrame; - cameraPlayer2.target.x -= offsetThisFrame; - } + UpdateCameraGamepad(&cameraPlayer1, 0); + UpdateCameraGamepad(&cameraPlayer2, 1); //---------------------------------------------------------------------------------- // Draw @@ -119,16 +103,15 @@ int main(void) BeginMode3D(cameraPlayer1); DrawScene(); EndMode3D(); - DrawText("PLAYER1 W/S to move", 10, 10, 20, RED); + DrawText("PLAYER1", 10, 10, 20, RED); EndTextureMode(); - // Draw Player2 view to the render texture BeginTextureMode(screenPlayer2); ClearBackground(SKYBLUE); BeginMode3D(cameraPlayer2); DrawScene(); EndMode3D(); - DrawText("PLAYER2 UP/DOWN to move", 10, 10, 20, BLUE); + DrawText("PLAYER2", 10, 10, 20, BLUE); EndTextureMode(); // Draw both views render textures to the screen side by side @@ -136,6 +119,7 @@ int main(void) ClearBackground(BLACK); DrawTextureRec(screenPlayer1.texture, splitScreenRect, (Vector2){ 0, 0 }, WHITE); DrawTextureRec(screenPlayer2.texture, splitScreenRect, (Vector2){ screenWidth/2.0f, 0 }, WHITE); + DrawRectangle(screenWidth/2 - 5, 0, 10, 720, BLACK); EndDrawing(); } diff --git a/examples-switch/core/resources/LICENSE.md b/examples-switch/romfs/resources/LICENSE (1).md similarity index 100% rename from examples-switch/core/resources/LICENSE.md rename to examples-switch/romfs/resources/LICENSE (1).md diff --git a/examples-switch/core/resources/distortion100.fs b/examples-switch/romfs/resources/distortion100.fs similarity index 100% rename from examples-switch/core/resources/distortion100.fs rename to examples-switch/romfs/resources/distortion100.fs diff --git a/examples-switch/core/resources/distortion330.fs b/examples-switch/romfs/resources/distortion330.fs similarity index 100% rename from examples-switch/core/resources/distortion330.fs rename to examples-switch/romfs/resources/distortion330.fs diff --git a/examples-switch/core/resources/ps3.png b/examples-switch/romfs/resources/ps3.png similarity index 100% rename from examples-switch/core/resources/ps3.png rename to examples-switch/romfs/resources/ps3.png diff --git a/examples-switch/romfs/resources/switch_pro.png b/examples-switch/romfs/resources/switch_pro.png new file mode 100644 index 000000000..cb7473cee Binary files /dev/null and b/examples-switch/romfs/resources/switch_pro.png differ diff --git a/examples-switch/core/resources/xbox.png b/examples-switch/romfs/resources/xbox.png similarity index 100% rename from examples-switch/core/resources/xbox.png rename to examples-switch/romfs/resources/xbox.png diff --git a/examples-switch/text/text_draw_3d.c b/examples-switch/text/text_draw_3d.c index d4508b36a..a8ab86e2f 100644 --- a/examples-switch/text/text_draw_3d.c +++ b/examples-switch/text/text_draw_3d.c @@ -141,7 +141,7 @@ int main(void) { // Update //---------------------------------------------------------------------------------- - UpdateCamera(&camera); + UpdateCameraGamepad(&camera, 0); // Handle font files dropped if (IsFileDropped()) diff --git a/src/config.h b/src/config.h index 9bad2e8ab..f5240133f 100644 --- a/src/config.h +++ b/src/config.h @@ -71,6 +71,7 @@ #define NX_SUPPORT_GAMEPAD_EMULATION 1 // Enabling this flag allows debugging by USB, the application will wait for an USB connection to start //#define NX_USB_DEBUGGER 1 +// #define ENABLE_DEV_EXIT 1 // Allows for exit when gamepad kbm emulation is disabled // rcore: Configuration values //------------------------------------------------------------------------------------ diff --git a/src/raylib.h b/src/raylib.h index c48380d82..41ea564be 100644 --- a/src/raylib.h +++ b/src/raylib.h @@ -303,6 +303,7 @@ typedef struct Font { // Camera, defines position/orientation in 3d space typedef struct Camera3D { Vector3 position; // Camera position + Vector2 angle; // Camera angle (Required for splitscreen instead of shared global) Vector3 target; // Camera target it looks-at Vector3 up; // Camera up vector (rotation over its axis) float fovy; // Camera field-of-view aperture in Y (degrees) in perspective, used as near plane width in orthographic @@ -1113,6 +1114,8 @@ RLAPI int GetGamepadButtonPressed(void); // Get the last ga RLAPI int GetGamepadAxisCount(int gamepad); // Get gamepad axis count for a gamepad RLAPI float GetGamepadAxisMovement(int gamepad, int axis); // Get axis movement value for a gamepad axis RLAPI int SetGamepadMappings(const char *mappings); // Set internal gamepad mappings (SDL_GameControllerDB) +RLAPI void SetGamepadYAxisInverted(int gamepad, float yInverted); +RLAPI float GetGamepadYAxisInverted(int gamepad); // Input-related functions: mouse RLAPI bool IsMouseButtonPressed(int button); // Check if a mouse button has been pressed once @@ -1154,6 +1157,9 @@ RLAPI float GetGesturePinchAngle(void); // Get gesture pinch ang //------------------------------------------------------------------------------------ RLAPI void SetCameraMode(Camera camera, int mode); // Set camera mode (multiple camera modes available) RLAPI void UpdateCamera(Camera *camera); // Update camera position for selected mode +RLAPI void UpdateCameraGamepad(Camera *camera, int Gamepad); // Update camera position for selected mode +RLAPI void SetCameraZoomFactor(Vector2 zoomFactor); // Gamepad equivalent of mousewheel +RLAPI void SetCameraPrevZoomFactor(Vector2 previousZoomFactor); // Gamepad equivalent for automation RLAPI void SetCameraPanControl(int keyPan); // Set camera pan key to combine with mouse movement (free camera) RLAPI void SetCameraAltControl(int keyAlt); // Set camera alt key to combine with mouse movement (free camera) diff --git a/src/rcamera.h b/src/rcamera.h index 37ea13a67..e658c90db 100644 --- a/src/rcamera.h +++ b/src/rcamera.h @@ -159,8 +159,12 @@ void SetCameraMoveControls(int keyFront, int keyBack, #define CAMERA_FREE_DISTANCE_MAX_CLAMP 120.0f #define CAMERA_FREE_MIN_CLAMP 85.0f #define CAMERA_FREE_MAX_CLAMP -85.0f -#define CAMERA_FREE_SMOOTH_ZOOM_SENSITIVITY 0.05f #define CAMERA_FREE_PANNING_DIVIDER 5.1f +#if defined(PLATFORM_NX) + #define CAMERA_FREE_SMOOTH_ZOOM_SENSITIVITY -0.5f +#else + #define CAMERA_FREE_SMOOTH_ZOOM_SENSITIVITY 0.05f +#endif // ORBITAL_CAMERA #define CAMERA_ORBITAL_SPEED 0.5f // Radians per second @@ -223,7 +227,11 @@ static CameraData CAMERA = { // Global CAMERA state context .playerEyesPosition = 1.85f, .angle = { 0 }, .moveControl = { 'W', 'S', 'D', 'A', 'E', 'Q' }, +#if defined(PLATFORM_NX) + .smoothZoomControl = GAMEPAD_BUTTON_RIGHT_FACE_RIGHT, // Npad button A +#else .smoothZoomControl = 341, // raylib: KEY_LEFT_CONTROL +#endif .altControl = 342, // raylib: KEY_LEFT_ALT .panControl = 2 // raylib: MOUSE_BUTTON_MIDDLE }; @@ -534,6 +542,285 @@ void UpdateCamera(Camera *camera) default: break; } } +// Update camera depending on selected mode +// NOTE: Camera controls depend on some raylib functions: +// System: EnableCursor(), DisableCursor() +// Mouse: IsMouseButtonDown(), GetMousePosition(), GetMouseWheelMove() +// Keys: IsKeyDown() +void UpdateCameraGamepad(Camera *camera, int gamepad) +{ + static float swingCounter[MAX_GAMEPADS] = { 0.0f, 0.0f, 0.0f, 0.0f }; // Used for 1st person swinging movement + + // TODO: Compute CAMERA.targetDistance and CAMERA.angle here (?) + + // Pan with Left Thumbstick + Vector2 leftStickDelta = { + -GetGamepadAxisMovement(gamepad, GAMEPAD_AXIS_LEFT_X), + GetGamepadAxisMovement(gamepad, GAMEPAD_AXIS_LEFT_Y) + }; + // Rotate with Right Thumbstick + Vector2 rightStickDelta = { + -GetGamepadAxisMovement(gamepad, GAMEPAD_AXIS_RIGHT_X), + GetGamepadAxisMovement(gamepad, GAMEPAD_AXIS_RIGHT_Y) + }; + float zoomFactor = GetMouseWheelMove(); + bool szoomKey = IsGamepadButtonDown(gamepad, CAMERA.smoothZoomControl); // Npad A + + bool direction[4] = { + GetGamepadAxisMovement(gamepad, GAMEPAD_AXIS_LEFT_Y) > 0, + GetGamepadAxisMovement(gamepad, GAMEPAD_AXIS_LEFT_Y) < 0, + GetGamepadAxisMovement(gamepad, GAMEPAD_AXIS_LEFT_X) > 0, + GetGamepadAxisMovement(gamepad, GAMEPAD_AXIS_LEFT_X) < 0 + }; + + // Support for multiple automatic camera modes + // NOTE: In case of CAMERA_CUSTOM nothing happens here, user must update it manually + switch (CAMERA.mode) + { + case CAMERA_FREE: // Camera free controls, using standard 3d-content-creation scheme + { + // Camera zoom + if ((CAMERA.targetDistance < CAMERA_FREE_DISTANCE_MAX_CLAMP) && (zoomFactor < 0)) + { + CAMERA.targetDistance -= (zoomFactor*CAMERA_MOUSE_SCROLL_SENSITIVITY); + if (CAMERA.targetDistance > CAMERA_FREE_DISTANCE_MAX_CLAMP) CAMERA.targetDistance = CAMERA_FREE_DISTANCE_MAX_CLAMP; + } + + // Camera looking down + else if ((camera->position.y > camera->target.y) && (CAMERA.targetDistance == CAMERA_FREE_DISTANCE_MAX_CLAMP) && (zoomFactor < 0)) + { + camera->target.x += zoomFactor*(camera->target.x - camera->position.x)*CAMERA_MOUSE_SCROLL_SENSITIVITY/CAMERA.targetDistance; + camera->target.y += zoomFactor*(camera->target.y - camera->position.y)*CAMERA_MOUSE_SCROLL_SENSITIVITY/CAMERA.targetDistance; + camera->target.z += zoomFactor*(camera->target.z - camera->position.z)*CAMERA_MOUSE_SCROLL_SENSITIVITY/CAMERA.targetDistance; + } + else if ((camera->position.y > camera->target.y) && (camera->target.y >= 0)) + { + camera->target.x += zoomFactor*(camera->target.x - camera->position.x)*CAMERA_MOUSE_SCROLL_SENSITIVITY/CAMERA.targetDistance; + camera->target.y += zoomFactor*(camera->target.y - camera->position.y)*CAMERA_MOUSE_SCROLL_SENSITIVITY/CAMERA.targetDistance; + camera->target.z += zoomFactor*(camera->target.z - camera->position.z)*CAMERA_MOUSE_SCROLL_SENSITIVITY/CAMERA.targetDistance; + + // if (camera->target.y < 0) camera->target.y = -0.001; + } + else if ((camera->position.y > camera->target.y) && (camera->target.y < 0) && (zoomFactor > 0)) + { + CAMERA.targetDistance -= (zoomFactor*CAMERA_MOUSE_SCROLL_SENSITIVITY); + if (CAMERA.targetDistance < CAMERA_FREE_DISTANCE_MIN_CLAMP) CAMERA.targetDistance = CAMERA_FREE_DISTANCE_MIN_CLAMP; + } + // Camera looking up + else if ((camera->position.y < camera->target.y) && (CAMERA.targetDistance == CAMERA_FREE_DISTANCE_MAX_CLAMP) && (zoomFactor < 0)) + { + camera->target.x += zoomFactor*(camera->target.x - camera->position.x)*CAMERA_MOUSE_SCROLL_SENSITIVITY/CAMERA.targetDistance; + camera->target.y += zoomFactor*(camera->target.y - camera->position.y)*CAMERA_MOUSE_SCROLL_SENSITIVITY/CAMERA.targetDistance; + camera->target.z += zoomFactor*(camera->target.z - camera->position.z)*CAMERA_MOUSE_SCROLL_SENSITIVITY/CAMERA.targetDistance; + } + else if ((camera->position.y < camera->target.y) && (camera->target.y <= 0)) + { + camera->target.x += zoomFactor*(camera->target.x - camera->position.x)*CAMERA_MOUSE_SCROLL_SENSITIVITY/CAMERA.targetDistance; + camera->target.y += zoomFactor*(camera->target.y - camera->position.y)*CAMERA_MOUSE_SCROLL_SENSITIVITY/CAMERA.targetDistance; + camera->target.z += zoomFactor*(camera->target.z - camera->position.z)*CAMERA_MOUSE_SCROLL_SENSITIVITY/CAMERA.targetDistance; + + // if (camera->target.y > 0) camera->target.y = 0.001; + } + else if ((camera->position.y < camera->target.y) && (camera->target.y > 0) && (zoomFactor > 0)) + { + CAMERA.targetDistance -= (zoomFactor*CAMERA_MOUSE_SCROLL_SENSITIVITY); + if (CAMERA.targetDistance < CAMERA_FREE_DISTANCE_MIN_CLAMP) CAMERA.targetDistance = CAMERA_FREE_DISTANCE_MIN_CLAMP; + } + + + // Camera rotation + CAMERA.angle.x += rightStickDelta.x*CAMERA_FREE_MOUSE_SENSITIVITY; + CAMERA.angle.y += rightStickDelta.y*CAMERA_FREE_MOUSE_SENSITIVITY; + + // Angle clamp + if (CAMERA.angle.y > CAMERA_FREE_MIN_CLAMP*DEG2RAD) CAMERA.angle.y = CAMERA_FREE_MIN_CLAMP*DEG2RAD; + else if (CAMERA.angle.y < CAMERA_FREE_MAX_CLAMP*DEG2RAD) CAMERA.angle.y = CAMERA_FREE_MAX_CLAMP*DEG2RAD; + if (szoomKey) + { + // Camera smooth zoom + CAMERA.targetDistance += (leftStickDelta.y*CAMERA_FREE_SMOOTH_ZOOM_SENSITIVITY); + } else { + // Camera panning + camera->target.x += ((leftStickDelta.x*CAMERA_FREE_MOUSE_SENSITIVITY)*cosf(CAMERA.angle.x) + (leftStickDelta.y*-CAMERA_FREE_MOUSE_SENSITIVITY)*sinf(CAMERA.angle.x)*sinf(CAMERA.angle.y))*(CAMERA.targetDistance/CAMERA_FREE_PANNING_DIVIDER); + camera->target.y += ((leftStickDelta.y*CAMERA_FREE_MOUSE_SENSITIVITY)*cosf(CAMERA.angle.y))*(CAMERA.targetDistance/CAMERA_FREE_PANNING_DIVIDER); + camera->target.z += ((leftStickDelta.x*-CAMERA_FREE_MOUSE_SENSITIVITY)*sinf(CAMERA.angle.x) + (leftStickDelta.y*-CAMERA_FREE_MOUSE_SENSITIVITY)*cosf(CAMERA.angle.x)*sinf(CAMERA.angle.y))*(CAMERA.targetDistance/CAMERA_FREE_PANNING_DIVIDER); + } + + // Update camera position with changes + camera->position.x = -sinf(CAMERA.angle.x)*CAMERA.targetDistance*cosf(CAMERA.angle.y) + camera->target.x; + camera->position.y = -sinf(CAMERA.angle.y)*CAMERA.targetDistance + camera->target.y; + camera->position.z = -cosf(CAMERA.angle.x)*CAMERA.targetDistance*cosf(CAMERA.angle.y) + camera->target.z; + + // L/R Bumpers to zoom out/in + SetCameraPrevZoomFactor((Vector2) { 0.0f, zoomFactor }); + if (IsGamepadButtonDown(gamepad, GAMEPAD_BUTTON_RIGHT_TRIGGER_1)) + { + SetCameraZoomFactor((Vector2){ 0.0f, 1.0f }); + } else if (IsGamepadButtonDown(gamepad, GAMEPAD_BUTTON_LEFT_TRIGGER_1)) + { + SetCameraZoomFactor((Vector2){ 0.0f, -1.0f }); + } else { + SetCameraZoomFactor((Vector2){ 0.0f, 0.0f }); + } + + } break; + case CAMERA_ORBITAL: // Camera just orbits around target, only zoom allowed + { + CAMERA.angle.x += CAMERA_ORBITAL_SPEED*GetFrameTime(); // Camera orbit angle + CAMERA.targetDistance -= (zoomFactor*CAMERA_MOUSE_SCROLL_SENSITIVITY); // Camera zoom + + // Camera distance clamp + if (CAMERA.targetDistance < CAMERA_THIRD_PERSON_DISTANCE_CLAMP) CAMERA.targetDistance = CAMERA_THIRD_PERSON_DISTANCE_CLAMP; + + // Update camera position with changes + camera->position.x = sinf(CAMERA.angle.x)*CAMERA.targetDistance*cosf(CAMERA.angle.y) + camera->target.x; + camera->position.y = ((CAMERA.angle.y <= 0.0f)? 1 : -1)*sinf(CAMERA.angle.y)*CAMERA.targetDistance*sinf(CAMERA.angle.y) + camera->target.y; + camera->position.z = cosf(CAMERA.angle.x)*CAMERA.targetDistance*cosf(CAMERA.angle.y) + camera->target.z; + + // L/R Bumpers to zoom out/in + SetCameraPrevZoomFactor((Vector2) { 0.0f, zoomFactor }); + if (IsGamepadButtonDown(gamepad, GAMEPAD_BUTTON_RIGHT_TRIGGER_1)) + { + SetCameraZoomFactor((Vector2){ 0.0f, 1.0f }); + } else if (IsGamepadButtonDown(gamepad, GAMEPAD_BUTTON_LEFT_TRIGGER_1)) + { + SetCameraZoomFactor((Vector2){ 0.0f, -1.0f }); + } else { + SetCameraZoomFactor((Vector2){ 0.0f, 0.0f }); + } + + } break; + case CAMERA_FIRST_PERSON: // Camera moves as in a first-person game, controls are configurable + { + camera->position.x += (sinf(camera->angle.x)*direction[MOVE_BACK] - + sinf(camera->angle.x)*direction[MOVE_FRONT] - + cosf(camera->angle.x)*direction[MOVE_LEFT] + + cosf(camera->angle.x)*direction[MOVE_RIGHT])*PLAYER_MOVEMENT_SENSITIVITY*GetFrameTime(); + + camera->position.y += (sinf(camera->angle.y)*direction[MOVE_FRONT] - + sinf(CAMERA.angle.y)*direction[MOVE_BACK]) *PLAYER_MOVEMENT_SENSITIVITY*GetFrameTime(); + // 1.0f*direction[MOVE_UP] - 1.0f*direction[MOVE_DOWN])*PLAYER_MOVEMENT_SENSITIVITY*GetFrameTime(); + + camera->position.z += (cosf(camera->angle.x)*direction[MOVE_BACK] - + cosf(camera->angle.x)*direction[MOVE_FRONT] + + sinf(camera->angle.x)*direction[MOVE_LEFT] - + sinf(camera->angle.x)*direction[MOVE_RIGHT])*PLAYER_MOVEMENT_SENSITIVITY*GetFrameTime(); + + // Camera orientation calculation + camera->angle.x += rightStickDelta.x*CAMERA_MOUSE_MOVE_SENSITIVITY*GetFrameTime(); + camera->angle.y += GetGamepadYAxisInverted(gamepad)*rightStickDelta.y*CAMERA_MOUSE_MOVE_SENSITIVITY*GetFrameTime(); + + // Angle clamp + if (camera->angle.y > CAMERA_FIRST_PERSON_MIN_CLAMP*DEG2RAD) camera->angle.y = CAMERA_FIRST_PERSON_MIN_CLAMP*DEG2RAD; + else if (camera->angle.y < CAMERA_FIRST_PERSON_MAX_CLAMP*DEG2RAD) camera->angle.y = CAMERA_FIRST_PERSON_MAX_CLAMP*DEG2RAD; + + // Calculate translation matrix + Matrix matTranslation = { 1.0f, 0.0f, 0.0f, 0.0f, + 0.0f, 1.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 1.0f, (CAMERA.targetDistance/CAMERA_FREE_PANNING_DIVIDER), + 0.0f, 0.0f, 0.0f, 1.0f }; + + // Calculate rotation matrix + Matrix matRotation = { 1.0f, 0.0f, 0.0f, 0.0f, + 0.0f, 1.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 1.0f, 0.0f, + 0.0f, 0.0f, 0.0f, 1.0f }; + + float cosz = cosf(0.0f); + float sinz = sinf(0.0f); + float cosy = cosf(-(PI*2 - camera->angle.x)); + float siny = sinf(-(PI*2 - camera->angle.x)); + float cosx = cosf(-(PI*2 - camera->angle.y)); + float sinx = sinf(-(PI*2 - camera->angle.y)); + + matRotation.m0 = cosz*cosy; + matRotation.m4 = (cosz*siny*sinx) - (sinz*cosx); + matRotation.m8 = (cosz*siny*cosx) + (sinz*sinx); + matRotation.m1 = sinz*cosy; + matRotation.m5 = (sinz*siny*sinx) + (cosz*cosx); + matRotation.m9 = (sinz*siny*cosx) - (cosz*sinx); + matRotation.m2 = -siny; + matRotation.m6 = cosy*sinx; + matRotation.m10= cosy*cosx; + + // Multiply translation and rotation matrices + Matrix matTransform = { 0 }; + matTransform.m0 = matTranslation.m0*matRotation.m0 + matTranslation.m1*matRotation.m4 + matTranslation.m2*matRotation.m8 + matTranslation.m3*matRotation.m12; + matTransform.m1 = matTranslation.m0*matRotation.m1 + matTranslation.m1*matRotation.m5 + matTranslation.m2*matRotation.m9 + matTranslation.m3*matRotation.m13; + matTransform.m2 = matTranslation.m0*matRotation.m2 + matTranslation.m1*matRotation.m6 + matTranslation.m2*matRotation.m10 + matTranslation.m3*matRotation.m14; + matTransform.m3 = matTranslation.m0*matRotation.m3 + matTranslation.m1*matRotation.m7 + matTranslation.m2*matRotation.m11 + matTranslation.m3*matRotation.m15; + matTransform.m4 = matTranslation.m4*matRotation.m0 + matTranslation.m5*matRotation.m4 + matTranslation.m6*matRotation.m8 + matTranslation.m7*matRotation.m12; + matTransform.m5 = matTranslation.m4*matRotation.m1 + matTranslation.m5*matRotation.m5 + matTranslation.m6*matRotation.m9 + matTranslation.m7*matRotation.m13; + matTransform.m6 = matTranslation.m4*matRotation.m2 + matTranslation.m5*matRotation.m6 + matTranslation.m6*matRotation.m10 + matTranslation.m7*matRotation.m14; + matTransform.m7 = matTranslation.m4*matRotation.m3 + matTranslation.m5*matRotation.m7 + matTranslation.m6*matRotation.m11 + matTranslation.m7*matRotation.m15; + matTransform.m8 = matTranslation.m8*matRotation.m0 + matTranslation.m9*matRotation.m4 + matTranslation.m10*matRotation.m8 + matTranslation.m11*matRotation.m12; + matTransform.m9 = matTranslation.m8*matRotation.m1 + matTranslation.m9*matRotation.m5 + matTranslation.m10*matRotation.m9 + matTranslation.m11*matRotation.m13; + matTransform.m10 = matTranslation.m8*matRotation.m2 + matTranslation.m9*matRotation.m6 + matTranslation.m10*matRotation.m10 + matTranslation.m11*matRotation.m14; + matTransform.m11 = matTranslation.m8*matRotation.m3 + matTranslation.m9*matRotation.m7 + matTranslation.m10*matRotation.m11 + matTranslation.m11*matRotation.m15; + matTransform.m12 = matTranslation.m12*matRotation.m0 + matTranslation.m13*matRotation.m4 + matTranslation.m14*matRotation.m8 + matTranslation.m15*matRotation.m12; + matTransform.m13 = matTranslation.m12*matRotation.m1 + matTranslation.m13*matRotation.m5 + matTranslation.m14*matRotation.m9 + matTranslation.m15*matRotation.m13; + matTransform.m14 = matTranslation.m12*matRotation.m2 + matTranslation.m13*matRotation.m6 + matTranslation.m14*matRotation.m10 + matTranslation.m15*matRotation.m14; + matTransform.m15 = matTranslation.m12*matRotation.m3 + matTranslation.m13*matRotation.m7 + matTranslation.m14*matRotation.m11 + matTranslation.m15*matRotation.m15; + + camera->target.x = camera->position.x - matTransform.m12; + camera->target.y = camera->position.y - matTransform.m13; + camera->target.z = camera->position.z - matTransform.m14; + + // Camera position update + // NOTE: On CAMERA_FIRST_PERSON player Y-movement is limited to player 'eyes position' + camera->position.y = CAMERA.playerEyesPosition; + + // Camera swinging (y-movement), only when walking (some key pressed) + for (int i = 0; i < MAX_GAMEPADS; i++) {if (direction[i]){ swingCounter[gamepad] += GetFrameTime(); break; }} + camera->position.y -= sinf(2*PI*CAMERA_FIRST_PERSON_STEP_FREQUENCY*swingCounter[gamepad])*CAMERA_FIRST_PERSON_SWINGING_DELTA; + + // Camera waiving (xz-movement), only when walking (some key pressed) + camera->up.x = sinf(2*PI*CAMERA_FIRST_PERSON_STEP_FREQUENCY*swingCounter[gamepad])*CAMERA_FIRST_PERSON_TILTING_DELTA; + camera->up.z = -sinf(2*PI*CAMERA_FIRST_PERSON_STEP_FREQUENCY*swingCounter[gamepad])*CAMERA_FIRST_PERSON_TILTING_DELTA; + + } break; + case CAMERA_THIRD_PERSON: // Camera moves as in a third-person game, following target at a distance, controls are configurable + { + camera->position.x += (sinf(CAMERA.angle.x)*direction[MOVE_BACK] - + sinf(CAMERA.angle.x)*direction[MOVE_FRONT] - + cosf(CAMERA.angle.x)*direction[MOVE_LEFT] + + cosf(CAMERA.angle.x)*direction[MOVE_RIGHT])*PLAYER_MOVEMENT_SENSITIVITY*GetFrameTime(); + + camera->position.y += (sinf(CAMERA.angle.y)*direction[MOVE_FRONT] - + sinf(CAMERA.angle.y)*direction[MOVE_BACK] + + 1.0f*direction[MOVE_UP] - 1.0f*direction[MOVE_DOWN])*PLAYER_MOVEMENT_SENSITIVITY*GetFrameTime(); + + camera->position.z += (cosf(CAMERA.angle.x)*direction[MOVE_BACK] - + cosf(CAMERA.angle.x)*direction[MOVE_FRONT] + + sinf(CAMERA.angle.x)*direction[MOVE_LEFT] - + sinf(CAMERA.angle.x)*direction[MOVE_RIGHT])*PLAYER_MOVEMENT_SENSITIVITY*GetFrameTime(); + + // Camera orientation calculation + CAMERA.angle.x += (leftStickDelta.x*-CAMERA_MOUSE_MOVE_SENSITIVITY); + CAMERA.angle.y += (leftStickDelta.y*-CAMERA_MOUSE_MOVE_SENSITIVITY); + + // Angle clamp + if (CAMERA.angle.y > CAMERA_THIRD_PERSON_MIN_CLAMP*DEG2RAD) CAMERA.angle.y = CAMERA_THIRD_PERSON_MIN_CLAMP*DEG2RAD; + else if (CAMERA.angle.y < CAMERA_THIRD_PERSON_MAX_CLAMP*DEG2RAD) CAMERA.angle.y = CAMERA_THIRD_PERSON_MAX_CLAMP*DEG2RAD; + + // Camera zoom + CAMERA.targetDistance -= (zoomFactor*CAMERA_MOUSE_SCROLL_SENSITIVITY); + + // Camera distance clamp + if (CAMERA.targetDistance < CAMERA_THIRD_PERSON_DISTANCE_CLAMP) CAMERA.targetDistance = CAMERA_THIRD_PERSON_DISTANCE_CLAMP; + + camera->position.x = sinf(CAMERA.angle.x)*CAMERA.targetDistance*cosf(CAMERA.angle.y) + camera->target.x; + + if (CAMERA.angle.y <= 0.0f) camera->position.y = sinf(CAMERA.angle.y)*CAMERA.targetDistance*sinf(CAMERA.angle.y) + camera->target.y; + else camera->position.y = -sinf(CAMERA.angle.y)*CAMERA.targetDistance*sinf(CAMERA.angle.y) + camera->target.y; + + camera->position.z = cosf(CAMERA.angle.x)*CAMERA.targetDistance*cosf(CAMERA.angle.y) + camera->target.z; + + } break; + case CAMERA_CUSTOM: break; + default: break; + } +} // Set camera pan key to combine with mouse movement (free camera) void SetCameraPanControl(int keyPan) { CAMERA.panControl = keyPan; } diff --git a/src/rcore.c b/src/rcore.c index 187ea817c..ed0024209 100644 --- a/src/rcore.c +++ b/src/rcore.c @@ -491,6 +491,8 @@ typedef struct CoreData { Vector2 position[MAX_TOUCH_POINTS]; // Touch position on screen char currentTouchState[MAX_TOUCH_POINTS]; // Registers current touch state char previousTouchState[MAX_TOUCH_POINTS]; // Registers previous touch state + // PLATFORM_NX + long int deltaTime[MAX_TOUCH_POINTS]; } Touch; struct { int lastButtonPressed; // Register last gamepad button pressed @@ -506,6 +508,8 @@ typedef struct CoreData { #endif #if defined(PLATFORM_NX) PadState nxPad[MAX_GAMEPADS]; // Gamepad state holder + HidNpadStyleTag nxPadStyle[MAX_GAMEPADS]; + float yInverted[MAX_GAMEPADS]; // True -1.f False 1.f #endif } Gamepad; } Input; @@ -540,6 +544,10 @@ static bool gifRecording = false; // GIF recording state static MsfGifState gifState = { 0 }; // MSGIF context state #endif +#if defined(PLATFORM_NX) + s32 prev_touchcount = 0; +#endif + #if defined(SUPPORT_EVENTS_AUTOMATION) #define MAX_CODE_AUTOMATION_EVENTS 16384 @@ -917,7 +925,12 @@ void InitWindow(int width, int height, const char *title) // Configure our supported input layout padConfigureInput(MAX_GAMEPADS, HidNpadStyleSet_NpadStandard); // Initialize the gamepads - padInitializeDefault(&CORE.Input.Gamepad.nxPad[0]); + for (int i = 0; i < MAX_GAMEPADS; i++) + { + padInitialize(&CORE.Input.Gamepad.nxPad[i], i); + } + + hidInitializeTouchScreen(); #endif #if defined(PLATFORM_WEB) @@ -3614,6 +3627,25 @@ const char *GetGamepadName(int gamepad) #endif #if defined(PLATFORM_WEB) return CORE.Input.Gamepad.name[gamepad]; +#endif +#if defined(PLATFORM_NX) + int type = CORE.Input.Gamepad.nxPadStyle[gamepad]; + switch(type) { + case HidNpadStyleTag_NpadFullKey: return "Nintendo Switch Pro Controller"; + case HidNpadStyleTag_NpadHandheld: return "Handheld Joy-Con controller"; + case HidNpadStyleTag_NpadJoyDual: return "Dual Joy-Con controller"; + case HidNpadStyleTag_NpadJoyLeft: return "Single Joy-Con left controller"; + case HidNpadStyleTag_NpadJoyRight: return "Single Joy-Con right controller"; + case HidNpadStyleTag_NpadGc: return "GameCube controller"; + case HidNpadStyleTag_NpadPalma: return "Poké Ball Plus controller"; + case HidNpadStyleTag_NpadLark: return "NES/Famicom controller"; + case HidNpadStyleTag_NpadHandheldLark: return "Handheld NES/Famicom controller"; + case HidNpadStyleTag_NpadLucia: return "SNES controller"; + case HidNpadStyleTag_NpadLagon: return "N64 controller"; + case HidNpadStyleTag_NpadLager: return "Sega Genesis controller"; + case HidNpadStyleTag_NpadSystemExt: return "Generic external controller"; + default: return "Generic controller"; + } #endif return NULL; } @@ -3641,6 +3673,21 @@ float GetGamepadAxisMovement(int gamepad, int axis) return value; } +#if defined(PLATFORM_NX) +void SetGamepadYAxisInverted(int gamepad, float yInverted) +{ + if (yInverted == -1.0f || yInverted == 1.0f) + { + CORE.Input.Gamepad.yInverted[gamepad] = yInverted; + } +} + +float GetGamepadYAxisInverted(int gamepad) +{ + return CORE.Input.Gamepad.yInverted[gamepad]; +} +#endif + // Check if a gamepad button has been pressed once bool IsGamepadButtonPressed(int gamepad, int button) { @@ -3823,7 +3870,7 @@ float GetMouseWheelMove(void) { float result = 0.0f; -#if !defined(PLATFORM_ANDROID) +#if !defined(PLATFORM_ANDROID) || !defined(PLATFORM_NX) if (fabsf(CORE.Input.Mouse.currentWheelMove.x) > fabsf(CORE.Input.Mouse.currentWheelMove.y)) result = (float)CORE.Input.Mouse.currentWheelMove.x; else result = (float)CORE.Input.Mouse.currentWheelMove.y; #endif @@ -3831,6 +3878,17 @@ float GetMouseWheelMove(void) return result; } +#if defined(PLATFORM_NX) +void SetCameraZoomFactor(Vector2 zoomFactor) +{ + CORE.Input.Mouse.currentWheelMove = zoomFactor; +} +void SetCameraPrevZoomFactor(Vector2 previousZoomFactor) +{ + CORE.Input.Mouse.previousWheelMove = previousZoomFactor; +} +#endif + // Get mouse wheel movement X/Y as a vector Vector2 GetMouseWheelMoveV(void) { @@ -3859,7 +3917,7 @@ void SetMouseCursor(int cursor) // Get touch position X for touch point 0 (relative to screen size) int GetTouchX(void) { -#if defined(PLATFORM_ANDROID) || defined(PLATFORM_WEB) +#if defined(PLATFORM_ANDROID) || defined(PLATFORM_WEB) || defined(PLATFORM_NX) return (int)CORE.Input.Touch.position[0].x; #else // PLATFORM_DESKTOP, PLATFORM_RPI, PLATFORM_DRM return GetMouseX(); @@ -3869,7 +3927,7 @@ int GetTouchX(void) // Get touch position Y for touch point 0 (relative to screen size) int GetTouchY(void) { -#if defined(PLATFORM_ANDROID) || defined(PLATFORM_WEB) +#if defined(PLATFORM_ANDROID) || defined(PLATFORM_WEB) || defined(PLATFORM_NX) return (int)CORE.Input.Touch.position[0].y; #else // PLATFORM_DESKTOP, PLATFORM_RPI, PLATFORM_DRM return GetMouseY(); @@ -3888,7 +3946,7 @@ Vector2 GetTouchPosition(int index) // https://docs.microsoft.com/en-us/windows/win32/wintouch/getting-started-with-multi-touch-messages if (index == 0) position = GetMousePosition(); #endif -#if defined(PLATFORM_ANDROID) || defined(PLATFORM_WEB) || defined(PLATFORM_RPI) || defined(PLATFORM_DRM) +#if defined(PLATFORM_ANDROID) || defined(PLATFORM_WEB) || defined(PLATFORM_RPI) || defined(PLATFORM_DRM) || defined(PLATFORM_NX) if (index < MAX_TOUCH_POINTS) position = CORE.Input.Touch.position[index]; else TRACELOG(LOG_WARNING, "INPUT: Required touch point out of range (Max touch points: %i)", MAX_TOUCH_POINTS); #endif @@ -5158,202 +5216,253 @@ void PollInputEvents(void) #endif #if defined(PLATFORM_NX) - int nxGamepadIndex = 0; - - // Scan the gamepad. This should be done once for each frame - padUpdate(&CORE.Input.Gamepad.nxPad[nxGamepadIndex]); - - CORE.Input.Gamepad.ready[nxGamepadIndex] = padIsConnected(&CORE.Input.Gamepad.nxPad[nxGamepadIndex]); - - if (CORE.Input.Gamepad.ready[nxGamepadIndex]) { - // Returns the set of buttons that are currently pressed - u64 kHeld = padGetButtons(&CORE.Input.Gamepad.nxPad[nxGamepadIndex]); - u64 kButton; - for (int k = 0; k < MAX_GAMEPAD_BUTTONS; k++) +/** + * Touch screen +*/ + HidTouchScreenState state = {0}; + if (hidGetTouchScreenStates(&state, 1)) { + if (state.count != prev_touchcount) { - // Register previous gamepad states - CORE.Input.Gamepad.previousButtonState[nxGamepadIndex][k] = CORE.Input.Gamepad.currentButtonState[nxGamepadIndex][k]; - - // Check digital buttons - kButton = 0; - switch (k) - { - case GAMEPAD_BUTTON_LEFT_FACE_UP: kButton = HidNpadButton_Up; break; - case GAMEPAD_BUTTON_LEFT_FACE_RIGHT: kButton = HidNpadButton_Right; break; - case GAMEPAD_BUTTON_LEFT_FACE_DOWN: kButton = HidNpadButton_Down; break; - case GAMEPAD_BUTTON_LEFT_FACE_LEFT: kButton = HidNpadButton_Left; break; - case GAMEPAD_BUTTON_RIGHT_FACE_UP: kButton = HidNpadButton_X; break; - case GAMEPAD_BUTTON_RIGHT_FACE_RIGHT: kButton = HidNpadButton_A; break; - case GAMEPAD_BUTTON_RIGHT_FACE_DOWN: kButton = HidNpadButton_B; break; - case GAMEPAD_BUTTON_RIGHT_FACE_LEFT: kButton = HidNpadButton_Y; break; - case GAMEPAD_BUTTON_LEFT_TRIGGER_1: kButton = HidNpadButton_L; break; - case GAMEPAD_BUTTON_LEFT_TRIGGER_2: kButton = HidNpadButton_ZL; break; - case GAMEPAD_BUTTON_RIGHT_TRIGGER_1: kButton = HidNpadButton_R; break; - case GAMEPAD_BUTTON_RIGHT_TRIGGER_2: kButton = HidNpadButton_ZR; break; - case GAMEPAD_BUTTON_MIDDLE_LEFT: kButton = HidNpadButton_Minus; break; - case GAMEPAD_BUTTON_MIDDLE_RIGHT: kButton = HidNpadButton_Plus; break; - case GAMEPAD_BUTTON_LEFT_THUMB: kButton = HidNpadButton_StickL; break; - case GAMEPAD_BUTTON_RIGHT_THUMB: kButton = HidNpadButton_StickR; break; - } - if (kHeld & kButton) { - CORE.Input.Gamepad.currentButtonState[nxGamepadIndex][k] = 1; - CORE.Input.Gamepad.lastButtonPressed = k; - } else { - CORE.Input.Gamepad.currentButtonState[nxGamepadIndex][k] = 0; - } + prev_touchcount = state.count; } + for(int i=0; i CORE.Window.screen.width/CORE.Input.Mouse.scale.x) CORE.Input.Mouse.currentPosition.x = CORE.Window.screen.width/CORE.Input.Mouse.scale.x; + // Clamp Mouse X to screen + if (CORE.Input.Mouse.currentPosition.x < 0) CORE.Input.Mouse.currentPosition.x = 0; + else if (CORE.Input.Mouse.currentPosition.x > CORE.Window.screen.width/CORE.Input.Mouse.scale.x) CORE.Input.Mouse.currentPosition.x = CORE.Window.screen.width/CORE.Input.Mouse.scale.x; - if (CORE.Input.Mouse.currentPosition.y < 0) CORE.Input.Mouse.currentPosition.y = 0; - else if (CORE.Input.Mouse.currentPosition.y > CORE.Window.screen.height/CORE.Input.Mouse.scale.y) CORE.Input.Mouse.currentPosition.y = CORE.Window.screen.height/CORE.Input.Mouse.scale.y; + // Clamp Mouse Y to screen + if (CORE.Input.Mouse.currentPosition.y < 0) CORE.Input.Mouse.currentPosition.y = 0; + else if (CORE.Input.Mouse.currentPosition.y > CORE.Window.screen.height/CORE.Input.Mouse.scale.y) CORE.Input.Mouse.currentPosition.y = CORE.Window.screen.height/CORE.Input.Mouse.scale.y; - if (CORE.Input.Keyboard.currentKeyState[CORE.Input.Keyboard.exitKey] == 1) CORE.Window.shouldClose = true; + // Gamepad +/- pressed to exit + if (CORE.Input.Keyboard.currentKeyState[CORE.Input.Keyboard.exitKey] == 1) CORE.Window.shouldClose = true; #endif + } } #endif