Mouse move on WPF image control using Kinect - wpf

I am trying to move the mouse using the kinect . I achieved using the interopservices in c#.
Now i want to move mouse only inside the image control . so mouse should not move on other layouts. Is there any way to achieve the mouse movement without using the interopservices.

Cursor.Position = new Point()
Will let you move the cursor. You can restrict where in the code too.
Is that what you're looking for, or am I missing something? There really isn't anything specific to the Kinect that I can see.
EDIT:
You can find the tracking function I use in the following post:
how to use skeletal joint to act as cursor using bounds (No gestures)
In it, I assign the position of the hand to a "RightHandX" and "RightHandY" parameter. These are basically the mouse position -- you could replace them with a call to Cursor.Position.
If you only want to move the mouse around the image, you can get the bounds of the image and then just add another 'if' statement that does or doesn't send a Cursor.Position based on those bounds and the calculated position of the hand.

Related

How to handle mouse motion events in GTK3?

I am trying to implement the following feature using C/GTK3/Cairo:
-Left click on an GtkDrawingArea Widget and printf the coordinates Xo and Yo.
-While keeping the left button down, move the mouse and draw a line conecting (Xo,Yo) to the current mouse position.
-Release the left mouse button and printf("something")
How do I do this? Anyone knows of a good tutorial showing how to handle mouse clicl-move events?
So far, the best I found was this zetcode lines (which shows how to handle mouse click events but not button-down/move/button-up and this , which explains how to change the mouse cursor when hovering over a Widget.
Thanks
Did you see this GtkDrawingArea demo from the Gtk people? This one is written in C, but there is a Python version of the same program (links updated - thanks #kyuuhachi).
Anyway, in the constructor (__init__), calls are connected to the motion_notify_event.
You also need to connect to the button_press_event and the button_release_event.
Then, on button press, you save the coordinates of the start point. (and save it to the end point too, which are the same for now).
On each motion_notify_event, you delete the previous line (by overwriting), and redraw it to the new end point.
Finally, when the button is released, the line is final.
It's much easier if you use a canvas widget, for example GooCanvas, which takes care of most of the updating. You can just update the coordinates of the line object, and it will move itself. Also you can easily remove lines. The 'algorithm' is similar as above:
Connect button_press_event, button_release_event, and motion_notifyevent to the canvas,
When a button press occurs, create a GooCanvas.polyline object, and set begin and endpoint,
Update the endpoint on each motion_notify_event
Finalize with a button_release_event.

Creating and moving a Shape in Visual Studio C++/CLI

I am working on a little school project and I have to use Visual Studio C++/CLI with Windows Forms Application.
Since I am new to Windows Forms I am having some difficulties.
What I would like to achieve:
Press a button
A PictureBox will be created at starting position
A timer will move the PictureBoxto some given position
Pressing the button again will spawn a NEW PictureBox with a different name which will begin to move in the same direction as the first rectangle
and so on.
Note: These pictureboxes have to have a different background color which must be randomly chosen out of 3 colors.
What I need to know is....
I know how to move a picturebox, but how do I dynamically create one with a custom name and color after a button press?
Thanks in advance!
Because you mention this is a school project, here is some high-level advice:
You can draw on a form by either subscribing to the Paint event (https://msdn.microsoft.com/en-us/library/system.windows.forms.control.paint%28v=vs.110%29.aspx) or overriding the OnPaint method (https://msdn.microsoft.com/en-us/library/system.windows.forms.control.onpaint(v=vs.110).aspx). Take a look at the Graphics object in the EventArgs.
When the timer elapses, make adjustments to local variables (keeping track of the desired position of the Rectangle) and then call Invalidate() (https://msdn.microsoft.com/en-us/library/system.windows.forms.control.invalidate(v=vs.110).aspx) to force the form to be redrawn.
I hope this helps you get pointed in the right direction.

How to imitate zune panning control

I'm looking to imitate the following control, found in the zune software, in the quickplay tab. When you move the mouse from left to right the boxes new, pinned and history move to the opposite direction.
I'm thinking of applying a method to the mousemove handler which checks for the relative position of the cursor and then moves a grid containing panels accordingly but before I try to reinvent the wheel I'd like to ask around if there are people who have more experience with this, especially getting a fluid motion.
Please let me know
Do you mean something like this http://sachabarber.net/?p=829

scrollviewer and canvas - scrolling view to given position

I have some problems with implementing autoscrolling in WPF (I think I could call it that way).
I have a canvas placed inside a scrollviwer. On my canvas I can dynamicly add different shapes. The position of this shapes can be changed with mouse. Everytime I add new shape on canvas or change position of shape I fire measureOverride function.Thanks to this scrollview "know" the real size of canvas and the scrollbars appear. However even if scrolbars appear, the view doesn't "follow" shape which I currently move. I mean if I reach visible part of canvas I would like canvas to srcoll.
I was trying to use this function
ScrollToHorizontalOffset()
However I have problem with proper use of that function. I was trying to use (as a parameter) canvas actualwidth but it didn't work well. I also was trying to use as a parameter current position of shape (which I move) but it works only one way. I the viewer follow the moving element if I was moving this element to right side of canvas. However if I move shape back(to the left) the view don't follow the shape.
I hope somebody will understand this :) It is hard to explain my problem.
I also was trying to use as a
parameter current position of shape
That is the correct way to implement. Waht you need is a converter, which will returns the position according to the direction you move the object.

Converting mouse position to world position OpenGL

Hey, I'm working on a map editor for my game, and I'm trying to convert the mouse position to a position in the game world, the view is set up using gluPerspective
A good place to start would be the function gluUnProject, which takes mouse coordinates and calculates object space coordinates. Take a look at http://nehe.gamedev.net/data/articles/article.asp?article=13 for a basic tutorial.
UPDATE:
You must enable depth buffering for the code in that article to work. The Z value for mouse coordinates is determined based on the value in the depth buffer at that point.
In your initialization code, make sure you do the following:
glEnable(GL_DEPTH);
A point on the screen represents an entire line (an infinite set of points) in 3D space.
Most people with questions similar to yours are really trying to select an object by clicking on it. If that's what you're after, OpenGL offers a selection mode that's generally more effective than trying to convert the screen coordinate into real-world coordinates.
Using selection mode is (usually) pretty simple: you start with gluPickMatrix, which you use to specify a small box around the click point. You then draw your scene in selection mode. When you're done, instead of actually drawing anything, it gives you back records of what would have been drawn in the box you specified. If memory serves, those are arranged in Z order, so the first one in the list is what would have displayed front-most (i.e., the one you usually want).

Resources