Is there a way to smooth out the mouse movements? I want to remove all the small jitter in normal mouse moving with the hand, like you can never draw a clean line in paint because of you hand doing small jittering movements.
This might be hard to understand what I mean, but if you know zbrush they have a feature that is called lazy mouse http://www.pixologic.com/docs/index.php/Lazy_Mouse im looking for a way to recreate this inside my app. I can read the mouse position with Cursor.Position but I don't find a way to average out these numbers before they get sent to the pointer on the screen.
This is only possible if you can delay the effect of the mouse movement slightly. You record the points of the mouse movement at a certain frequency and then average them out to a line. Then use that line to draw whatever you need. You wont be able to directly set the mouse cursor to the averaged position as that would then feedback into your program as a new mouse movement.
Make sure you build it so you can tweak how long you delay the mouse movement, and how aggressive the averaging is (say by restricting the number of points it includes), and the frequency at which you record mouse movements (this is could affect cpu usage if its too frequent).
You will of course have to create some sort of abstraction for the mouse in your application and create a way for the application to get hold of it. (I would be trying to keep this as similar as possible to normal winforms/wpf so I could revert the change and just use mouse movement directly if needed).
Related
Okay so there are plenty of samples for mouse global hooking.
My issue is how can I add a timer/delay for mouse movement.
What is the way of doing this? I thought maybe I should Thread.Sleep() on detecting WM_MOUSEMOVE ?
if (MouseMessages.WM_MOUSEMOVE == (MouseMessages)wParam)
{
Thread.Sleep(delay)
}
Thanks.
i'm afraid you cannot slow down the mouse movement in this way.
Here you are just notified of a new mouse position, the system doesn't care what you do with this notification and how long it takes to complete, or if it sleeps.
I suppose you should "record" the mouse position every "delay" time, and then every time a new WM_MOUSEMOVE event arrives (and the coordinates are different from the record ones), then you should "reset" the mouse cursor position to the saved coordinates.
of course, this until the WM_MOUSEMOVE arrives within "delay" time. Otherwise just record a new position and wait for the next event.
.NET have the Cursor.Position property that should allow you to move the mouse cursor where you want, other languages should have their analogous, but i've never tried it and i'm not sure it operates correctly in your "global" context.
anyway messing around with the cursor position is something that can make the user very upset
maybe you don't want to stop completely the cursor for "delay" time, maybe you want to linear interpolate the new position with the previous one with a <1 factor? this will slow down the mouse but with a smoother effect.
I'm fairly new to game development and I'm trying to develop a 2D game in unity where the main character has a jetpack with two thrusters and I want him to control each one individually. So if he only turns on one thruster he goes 5 meters above ground and hovers there while using both would make him hover at a height of 10 meters. How would i go about doing this?
I tried just simply adding forces as if the character was jumping and freezing the y-axis to 0 until he let go of the jetpack button but that did not give me the feel i was looking for. I also tried raycasting a line out of the jetpacks to the closest surface and adding a force to the jetpack to allow the player to float at that height but that I couldn't figure out a proper way to implement it.
The Raycast sounds like a great idea. Do the raycast to the next available platform and do as #Ahndwoo said in a comment, `
What you would need to do is divide the force of your thrusters by the
magnitude of the Ray. Thus, as the Ray gets longer, the force
decreases.
By doing this you'll get the natural movement from a force and you'll control how high can you get.
I would Make your thrusters holder as an object and as more turbines it has, the more powerful i'll get.
I have to make a Windows Form Application which has to be a cat chasing a mouse. And you move the mouse with the arrow keys while that cat is going towards the mouse. It should detect when they both get in contact and show the time it took.
Both the cat and mouse should be placed randomly in the window each new game. And in higher difficulty, it should have two holes and when the mouse goes in one of them it shows on the other. Can someone help because I have no idea where to start the main part?
I've already placed pictures if a cat and a mouse in separate picture boxes and made the part with choosing difficulty.
You'd basically be combining these steps:
Implement an OnKeyDown handler to respond to key presses. Reposition the mouse image when this occurs.
Create a timer for the cat animation. At each step move the cat towards the mouse's position.
Whenever the position of one of the objects changes, check if there's a collision and handle it appropriately.
It's pretty simple to do this with a game engine as well. That would handle the animation for you. Here's how you'd get started with Unity for example:
https://msdn.microsoft.com/en-us/magazine/dn759441.aspx
I need to freeze the windows mouse cursor on the screen, so it stays hovered over a specific UI element. While the mouse is in this frozen state, I would still like to be able to interact with the UI using a "fake" mouse pointer.
Currently, I've got a low level mouse hook that prevents WM_MOUSEMOVE messages from being passed along, effectively stopping all real mouse movement. However, when I don't pass along the updated coordinates, windows actually sends me the old coordinates in a separate WM_MOUSEMOVE message, as if to correct for the fact that the mouse didn't move.
Any idea on either how to prevent Windows from sending me these corrected coordinates, or another approach of how I can freeze the actual mouse curosr and still allow the physical mouse to control a "Fake" cursor?
You can suppress mouse cursor movement by using DirectInput exclusive mode.
You should acquire mouse input device when cursor movement must be suppressed. This will block windows cursor movement but you can get messages for your fake cursor using DirectInput API.
If you move the mouse cursor position in response to a WM_MOUSEMOVE message, to put the mouse back to where you want it, you will get another mouse move message because the mouse has been moved again (because you moved it). To stop this, don't set the mouse position if it is already in the right place.
You may also want to clip the mouse position to your window and get exclusive access to it.
Why don't you just draw an image of the cursor at the place you want it frozen, then set the real mouse cursor to be hidden (Cursor.Hide IIRC).
It's not clear to me what you are trying to do, perhaps making a tutorial for your app and you want to show mouse movements, etc. Perhaps this library will be useful:
http://www.codeproject.com/KB/system/globalmousekeyboardlib.aspx
I am working on wpf project, I want to know how to measure the angle of the stroke on the ink canvas? whether the stroke is right inclined or left inclined?
When you get a mouse down on the canvas, save away the current mouse position. Later, when you receive a mouse up event, you know the stroke is finished. Get the mouse position a second time and calculate the difference between the second position and the first position. Then you just have some simple math to do, and there are a couple cases to consider.
Note that this will not work so well for complex, curved strokes (because you will only receive a mouse-up event at the end of the stroke). This will work best in the case of single, straight lines.