Ray пре 8 година
родитељ
комит
c47b04a2c6

+ 146 - 27
docs/examples/web/core_input_gamepad.c

@@ -1,14 +1,17 @@
 /*******************************************************************************************
 *
-*   raylib [core] example - Gamepad input (adapted for HTML5 platform)
+*   raylib [core] example - Gamepad input
 *
 *   NOTE: This example requires a Gamepad connected to the system
-*         raylib is configured to work with Xbox 360 gamepad, check raylib.h for buttons configuration
+*         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
 *
-*   This example has been created using raylib 1.3 (www.raylib.com)
+*   This example has been created using raylib 1.7 (www.raylib.com)
 *   raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
 *
-*   Copyright (c) 2015 Ramon Santamaria (@raysan5)
+*   Copyright (c) 2017 Ramon Santamaria (@raysan5)
 *
 ********************************************************************************************/
 
@@ -18,15 +21,23 @@
     #include <emscripten/emscripten.h>
 #endif
 
+// NOTE: Gamepad name ID depends on drivers and OS
+#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
+
 //----------------------------------------------------------------------------------
 // Global Variables Definition
 //----------------------------------------------------------------------------------
 int screenWidth = 800;
 int screenHeight = 450;
 
-Vector2 ballPosition;
-Vector2 gamepadMovement = { 0.0f, 0.0f };
-
+Texture2D texPs3Pad;
+Texture2D texXboxPad;
 
 //----------------------------------------------------------------------------------
 // Module Functions Declaration
@@ -41,8 +52,9 @@ int main()
     // Initialization
     //--------------------------------------------------------------------------------------
     InitWindow(screenWidth, screenHeight, "raylib [core] example - gamepad input");
-    
-    ballPosition = (Vector2){ (float)screenWidth/2, (float)screenHeight/2 };
+
+    texPs3Pad = LoadTexture("resources/ps3.png");
+    texXboxPad = LoadTexture("resources/xbox.png");
     
 #if defined(PLATFORM_WEB)
     emscripten_set_main_loop(UpdateDrawFrame, 0, 1);
@@ -59,6 +71,9 @@ int main()
 
     // De-Initialization
     //--------------------------------------------------------------------------------------
+    UnloadTexture(texPs3Pad);
+    UnloadTexture(texXboxPad);
+    
     CloseWindow();        // Close window and OpenGL context
     //--------------------------------------------------------------------------------------
 
@@ -72,20 +87,7 @@ void UpdateDrawFrame(void)
 {
     // Update
     //----------------------------------------------------------------------------------
-    if (IsGamepadAvailable(GAMEPAD_PLAYER1))
-    {
-        gamepadMovement.x = GetGamepadAxisMovement(GAMEPAD_PLAYER1, GAMEPAD_XBOX_AXIS_LEFT_X);
-        gamepadMovement.y = GetGamepadAxisMovement(GAMEPAD_PLAYER1, GAMEPAD_XBOX_AXIS_LEFT_Y);
-
-        ballPosition.x += gamepadMovement.x;
-        ballPosition.y -= gamepadMovement.y;
-
-        if (IsGamepadButtonPressed(GAMEPAD_PLAYER1, GAMEPAD_BUTTON_A))
-        {
-            ballPosition.x = (float)screenWidth/2;
-            ballPosition.y = (float)screenHeight/2;
-        }
-    }
+    // ...
     //----------------------------------------------------------------------------------
 
     // Draw
@@ -93,10 +95,127 @@ void UpdateDrawFrame(void)
     BeginDrawing();
 
         ClearBackground(RAYWHITE);
-
-        DrawText("move the ball with gamepad", 10, 10, 20, DARKGRAY);
-
-        DrawCircleV(ballPosition, 50, MAROON);
+        
+        if (IsGamepadAvailable(GAMEPAD_PLAYER1))
+        {
+            DrawText(FormatText("GP1: %s", GetGamepadName(GAMEPAD_PLAYER1)), 10, 10, 10, BLACK);
+
+            if (IsGamepadName(GAMEPAD_PLAYER1, XBOX360_NAME_ID))
+            {
+                DrawTexture(texXboxPad, 0, 0, DARKGRAY);
+                
+                // Draw buttons: xbox home
+                if (IsGamepadButtonDown(GAMEPAD_PLAYER1, GAMEPAD_XBOX_BUTTON_HOME)) DrawCircle(394, 89, 19, RED);
+
+                // Draw buttons: basic
+                if (IsGamepadButtonDown(GAMEPAD_PLAYER1, GAMEPAD_XBOX_BUTTON_START)) DrawCircle(436, 150, 9, RED);
+                if (IsGamepadButtonDown(GAMEPAD_PLAYER1, GAMEPAD_XBOX_BUTTON_SELECT)) DrawCircle(352, 150, 9, RED);
+                if (IsGamepadButtonDown(GAMEPAD_PLAYER1, GAMEPAD_XBOX_BUTTON_X)) DrawCircle(501, 151, 15, BLUE);
+                if (IsGamepadButtonDown(GAMEPAD_PLAYER1, GAMEPAD_XBOX_BUTTON_A)) DrawCircle(536, 187, 15, LIME);
+                if (IsGamepadButtonDown(GAMEPAD_PLAYER1, GAMEPAD_XBOX_BUTTON_B)) DrawCircle(572, 151, 15, MAROON);
+                if (IsGamepadButtonDown(GAMEPAD_PLAYER1, GAMEPAD_XBOX_BUTTON_Y)) DrawCircle(536, 115, 15, GOLD);
+                
+                // Draw buttons: d-pad
+                DrawRectangle(317, 202, 19, 71, BLACK);
+                DrawRectangle(293, 228, 69, 19, BLACK);
+                if (IsGamepadButtonDown(GAMEPAD_PLAYER1, GAMEPAD_XBOX_BUTTON_UP)) DrawRectangle(317, 202, 19, 26, RED);
+                if (IsGamepadButtonDown(GAMEPAD_PLAYER1, GAMEPAD_XBOX_BUTTON_DOWN)) DrawRectangle(317, 202 + 45, 19, 26, RED);
+                if (IsGamepadButtonDown(GAMEPAD_PLAYER1, GAMEPAD_XBOX_BUTTON_LEFT)) DrawRectangle(292, 228, 25, 19, RED);
+                if (IsGamepadButtonDown(GAMEPAD_PLAYER1, GAMEPAD_XBOX_BUTTON_RIGHT)) DrawRectangle(292 + 44, 228, 26, 19, RED);
+                
+                // Draw buttons: left-right back
+                if (IsGamepadButtonDown(GAMEPAD_PLAYER1, GAMEPAD_XBOX_BUTTON_LB)) DrawCircle(259, 61, 20, RED);
+                if (IsGamepadButtonDown(GAMEPAD_PLAYER1, GAMEPAD_XBOX_BUTTON_RB)) DrawCircle(536, 61, 20, RED);
+
+                // Draw axis: left joystick
+                DrawCircle(259, 152, 39, BLACK);
+                DrawCircle(259, 152, 34, LIGHTGRAY);
+                DrawCircle(259 + (GetGamepadAxisMovement(GAMEPAD_PLAYER1, GAMEPAD_XBOX_AXIS_LEFT_X)*20), 
+                           152 - (GetGamepadAxisMovement(GAMEPAD_PLAYER1, GAMEPAD_XBOX_AXIS_LEFT_Y)*20), 25, BLACK);
+                
+                // Draw axis: right joystick
+                DrawCircle(461, 237, 38, BLACK);
+                DrawCircle(461, 237, 33, LIGHTGRAY);
+                DrawCircle(461 + (GetGamepadAxisMovement(GAMEPAD_PLAYER1, GAMEPAD_XBOX_AXIS_RIGHT_X)*20), 
+                           237 - (GetGamepadAxisMovement(GAMEPAD_PLAYER1, GAMEPAD_XBOX_AXIS_RIGHT_Y)*20), 25, BLACK);
+
+                // Draw axis: left-right triggers
+                DrawRectangle(170, 30, 15, 70, GRAY);
+                DrawRectangle(604, 30, 15, 70, GRAY);              
+                DrawRectangle(170, 30, 15, (((1.0f + GetGamepadAxisMovement(GAMEPAD_PLAYER1, GAMEPAD_XBOX_AXIS_LT))/2.0f)*70), RED);
+                DrawRectangle(604, 30, 15, (((1.0f + GetGamepadAxisMovement(GAMEPAD_PLAYER1, GAMEPAD_XBOX_AXIS_RT))/2.0f)*70), RED);
+                
+                //DrawText(FormatText("Xbox axis LT: %02.02f", GetGamepadAxisMovement(GAMEPAD_PLAYER1, GAMEPAD_XBOX_AXIS_LT)), 10, 40, 10, BLACK);
+                //DrawText(FormatText("Xbox axis RT: %02.02f", GetGamepadAxisMovement(GAMEPAD_PLAYER1, GAMEPAD_XBOX_AXIS_RT)), 10, 60, 10, BLACK);
+            }
+            else if (IsGamepadName(GAMEPAD_PLAYER1, PS3_NAME_ID))
+            {
+                DrawTexture(texPs3Pad, 0, 0, DARKGRAY);
+
+                // Draw buttons: ps
+                if (IsGamepadButtonDown(GAMEPAD_PLAYER1, GAMEPAD_PS3_BUTTON_PS)) DrawCircle(396, 222, 13, RED);
+                
+                // Draw buttons: basic
+                if (IsGamepadButtonDown(GAMEPAD_PLAYER1, GAMEPAD_PS3_BUTTON_SELECT)) DrawRectangle(328, 170, 32, 13, RED);
+                if (IsGamepadButtonDown(GAMEPAD_PLAYER1, GAMEPAD_PS3_BUTTON_START)) DrawTriangle((Vector2){ 436, 168 }, (Vector2){ 436, 185 }, (Vector2){ 464, 177 }, RED);
+                if (IsGamepadButtonDown(GAMEPAD_PLAYER1, GAMEPAD_PS3_BUTTON_TRIANGLE)) DrawCircle(557, 144, 13, LIME);
+                if (IsGamepadButtonDown(GAMEPAD_PLAYER1, GAMEPAD_PS3_BUTTON_CIRCLE)) DrawCircle(586, 173, 13, RED);
+                if (IsGamepadButtonDown(GAMEPAD_PLAYER1, GAMEPAD_PS3_BUTTON_CROSS)) DrawCircle(557, 203, 13, VIOLET);
+                if (IsGamepadButtonDown(GAMEPAD_PLAYER1, GAMEPAD_PS3_BUTTON_SQUARE)) DrawCircle(527, 173, 13, PINK);
+
+                // Draw buttons: d-pad
+                DrawRectangle(225, 132, 24, 84, BLACK);
+                DrawRectangle(195, 161, 84, 25, BLACK);
+                if (IsGamepadButtonDown(GAMEPAD_PLAYER1, GAMEPAD_PS3_BUTTON_UP)) DrawRectangle(225, 132, 24, 29, RED);
+                if (IsGamepadButtonDown(GAMEPAD_PLAYER1, GAMEPAD_PS3_BUTTON_DOWN)) DrawRectangle(225, 132 + 54, 24, 30, RED);
+                if (IsGamepadButtonDown(GAMEPAD_PLAYER1, GAMEPAD_PS3_BUTTON_LEFT)) DrawRectangle(195, 161, 30, 25, RED);
+                if (IsGamepadButtonDown(GAMEPAD_PLAYER1, GAMEPAD_PS3_BUTTON_RIGHT)) DrawRectangle(195 + 54, 161, 30, 25, RED);
+                
+                // Draw buttons: left-right back buttons
+                if (IsGamepadButtonDown(GAMEPAD_PLAYER1, GAMEPAD_PS3_BUTTON_L1)) DrawCircle(239, 82, 20, RED);
+                if (IsGamepadButtonDown(GAMEPAD_PLAYER1, GAMEPAD_PS3_BUTTON_R1)) DrawCircle(557, 82, 20, RED);
+
+                // Draw axis: left joystick
+                DrawCircle(319, 255, 35, BLACK);
+                DrawCircle(319, 255, 31, LIGHTGRAY);
+                DrawCircle(319 + (GetGamepadAxisMovement(GAMEPAD_PLAYER1, GAMEPAD_PS3_AXIS_LEFT_X)*20), 
+                           255 + (GetGamepadAxisMovement(GAMEPAD_PLAYER1, GAMEPAD_PS3_AXIS_LEFT_Y)*20), 25, BLACK);
+                
+                // Draw axis: right joystick
+                DrawCircle(475, 255, 35, BLACK);
+                DrawCircle(475, 255, 31, LIGHTGRAY);
+                DrawCircle(475 + (GetGamepadAxisMovement(GAMEPAD_PLAYER1, GAMEPAD_PS3_AXIS_RIGHT_X)*20), 
+                           255 + (GetGamepadAxisMovement(GAMEPAD_PLAYER1, GAMEPAD_PS3_AXIS_RIGHT_Y)*20), 25, BLACK);
+
+                // Draw axis: left-right triggers
+                DrawRectangle(169, 48, 15, 70, GRAY);
+                DrawRectangle(611, 48, 15, 70, GRAY);              
+                DrawRectangle(169, 48, 15, (((1.0f - GetGamepadAxisMovement(GAMEPAD_PLAYER1, GAMEPAD_PS3_AXIS_L2))/2.0f)*70), RED);
+                DrawRectangle(611, 48, 15, (((1.0f - GetGamepadAxisMovement(GAMEPAD_PLAYER1, GAMEPAD_PS3_AXIS_R2))/2.0f)*70), RED);
+            }
+            else
+            {
+                DrawText("- GENERIC GAMEPAD -", 280, 180, 20, GRAY);
+                
+                // TODO: Draw generic gamepad
+            }
+            
+            DrawText(FormatText("DETECTED AXIS [%i]:", GetGamepadAxisCount(GAMEPAD_PLAYER1)), 10, 50, 10, MAROON); 
+            
+            for (int i = 0; i < GetGamepadAxisCount(GAMEPAD_PLAYER1); i++)
+            {
+                DrawText(FormatText("AXIS %i: %.02f", i, GetGamepadAxisMovement(GAMEPAD_PLAYER1, i)), 20, 70 + 20*i, 10, DARKGRAY);
+            }
+            
+            if (GetGamepadButtonPressed() != -1) DrawText(FormatText("DETECTED BUTTON: %i", GetGamepadButtonPressed()), 10, 430, 10, RED);
+            else DrawText("DETECTED BUTTON: NONE", 10, 430, 10, GRAY);
+        }
+        else
+        {
+            DrawText("GP1: NOT DETECTED", 10, 10, 10, GRAY);
+            
+            DrawTexture(texXboxPad, 0, 0, LIGHTGRAY);
+        }
 
     EndDrawing();
     //----------------------------------------------------------------------------------

BIN
docs/examples/web/core_input_gamepad.data


Разлика између датотеке није приказан због своје велике величине
+ 1781 - 0
docs/examples/web/core_input_gamepad.js


+ 19 - 16
docs/examples/web/core_oculus_rift.c → docs/examples/web/core_vr_simulator.c

@@ -1,11 +1,8 @@
 /*******************************************************************************************
 *
-*   raylib [core] example - Oculus Rift CV1
+*   raylib [core] example - VR Simulator (Oculus Rift CV1 parameters)
 *
-*   Compile example using:
-*   gcc -o $(NAME_PART).exe $(FILE_NAME) -L. -L..\src\external\OculusSDK\LibOVR -lLibOVRRT32_1 -lraylib -lglfw3 -lopengl32 -lgdi32 -std=c99
-*
-*   This example has been created using raylib 1.5 (www.raylib.com)
+*   This example has been created using raylib 1.7 (www.raylib.com)
 *   raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
 *
 *   Copyright (c) 2016 Ramon Santamaria (@raysan5)
@@ -45,14 +42,16 @@ int main()
     InitWindow(screenWidth, screenHeight, "raylib [core] example - oculus rift");
     
     // NOTE: If device is not available, it fallbacks to default device (simulator)
-    InitVrDevice(HMD_OCULUS_RIFT_CV1);                  // Init VR device (Oculus Rift CV1)
+    InitVrSimulator(HMD_OCULUS_RIFT_CV1);               // Init VR simulator (Oculus Rift CV1 parameters)
     
     // Define the camera to look into our 3d world
     camera.position = (Vector3){ 5.0f, 5.0f, 5.0f };    // Camera position
     camera.target = (Vector3){ 0.0f, 0.0f, 0.0f };      // Camera looking at point
     camera.up = (Vector3){ 0.0f, 1.0f, 0.0f };          // Camera up vector (rotation towards target)
     camera.fovy = 60.0f;                                // Camera field-of-view Y
-
+    
+    SetCameraMode(camera, CAMERA_FIRST_PERSON);         // Set first person camera mode
+    
 #if defined(PLATFORM_WEB)
     emscripten_set_main_loop(UpdateDrawFrame, 0, 1);
 #else
@@ -68,7 +67,7 @@ int main()
 
     // De-Initialization
     //--------------------------------------------------------------------------------------
-    CloseVrDevice();        // Close VR device
+    CloseVrSimulator();     // Close VR simulator
     
     CloseWindow();          // Close window and OpenGL context
     //--------------------------------------------------------------------------------------
@@ -83,9 +82,9 @@ void UpdateDrawFrame(void)
 {
     // Update
     //----------------------------------------------------------------------------------
-    UpdateVrTracking();
-    
-    if (IsKeyPressed(KEY_SPACE)) ToggleVrMode();
+    UpdateCamera(&camera);          // Update camera (simulator mode)
+
+    if (IsKeyPressed(KEY_SPACE)) ToggleVrMode();    // Toggle VR mode
     //----------------------------------------------------------------------------------
 
     // Draw
@@ -94,14 +93,18 @@ void UpdateDrawFrame(void)
 
         ClearBackground(RAYWHITE);
 
-        Begin3dMode(camera);
+        BeginVrDrawing();
+
+            Begin3dMode(camera);
 
-            DrawCube(cubePosition, 2.0f, 2.0f, 2.0f, RED);
-            DrawCubeWires(cubePosition, 2.0f, 2.0f, 2.0f, MAROON);
+                DrawCube(cubePosition, 2.0f, 2.0f, 2.0f, RED);
+                DrawCubeWires(cubePosition, 2.0f, 2.0f, 2.0f, MAROON);
 
-            DrawGrid(10, 1.0f);
+                DrawGrid(40, 1.0f);
 
-        End3dMode();
+            End3dMode();
+        
+        EndVrDrawing();
 
         DrawFPS(10, 10);
 

Разлика између датотеке није приказан због своје велике величине
+ 1611 - 0
docs/examples/web/core_vr_simulator.js


+ 4 - 7
docs/examples/web/makefile

@@ -227,6 +227,7 @@ EXAMPLES = \
     core_3d_camera_first_person \
     core_2d_camera \
     core_world_screen \
+    core_vr_simulator \
     shapes_logo_raylib \
     shapes_basic_shapes \
     shapes_colors_palette \
@@ -291,11 +292,7 @@ core_mouse_wheel: core_mouse_wheel.c
 
 # compile [core] example - gamepad input
 core_input_gamepad: core_input_gamepad.c
-ifeq ($(PLATFORM), $(filter $(PLATFORM),PLATFORM_DESKTOP PLATFORM_RPI))
-	$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -D$(PLATFORM) $(WINFLAGS)
-else
-	@echo core_input_gamepad: Example not supported on PLATFORM_ANDROID or PLATFORM_WEB
-endif
+	$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -D$(PLATFORM) $(WINFLAGS) --preload-file resources/ps3.png --preload-file resources/xbox.png
 
 # compile [core] example - generate random values
 core_random_values: core_random_values.c
@@ -350,8 +347,8 @@ core_world_screen: core_world_screen.c
 	$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -D$(PLATFORM) $(WINFLAGS)
 
 # compile [core] example - oculus rift
-#core_oculus_rift: core_oculus_rift.c
-#	$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -D$(PLATFORM) $(WINFLAGS)
+core_vr_simulator: core_vr_simulator.c
+	$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -D$(PLATFORM) $(WINFLAGS)
 
 # compile [shapes] example - raylib logo (with basic shapes)
 shapes_logo_raylib: shapes_logo_raylib.c

Разлика између датотеке није приказан због своје велике величине
+ 2 - 2
docs/examples/web/text_sprite_fonts.js


Разлика између датотеке није приказан због своје велике величине
+ 2 - 2
docs/examples/web/textures_image_loading.js


Разлика између датотеке није приказан због своје велике величине
+ 2 - 2
docs/examples/web/textures_particles_trail_blending.js


Разлика између датотеке није приказан због своје велике величине
+ 2 - 2
docs/examples/web/textures_raw_data.js


Разлика између датотеке није приказан због своје велике величине
+ 2 - 2
docs/examples/web/textures_to_image.js


+ 2 - 2
examples/core/core_input_gamepad.c

@@ -4,8 +4,8 @@
 *
 *   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 
+*                - Xbox 360 Controller (Xbox 360, Xbox One)
+*                - PLAYSTATION(R)3 Controller 
 *         Check raylib.h for buttons configuration
 *
 *   This example has been created using raylib 1.6 (www.raylib.com)

+ 2 - 2
examples/core/core_vr_simulator.c

@@ -5,7 +5,7 @@
 *   This example has been created using raylib 1.7 (www.raylib.com)
 *   raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
 *
-*   Copyright (c) 2016 Ramon Santamaria (@raysan5)
+*   Copyright (c) 2017 Ramon Santamaria (@raysan5)
 *
 ********************************************************************************************/
 
@@ -75,7 +75,7 @@ int main()
 
     // De-Initialization
     //--------------------------------------------------------------------------------------
-    CloseVrSimulator();
+    CloseVrSimulator();     // Close VR simulator
     
     CloseWindow();          // Close window and OpenGL context
     //--------------------------------------------------------------------------------------

Неке датотеке нису приказане због велике количине промена