How to detect direction of HorizontalDrag in WP7 XNA? - c#

Like mentioned what is the best way of detecting in which direction the user is dragging horizontally. I'm trying to create a camera class that responds to this gesture but am having problems determining which direction they are dragging. Any suggestions are appreciated.

Admittedly I haven't tested this, but the documentation suggests that you should check the value of GestureSample.Delta.X, which should be negative for a left movement, and positive for a rightwards one.
Because the delta is only for that particular gesture sample (not the overall gesture), you may need to accumulate it, and only trigger your drag action if the accumulated value is above some threshold (possibly upon receiving a DragComplete).

Related

How to a read raw mouse data in the form of either Delta or Pixel movement?

Ill get this out of the way at the beginning, I know how to read POINTER or CURSOR data, I can get the X,Y coords and through a interval of some sort calculate mouse Δ or movement, but this falls apart when he mouse reaches the edge of the screen as every known method I have seen relies on the concept of the derived cursor movement and not the mouse device itself.
I am also aware of the ability to "capture" the mouse (cursor) in a predefined space and or constantly reset the position to keep the mouse from ever actually reaching the edge of the screen, but this will not work for me as I would like the mouse to remain fully usable and not in a trapped state.
Every single result I have found in my searches for an answer have yielded code that only cares about the mouse cursor, so please don't carelessly mark this as duplicate of some other answer that is just doing one of the above.
I find it hard to believe that there isnt a low level function out there somewhere that gets me raw data.
To accomplish your task, use the WM_INPUT API (https://msdn.microsoft.com/en-us/library/windows/desktop/ee418864%28v=vs.85%29.aspx?f=255&MSPPError=-2147217396#WM_INPUT). WM_INPUT messages are read directly from the Human Interface Device (HID) stack and reflect high-definition results.

Project to track on screen object - Unsure how to go about it

I've started learning c# and vb.net and have a project related to tracking a moving object on the screen to help me learn some basics.
In essence, I will have a ball on the screen which moves from left to right (only horizontally), and when it reaches a certain point (e.g. 250 pixels from the "mid" point either side) I need to know this, and click an on-screen counter to increase a value (or decrease depending on left or right) and reset the ball to the centre (note that the ball speed will vary from incredible slow to an instant "jump").
I've been asked to look into c# and vb and decide which is best, then use it to create the program. As a complete newbie in both of these, does anyone have a recommendation and a starting point please?
My background is Javascript, HTML and very basic Java.
Thanks!
Not too sure what you define as a "Starting Point" do you mean like different C# libs to use etc. If all you are trying to do is move a ball from left to right basically and count the difference it would be so simple to do in C# XNA.
You can also do it in windows forms too which I really thing shouldn't be too hard at all. Obviously you would create the velocity formulas yourself I don't believe that's what you're asking.
One way to get the screen size in windows forms is:
public Rectangle GetScreen()
{
return Screen.FromControl(this).Bounds;
}
This will return a rectangle with a width and height that you can call, divide both values by 2 and it will give you the center of the screen. Then just add a method that is called every frame to check the balls value from the middle of the screen.
From what I've read I understand what you want to do, but I'm unsure if you just want a windows form or if you'd prefer to use a small game engine like XNA etc.
Either way best of luck and let me know :)

How do I implement a wave gesture in kinect?

I would like to use a gesture, so the kinect can select the person with the gesture as the main player. After this he can control the PC. Selecting the person and giving them control is done. Now i have to implement a gesture, but i dont know how to start.
Can anyone help me?
I guess that is what you want (if you like to recognize gestures by yourself):
MS explains how to recognize a wave gesture with a full code example here:
http://blogs.msdn.com/b/mcsuksoldev/archive/2011/08/08/writing-a-gesture-service-with-the-kinect-for-windows-sdk.aspx
By now there are also some gesture recognizer toolkits available.
See this for example:
http://kinecttoolbox.codeplex.com/
You can also surf on http://channel9.msdn.com for similar projects, like that one:
http://channel9.msdn.com/coding4fun/kinect/Gestures-and-Tools-for-Kinect-and-matching-Toolkit-too
Did you get as far that you have the skeleton?
The easiest is to check how many times the hand changed velocity direction
+x --> -X means it went left and is now coming back right, you can do a distance check between these points to determine if the wave gesture is obvious enough (omits very tiny waves/jitter)
Take some reference for hand have - say elbow - and store it into a variable and take some reference distance for the hand move such that whenever the hand moves on both sides beyond the reference distance on both sides, calculate the number of waves with the waves you require in your program. If both match select that person for your program

What does the DragCompletedGestureEventArgs.Velocity parameter mean exactly?

The DragCompleted event of a wp7 control has a parameter of type DragCompletedGestureEventArgs that contains the variables HorizontalVelocity and VerticalVelocity.
How are these velocity variables interpreted? I get a value of 0 for a slow drag and a value of >4000 for a fast drag, but I'm not sure how I can relate these numbers into a number of pixels dragged per time interval value.
Background of my question: In my program the user can grab an object and then drag it. I want the object to continue moving (up to a standstill) when the user lets go of the object.
You can't relate them into pixels. But you can create a relative scale according to the velocity, and then how much it should slow down / speed up, based on the velocity.
If you think of the Pictures Hub image viewer, then you can see that you can pan around images, but if you use a high enough velocity, it'll flick to the next/previous image.

WPF Slider problems

I have seen this behaviour, on an old win32 app, where when you hold down the mouse at some position on the slider track (other than on the thumb), the thumb moves to that position.
In WPF what seems to be happening is the thumb moves a distance defined either by SmallChange or LargeChange. If you keep holding, it moves by SmallChange/LargeChange again after some time as defined by the Delay property.
Now I want to get the old behaviour? So if the thumb is at 2 and I press the mouse down near 10 I want it to jump to 10. Whats the best way to do this?
Thanks in advance for any suggestions.
Slider.IsMoveToPointEnabled
I dont know how many times I went through all the properties before finding it.

Categories