SDL_SetRelativeMouseMode Starting Position |
Alundra
|
I tried a lot and it's not possible to have the cursor start in the center of the window using : SDL_SetRelativeMouseMode( SDL_TRUE ).
I hope a fix can be there fast. |
|||||||||||
|
Naith
|
By using this function, the mouse cursor will be positioned at the center of the window at program start:
Note that I'm using two defines named WINDOW_WIDTH and WINDOW_HEIGHT so just create two defines named like those or just write the window width and window height instead of the define's. |
|||||||||||||
|
Alundra
|
Using that the cursor start at the center of the window when the program start but once the mouse is moved the cursor is directly on the top-left of the screen.
|
|||||||||||
|
Naith
|
Weird. May I see your code that's creating the window, handling mouse events and stuff?
|
|||||||||||
|
Alundra
|
Here the event code of the mouse called each beginning of the main loop :
|
|||||||||||||||
|
Naith
|
Nothing weird there. So what you want to do is position the mouse pointer in the middle of the window even though you're moving the mouse, like in a FPS game. Correct?
How do you know that the mouse pointer is moved to the upper left corner? The mouse pointer isn't visible when you're using SDL_SetRelativeMouseMode. Is your m_MousePositionX and m_MousePositionY variables telling you this information? |
|||||||||||
|
Naith
|
Okay, I just tested it in one of my programs and SDL_SetRelativeMouseMode(SDL_TRUE) does indeed move the mouse pointer to the upper left corner and there's nothing that can be done about it. I've tryed set the mouse pointer to the middle of the screen, each frame, by using SDL_WarpMouseInWindow(m_pWindow, WINDOW_WIDTH / 2, WINDOW_HEIGHT / 2) but the mouse pointer stays in the upper left corner. I guess that's just how the SetRelativeMouseMode function works.
|
|||||||||||
|
Alundra
|
I'm working on a RTS but DOTA style has the same problem.
I render the cursor using a sprite 32x32 and I want the mouse start at the center and can't be outside the window. All works good except the start on the center of the window, the only way is to warp the cursor in the center each frame and compute the mouse position ? |
|||||||||||
|
Naith
|
What I'm doing when I want to center the mouse pointer in the window and also trap it inside the window is by first using this function:
Then I use this function to trap the mouse pointer inside the window:
Note that the mouse pointer will still be visible when using this function. If you want to hide the mouse pointer you can use this function to hide it:
The mouse pointer should, if you've made everything right, be centered and trapped inside the window when you're starting the program. If you would like to center the mouse pointer all the time even if the mouse is moved, use SDL_WarpMouseInWindow each frame to center the mouse pointer. |
|||||||||||||||||
|
Alundra
|
Thanks you ! That kill a big question, all works good
|
|||||||||||
|
Naith
|
No problem.
|
|||||||||||
|