Get pointer-locking working with SDL-device and emscripten (fullscreen only so far).

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/branches/ogl-es@5455 dfc29bdd-3216-0410-991c-e03cc46cb475
master
cutealien 2017-04-25 13:54:19 +00:00
parent a12369f2ef
commit 81caa16886
2 changed files with 27 additions and 1 deletions

View File

@ -64,7 +64,7 @@ namespace irr
CIrrDeviceSDL::CIrrDeviceSDL(const SIrrlichtCreationParameters& param)
: CIrrDeviceStub(param),
Screen((SDL_Surface*)param.WindowId), SDL_Flags(SDL_ANYFORMAT),
MouseX(0), MouseY(0), MouseButtonStates(0),
MouseX(0), MouseY(0), MouseXRel(0), MouseYRel(0), MouseButtonStates(0),
Width(param.WindowSize.Width), Height(param.WindowSize.Height),
Resizable(false), WindowHasFocus(false), WindowMinimized(false)
{
@ -342,6 +342,8 @@ bool CIrrDeviceSDL::run()
irrevent.MouseInput.Event = irr::EMIE_MOUSE_MOVED;
MouseX = irrevent.MouseInput.X = SDL_event.motion.x;
MouseY = irrevent.MouseInput.Y = SDL_event.motion.y;
MouseXRel = SDL_event.motion.xrel;
MouseYRel = SDL_event.motion.yrel;
irrevent.MouseInput.ButtonStates = MouseButtonStates;
postEventFromUser(irrevent);

View File

@ -16,6 +16,10 @@
#include "IImagePresenter.h"
#include "ICursorControl.h"
#ifdef _IRR_EMSCRIPTEN_PLATFORM_
#include <emscripten/html5.h>
#endif
#include <SDL/SDL.h>
#include <SDL/SDL_syswm.h>
@ -168,6 +172,24 @@ namespace irr
void updateCursorPos()
{
#ifdef _IRR_EMSCRIPTEN_PLATFORM_
EmscriptenPointerlockChangeEvent pointerlockStatus; // let's hope that test is not expensive ...
if ( emscripten_get_pointerlock_status(&pointerlockStatus) == EMSCRIPTEN_RESULT_SUCCESS )
{
if ( pointerlockStatus.isActive )
{
CursorPos.X += Device->MouseXRel;
CursorPos.Y += Device->MouseYRel;
Device->MouseXRel = 0;
Device->MouseYRel = 0;
}
else
{
CursorPos.X = Device->MouseX;
CursorPos.Y = Device->MouseY;
}
}
#else
CursorPos.X = Device->MouseX;
CursorPos.Y = Device->MouseY;
@ -179,6 +201,7 @@ namespace irr
CursorPos.Y = 0;
if (CursorPos.Y > (s32)Device->Height)
CursorPos.Y = Device->Height;
#endif
}
CIrrDeviceSDL* Device;
@ -202,6 +225,7 @@ namespace irr
#endif
s32 MouseX, MouseY;
s32 MouseXRel, MouseYRel;
u32 MouseButtonStates;
u32 Width, Height;