-
December 26th, 2009, 07:32 PM
#1
Mouse hit test/know when mouse is over something.
I'm using Win32 and Direct2D and I need to know when the mouse is over something so I can move/rotate it only when the mouse is over it and is down.
I know how to rotate/move stuff with the mouse and how to tell when the mouse is down and up, all I need to know is when it's over something, like a simple square or circle.
Could someone tell me how that is done?
-
December 28th, 2009, 07:03 PM
#2
Re: Mouse hit test/know when mouse is over something.
You can determine whether the left mouse button is down or up by trapping WM_LBUTTONDOWN or WM_LBUTTONUP messages.
Also, assuming that the window background is one consistent color. Let's assume white, you can call GetPixel in WM_MOUSEMOVE to determine the RGB values of the pixel at the cursor location. If the cursor is on the white backround, the RGB values would be 0xff, 0xff, 0xff. Otherwise, if the cursor is on a colored rectangle, then the RBG values would be something other than 0xff, 0xff, 0xff. The return values from GetPixel would be the RGB values of the rectangle. Thus, if the RGB values change from white to some other value, you then know your cursor is on an object.
-
January 3rd, 2010, 03:15 PM
#3
Re: Mouse hit test/know when mouse is over something.
D3DXIntersect can do it , check the pick example in dx sdk
-
January 4th, 2010, 09:46 PM
#4
Re: Mouse hit test/know when mouse is over something.
The technique that you want is called picking. Basically, you need to draw everything twice, once on the screen in real colour, and again on a picking buffer in a solid, unique colour. When the mouse button goes goes, check it's position, check which colour is on the picking buffer at that coordinate, and it'll tell you which object was clicked on. It's the best for things that are arbitrarily rotated or have a lot of objects, because it's pixel perfect.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|