Skip to main content
gamedev.net
🔒 Locked

snap-to mouse

Started by Dwiel May 28, 2002 at 10:24 PM 3 replies 300+ views
Original Post
Dwiel
Dwiel
I was just wondering how to get the mouse to snap to every nth pixel on the screen. Id like to be able to do this for only a certain region of the screen. Thanx for the help ahead of time!! Dwiel ~ Tazzel3d
DiscipleOfTorak
DiscipleOfTorak
Ok, never done this, but I think you could do something like this.

1. Check if the mousepointer is in the area

2. Calc which pixels are to be snapped to.

3. Move mousepointer to nearest snappable pixel


I don''t think it can be much harder. The hardets part should be to calc which pixels to snap to. But should not prove to be very hard either.

Hope it helps
Carrot
Carrot
Try:

SnapXPos =((int)MouseXPos+(GridXSize*0.5)/GridXSize)*GridXSize
SnapYPos =((int)MouseYPos+(GridYSize*0.5)/GridYSize)*GridYSize
Dwiel
Dwiel
Really, I guess I should have written that I mostly wanted to know how, with DX, to draw the mouse at coord x, y and how to retrieve the mouse movement data and what form it will be in.

Thanx alot

Dwiel~Tazzel3d
IndirectX
IndirectX
To retrieve mouse data, use DirectInput (naturally). The SDK docs have the tutorial that explains how to set up DI and how to get both immediate and buffered data from it, as well as their format.

To draw the cursor, you need a cursor image and the ''hotspot''. Hotspot is the position within the cursor image that should coincide with the current mouse position. For example, hotspot for the standard arrow cursor is somethere close to its top-left corner, and the hotspot of a crosshair cursor is in its center. Once you know the current mouse coordinate and the hotspot coordinates, calculate the position at which the cursor bitmap starts so that its hotspot coincides with the cursor position and draw it there. You can use a textured quad, for example.

Note that since DirectInput works directly with hardware, it doesn''t know what "screen" is. Therefore it''s your job to constrain mouse cursor to screen. You can use a simple point-rect test.
---visit #directxdev on afternet <- not just for directx, despite the name

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.