Possible to change the hardware cursor in SFML? - sfml

Is SFML capable of changing the hardware cursor, i.e. replacing the OS cursor with a custom image? Moving a sprite around is not really satisfying as responsiveness decreases with framerate.

sf::RenderWindow window(sf::VideoMode(800,600,32),"Demo");
window.ShowMouseCursor(false);
Then you can set the position of a sprite to wherever the mouse is!

Related

How do you handle a mouse cursor in the FPS game?

I'm making an FPS game. In the FPS game, the mouse cursor is in the middle of the screen. So I put the mouse cursor in the center with the next code. But how can I solve this problem when the camera stutters very much every time I move the mouse?
SetCursorPos(CRenderMgr::GetInst()->GetResolution().fWidth / 2, CRenderMgr::GetInst()->GetResolution().fHeight / 2);
CRenderMgr::GetInst()->GetResolution() is Screen Width and height
What you are doing is referred to as 'relative mode' mouse movement.
For classic Win32, this is typically done using "raw input". See this article.
If you want "raw input" to also to work in a Remote Desktop, see this code. In Remote Desktop, you don't get MOUSE_MOVE_RELATIVE data, and in normal desktop scenarios you never get MOUSE_MOVE_ABSOLUTE data.
For UWP, this is implemented as mentioned in this article.
You can see the Mouse class in the DirectX Tool Kit.

Qt4.8 embedded. Adjusting mouse input with QCursor::setPos() results in a twitching cursor

I'm trying to adjust user mouse input (slow down/fasten mouse pointer) by calculating and setting the new position of the pointer every mouseMoveEvent().
It looks like the pointer is drawn in it's normal position before mouseMoveEvent() is executed. This results in a bad looking, twitching cursor.
Here is an example of how I would try to keep the pointer in a place, ignoring user input.
Expected behaviour: The pointer stays steady in one place when I move the mouse.
Observed bahaviour: The pointer jiggles. For a fraction of a second, a new pointer is drawn in the position where the mouse is moved, after which it's moved back to it's oldPosition.
void MainWindow::mouseMoveEvent(QMouseEvent *)
{
// [event->accept();] Setting this does not help
// [setCursor(Qt::BlankCursor);] Setting this does not help
QCursor::setPos(oldPosition);
// [setCursor(Qt::ArrowCursor);]
}
P.S. May be there are other ways to adjust mouse sensitivity in qt embedded. Am I doing it right?
Short answer: No.
Unfortunately, there is no way to adjust mouse sensitivity using only QT libraries.
The twitching you are experiencing is because the OS does the work of drawing the mouse pointer, the frequency of which can be different from how frequently you receive mouse move events from the OS.
There is also no way to tell QT or the OS to send you mouse move events before every frame the cursor is drawn.
Workaround: You could hide the mouse pointer completely, and draw your own. This way you will have full control over when the cursor is drawn avoiding the glitches.

Pygame: Character Centered Movement System (Diablo II like click-to-move)

I am currently working on a new RPG game using Pygame (my aim here is really to learn how to use object oriented programming). I started a few days ago and developed a movement system where the player clicks a location and the character sprite goes to that location and stops when it get's there by checking if the sprite 'collides' with the mouse position.
I quickly found however that this greatly limited the world size (to the app window size).
I started having a look into making a movement system where the background would move with respect to the player, hence providing the illusion of movement.
I managed to achieve this by creating a variable keeping track of my background map position. The map is much bigger than the app window. And each time I want my player to move I offset the background by the speed of the player in the opposite direction.
My next problem now is that I can't get my character to stop moving... because the character sprite never actually reaches the last position clicked by the mouse, since it is the background that is moving, not the character sprite.
I was thinking of spending some time coding in a variable that would keep track of how many displacements it would take the character sprite to reach the mouse clicked position if it was to move. Since the background moves at the character sprite's speed it would take as many displacement of the background in the x and y directions to center the clicked position on the background to the character sprite at the center of the screen.
It would be something like that:
If MOUSEBUTTON clicked:
NM = set number of moves needed to reach the clicked position based on character sprite distance to click and character sprite speed.
If NM != 0:
Move background image
Else:
pass
This would mean that when my background has moved enough for the character sprite to now be just over the area of the background that was originally clicked by the player, the movement would stop since NM == 0.
I guess that my question is: Does that sound like a good idea or will it be a nightmare to handle the movement of other sprites and collisions ? And are there better tools in Pygame to achieve this movement system ?
I could also maybe use a clock and work out how many seconds the movements would take.
I guess that ultimately the whole challenge is dealing with a fixed reference point and make everything move around it, both with respect to this fixed reference, but also to their own. e.g. If two other sprites move toward one another, and the character of the player also "moves" then the movement of the other two sprites will have to depend both on the position of the other sprite and also on the offset of the background caused by the movement of the player's character.
An interesting topic which has been frying my brain for a few nights !
Thank you for your suggestions !
You actually asking for an opinion on game design. The way I look at it, nothing is impossible so go ahead and try your coding. Also it would be wise to look around at similar projects scattered around the net. You may be able to pick up a lot of tips without re inventing the wheel. Here is a good place to start.
scrolling mini map

How do I change the cursor to a line in an OpenGL window?

I want to have a red line instead of mouse pointer in my (written in C++ with OpenGL) application. For example when I move the mouse over an OpenGL window, I would like the cursor to become a red line. How can I do that?
Also, how can I call the mouse related functions (OpenGL) for that line and specify the functionality?
As Nicol Bolas said in his comment, OpenGL knows nothing of the mouse. You'll need to interact with the windowing system one way or another (via direct Win32/X11/etc. API or via a portable windowing library a la Qt, wxWidgets, etc) to monitor mouse position.
If the cursor you're trying to draw is a bitmap, your best bet is likely to handle mouse enter/leave events sent to your window and respond to them by using an API function to change the cursor. This will handle automatically updating the cursor as the mouse moves around and will add minimal overhead to your application (windowing system cursors generally draw in an overlay plane that avoids sending redraw events to your window every time the mouse moves).
If you have a more procedural description of your cursor (that is, you intend to draw it with OpenGL drawing commands), you'll instead want to handle the mouse enter/leave events by using HideCursor()/ShowCursor() commands or the equivalent to turn off the windowing system's native cursor when the mouse is over your window. Then, you'll hook the mouse move callbacks and redraw your scene, adding whatever commands you need to draw the cursor at the position specified in the mouse move event.
The first approach is definitely preferred for performance & latency reasons--but there are some cursor types (think full screen crosshairs) that can't be accomodated that way.

Getting mouse position unbounded by screen size, c++ & windows

I'm currently writing a c++ console application that grabs the mouse position at regular intervals and sends it to another visual application where it is used to drive some 3d graphics in real time. The visual app is closed source and cannot be altered outside it's limited plug-in functionality.
Currently I'm using the GetCursorPos() function which is easy and fast enough, but I'm running into the issue that all of the data is clipped based on the current screen resolution of 1920x1600 so that all x values are between 0 and 1920 and all y values are between 0 and 1600 no matter how far the mouse is physically moved.
I need to get the mouse position before it's clipped at the edge of the screen, or possibly the deltas which I could use to calculate the current position.
I've seen some references to the windows MouseMove event but I would really not want to implement a window to make it work or especially have it as the active to receive those events.
I'm working in a windows environment and a language change is not feasible.
I might be wrong, but in Win32 land you don't get mouse move messages when the mouse is at the edge of the screen because, well, the mouse isn't moving. The usual way to get an infinite mouse area is to do the following:
Hide the mouse, get exclusive access and record position
Centre mouse to window
When mouse moves, get delta from centre of screen to current position
Centre mouse to window again
The next mouse move should have a delta of (0,0), so ignore it
Go to 3 until end of mouse move operation
Reset position, show the mouse and release exclusive access
If you didn't hide the mouse, then you'd see the mouse moving a small distance and then snapping back to the centre position, which looks nasty.
This method does require a message pump for the mouse move messages so the console application idea probably won't work with this. Can you create a full screen invisible window for grabbing the mouse?
Just get the position, and move it to the center and return the delta yourself
This is how FPS games do it
I don't have any direct experience with raw input, which is probably what you need to tap into. According to MSDN, you have to register the device, then setup your winproc to accept the WM_INPUT messages and then do your calculations based on the raw data.
Here's another relevant link.