implement linux mouselook

This commit is contained in:
Adam Jensen 2022-11-12 21:51:14 +00:00
parent 7721e5b9b0
commit f0f14eb291
5 changed files with 39 additions and 3 deletions

View File

@ -5,8 +5,6 @@
# How to build (Linux 32-bit binary on Linux)
This build uses DirectX 11 through the [dxvk-native](https://github.com/Joshua-Ashton/dxvk-native) project. CMake will automatically download and build the sources.
Note: Looking around using the mouse is not supported right now.
git clone https://github.com/rrika/cdcEngineDXHR.git
cd cdcEngineDXHR
mkdir native_build

View File

@ -11,6 +11,8 @@
using namespace cdc;
HWND hwnd1;
HWND hwnd2;
HWND hwnd3;
bool createWindow() {
SDL_Window* window = SDL_CreateWindow(
@ -23,7 +25,9 @@ bool createWindow() {
return false;
}
hwnd1 = window;
SDL_CaptureMouse(SDL_TRUE);
hwnd1 = hwnd2 = hwnd3 = window;
return true;
}

View File

@ -7,6 +7,10 @@
#include <hidusage.h>
#endif
#ifdef __linux__
#include <SDL2/SDL.h>
#endif
extern HWND hwnd2;
float g_mouseXSensitivity2 = 0.00135f;
@ -47,6 +51,19 @@ void PCMouseKeyboard::processWndProc(UINT uMsg, WPARAM wParam, LPARAM lParam) {
}
#endif
#ifdef __linux__
void PCMouseKeyboard::processSDLEvent(SDL_Event *event) {
switch (event->type) {
case SDL_MOUSEMOTION: {
deltaX += event->motion.xrel;
deltaY += event->motion.yrel;
}
default:
break;
}
}
#endif
void PCMouseKeyboard::setCursorPos(float x, float y) {
#ifdef _WIN32
if (cursorGrab) {
@ -74,6 +91,10 @@ void PCMouseKeyboard::setupClip() {
ClientToScreen(hwnd2, reinterpret_cast<POINT*>(&m_rect.right));
ClipCursor(&m_rect);
}
#elif defined(__linux__)
SDL_SetWindowGrab((SDL_Window*) hwnd2, (SDL_bool)cursorGrab);
SDL_SetRelativeMouseMode((SDL_bool)cursorGrab);
#endif
}

View File

@ -2,6 +2,10 @@
#include <windows.h>
#include "InputProducer.h"
#ifdef __linux__
union SDL_Event;
#endif
namespace cdc {
struct Keybind {
@ -13,6 +17,9 @@ public:
PCMouseKeyboard();
#ifdef _WIN32
void processWndProc(UINT uMsg, WPARAM wParam, LPARAM lParam);
#endif
#ifdef __linux__
void processSDLEvent(SDL_Event *event);
#endif
void setCursorPos(float x, float y);
void setupClip();

View File

@ -405,7 +405,13 @@ int spinnyCube(HWND window,
#if ENABLE_IMGUI
ImGui_ImplSDL2_ProcessEvent(&event);
#endif
mouseKeyboard->processSDLEvent(&event);
switch (event.type) {
case SDL_WINDOWEVENT:
if (event.window.event == SDL_WINDOWEVENT_SIZE_CHANGED)
renderDevice->handleResize(event.window.data1, event.window.data2);
break;
case SDL_QUIT:
goto end;
default: