Skip to main content

Relative Mouse Pointer Issue SDL2

Until now UE4 does not use the "real" relative mouse movement which SDL2 provides already in the version 2.0.4. That means SDL2 is calculating internal the rel. mouse movement and provides it via the SDL_MOUSEMOTION  event using xrel and yrel. Here some code fragments:


SDL_MouseMotionEvent motionEvent = Event.motion;
...
if(bUsingHighPrecisionMouseInput)
{
    MessageHandler->OnRawMouseMove(motionEvent.xrel, motionEvent.yrel);
}
else
{
     MessageHandler->OnMouseMove();
}
As mentioned xrel and yrel are not using the XInput2 extension which causes to stop giving values when the cursor reaches the end of the window.

Luckily SDL2 provides with 2.0.4 the real rel mouse movement with



SDL_SetRelativeMouseMode(Enable ? SDL_TRUE : SDL_FALSE);

The relative mouse movement stuff on windows/mac and linux is done in this method:
void FLinuxApplication::SetHighPrecisionMouseMode( const bool Enable, const TSharedPtr< FGenericWindow >& InWindow ) 


{

  ...

}


In that part the relative mouse mode is switched on. Using the SDL2 method our function would now look like this:
void FLinuxApplication::SetHighPrecisionMouseMode( const bool Enable, const TSharedPtr< FGenericWindow >& InWindow )

{

     MessageHandler->OnCursorSet();

     bUsingHighPrecisionMouseInput = Enable;
    // Add this new line.

    SDL_SetRelativeMouseMode(Enable ? SDL_TRUE : SDL_FALSE);

}
Doing that the issue becomes more visible which is actually happening without it too somehow. Best and easy to see that issue is


    Create a particle asset

    Open it

    Right click in the area where you can add additional components etc.


The effect is the mouse pointer will jump around, try right click couple of times you will see definitely.


I figured out that xrel and yrel get really high values then the mouse pointer crosses window borders. That means, if you right click to open a popup menu sometimes

it jumps because it crosses the border of the popup window.

Here is a simple SDL2 application where you can see how xrel and yrel jumps to high values:
#include <SDL.h>

#include <stdio.h>


int main(int argc, char **argv)

{

   SDL_Init(SDL_INIT_EVERYTHING);

   SDL_Window* window1 = SDL_CreateWindow(“Window 1”, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 640, 480, 0);

   SDL_Window* window2 = SDL_CreateWindow(“Window 2”, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 640, 480, 0);


   while(true) {

     SDL_Event e;

     if(SDL_PollEvent(&e)) {

       if(e.type == SDL_QUIT) {

         break;

       } else if(e.type == SDL_KEYDOWN) {

         break;

       } else if(e.type == SDL_MOUSEMOTION) {

         printf("MOTION: abs=(%d, %d) rel=(%d, %d)\n", (int)e.motion.x, (int)e.motion.y, (int)e.motion.xrel, (int)e.motion.yrel);

       }

     }

   }


   SDL_DestroyWindow(window1);

   SDL_DestroyWindow(window2);

   SDL_Quit();

   return 0;

}
Here are some values of this example when you cross from one window to the other


MOTION: abs=(420, 257) rel=(-1, 0)MOTION: abs=(419, 257) rel=(-1, 0)MOTION: abs=(417, 257) rel=(-2, 0)MOTION: abs=(639, 104) rel=(222, -153)MOTION: abs=(638, 104) rel=(-1, 0)MOTION: abs=(637, 104) rel=(-1, 0)MOTION: abs=(636, 104) rel=(-1, 0)MOTION: abs=(635, 105) rel=(-1, 1)


I think you can already see which part is strange. Because at some place a right click causes to enable SetHighPrecisionMouseMode(Enable = true, ...)

the bUsingHighPrecisionMouseInput = true and in the motion event the


if(bUsingHighPrecisionMouseInput) {    MessageHandler->OnRawMouseMove(motionEvent.xrel, motionEvent.yrel); }


Gets active and causes jumps. Actually that happens all over the place. Sometimes the mouse pointer is doing some weird stuff. I think fixing this issue would make UE4Editor on Linux feel more as it feels like on windows. I couldn't see any jumps there, if feels nice and stiff. This issue prevents us from using it and causes an issue in the 3d viewport not being able to rotate,scale or move infinite. It will stop as soon as the hidden pointer stop at the border.


I hope this helps and/or you can forward this message to icculus. He knows already but I don't know if he found a solution or about the priority of this issue.

Comments

Popular posts from this blog

Using Vulkan RHI on GNU/Linux

Hi fellows This time it's about the Vulkan support of the Unreal Engine 4. It's nice to see that Epic Games decided to support Vulkan as first class citizen. Unfortunately they didn't make their Vulkan RHI GNU/Linux compatible so I had to do something about it. See here: Yaakuro

CodeLite Source Code Access and Project File Generator for Unreal Engine 4

Hi folks At the moment I am working on a CodeLite Project File Generator and Source Code Access Plugin for Unreal Engine 4. Thx to CodeLite I am able to work either on GNU/Linux, MacOSX or Windows (CodeLite supports even more development platforms but not UE4 :D). The modified version of UBT will just create the workspace and project files you need for your specific platform. Features: Creates Workspace/Projects for Platforms/Targets with their configurations. CodeLite itself is cross platform. The modified version of UBT will create your project files for GNU/Linux, Mac and Windows platforms.  Start your game project within CodeLite in the Editor target. Source Code Access within UE4Editor using the Plugin. Added Custom Build Targets for "Cooking"/"Non Cooking" and "Cooking on the fly". Means you can cook your project easy withing the CodeLite editor. Just select one of those 3 submenus Game projects will have two targets Game and Editor.