Visual Basic - Change Mouse Speed on control only - vb.net

I need to change the mouse speed on a Picture Box in my VB paint program.
Is there a way to do this specifically for the object without changing the system's settings?

Rather than change the speed, you could modify the distance the pointer moves for each mouse event. This may not be a permanent solution, and if the UI thread is otherwise busy it could lead to jerky movement, but the technique is simply enough you could code it in less time than I took to write this paragraph.
In your event handler for MouseMove, get the distance (X,Y) the mouse pointer has moved.
Set Cursor.Position using some scaled value (nX, nY), where n determines the distance (and hence speed) the mouse pointer moves.
In other words, you'll be treating the mouse move increment as a vector, and you'll be multiplying that vector by a scalar value to modify the speed.
http://msdn.microsoft.com/en-us/library/system.windows.forms.cursor.position.aspx
As needed, use Boolean flags within the event handler to ensure that setting Cursor.Position does not trigger another even just because set Cursor.Position to a new point.
You might find that using the same scaling factor for all distances is inappropriate. For example, multiplying the move by a factor of 2 may be okay for short distances, but much too fast for large increments, in which case a lookup table or function would calculate the desired factor.
This technique would probably perform poorly if you need to decrease the speed of a move, as it could cause the mouse pointer to jump backward some fraction of the distance of its most recent move.

Related

How to smoothly move mouse along a line in VB.NET

I have been trying to move the mouse pointer along a line over a given timespan with mixed results. If the timespan is small enough, then each "delta" is big enough to move without too much inaccuracy caused by rounding off a PointF to a Point.
However, for longer timespans the deltas are so small that they suffer from rounding errors which causes my mouse point to not move along the original desired line.
How can I make the mouse move from one point to another in a fairly straight line without inaccuracy?
EDIT: Perhaps these would be of use?
http://en.wikipedia.org/wiki/Bresenham%27s_line_algorithm
Moving the mouse along a diagonal line

simple movement tracking (& saving of coordinates) with Kinect

I'm looking for a simple Kinect app which allows me to a) detect and b) track a single moving object in an otherwise static background.
I don't need any fancy skeleton or other features, just the center of mass of the moving object will do it.
Any pointers?
I would see Comparing a saved movement with other movement with Kinect to track the entire body. The answer shows the code here which shows how to save skeleton data. And mapping an ellipse to a joint in kinect sdk 1.5 to have the tracking of joints if you want to track the joints not the entire body (currently works better, but when the tracking the entire body works, use that because it is more effective and efficient).
your case is pretty simple, but requires initialization for the object since in general a term "object" is ill-defined. It can be a closest object or moving object or even the object that was touched, has certain color, size or shape.
Let's assume that you define object by motion that is whatever moves in your point cloud is an object. I suggest to do this:
Object detection is easy if object moves more than its size since
then you just may subtract depth maps and end up with your object:
depth1-depth2 > T but if the object moves slowly and shifts only by a
fraction of its size you have to use whatever high frequency info you
have, which can be depth or colour or both. It is going to be noisy as the figure below shows
as soon as you have your object selected you may want to clean it by running some morphological filters (erode +
dilate) to erase noise and get a single blob. After that you just
need to find some features in the blob such as average depth or mean
color and look for them in a small window around the object's previous
location in order to rediscover the object;
finally don't forget to update these features as object moves
through.
Some other ideas you may want to use are: depth gradient, connected components in depth, pre-recording background depth for cleaner subtraction, running grabCut on depth area selected by mouse click, etc.

Corona SDK and moving objects

I have shapes (Rectangle) in my game and want to implement something like -
when the shape object is pressed for small amount of time and pushed in any direction it should move small distance but pressing the shape for longer time it should be moved to large distance ( means depending on the pressure put on the shape and when it is thrown it should move distance relative to pressure applied.
Regards
You can break the problem into two pieces:
While the object is being pressed, it accelerates (so the longer it is pressed the greater the speed it gets up to).
As it travels, it decelerates at a constant rate (so the faster it's going at the beginning, the longer it keeps moving, and the farther it moves before it stops).
Now all you have to do is implement velocity and accelaration, then pressure and drag.
If this approach doesn't give the appearance you want, there are ways to modify it.

How to code a random movement in limited area

I have a limited area (screen) populated with a few moving objects (3-20 of them, so it's not like 10.000 :). Those objects should be moving with a constant speed and into random direction. But, there are a few limitation to it:
objects shouldn't exit the area - so if it's close to the edge, it should move away from it
objects shouldn't bump onto each other - so when one is close to another one it should move away (but not get too close to different one).
On the image below I have marked the allowed moves in this situation - for example object D shouldn't move straight up, as it would bring it to the "wall".
What I would like to have is a way to move them (one by one). Is there any simple way to achieve it, without too much calculations?
The density of objects in the area would be rather low.
There are a number of ways you might programmatically enforce your desired behavior, given that you have such a small number of objects. However, I'm going to suggest something slightly different.
What if you ran the whole thing as a physics simulation? For instance, you could set up a Box2D world with no gravity, no friction, and perfectly elastic collisions. You could model your enclosed region and populate it with objects that are proportionally larger than their on-screen counterparts so that the on-screen versions never get too close to each other (because the underlying objects in the physics simulation will collide and change direction before that can happen), and assign each object a random initial position and velocity.
Then all you have to do is step the physics simulation, and map its current state into your UI. All the tricky stuff is handled for you, and the result will probably be more believable/realistic than what you would get by trying to come up with your own movement algorithm (or if you wanted it to appear more random and less believable, you could also just periodically apply a random impulse to a random object to keep things changing unpredictably).
You can use the hitTest: method of UIView
UIView* touchedView=[self.superview hitTest:currentOrigin withEvent:nil];
In This method you have to pass the current origin of the ball and in second argument you can pass nil.
that method will return the view with which the ball is hited.
If there is any hit view you just change the direction of the ball.
for border you can set the condition for the frame of the ball if the ball go out of the boundary just change the direction of the ball.

How to set/corrent the resting position of UIScrollView contents after it has scrolled

I am implementing a view similar to a Table View which contains rows of data. What I am trying to do is that after scrolling, each row snaps to a set of correct positions so the boundaries of the top and bottom row are completely visible - and not trimmed as it normally happens. Is there a way to get the scroll destination before the scrolling starts? This way I will be able to correct the final y-position, for example, in multiples of row height.
I asked the same question a couple of weeks ago.
There is definitely no public API to determine the final resting Y offset of a scroll deceleration. After researching it further, I wasn't able to figure out Apple's formula for how they manage deceleration. I gathered a bunch of data from scrolling events, recording the beginning velocity and how far the deceleration traveled, and from that made some rough estimates of where it was likely to stop.
My goal was to predict well in advance where it would stop, and to convert the deceleration into a specific move to an offset. The problem with this technique is that scrollRectToVisible:animated: always occurs over a set period of time, so instead of the velocity the user expects from a flick gesture, it's either much faster or much slower, depending on the strength of the flick.
Another choice is to observe the deceleration and wait until it slows down to some threshold, then call scrollRectToVisible:animated:, but even this is difficult to get "just right."
A third choice is to wait until the deceleration completes on its own, check to see if it happened to stop at your desired offset multiple, and then adjust if not. I don't care for this personally, as you either coast to a stop and then speed up or coast to a stop and reverse direction.