switch-examples:
- added full controller support - added multi-controller support - added splitscreen support - added touch screen support - added full camera-controller support - updated related examples
This commit is contained in:
parent
6719c57ba8
commit
65a4a0092a
|
|
@ -413,6 +413,7 @@ CORE = \
|
||||||
core/core_input_mouse \
|
core/core_input_mouse \
|
||||||
core/core_input_mouse_wheel \
|
core/core_input_mouse_wheel \
|
||||||
core/core_input_gamepad \
|
core/core_input_gamepad \
|
||||||
|
core/core_input_multi_gamepad \
|
||||||
core/core_input_multitouch \
|
core/core_input_multitouch \
|
||||||
core/core_input_gestures \
|
core/core_input_gestures \
|
||||||
core/core_2d_camera \
|
core/core_2d_camera \
|
||||||
|
|
|
||||||
|
|
@ -60,15 +60,15 @@ int main(void)
|
||||||
// Update
|
// Update
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
// Player movement
|
// Player movement
|
||||||
if (IsKeyDown(KEY_RIGHT)) player.x += 2;
|
if (GetGamepadAxisMovement(0, GAMEPAD_AXIS_LEFT_X) > 0) player.x += 2;
|
||||||
else if (IsKeyDown(KEY_LEFT)) player.x -= 2;
|
else if (GetGamepadAxisMovement(0, GAMEPAD_AXIS_LEFT_X) < 0) player.x -= 2;
|
||||||
|
|
||||||
// Camera target follows player
|
// Camera target follows player
|
||||||
camera.target = (Vector2){ player.x + 20, player.y + 20 };
|
camera.target = (Vector2){ player.x + 20, player.y + 20 };
|
||||||
|
|
||||||
// Camera rotation controls
|
// Camera rotation controls
|
||||||
if (IsKeyDown(KEY_A)) camera.rotation--;
|
if (GetGamepadAxisMovement(0, GAMEPAD_AXIS_RIGHT_X) > 0) camera.rotation--;
|
||||||
else if (IsKeyDown(KEY_S)) camera.rotation++;
|
else if (GetGamepadAxisMovement(0, GAMEPAD_AXIS_RIGHT_X) < 0) camera.rotation++;
|
||||||
|
|
||||||
// Limit camera rotation to 80 degrees (-40 to 40)
|
// Limit camera rotation to 80 degrees (-40 to 40)
|
||||||
if (camera.rotation > 40) camera.rotation = 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("Free 2d camera controls:", 20, 20, 10, BLACK);
|
||||||
DrawText("- Right/Left to move Offset", 40, 40, 10, DARKGRAY);
|
DrawText("- Right/Left to move Offset", 40, 40, 10, DARKGRAY);
|
||||||
DrawText("- Mouse Wheel to Zoom in-out", 40, 60, 10, DARKGRAY);
|
DrawText("- R/L bumpers to Zoom in-out", 40, 60, 10, DARKGRAY);
|
||||||
DrawText("- A / S to Rotate", 40, 80, 10, DARKGRAY);
|
DrawText("- Right thumbstick X-axis to Rotate", 40, 80, 10, DARKGRAY);
|
||||||
DrawText("- R to reset Zoom and Rotation", 40, 100, 10, DARKGRAY);
|
DrawText("- X button to reset Zoom and Rotation", 40, 100, 10, DARKGRAY);
|
||||||
|
|
||||||
EndDrawing();
|
EndDrawing();
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
|
@ -106,7 +106,14 @@ int main(void)
|
||||||
|
|
||||||
UpdatePlayer(&player, envItems, envItemsLength, deltaTime);
|
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;
|
if (camera.zoom > 3.0f) camera.zoom = 3.0f;
|
||||||
else if (camera.zoom < 0.25f) camera.zoom = 0.25f;
|
else if (camera.zoom < 0.25f) camera.zoom = 0.25f;
|
||||||
|
|
@ -117,7 +124,7 @@ int main(void)
|
||||||
player.position = (Vector2){ 400, 280 };
|
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
|
// Call update camera function by its pointer
|
||||||
cameraUpdaters[cameraOption](&camera, &player, envItems, envItemsLength, deltaTime, screenWidth, screenHeight);
|
cameraUpdaters[cameraOption](&camera, &player, envItems, envItemsLength, deltaTime, screenWidth, screenHeight);
|
||||||
|
|
@ -139,10 +146,10 @@ int main(void)
|
||||||
EndMode2D();
|
EndMode2D();
|
||||||
|
|
||||||
DrawText("Controls:", 20, 20, 10, BLACK);
|
DrawText("Controls:", 20, 20, 10, BLACK);
|
||||||
DrawText("- Right/Left to move", 40, 40, 10, DARKGRAY);
|
DrawText("- Right/Left thumbstick to move", 40, 40, 10, DARKGRAY);
|
||||||
DrawText("- Space to jump", 40, 60, 10, DARKGRAY);
|
DrawText("- A button to jump", 40, 60, 10, DARKGRAY);
|
||||||
DrawText("- Mouse Wheel to Zoom in-out, R to reset zoom", 40, 80, 10, DARKGRAY);
|
DrawText("- R/L buttons to Zoom in-out, X to reset zoom", 40, 80, 10, DARKGRAY);
|
||||||
DrawText("- C to change camera mode", 40, 100, 10, DARKGRAY);
|
DrawText("- Y button to change camera mode", 40, 100, 10, DARKGRAY);
|
||||||
DrawText("Current camera mode:", 20, 120, 10, BLACK);
|
DrawText("Current camera mode:", 20, 120, 10, BLACK);
|
||||||
DrawText(cameraDescriptions[cameraOption], 40, 140, 10, DARKGRAY);
|
DrawText(cameraDescriptions[cameraOption], 40, 140, 10, DARKGRAY);
|
||||||
|
|
||||||
|
|
@ -160,9 +167,9 @@ int main(void)
|
||||||
|
|
||||||
void UpdatePlayer(Player *player, EnvItem *envItems, int envItemsLength, float delta)
|
void UpdatePlayer(Player *player, EnvItem *envItems, int envItemsLength, float delta)
|
||||||
{
|
{
|
||||||
if (IsKeyDown(KEY_LEFT)) player->position.x -= PLAYER_HOR_SPD*delta;
|
if (GetGamepadAxisMovement(0, 0) < 0) player->position.x -= PLAYER_HOR_SPD*delta;
|
||||||
if (IsKeyDown(KEY_RIGHT)) player->position.x += PLAYER_HOR_SPD*delta;
|
if (GetGamepadAxisMovement(0, 0) > 0) player->position.x += PLAYER_HOR_SPD*delta;
|
||||||
if (IsKeyDown(KEY_SPACE) && player->canJump)
|
if (IsGamepadButtonPressed(0, GAMEPAD_BUTTON_RIGHT_FACE_RIGHT) && player->canJump)
|
||||||
{
|
{
|
||||||
player->speed = -PLAYER_JUMP_SPD;
|
player->speed = -PLAYER_JUMP_SPD;
|
||||||
player->canJump = false;
|
player->canJump = false;
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,8 @@
|
||||||
#include "raylib.h"
|
#include "raylib.h"
|
||||||
|
|
||||||
#define MAX_COLUMNS 20
|
#define MAX_COLUMNS 20
|
||||||
|
#define CAMERA_INVERTED_Y_TRUE -1.0f
|
||||||
|
#define CAMERA_INVERTED_Y_FALSE 1.0f
|
||||||
|
|
||||||
//------------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------------
|
||||||
// Program main entry point
|
// Program main entry point
|
||||||
|
|
@ -48,6 +50,7 @@ int main(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
SetCameraMode(camera, CAMERA_FIRST_PERSON); // Set a first person camera mode
|
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
|
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
@ -57,7 +60,11 @@ int main(void)
|
||||||
{
|
{
|
||||||
// Update
|
// Update
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
UpdateCamera(&camera);
|
UpdateCameraGamepad(&camera, 0);
|
||||||
|
if (IsGamepadButtonPressed(0, GAMEPAD_BUTTON_RIGHT_TRIGGER_1))
|
||||||
|
{
|
||||||
|
SetGamepadYAxisInverted(0, -GetGamepadYAxisInverted(0));
|
||||||
|
}
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
// Draw
|
// Draw
|
||||||
|
|
@ -82,12 +89,13 @@ int main(void)
|
||||||
|
|
||||||
EndMode3D();
|
EndMode3D();
|
||||||
|
|
||||||
DrawRectangle( 10, 10, 220, 70, Fade(SKYBLUE, 0.5f));
|
DrawRectangle( 10, 10, 220, 90, Fade(SKYBLUE, 0.5f));
|
||||||
DrawRectangleLines( 10, 10, 220, 70, BLUE);
|
DrawRectangleLines( 10, 10, 220, 90, BLUE);
|
||||||
|
|
||||||
DrawText("First person camera default controls:", 20, 20, 10, BLACK);
|
DrawText("First person camera default controls:", 20, 20, 10, BLACK);
|
||||||
DrawText("- Move with keys: W, A, S, D", 40, 40, 10, DARKGRAY);
|
DrawText("- Move with Left Thumbstick", 40, 40, 10, DARKGRAY);
|
||||||
DrawText("- Mouse move to look around", 40, 60, 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();
|
EndDrawing();
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
|
@ -45,9 +45,9 @@ int main(void)
|
||||||
{
|
{
|
||||||
// Update
|
// 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
|
// Draw
|
||||||
|
|
@ -69,11 +69,11 @@ int main(void)
|
||||||
DrawRectangleLines( 10, 10, 320, 133, BLUE);
|
DrawRectangleLines( 10, 10, 320, 133, BLUE);
|
||||||
|
|
||||||
DrawText("Free camera default controls:", 20, 20, 10, BLACK);
|
DrawText("Free camera default controls:", 20, 20, 10, BLACK);
|
||||||
DrawText("- Mouse Wheel to Zoom in-out", 40, 40, 10, DARKGRAY);
|
DrawText("- R/L Bumpers to Zoom", 40, 40, 10, DARKGRAY);
|
||||||
DrawText("- Mouse Wheel Pressed to Pan", 40, 60, 10, DARKGRAY);
|
DrawText("- Left Thumbstick to Pan", 40, 60, 10, DARKGRAY);
|
||||||
DrawText("- Alt + Mouse Wheel Pressed to Rotate", 40, 80, 10, DARKGRAY);
|
DrawText("- Right Thumbstick to Rotate", 40, 80, 10, DARKGRAY);
|
||||||
DrawText("- Alt + Ctrl + Mouse Wheel Pressed for Smooth Zoom", 40, 100, 10, DARKGRAY);
|
DrawText("- Hold button A for Smooth Zoom with Left Thumbstick", 40, 100, 10, DARKGRAY);
|
||||||
DrawText("- Z to zoom to (0, 0, 0)", 40, 120, 10, DARKGRAY);
|
DrawText("- Press X button to zoom to (0, 0, 0)", 40, 120, 10, DARKGRAY);
|
||||||
|
|
||||||
EndDrawing();
|
EndDrawing();
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
|
@ -50,14 +50,13 @@ int main(void)
|
||||||
{
|
{
|
||||||
// Update
|
// Update
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
UpdateCamera(&camera);
|
UpdateCameraGamepad(&camera, 0);
|
||||||
|
|
||||||
if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT))
|
if (GetTouchPointCount() > 0)
|
||||||
{
|
{
|
||||||
if (!collision.hit)
|
if (!collision.hit)
|
||||||
{
|
{
|
||||||
ray = GetMouseRay(GetMousePosition(), camera);
|
ray = GetMouseRay(GetTouchPosition(0), camera);
|
||||||
|
|
||||||
// Check collision between ray and box
|
// Check collision between ray and box
|
||||||
collision = GetRayCollisionBox(ray,
|
collision = GetRayCollisionBox(ray,
|
||||||
(BoundingBox){(Vector3){ cubePosition.x - cubeSize.x/2, cubePosition.y - cubeSize.y/2, cubePosition.z - cubeSize.z/2 },
|
(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();
|
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);
|
if (collision.hit) DrawText("BOX SELECTED", (screenWidth - MeasureText("BOX SELECTED", 30)) / 2, (int)(screenHeight * 0.1f), 30, GREEN);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@
|
||||||
|
|
||||||
#include "raylib.h"
|
#include "raylib.h"
|
||||||
|
|
||||||
|
#define START_BUTTON GAMEPAD_BUTTON_MIDDLE_RIGHT
|
||||||
//------------------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------------------
|
||||||
// Types and Structures Definition
|
// Types and Structures Definition
|
||||||
//------------------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------------------
|
||||||
|
|
@ -41,11 +42,16 @@ int main(void)
|
||||||
SetTargetFPS(60); // Set desired framerate (frames-per-second)
|
SetTargetFPS(60); // Set desired framerate (frames-per-second)
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Gesture detection for TAP
|
||||||
|
bool hasScreenBeenTouched = false;
|
||||||
|
|
||||||
// Main game loop
|
// Main game loop
|
||||||
while (!WindowShouldClose()) // Detect window close button or ESC key
|
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||||
{
|
{
|
||||||
// Update
|
// Update
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
bool isNextButtonPressed = IsGamepadButtonPressed(0, START_BUTTON);
|
||||||
|
|
||||||
switch(currentScreen)
|
switch(currentScreen)
|
||||||
{
|
{
|
||||||
case LOGO:
|
case LOGO:
|
||||||
|
|
@ -65,33 +71,38 @@ int main(void)
|
||||||
// TODO: Update TITLE screen variables here!
|
// TODO: Update TITLE screen variables here!
|
||||||
|
|
||||||
// Press enter to change to GAMEPLAY screen
|
// Press enter to change to GAMEPLAY screen
|
||||||
if (IsKeyPressed(KEY_ENTER) || IsGestureDetected(GESTURE_TAP))
|
if (isNextButtonPressed || (!hasScreenBeenTouched && GetTouchPointCount() > 0))
|
||||||
{
|
{
|
||||||
currentScreen = GAMEPLAY;
|
currentScreen = GAMEPLAY;
|
||||||
|
hasScreenBeenTouched = true;
|
||||||
}
|
}
|
||||||
} break;
|
} break;
|
||||||
case GAMEPLAY:
|
case GAMEPLAY:
|
||||||
{
|
{
|
||||||
// TODO: Update GAMEPLAY screen variables here!
|
// TODO: Update GAMEPLAY screen variables here!
|
||||||
|
|
||||||
// Press enter to change to ENDING screen
|
// Press enter to change to ENDING screen
|
||||||
if (IsKeyPressed(KEY_ENTER) || IsGestureDetected(GESTURE_TAP))
|
if (isNextButtonPressed || (!hasScreenBeenTouched && GetTouchPointCount() > 0))
|
||||||
{
|
{
|
||||||
currentScreen = ENDING;
|
currentScreen = ENDING;
|
||||||
|
hasScreenBeenTouched = true;
|
||||||
}
|
}
|
||||||
} break;
|
} break;
|
||||||
case ENDING:
|
case ENDING:
|
||||||
{
|
{
|
||||||
// TODO: Update ENDING screen variables here!
|
// TODO: Update ENDING screen variables here!
|
||||||
|
|
||||||
// Press enter to return to TITLE screen
|
// Press enter to return to TITLE screen
|
||||||
if (IsKeyPressed(KEY_ENTER) || IsGestureDetected(GESTURE_TAP))
|
if (isNextButtonPressed || (!hasScreenBeenTouched && GetTouchPointCount() > 0))
|
||||||
{
|
{
|
||||||
currentScreen = TITLE;
|
currentScreen = TITLE;
|
||||||
|
hasScreenBeenTouched = true;
|
||||||
}
|
}
|
||||||
} break;
|
} break;
|
||||||
default: break;
|
default: break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Reset TAP gesture
|
||||||
|
hasScreenBeenTouched = GetTouchPointCount() > 0;
|
||||||
|
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
// Draw
|
// Draw
|
||||||
|
|
@ -99,6 +110,8 @@ int main(void)
|
||||||
BeginDrawing();
|
BeginDrawing();
|
||||||
|
|
||||||
ClearBackground(RAYWHITE);
|
ClearBackground(RAYWHITE);
|
||||||
|
const int horizontalCenter = screenHeight / 2;
|
||||||
|
int touchCount = GetTouchPointCount();
|
||||||
|
|
||||||
switch(currentScreen)
|
switch(currentScreen)
|
||||||
{
|
{
|
||||||
|
|
@ -114,7 +127,7 @@ int main(void)
|
||||||
// TODO: Draw TITLE screen here!
|
// TODO: Draw TITLE screen here!
|
||||||
DrawRectangle(0, 0, screenWidth, screenHeight, GREEN);
|
DrawRectangle(0, 0, screenWidth, screenHeight, GREEN);
|
||||||
DrawText("TITLE SCREEN", 20, 20, 40, DARKGREEN);
|
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;
|
} break;
|
||||||
case GAMEPLAY:
|
case GAMEPLAY:
|
||||||
|
|
@ -122,7 +135,7 @@ int main(void)
|
||||||
// TODO: Draw GAMEPLAY screen here!
|
// TODO: Draw GAMEPLAY screen here!
|
||||||
DrawRectangle(0, 0, screenWidth, screenHeight, PURPLE);
|
DrawRectangle(0, 0, screenWidth, screenHeight, PURPLE);
|
||||||
DrawText("GAMEPLAY SCREEN", 20, 20, 40, MAROON);
|
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;
|
} break;
|
||||||
case ENDING:
|
case ENDING:
|
||||||
|
|
@ -130,12 +143,17 @@ int main(void)
|
||||||
// TODO: Draw ENDING screen here!
|
// TODO: Draw ENDING screen here!
|
||||||
DrawRectangle(0, 0, screenWidth, screenHeight, BLUE);
|
DrawRectangle(0, 0, screenWidth, screenHeight, BLUE);
|
||||||
DrawText("ENDING SCREEN", 20, 20, 40, DARKBLUE);
|
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;
|
} break;
|
||||||
default: break;
|
default: break;
|
||||||
}
|
}
|
||||||
|
for (int i = 0; i < touchCount; i++)
|
||||||
|
{
|
||||||
|
Vector2 touchPosition = GetTouchPosition(i);
|
||||||
|
DrawCircle(touchPosition.x, touchPosition.y, 75, RED);
|
||||||
|
}
|
||||||
|
|
||||||
EndDrawing();
|
EndDrawing();
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,7 @@
|
||||||
********************************************************************************************/
|
********************************************************************************************/
|
||||||
|
|
||||||
#include "raylib.h"
|
#include "raylib.h"
|
||||||
|
#include <switch.h>
|
||||||
|
|
||||||
// NOTE: Gamepad name ID depends on drivers and OS
|
// NOTE: Gamepad name ID depends on drivers and OS
|
||||||
#define XBOX360_LEGACY_NAME_ID "Xbox Controller"
|
#define XBOX360_LEGACY_NAME_ID "Xbox Controller"
|
||||||
|
|
@ -38,13 +39,15 @@ int main(void)
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
const int screenWidth = 1280;
|
const int screenWidth = 1280;
|
||||||
const int screenHeight = 720;
|
const int screenHeight = 720;
|
||||||
|
|
||||||
|
romfsInit();
|
||||||
SetConfigFlags(FLAG_MSAA_4X_HINT); // Set MSAA 4X hint before windows creation
|
SetConfigFlags(FLAG_MSAA_4X_HINT); // Set MSAA 4X hint before windows creation
|
||||||
|
|
||||||
InitWindow(screenWidth, screenHeight, "raylib [core] example - gamepad input");
|
InitWindow(screenWidth, screenHeight, "raylib [core] example - gamepad input");
|
||||||
|
|
||||||
Texture2D texPs3Pad = LoadTexture("resources/ps3.png");
|
Texture2D texPs3Pad = LoadTexture("romfs:/resources/ps3.png");
|
||||||
Texture2D texXboxPad = LoadTexture("resources/xbox.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
|
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
@ -66,7 +69,6 @@ int main(void)
|
||||||
if (IsGamepadAvailable(0))
|
if (IsGamepadAvailable(0))
|
||||||
{
|
{
|
||||||
DrawText(TextFormat("GP1: %s", GetGamepadName(0)), 10, 10, 10, BLACK);
|
DrawText(TextFormat("GP1: %s", GetGamepadName(0)), 10, 10, 10, BLACK);
|
||||||
|
|
||||||
if (TextIsEqual(GetGamepadName(0), XBOX360_NAME_ID) || TextIsEqual(GetGamepadName(0), XBOX360_LEGACY_NAME_ID))
|
if (TextIsEqual(GetGamepadName(0), XBOX360_NAME_ID) || TextIsEqual(GetGamepadName(0), XBOX360_LEGACY_NAME_ID))
|
||||||
{
|
{
|
||||||
DrawTexture(texXboxPad, 0, 0, DARKGRAY);
|
DrawTexture(texXboxPad, 0, 0, DARKGRAY);
|
||||||
|
|
@ -98,13 +100,13 @@ int main(void)
|
||||||
DrawCircle(259, 152, 39, BLACK);
|
DrawCircle(259, 152, 39, BLACK);
|
||||||
DrawCircle(259, 152, 34, LIGHTGRAY);
|
DrawCircle(259, 152, 34, LIGHTGRAY);
|
||||||
DrawCircle(259 + (int)(GetGamepadAxisMovement(0, GAMEPAD_AXIS_LEFT_X)*20),
|
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
|
// Draw axis: right joystick
|
||||||
DrawCircle(461, 237, 38, BLACK);
|
DrawCircle(450, 240, 60, BLACK);
|
||||||
DrawCircle(461, 237, 33, LIGHTGRAY);
|
DrawCircle(450, 240, 33, LIGHTGRAY);
|
||||||
DrawCircle(461 + (int)(GetGamepadAxisMovement(0, GAMEPAD_AXIS_RIGHT_X)*20),
|
DrawCircle(450 + (int)(GetGamepadAxisMovement(0, GAMEPAD_AXIS_RIGHT_X)*20),
|
||||||
237 + (int)(GetGamepadAxisMovement(0, GAMEPAD_AXIS_RIGHT_Y)*20), 25, BLACK);
|
240 + (int)(GetGamepadAxisMovement(0, GAMEPAD_AXIS_RIGHT_Y)*20), 25, BLACK);
|
||||||
|
|
||||||
// Draw axis: left-right triggers
|
// Draw axis: left-right triggers
|
||||||
DrawRectangle(170, 30, 15, 70, GRAY);
|
DrawRectangle(170, 30, 15, 70, GRAY);
|
||||||
|
|
@ -146,13 +148,13 @@ int main(void)
|
||||||
DrawCircle(319, 255, 35, BLACK);
|
DrawCircle(319, 255, 35, BLACK);
|
||||||
DrawCircle(319, 255, 31, LIGHTGRAY);
|
DrawCircle(319, 255, 31, LIGHTGRAY);
|
||||||
DrawCircle(319 + (int)(GetGamepadAxisMovement(0, GAMEPAD_AXIS_LEFT_X) * 20),
|
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
|
// Draw axis: right joystick
|
||||||
DrawCircle(475, 255, 35, BLACK);
|
DrawCircle(475, 255, 35, BLACK);
|
||||||
DrawCircle(475, 255, 31, LIGHTGRAY);
|
DrawCircle(475, 255, 31, LIGHTGRAY);
|
||||||
DrawCircle(475 + (int)(GetGamepadAxisMovement(0, GAMEPAD_AXIS_RIGHT_X) * 20),
|
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
|
// Draw axis: left-right triggers
|
||||||
DrawRectangle(169, 48, 15, 70, GRAY);
|
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(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);
|
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
|
else
|
||||||
{
|
{
|
||||||
DrawText("- GENERIC GAMEPAD -", 280, 180, 20, GRAY);
|
DrawText("- GENERIC GAMEPAD -", 280, 180, 20, GRAY);
|
||||||
|
|
@ -192,9 +247,11 @@ int main(void)
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
UnloadTexture(texPs3Pad);
|
UnloadTexture(texPs3Pad);
|
||||||
UnloadTexture(texXboxPad);
|
UnloadTexture(texXboxPad);
|
||||||
|
UnloadTexture(texNinProPad);
|
||||||
|
|
||||||
CloseWindow(); // Close window and OpenGL context
|
CloseWindow(); // Close window and OpenGL context
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
romfsExit();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
96
examples-switch/core/core_input_multi_gamepad.c
Normal file
96
examples-switch/core/core_input_multi_gamepad.c
Normal file
|
|
@ -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 <switch.h>
|
||||||
|
|
||||||
|
// 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;
|
||||||
|
}
|
||||||
|
|
@ -56,7 +56,7 @@ int main(void)
|
||||||
{
|
{
|
||||||
// Draw circle and touch index number
|
// Draw circle and touch index number
|
||||||
DrawCircleV(touchPositions[i], 34, ORANGE);
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -59,6 +59,7 @@ int main(void)
|
||||||
cameraPlayer1.target.y = 1.0f;
|
cameraPlayer1.target.y = 1.0f;
|
||||||
cameraPlayer1.position.z = -3.0f;
|
cameraPlayer1.position.z = -3.0f;
|
||||||
cameraPlayer1.position.y = 1.0f;
|
cameraPlayer1.position.y = 1.0f;
|
||||||
|
cameraPlayer1.projection = CAMERA_PERSPECTIVE;
|
||||||
|
|
||||||
RenderTexture screenPlayer1 = LoadRenderTexture(screenWidth/2, screenHeight);
|
RenderTexture screenPlayer1 = LoadRenderTexture(screenWidth/2, screenHeight);
|
||||||
|
|
||||||
|
|
@ -68,9 +69,13 @@ int main(void)
|
||||||
cameraPlayer2.target.y = 3.0f;
|
cameraPlayer2.target.y = 3.0f;
|
||||||
cameraPlayer2.position.x = -3.0f;
|
cameraPlayer2.position.x = -3.0f;
|
||||||
cameraPlayer2.position.y = 3.0f;
|
cameraPlayer2.position.y = 3.0f;
|
||||||
|
cameraPlayer2.projection = CAMERA_PERSPECTIVE;
|
||||||
|
|
||||||
RenderTexture screenPlayer2 = LoadRenderTexture(screenWidth / 2, screenHeight);
|
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
|
// 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 };
|
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
|
// 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
|
// 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)
|
UpdateCameraGamepad(&cameraPlayer1, 0);
|
||||||
if (IsKeyDown(KEY_W))
|
UpdateCameraGamepad(&cameraPlayer2, 1);
|
||||||
{
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
// Draw
|
// Draw
|
||||||
|
|
@ -119,16 +103,15 @@ int main(void)
|
||||||
BeginMode3D(cameraPlayer1);
|
BeginMode3D(cameraPlayer1);
|
||||||
DrawScene();
|
DrawScene();
|
||||||
EndMode3D();
|
EndMode3D();
|
||||||
DrawText("PLAYER1 W/S to move", 10, 10, 20, RED);
|
DrawText("PLAYER1", 10, 10, 20, RED);
|
||||||
EndTextureMode();
|
EndTextureMode();
|
||||||
|
|
||||||
// Draw Player2 view to the render texture
|
// Draw Player2 view to the render texture
|
||||||
BeginTextureMode(screenPlayer2);
|
BeginTextureMode(screenPlayer2);
|
||||||
ClearBackground(SKYBLUE);
|
ClearBackground(SKYBLUE);
|
||||||
BeginMode3D(cameraPlayer2);
|
BeginMode3D(cameraPlayer2);
|
||||||
DrawScene();
|
DrawScene();
|
||||||
EndMode3D();
|
EndMode3D();
|
||||||
DrawText("PLAYER2 UP/DOWN to move", 10, 10, 20, BLUE);
|
DrawText("PLAYER2", 10, 10, 20, BLUE);
|
||||||
EndTextureMode();
|
EndTextureMode();
|
||||||
|
|
||||||
// Draw both views render textures to the screen side by side
|
// Draw both views render textures to the screen side by side
|
||||||
|
|
@ -136,6 +119,7 @@ int main(void)
|
||||||
ClearBackground(BLACK);
|
ClearBackground(BLACK);
|
||||||
DrawTextureRec(screenPlayer1.texture, splitScreenRect, (Vector2){ 0, 0 }, WHITE);
|
DrawTextureRec(screenPlayer1.texture, splitScreenRect, (Vector2){ 0, 0 }, WHITE);
|
||||||
DrawTextureRec(screenPlayer2.texture, splitScreenRect, (Vector2){ screenWidth/2.0f, 0 }, WHITE);
|
DrawTextureRec(screenPlayer2.texture, splitScreenRect, (Vector2){ screenWidth/2.0f, 0 }, WHITE);
|
||||||
|
DrawRectangle(screenWidth/2 - 5, 0, 10, 720, BLACK);
|
||||||
EndDrawing();
|
EndDrawing();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
Before Width: | Height: | Size: 19 KiB After Width: | Height: | Size: 19 KiB |
BIN
examples-switch/romfs/resources/switch_pro.png
Normal file
BIN
examples-switch/romfs/resources/switch_pro.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.2 MiB |
|
Before Width: | Height: | Size: 16 KiB After Width: | Height: | Size: 16 KiB |
|
|
@ -141,7 +141,7 @@ int main(void)
|
||||||
{
|
{
|
||||||
// Update
|
// Update
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
UpdateCamera(&camera);
|
UpdateCameraGamepad(&camera, 0);
|
||||||
|
|
||||||
// Handle font files dropped
|
// Handle font files dropped
|
||||||
if (IsFileDropped())
|
if (IsFileDropped())
|
||||||
|
|
|
||||||
|
|
@ -71,6 +71,7 @@
|
||||||
#define NX_SUPPORT_GAMEPAD_EMULATION 1
|
#define NX_SUPPORT_GAMEPAD_EMULATION 1
|
||||||
// Enabling this flag allows debugging by USB, the application will wait for an USB connection to start
|
// Enabling this flag allows debugging by USB, the application will wait for an USB connection to start
|
||||||
//#define NX_USB_DEBUGGER 1
|
//#define NX_USB_DEBUGGER 1
|
||||||
|
// #define ENABLE_DEV_EXIT 1 // Allows for exit when gamepad kbm emulation is disabled
|
||||||
|
|
||||||
// rcore: Configuration values
|
// rcore: Configuration values
|
||||||
//------------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
|
@ -303,6 +303,7 @@ typedef struct Font {
|
||||||
// Camera, defines position/orientation in 3d space
|
// Camera, defines position/orientation in 3d space
|
||||||
typedef struct Camera3D {
|
typedef struct Camera3D {
|
||||||
Vector3 position; // Camera position
|
Vector3 position; // Camera position
|
||||||
|
Vector2 angle; // Camera angle (Required for splitscreen instead of shared global)
|
||||||
Vector3 target; // Camera target it looks-at
|
Vector3 target; // Camera target it looks-at
|
||||||
Vector3 up; // Camera up vector (rotation over its axis)
|
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
|
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 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 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 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
|
// Input-related functions: mouse
|
||||||
RLAPI bool IsMouseButtonPressed(int button); // Check if a mouse button has been pressed once
|
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 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 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 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)
|
RLAPI void SetCameraAltControl(int keyAlt); // Set camera alt key to combine with mouse movement (free camera)
|
||||||
|
|
|
||||||
289
src/rcamera.h
289
src/rcamera.h
|
|
@ -159,8 +159,12 @@ void SetCameraMoveControls(int keyFront, int keyBack,
|
||||||
#define CAMERA_FREE_DISTANCE_MAX_CLAMP 120.0f
|
#define CAMERA_FREE_DISTANCE_MAX_CLAMP 120.0f
|
||||||
#define CAMERA_FREE_MIN_CLAMP 85.0f
|
#define CAMERA_FREE_MIN_CLAMP 85.0f
|
||||||
#define CAMERA_FREE_MAX_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
|
#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
|
// ORBITAL_CAMERA
|
||||||
#define CAMERA_ORBITAL_SPEED 0.5f // Radians per second
|
#define CAMERA_ORBITAL_SPEED 0.5f // Radians per second
|
||||||
|
|
@ -223,7 +227,11 @@ static CameraData CAMERA = { // Global CAMERA state context
|
||||||
.playerEyesPosition = 1.85f,
|
.playerEyesPosition = 1.85f,
|
||||||
.angle = { 0 },
|
.angle = { 0 },
|
||||||
.moveControl = { 'W', 'S', 'D', 'A', 'E', 'Q' },
|
.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
|
.smoothZoomControl = 341, // raylib: KEY_LEFT_CONTROL
|
||||||
|
#endif
|
||||||
.altControl = 342, // raylib: KEY_LEFT_ALT
|
.altControl = 342, // raylib: KEY_LEFT_ALT
|
||||||
.panControl = 2 // raylib: MOUSE_BUTTON_MIDDLE
|
.panControl = 2 // raylib: MOUSE_BUTTON_MIDDLE
|
||||||
};
|
};
|
||||||
|
|
@ -534,6 +542,285 @@ void UpdateCamera(Camera *camera)
|
||||||
default: break;
|
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)
|
// Set camera pan key to combine with mouse movement (free camera)
|
||||||
void SetCameraPanControl(int keyPan) { CAMERA.panControl = keyPan; }
|
void SetCameraPanControl(int keyPan) { CAMERA.panControl = keyPan; }
|
||||||
|
|
|
||||||
467
src/rcore.c
467
src/rcore.c
|
|
@ -491,6 +491,8 @@ typedef struct CoreData {
|
||||||
Vector2 position[MAX_TOUCH_POINTS]; // Touch position on screen
|
Vector2 position[MAX_TOUCH_POINTS]; // Touch position on screen
|
||||||
char currentTouchState[MAX_TOUCH_POINTS]; // Registers current touch state
|
char currentTouchState[MAX_TOUCH_POINTS]; // Registers current touch state
|
||||||
char previousTouchState[MAX_TOUCH_POINTS]; // Registers previous touch state
|
char previousTouchState[MAX_TOUCH_POINTS]; // Registers previous touch state
|
||||||
|
// PLATFORM_NX
|
||||||
|
long int deltaTime[MAX_TOUCH_POINTS];
|
||||||
} Touch;
|
} Touch;
|
||||||
struct {
|
struct {
|
||||||
int lastButtonPressed; // Register last gamepad button pressed
|
int lastButtonPressed; // Register last gamepad button pressed
|
||||||
|
|
@ -506,6 +508,8 @@ typedef struct CoreData {
|
||||||
#endif
|
#endif
|
||||||
#if defined(PLATFORM_NX)
|
#if defined(PLATFORM_NX)
|
||||||
PadState nxPad[MAX_GAMEPADS]; // Gamepad state holder
|
PadState nxPad[MAX_GAMEPADS]; // Gamepad state holder
|
||||||
|
HidNpadStyleTag nxPadStyle[MAX_GAMEPADS];
|
||||||
|
float yInverted[MAX_GAMEPADS]; // True -1.f False 1.f
|
||||||
#endif
|
#endif
|
||||||
} Gamepad;
|
} Gamepad;
|
||||||
} Input;
|
} Input;
|
||||||
|
|
@ -540,6 +544,10 @@ static bool gifRecording = false; // GIF recording state
|
||||||
static MsfGifState gifState = { 0 }; // MSGIF context state
|
static MsfGifState gifState = { 0 }; // MSGIF context state
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if defined(PLATFORM_NX)
|
||||||
|
s32 prev_touchcount = 0;
|
||||||
|
#endif
|
||||||
|
|
||||||
#if defined(SUPPORT_EVENTS_AUTOMATION)
|
#if defined(SUPPORT_EVENTS_AUTOMATION)
|
||||||
#define MAX_CODE_AUTOMATION_EVENTS 16384
|
#define MAX_CODE_AUTOMATION_EVENTS 16384
|
||||||
|
|
||||||
|
|
@ -917,7 +925,12 @@ void InitWindow(int width, int height, const char *title)
|
||||||
// Configure our supported input layout
|
// Configure our supported input layout
|
||||||
padConfigureInput(MAX_GAMEPADS, HidNpadStyleSet_NpadStandard);
|
padConfigureInput(MAX_GAMEPADS, HidNpadStyleSet_NpadStandard);
|
||||||
// Initialize the gamepads
|
// 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
|
#endif
|
||||||
|
|
||||||
#if defined(PLATFORM_WEB)
|
#if defined(PLATFORM_WEB)
|
||||||
|
|
@ -3614,6 +3627,25 @@ const char *GetGamepadName(int gamepad)
|
||||||
#endif
|
#endif
|
||||||
#if defined(PLATFORM_WEB)
|
#if defined(PLATFORM_WEB)
|
||||||
return CORE.Input.Gamepad.name[gamepad];
|
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
|
#endif
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
@ -3641,6 +3673,21 @@ float GetGamepadAxisMovement(int gamepad, int axis)
|
||||||
return value;
|
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
|
// Check if a gamepad button has been pressed once
|
||||||
bool IsGamepadButtonPressed(int gamepad, int button)
|
bool IsGamepadButtonPressed(int gamepad, int button)
|
||||||
{
|
{
|
||||||
|
|
@ -3823,7 +3870,7 @@ float GetMouseWheelMove(void)
|
||||||
{
|
{
|
||||||
float result = 0.0f;
|
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;
|
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;
|
else result = (float)CORE.Input.Mouse.currentWheelMove.y;
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -3831,6 +3878,17 @@ float GetMouseWheelMove(void)
|
||||||
return result;
|
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
|
// Get mouse wheel movement X/Y as a vector
|
||||||
Vector2 GetMouseWheelMoveV(void)
|
Vector2 GetMouseWheelMoveV(void)
|
||||||
{
|
{
|
||||||
|
|
@ -3859,7 +3917,7 @@ void SetMouseCursor(int cursor)
|
||||||
// Get touch position X for touch point 0 (relative to screen size)
|
// Get touch position X for touch point 0 (relative to screen size)
|
||||||
int GetTouchX(void)
|
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;
|
return (int)CORE.Input.Touch.position[0].x;
|
||||||
#else // PLATFORM_DESKTOP, PLATFORM_RPI, PLATFORM_DRM
|
#else // PLATFORM_DESKTOP, PLATFORM_RPI, PLATFORM_DRM
|
||||||
return GetMouseX();
|
return GetMouseX();
|
||||||
|
|
@ -3869,7 +3927,7 @@ int GetTouchX(void)
|
||||||
// Get touch position Y for touch point 0 (relative to screen size)
|
// Get touch position Y for touch point 0 (relative to screen size)
|
||||||
int GetTouchY(void)
|
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;
|
return (int)CORE.Input.Touch.position[0].y;
|
||||||
#else // PLATFORM_DESKTOP, PLATFORM_RPI, PLATFORM_DRM
|
#else // PLATFORM_DESKTOP, PLATFORM_RPI, PLATFORM_DRM
|
||||||
return GetMouseY();
|
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
|
// https://docs.microsoft.com/en-us/windows/win32/wintouch/getting-started-with-multi-touch-messages
|
||||||
if (index == 0) position = GetMousePosition();
|
if (index == 0) position = GetMousePosition();
|
||||||
#endif
|
#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];
|
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);
|
else TRACELOG(LOG_WARNING, "INPUT: Required touch point out of range (Max touch points: %i)", MAX_TOUCH_POINTS);
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -5158,202 +5216,253 @@ void PollInputEvents(void)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(PLATFORM_NX)
|
#if defined(PLATFORM_NX)
|
||||||
int nxGamepadIndex = 0;
|
/**
|
||||||
|
* Touch screen
|
||||||
// Scan the gamepad. This should be done once for each frame
|
*/
|
||||||
padUpdate(&CORE.Input.Gamepad.nxPad[nxGamepadIndex]);
|
HidTouchScreenState state = {0};
|
||||||
|
if (hidGetTouchScreenStates(&state, 1)) {
|
||||||
CORE.Input.Gamepad.ready[nxGamepadIndex] = padIsConnected(&CORE.Input.Gamepad.nxPad[nxGamepadIndex]);
|
if (state.count != prev_touchcount)
|
||||||
|
|
||||||
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++)
|
|
||||||
{
|
{
|
||||||
// Register previous gamepad states
|
prev_touchcount = state.count;
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
for(int i=0; i<state.count; i++)
|
||||||
|
{
|
||||||
|
CORE.Input.Touch.position[i].x = state.touches[i].x;
|
||||||
|
CORE.Input.Touch.position[i].y = state.touches[i].y;
|
||||||
|
CORE.Input.Touch.pointId[i] = state.touches[i].finger_id;
|
||||||
|
|
||||||
// Check analogic axis and buttons
|
CORE.Input.Touch.deltaTime[i] = state.touches[i].delta_time;
|
||||||
HidAnalogStickState kAxisL = padGetStickPos(&CORE.Input.Gamepad.nxPad[nxGamepadIndex], 0);
|
}
|
||||||
HidAnalogStickState kAxisR = padGetStickPos(&CORE.Input.Gamepad.nxPad[nxGamepadIndex], 1);
|
CORE.Input.Touch.pointCount = state.count;
|
||||||
|
}
|
||||||
|
|
||||||
CORE.Input.Gamepad.axisState[nxGamepadIndex][GAMEPAD_AXIS_LEFT_X] = (float)kAxisL.x / 32767.0f;
|
/**
|
||||||
CORE.Input.Gamepad.axisState[nxGamepadIndex][GAMEPAD_AXIS_LEFT_Y] = (float)kAxisL.y / 32767.0f;
|
* Gamepad
|
||||||
CORE.Input.Gamepad.axisState[nxGamepadIndex][GAMEPAD_AXIS_RIGHT_X] = (float)kAxisR.x / 32767.0f;
|
*/
|
||||||
CORE.Input.Gamepad.axisState[nxGamepadIndex][GAMEPAD_AXIS_RIGHT_Y] = (float)kAxisR.y / 32767.0f;
|
for (int nxGamepadIndex = 0; nxGamepadIndex < MAX_GAMEPADS; nxGamepadIndex++)
|
||||||
CORE.Input.Gamepad.axisState[nxGamepadIndex][GAMEPAD_AXIS_LEFT_TRIGGER] = (kHeld & HidNpadButton_ZL) ? 1.0f : 0.0f;
|
{
|
||||||
CORE.Input.Gamepad.axisState[nxGamepadIndex][GAMEPAD_AXIS_RIGHT_TRIGGER] = (kHeld & HidNpadButton_ZR) ? 1.0f : 0.0f;
|
// 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]) {
|
||||||
|
CORE.Input.Gamepad.nxPadStyle[nxGamepadIndex] = hidGetNpadStyleSet(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++)
|
||||||
|
{
|
||||||
|
// 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check analogic axis and buttons
|
||||||
|
HidAnalogStickState kAxisL = padGetStickPos(&CORE.Input.Gamepad.nxPad[nxGamepadIndex], 0);
|
||||||
|
HidAnalogStickState kAxisR = padGetStickPos(&CORE.Input.Gamepad.nxPad[nxGamepadIndex], 1);
|
||||||
|
|
||||||
|
CORE.Input.Gamepad.axisState[nxGamepadIndex][GAMEPAD_AXIS_LEFT_X] = (float)kAxisL.x / 32767.0f;
|
||||||
|
CORE.Input.Gamepad.axisState[nxGamepadIndex][GAMEPAD_AXIS_LEFT_Y] = (float)kAxisL.y / 32767.0f;
|
||||||
|
CORE.Input.Gamepad.axisState[nxGamepadIndex][GAMEPAD_AXIS_RIGHT_X] = (float)kAxisR.x / 32767.0f;
|
||||||
|
CORE.Input.Gamepad.axisState[nxGamepadIndex][GAMEPAD_AXIS_RIGHT_Y] = (float)kAxisR.y / 32767.0f;
|
||||||
|
CORE.Input.Gamepad.axisState[nxGamepadIndex][GAMEPAD_AXIS_LEFT_TRIGGER] = (kHeld & HidNpadButton_ZL) ? 1.0f : 0.0f;
|
||||||
|
CORE.Input.Gamepad.axisState[nxGamepadIndex][GAMEPAD_AXIS_RIGHT_TRIGGER] = (kHeld & HidNpadButton_ZR) ? 1.0f : 0.0f;
|
||||||
|
|
||||||
|
#if defined(ENABLE_DEV_EXIT)
|
||||||
|
if (kHeld & HidNpadButton_Plus && kHeld & HidNpadButton_Minus)
|
||||||
|
{
|
||||||
|
CORE.Window.shouldClose = true;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#if defined(NX_SUPPORT_GAMEPAD_EMULATION)
|
#if defined(NX_SUPPORT_GAMEPAD_EMULATION)
|
||||||
CORE.Input.Keyboard.previousKeyState[KEY_RIGHT] = CORE.Input.Keyboard.currentKeyState[KEY_RIGHT];
|
|
||||||
CORE.Input.Keyboard.previousKeyState[KEY_D] = CORE.Input.Keyboard.currentKeyState[KEY_D];
|
|
||||||
if (kHeld & HidNpadButton_Right || kHeld & HidNpadButton_StickLRight) {
|
|
||||||
CORE.Input.Keyboard.currentKeyState[KEY_RIGHT] = 1;
|
|
||||||
CORE.Input.Keyboard.currentKeyState[KEY_D] = 1;
|
|
||||||
} else {
|
|
||||||
CORE.Input.Keyboard.currentKeyState[KEY_RIGHT] = 0;
|
|
||||||
CORE.Input.Keyboard.currentKeyState[KEY_D] = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
CORE.Input.Keyboard.previousKeyState[KEY_LEFT] = CORE.Input.Keyboard.currentKeyState[KEY_LEFT];
|
// Move Right (D key or right arrow)
|
||||||
CORE.Input.Keyboard.previousKeyState[KEY_A] = CORE.Input.Keyboard.currentKeyState[KEY_A];
|
CORE.Input.Keyboard.previousKeyState[KEY_RIGHT] = CORE.Input.Keyboard.currentKeyState[KEY_RIGHT];
|
||||||
if (kHeld & HidNpadButton_Left || kHeld & HidNpadButton_StickLLeft) {
|
CORE.Input.Keyboard.previousKeyState[KEY_D] = CORE.Input.Keyboard.currentKeyState[KEY_D];
|
||||||
CORE.Input.Keyboard.currentKeyState[KEY_LEFT] = 1;
|
if (kHeld & HidNpadButton_Right || kHeld & HidNpadButton_StickLRight) {
|
||||||
CORE.Input.Keyboard.currentKeyState[KEY_A] = 1;
|
CORE.Input.Keyboard.currentKeyState[KEY_RIGHT] = 1;
|
||||||
} else {
|
CORE.Input.Keyboard.currentKeyState[KEY_D] = 1;
|
||||||
CORE.Input.Keyboard.currentKeyState[KEY_LEFT] = 0;
|
|
||||||
CORE.Input.Keyboard.currentKeyState[KEY_A] = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
CORE.Input.Keyboard.previousKeyState[KEY_DOWN] = CORE.Input.Keyboard.currentKeyState[KEY_DOWN];
|
|
||||||
CORE.Input.Keyboard.previousKeyState[KEY_S] = CORE.Input.Keyboard.currentKeyState[KEY_S];
|
|
||||||
if (kHeld & HidNpadButton_Down || kHeld & HidNpadButton_StickLDown) {
|
|
||||||
CORE.Input.Keyboard.currentKeyState[KEY_DOWN] = 1;
|
|
||||||
CORE.Input.Keyboard.currentKeyState[KEY_S] = 1;
|
|
||||||
} else {
|
|
||||||
CORE.Input.Keyboard.currentKeyState[KEY_DOWN] = 0;
|
|
||||||
CORE.Input.Keyboard.currentKeyState[KEY_S] = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
CORE.Input.Keyboard.previousKeyState[KEY_UP] = CORE.Input.Keyboard.currentKeyState[KEY_UP];
|
|
||||||
CORE.Input.Keyboard.previousKeyState[KEY_W] = CORE.Input.Keyboard.currentKeyState[KEY_W];
|
|
||||||
if (kHeld & HidNpadButton_Up || kHeld & HidNpadButton_StickLUp) {
|
|
||||||
CORE.Input.Keyboard.currentKeyState[KEY_UP] = 1;
|
|
||||||
CORE.Input.Keyboard.currentKeyState[KEY_W] = 1;
|
|
||||||
} else {
|
|
||||||
CORE.Input.Keyboard.currentKeyState[KEY_UP] = 0;
|
|
||||||
CORE.Input.Keyboard.currentKeyState[KEY_W] = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
CORE.Input.Keyboard.previousKeyState[KEY_Q] = CORE.Input.Keyboard.currentKeyState[KEY_Q];
|
|
||||||
if (kHeld & HidNpadButton_Y) {
|
|
||||||
CORE.Input.Keyboard.currentKeyState[KEY_Q] = 1;
|
|
||||||
} else {
|
|
||||||
CORE.Input.Keyboard.currentKeyState[KEY_Q] = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
CORE.Input.Keyboard.previousKeyState[KEY_E] = CORE.Input.Keyboard.currentKeyState[KEY_E];
|
|
||||||
if (kHeld & HidNpadButton_A) {
|
|
||||||
CORE.Input.Keyboard.currentKeyState[KEY_E] = 1;
|
|
||||||
} else {
|
|
||||||
CORE.Input.Keyboard.currentKeyState[KEY_E] = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
CORE.Input.Keyboard.previousKeyState[KEY_R] = CORE.Input.Keyboard.currentKeyState[KEY_R];
|
|
||||||
if (kHeld & HidNpadButton_X) {
|
|
||||||
CORE.Input.Keyboard.currentKeyState[KEY_R] = 1;
|
|
||||||
} else {
|
|
||||||
CORE.Input.Keyboard.currentKeyState[KEY_R] = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
CORE.Input.Keyboard.previousKeyState[KEY_F] = CORE.Input.Keyboard.currentKeyState[KEY_F];
|
|
||||||
if (kHeld & HidNpadButton_B) {
|
|
||||||
CORE.Input.Keyboard.currentKeyState[KEY_F] = 1;
|
|
||||||
} else {
|
|
||||||
CORE.Input.Keyboard.currentKeyState[KEY_F] = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
CORE.Input.Keyboard.previousKeyState[KEY_ENTER] = CORE.Input.Keyboard.currentKeyState[KEY_ENTER];
|
|
||||||
CORE.Input.Keyboard.previousKeyState[KEY_SPACE] = CORE.Input.Keyboard.currentKeyState[KEY_SPACE];
|
|
||||||
CORE.Input.Keyboard.previousKeyState[KEY_ESCAPE] = CORE.Input.Keyboard.currentKeyState[KEY_ESCAPE];
|
|
||||||
if (kHeld & HidNpadButton_Plus && kHeld & HidNpadButton_Minus) {
|
|
||||||
CORE.Input.Keyboard.currentKeyState[KEY_ENTER] = 0;
|
|
||||||
CORE.Input.Keyboard.currentKeyState[KEY_SPACE] = 0;
|
|
||||||
CORE.Input.Keyboard.currentKeyState[KEY_ESCAPE] = 1;
|
|
||||||
} else {
|
|
||||||
if (kHeld & HidNpadButton_Plus) {
|
|
||||||
CORE.Input.Keyboard.currentKeyState[KEY_ENTER] = 1;
|
|
||||||
} else {
|
} else {
|
||||||
|
CORE.Input.Keyboard.currentKeyState[KEY_RIGHT] = 0;
|
||||||
|
CORE.Input.Keyboard.currentKeyState[KEY_D] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Move Left (A key or left arrow)
|
||||||
|
CORE.Input.Keyboard.previousKeyState[KEY_LEFT] = CORE.Input.Keyboard.currentKeyState[KEY_LEFT];
|
||||||
|
CORE.Input.Keyboard.previousKeyState[KEY_A] = CORE.Input.Keyboard.currentKeyState[KEY_A];
|
||||||
|
if (kHeld & HidNpadButton_Left || kHeld & HidNpadButton_StickLLeft) {
|
||||||
|
CORE.Input.Keyboard.currentKeyState[KEY_LEFT] = 1;
|
||||||
|
CORE.Input.Keyboard.currentKeyState[KEY_A] = 1;
|
||||||
|
} else {
|
||||||
|
CORE.Input.Keyboard.currentKeyState[KEY_LEFT] = 0;
|
||||||
|
CORE.Input.Keyboard.currentKeyState[KEY_A] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Move down (S key or down arrow)
|
||||||
|
CORE.Input.Keyboard.previousKeyState[KEY_DOWN] = CORE.Input.Keyboard.currentKeyState[KEY_DOWN];
|
||||||
|
CORE.Input.Keyboard.previousKeyState[KEY_S] = CORE.Input.Keyboard.currentKeyState[KEY_S];
|
||||||
|
if (kHeld & HidNpadButton_Down || kHeld & HidNpadButton_StickLDown) {
|
||||||
|
CORE.Input.Keyboard.currentKeyState[KEY_DOWN] = 1;
|
||||||
|
CORE.Input.Keyboard.currentKeyState[KEY_S] = 1;
|
||||||
|
} else {
|
||||||
|
CORE.Input.Keyboard.currentKeyState[KEY_DOWN] = 0;
|
||||||
|
CORE.Input.Keyboard.currentKeyState[KEY_S] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Move up (W key or up arrow)
|
||||||
|
CORE.Input.Keyboard.previousKeyState[KEY_UP] = CORE.Input.Keyboard.currentKeyState[KEY_UP];
|
||||||
|
CORE.Input.Keyboard.previousKeyState[KEY_W] = CORE.Input.Keyboard.currentKeyState[KEY_W];
|
||||||
|
if (kHeld & HidNpadButton_Up || kHeld & HidNpadButton_StickLUp) {
|
||||||
|
CORE.Input.Keyboard.currentKeyState[KEY_UP] = 1;
|
||||||
|
CORE.Input.Keyboard.currentKeyState[KEY_W] = 1;
|
||||||
|
} else {
|
||||||
|
CORE.Input.Keyboard.currentKeyState[KEY_UP] = 0;
|
||||||
|
CORE.Input.Keyboard.currentKeyState[KEY_W] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Gamepad Y (Q key)
|
||||||
|
CORE.Input.Keyboard.previousKeyState[KEY_Q] = CORE.Input.Keyboard.currentKeyState[KEY_Q];
|
||||||
|
if (kHeld & HidNpadButton_Y) {
|
||||||
|
CORE.Input.Keyboard.currentKeyState[KEY_Q] = 1;
|
||||||
|
} else {
|
||||||
|
CORE.Input.Keyboard.currentKeyState[KEY_Q] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Gamepad A (E key)
|
||||||
|
CORE.Input.Keyboard.previousKeyState[KEY_E] = CORE.Input.Keyboard.currentKeyState[KEY_E];
|
||||||
|
if (kHeld & HidNpadButton_A) {
|
||||||
|
CORE.Input.Keyboard.currentKeyState[KEY_E] = 1;
|
||||||
|
} else {
|
||||||
|
CORE.Input.Keyboard.currentKeyState[KEY_E] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Gamepad X (R key)
|
||||||
|
CORE.Input.Keyboard.previousKeyState[KEY_R] = CORE.Input.Keyboard.currentKeyState[KEY_R];
|
||||||
|
if (kHeld & HidNpadButton_X) {
|
||||||
|
CORE.Input.Keyboard.currentKeyState[KEY_R] = 1;
|
||||||
|
} else {
|
||||||
|
CORE.Input.Keyboard.currentKeyState[KEY_R] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Gamepad B (F key)
|
||||||
|
CORE.Input.Keyboard.previousKeyState[KEY_F] = CORE.Input.Keyboard.currentKeyState[KEY_F];
|
||||||
|
if (kHeld & HidNpadButton_B) {
|
||||||
|
CORE.Input.Keyboard.currentKeyState[KEY_F] = 1;
|
||||||
|
} else {
|
||||||
|
CORE.Input.Keyboard.currentKeyState[KEY_F] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Gamepad + and - (Escape)
|
||||||
|
CORE.Input.Keyboard.previousKeyState[KEY_ENTER] = CORE.Input.Keyboard.currentKeyState[KEY_ENTER];
|
||||||
|
CORE.Input.Keyboard.previousKeyState[KEY_SPACE] = CORE.Input.Keyboard.currentKeyState[KEY_SPACE];
|
||||||
|
CORE.Input.Keyboard.previousKeyState[KEY_ESCAPE] = CORE.Input.Keyboard.currentKeyState[KEY_ESCAPE];
|
||||||
|
if (kHeld & HidNpadButton_Plus && kHeld & HidNpadButton_Minus) {
|
||||||
CORE.Input.Keyboard.currentKeyState[KEY_ENTER] = 0;
|
CORE.Input.Keyboard.currentKeyState[KEY_ENTER] = 0;
|
||||||
}
|
|
||||||
if (kHeld & HidNpadButton_Minus) {
|
|
||||||
CORE.Input.Keyboard.currentKeyState[KEY_SPACE] = 1;
|
|
||||||
} else {
|
|
||||||
CORE.Input.Keyboard.currentKeyState[KEY_SPACE] = 0;
|
CORE.Input.Keyboard.currentKeyState[KEY_SPACE] = 0;
|
||||||
|
CORE.Input.Keyboard.currentKeyState[KEY_ESCAPE] = 1;
|
||||||
|
} else {
|
||||||
|
if (kHeld & HidNpadButton_Plus) {
|
||||||
|
CORE.Input.Keyboard.currentKeyState[KEY_ENTER] = 1;
|
||||||
|
} else {
|
||||||
|
CORE.Input.Keyboard.currentKeyState[KEY_ENTER] = 0;
|
||||||
|
}
|
||||||
|
if (kHeld & HidNpadButton_Minus) {
|
||||||
|
CORE.Input.Keyboard.currentKeyState[KEY_SPACE] = 1;
|
||||||
|
} else {
|
||||||
|
CORE.Input.Keyboard.currentKeyState[KEY_SPACE] = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
CORE.Input.Keyboard.previousKeyState[KEY_LEFT_SHIFT] = CORE.Input.Keyboard.currentKeyState[KEY_LEFT_SHIFT];
|
// Gamepad Left Thumb (shift)
|
||||||
if (kHeld & GAMEPAD_BUTTON_LEFT_THUMB) {
|
CORE.Input.Keyboard.previousKeyState[KEY_LEFT_SHIFT] = CORE.Input.Keyboard.currentKeyState[KEY_LEFT_SHIFT];
|
||||||
CORE.Input.Keyboard.currentKeyState[KEY_LEFT_SHIFT] = 1;
|
if (kHeld & GAMEPAD_BUTTON_LEFT_THUMB) {
|
||||||
} else {
|
CORE.Input.Keyboard.currentKeyState[KEY_LEFT_SHIFT] = 1;
|
||||||
CORE.Input.Keyboard.currentKeyState[KEY_LEFT_SHIFT] = 0;
|
} else {
|
||||||
}
|
CORE.Input.Keyboard.currentKeyState[KEY_LEFT_SHIFT] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
CORE.Input.Mouse.previousButtonState[MOUSE_BUTTON_LEFT] = CORE.Input.Mouse.currentButtonState[MOUSE_BUTTON_LEFT];
|
// Gamepad ZL (mouse right)
|
||||||
if (kHeld & HidNpadButton_ZL) {
|
CORE.Input.Mouse.previousButtonState[MOUSE_BUTTON_LEFT] = CORE.Input.Mouse.currentButtonState[MOUSE_BUTTON_LEFT];
|
||||||
CORE.Input.Mouse.currentButtonState[MOUSE_BUTTON_RIGHT] = 1;
|
if (kHeld & HidNpadButton_ZL) {
|
||||||
} else {
|
CORE.Input.Mouse.currentButtonState[MOUSE_BUTTON_RIGHT] = 1;
|
||||||
CORE.Input.Mouse.currentButtonState[MOUSE_BUTTON_RIGHT] = 0;
|
} else {
|
||||||
}
|
CORE.Input.Mouse.currentButtonState[MOUSE_BUTTON_RIGHT] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
CORE.Input.Mouse.previousButtonState[MOUSE_BUTTON_MIDDLE] = CORE.Input.Mouse.currentButtonState[MOUSE_BUTTON_MIDDLE];
|
// Gamepad Right Thumb (mouse middle)
|
||||||
if (kHeld & GAMEPAD_BUTTON_RIGHT_THUMB) {
|
CORE.Input.Mouse.previousButtonState[MOUSE_BUTTON_MIDDLE] = CORE.Input.Mouse.currentButtonState[MOUSE_BUTTON_MIDDLE];
|
||||||
CORE.Input.Mouse.currentButtonState[MOUSE_BUTTON_MIDDLE] = 1;
|
if (kHeld & GAMEPAD_BUTTON_RIGHT_THUMB) {
|
||||||
} else {
|
CORE.Input.Mouse.currentButtonState[MOUSE_BUTTON_MIDDLE] = 1;
|
||||||
CORE.Input.Mouse.currentButtonState[MOUSE_BUTTON_MIDDLE] = 0;
|
} else {
|
||||||
}
|
CORE.Input.Mouse.currentButtonState[MOUSE_BUTTON_MIDDLE] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
CORE.Input.Mouse.previousButtonState[MOUSE_BUTTON_RIGHT] = CORE.Input.Mouse.currentButtonState[MOUSE_BUTTON_RIGHT];
|
// Gamepad ZR (mouse left)
|
||||||
if (kHeld & HidNpadButton_ZR) {
|
CORE.Input.Mouse.previousButtonState[MOUSE_BUTTON_RIGHT] = CORE.Input.Mouse.currentButtonState[MOUSE_BUTTON_RIGHT];
|
||||||
CORE.Input.Mouse.currentButtonState[MOUSE_BUTTON_LEFT] = 1;
|
if (kHeld & HidNpadButton_ZR) {
|
||||||
} else {
|
CORE.Input.Mouse.currentButtonState[MOUSE_BUTTON_LEFT] = 1;
|
||||||
CORE.Input.Mouse.currentButtonState[MOUSE_BUTTON_LEFT] = 0;
|
} else {
|
||||||
}
|
CORE.Input.Mouse.currentButtonState[MOUSE_BUTTON_LEFT] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
CORE.Input.Mouse.previousWheelMove = CORE.Input.Mouse.currentWheelMove;
|
// Gamepad L/R Bumpers (mouse wheel)
|
||||||
if (kHeld & HidNpadButton_L) {
|
CORE.Input.Mouse.previousWheelMove = CORE.Input.Mouse.currentWheelMove;
|
||||||
CORE.Input.Mouse.currentWheelMove = (Vector2){ 0.0f, -1.0f };
|
if (kHeld & HidNpadButton_L) {
|
||||||
} else if (kHeld & HidNpadButton_R) {
|
CORE.Input.Mouse.currentWheelMove = (Vector2){ 0.0f, -1.0f };
|
||||||
CORE.Input.Mouse.currentWheelMove = (Vector2){ 0.0f, 1.0f };
|
} else if (kHeld & HidNpadButton_R) {
|
||||||
} else {
|
CORE.Input.Mouse.currentWheelMove = (Vector2){ 0.0f, 1.0f };
|
||||||
CORE.Input.Mouse.currentWheelMove = (Vector2){ 0.0f, 0.0f };
|
} else {
|
||||||
}
|
CORE.Input.Mouse.currentWheelMove = (Vector2){ 0.0f, 0.0f };
|
||||||
|
}
|
||||||
|
|
||||||
CORE.Input.Mouse.previousPosition.x = CORE.Input.Mouse.currentPosition.x;
|
// Gamepad Axis (mouse position)
|
||||||
CORE.Input.Mouse.previousPosition.y = CORE.Input.Mouse.currentPosition.y;
|
CORE.Input.Mouse.previousPosition.x = CORE.Input.Mouse.currentPosition.x;
|
||||||
|
CORE.Input.Mouse.previousPosition.y = CORE.Input.Mouse.currentPosition.y;
|
||||||
|
|
||||||
CORE.Input.Mouse.currentPosition.x += CORE.Input.Gamepad.axisState[nxGamepadIndex][GAMEPAD_AXIS_RIGHT_X] * 10;
|
CORE.Input.Mouse.currentPosition.x += CORE.Input.Gamepad.axisState[nxGamepadIndex][GAMEPAD_AXIS_RIGHT_X] * 10;
|
||||||
CORE.Input.Mouse.currentPosition.y -= CORE.Input.Gamepad.axisState[nxGamepadIndex][GAMEPAD_AXIS_RIGHT_Y] * 10;
|
CORE.Input.Mouse.currentPosition.y -= CORE.Input.Gamepad.axisState[nxGamepadIndex][GAMEPAD_AXIS_RIGHT_Y] * 10;
|
||||||
|
|
||||||
if (CORE.Input.Mouse.currentPosition.x < 0) CORE.Input.Mouse.currentPosition.x = 0;
|
// Clamp Mouse X to screen
|
||||||
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.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;
|
// Clamp Mouse Y to screen
|
||||||
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.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
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user