🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Mouse with DirectInput.

Started by
4 comments, last by VisualLR 24 years, 5 months ago
Hey, Im having a bit of problems using the mouse with DI, what I want to do is to handle the mouse coordinates in the same way screen coordinates are handled, like make a function that works kinda like this: mx = GetMouseX(); // returns the screen coordinate the mouse // is on the thing is, Ive tried using Absolute coordinates and relative coordinates, and so far with relative coordinates the only thing Ive managed to get to work is that the cursor appears in the center of the screen but when I move it to the sides, it automatically gets returned to the center which isn''t what I need.. So how do I go about doing this? Thanks! Luis Sempe
visuallr@guate.net
http://www.geocities.com/SiliconValley/6276


Advertisement
Try something like this...

void GetMouseInput()
{

// Get The Relative Mouse Position
DIMOUSESTATE2 diMouseState2;
g_lpDID7_Mouse->GetDeviceState(sizeof(DIMOUSESTATE2), (void*)&diMouseState2);

// Update Our Cursor Position
g_nMouseX += diMouseState2.lX;
g_nMouseY += diMouseState2.lY;

// Now Make Sure The Cursor Is Still On The Screen
if (g_nMouseX < 0) g_nMouseX = 0;
if (g_nMouseX > c_ScreenWidth) g_nMouseX = ScreenWidth;
if (g_nMouseY < 0) g_nMouseY = 0;
if (g_nMouseY > ScreenHeight) g_nMouseY = ScreenHeight;

// Get Our Mouse Wheel Position
g_nMouseZ = diMouseState2.lZ;

// Get Our Button States
g_bLButtonDown = diMouseState2.rgbButtons[0] ? true : false;
g_bMButtonDown = diMouseState2.rgbButtons[2] ? true : false;
g_bRButtonDown = diMouseState2.rgbButtons[1] ? true : false;

}

This code stores the mouse information in global variables. Obviously, this isn''t a great programming practice, but I thought it would help the explination. You may want to multiply the mouse input by some constant to help speed up the movement of the mouse (this is a little too slow for me), but that''s just a thought.

One side note, the mouse wheel is better handled in most cases as a relative position anyway. If this isn''t obvious, just think about how it''s used.
Thanks! That''s exactly what I wanted to do.

One question tho, what''s the mouse wheel useful for?



Luis Sempe
visuallr@guate.net
http://www.geocities.com/SiliconValley/6276


Just in case you didn't know : a mouse wheel is something like a wheel (really?) which is located between the two buttons of the mouse. It is mainly used for scrolling in windows but there are other things for which it might be useful. You can use it to change weapons in a FPS (like Q3A) or to zoom in or out in a real-time strategy game (like Homeworld). The only limitation that you have to think about is, that not everbody owns one (you're one of them, I suppose .

And uh yea, I forgot. Some of the wheels (including mine) can also act as a third button if you press them (instead of rolling them)

Edited by - Chappa on 1/12/00 6:20:13 AM
Yep! MouseWheels are a cool thing and every game should support them. (I''m going to support it im my game,too).

Well, I dont have a mouse wheel on this computer, but I do have a mouse with a mouse wheel (I just didnt know it was called like that, I always referred to is as "that little thing in the middle") and I''d have it on this computer, but it''s so old it doesn''t have a PS2 slot, so I can''t use it (a serial to PS2 doesnt work either)...

So, when I finish building my new computer (currently I only have a motherboard..) Im might add support for a mouse wheel...

later!

Luis Sempe
visual@guate.net

This topic is closed to new replies.

Advertisement