From 59652c75b43d0437217c0000b03428545905801e Mon Sep 17 00:00:00 2001 From: Ray Date: Mon, 20 Mar 2017 20:34:44 +0100 Subject: Review some comments --- src/camera.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/camera.h') diff --git a/src/camera.h b/src/camera.h index 87ba1942..e1b00ac2 100644 --- a/src/camera.h +++ b/src/camera.h @@ -1,6 +1,6 @@ /******************************************************************************************* * -* raylib Camera System - Camera Modes Setup and Control Functions +* raylib.camera - Camera system with multiple modes support * * NOTE: Memory footprint of this library is aproximately 52 bytes (global variables) * @@ -22,7 +22,7 @@ * * LICENSE: zlib/libpng * -* Copyright (c) 2015-2016 Ramon Santamaria (@raysan5) +* Copyright (c) 2015-2017 Ramon Santamaria (@raysan5) * * This software is provided "as-is", without any express or implied warranty. In no event * will the authors be held liable for any damages arising from the use of this software. -- cgit v1.2.3 From fd1fe3ac14adbd4bdc8ed409a65aad9d7d7133ca Mon Sep 17 00:00:00 2001 From: Ray Date: Mon, 8 May 2017 21:03:48 +0200 Subject: Lock cursor on first person camera --- src/camera.h | 52 +++++++++++++++------------------------------------- src/core.c | 21 ++++++++++++++++----- 2 files changed, 31 insertions(+), 42 deletions(-) (limited to 'src/camera.h') diff --git a/src/camera.h b/src/camera.h index e1b00ac2..e4aa8478 100644 --- a/src/camera.h +++ b/src/camera.h @@ -203,15 +203,14 @@ static int cameraMode = CAMERA_CUSTOM; // Current camera mode #if defined(CAMERA_STANDALONE) // NOTE: Camera controls depend on some raylib input functions // TODO: Set your own input functions (used in UpdateCamera()) -static Vector2 GetMousePosition() { return (Vector2){ 0.0f, 0.0f }; } -static void SetMousePosition(Vector2 pos) {} +static void EnableCursor() {} // Unlock cursor +static void DisableCursor() {} // Lock cursor + +static int IsKeyDown(int key) { return 0; } + static int IsMouseButtonDown(int button) { return 0;} static int GetMouseWheelMove() { return 0; } -static int GetScreenWidth() { return 1280; } -static int GetScreenHeight() { return 720; } -static void ShowCursor() {} -static void HideCursor() {} -static int IsKeyDown(int key) { return 0; } +static Vector2 GetMousePosition() { return (Vector2){ 0.0f, 0.0f }; } #endif //---------------------------------------------------------------------------------- @@ -246,14 +245,19 @@ void SetCameraMode(Camera camera, int mode) //cameraAngle.y = -60.0f*DEG2RAD; // Camera angle in plane XY (0 aligned with X, move positive CW) playerEyesPosition = camera.position.y; + + // Lock cursor for first person and third person cameras + if ((mode == CAMERA_FIRST_PERSON) || + (mode == CAMERA_THIRD_PERSON)) DisableCursor(); + else EnableCursor(); cameraMode = mode; } // Update camera depending on selected mode // NOTE: Camera controls depend on some raylib functions: +// System: EnableCursor(), DisableCursor() // Mouse: GetMousePosition(), SetMousePosition(), IsMouseButtonDown(), GetMouseWheelMove() -// System: GetScreenWidth(), GetScreenHeight(), ShowCursor(), HideCursor() // Keys: IsKeyDown() // TODO: Port to quaternion-based camera void UpdateCamera(Camera *camera) @@ -284,36 +288,10 @@ void UpdateCamera(Camera *camera) if (cameraMode != CAMERA_CUSTOM) { - // Get screen size - int screenWidth = GetScreenWidth(); - int screenHeight = GetScreenHeight(); - - if ((cameraMode == CAMERA_FIRST_PERSON) || - (cameraMode == CAMERA_THIRD_PERSON)) - { - HideCursor(); - - if (mousePosition.x < (float)screenHeight/3.0f) SetMousePosition((Vector2){ screenWidth - screenHeight/3, mousePosition.y }); - else if (mousePosition.y < (float)screenHeight/3.0f) SetMousePosition((Vector2){ mousePosition.x, screenHeight - screenHeight/3 }); - else if (mousePosition.x > (screenWidth - (float)screenHeight/3.0f)) SetMousePosition((Vector2){ screenHeight/3, mousePosition.y }); - else if (mousePosition.y > (screenHeight - (float)screenHeight/3.0f)) SetMousePosition((Vector2){ mousePosition.x, screenHeight/3 }); - else - { - mousePositionDelta.x = mousePosition.x - previousMousePosition.x; - mousePositionDelta.y = mousePosition.y - previousMousePosition.y; - } - } - else // CAMERA_FREE, CAMERA_ORBITAL - { - ShowCursor(); - - mousePositionDelta.x = mousePosition.x - previousMousePosition.x; - mousePositionDelta.y = mousePosition.y - previousMousePosition.y; - } + mousePositionDelta.x = mousePosition.x - previousMousePosition.x; + mousePositionDelta.y = mousePosition.y - previousMousePosition.y; - // NOTE: We GetMousePosition() again because it can be modified by a previous SetMousePosition() call - // If using directly mousePosition variable we have problems on CAMERA_FIRST_PERSON and CAMERA_THIRD_PERSON - previousMousePosition = GetMousePosition(); + previousMousePosition = mousePosition; } // Support for multiple automatic camera modes diff --git a/src/core.c b/src/core.c index 1448743f..508049c9 100644 --- a/src/core.c +++ b/src/core.c @@ -286,6 +286,10 @@ static int gamepadAxisCount = 0; // Register number of available game static Vector2 mousePosition; // Mouse position on screen +#if defined(PLATFORM_WEB) +static bool toggleCursorLock = false; // Ask for cursor pointer lock on next click +#endif + #if defined(SUPPORT_GESTURES_SYSTEM) static Vector2 touchPosition[MAX_TOUCH_POINTS]; // Touch position on screen #endif @@ -708,6 +712,9 @@ void EnableCursor() { #if defined(PLATFORM_DESKTOP) glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_NORMAL); +#endif +#if defined(PLATFORM_WEB) + toggleCursorLock = true; #endif cursorHidden = false; } @@ -717,6 +724,9 @@ void DisableCursor() { #if defined(PLATFORM_DESKTOP) glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_DISABLED); +#endif +#if defined(PLATFORM_WEB) + toggleCursorLock = true; #endif cursorHidden = true; } @@ -1821,12 +1831,13 @@ static void InitGraphicsDevice(int width, int height) const EGLint framebufferAttribs[] = { - EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, // Type of context support -> Required on RPI? - //EGL_SURFACE_TYPE, EGL_WINDOW_BIT, // Don't use it on Android! + EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, // Type of context support -> Required on RPI? + //EGL_SURFACE_TYPE, EGL_WINDOW_BIT, // Don't use it on Android! EGL_RED_SIZE, 8, // RED color bit depth (alternative: 5) EGL_GREEN_SIZE, 8, // GREEN color bit depth (alternative: 6) EGL_BLUE_SIZE, 8, // BLUE color bit depth (alternative: 5) //EGL_ALPHA_SIZE, 8, // ALPHA bit depth + //EGL_TRANSPARENT_TYPE, EGL_TRANSPARENT_RGB, // Request transparent framebuffer EGL_DEPTH_SIZE, 16, // Depth buffer size (Required to use Depth testing!) //EGL_STENCIL_SIZE, 8, // Stencil buffer size EGL_SAMPLE_BUFFERS, sampleBuffer, // Activate MSAA @@ -2744,9 +2755,8 @@ static EM_BOOL EmscriptenKeyboardCallback(int eventType, const EmscriptenKeyboar // Register mouse input events static EM_BOOL EmscriptenMouseCallback(int eventType, const EmscriptenMouseEvent *mouseEvent, void *userData) { - /* // Lock mouse pointer when click on screen - if (eventType == EMSCRIPTEN_EVENT_CLICK) + if ((eventType == EMSCRIPTEN_EVENT_CLICK) && toggleCursorLock) { EmscriptenPointerlockChangeEvent plce; emscripten_get_pointerlock_status(&plce); @@ -2758,8 +2768,9 @@ static EM_BOOL EmscriptenMouseCallback(int eventType, const EmscriptenMouseEvent emscripten_get_pointerlock_status(&plce); //if (plce.isActive) TraceLog(WARNING, "Pointer lock exit did not work!"); } + + toggleCursorLock = false; } - */ return 0; } -- cgit v1.2.3 From f05d6dfc3c778f55564680405ad8365b87d4eb39 Mon Sep 17 00:00:00 2001 From: Ray Date: Mon, 8 May 2017 21:16:46 +0200 Subject: Some comment tweaks Still some work left on camera... --- src/camera.h | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'src/camera.h') diff --git a/src/camera.h b/src/camera.h index e4aa8478..8067e7bf 100644 --- a/src/camera.h +++ b/src/camera.h @@ -181,7 +181,14 @@ void SetCameraMoveControls(int frontKey, int backKey, // Types and Structures Definition //---------------------------------------------------------------------------------- // Camera move modes (first person and third person cameras) -typedef enum { MOVE_FRONT = 0, MOVE_BACK, MOVE_RIGHT, MOVE_LEFT, MOVE_UP, MOVE_DOWN } CameraMove; +typedef enum { + MOVE_FRONT = 0, + MOVE_BACK, + MOVE_RIGHT, + MOVE_LEFT, + MOVE_UP, + MOVE_DOWN +} CameraMove; //---------------------------------------------------------------------------------- // Global Variables Definition @@ -241,7 +248,7 @@ void SetCameraMode(Camera camera, int mode) cameraAngle.y = -asinf(fabsf(dy)/distance.y); // Camera angle in plane XY (0 aligned with X, move positive CW) // NOTE: Just testing what cameraAngle means - //cameraAngle.x = 0.0f*DEG2RAD; // Camera angle in plane XZ (0 aligned with Z, move positive CCW) + //cameraAngle.x = 0.0f*DEG2RAD; // Camera angle in plane XZ (0 aligned with Z, move positive CCW) //cameraAngle.y = -60.0f*DEG2RAD; // Camera angle in plane XY (0 aligned with X, move positive CW) playerEyesPosition = camera.position.y; @@ -257,7 +264,7 @@ void SetCameraMode(Camera camera, int mode) // Update camera depending on selected mode // NOTE: Camera controls depend on some raylib functions: // System: EnableCursor(), DisableCursor() -// Mouse: GetMousePosition(), SetMousePosition(), IsMouseButtonDown(), GetMouseWheelMove() +// Mouse: IsMouseButtonDown(), GetMousePosition(), GetMouseWheelMove() // Keys: IsKeyDown() // TODO: Port to quaternion-based camera void UpdateCamera(Camera *camera) -- cgit v1.2.3