Game Resolution And Mouse Coords

Started by
4 comments, last by Quinnie 17 years, 4 months ago
Hey everyone, i'm having, a hopefully simple, problem with DirectX and the Coördinates of the mouse cursor. I would like to set the screen resolution to 800x600. This is my CreateWindow function:

hWnd = CreateWindowEx( WS_EX_APPWINDOW, "Program1", "Program 1", WS_POPUP, 0, 0,
                       GetSystemMetrics(SM_CXSCREEN),
                       GetSystemMetrics(SM_CYSCREEN),
                       NULL, NULL, GetModuleHandle(NULL), NULL ); 

And here my backbuffer settings: (Not sure if they are important anyway)

d3dpp.BackBufferWidth			= 800;
d3dpp.BackBufferHeight			= 600;

This is the code where I set my cursor

g_pd3dDevice->SetCursorProperties(0, 0, g_pMouseSurface)

This is the code I use to retreive the current mouse coordinates

g_lpMouse->GetDeviceState( sizeof(DIMOUSESTATE2), &MouseState )

Now when I check de coordinates the GetDeviceState function gets they don't match the range of [0,800] and [0,600] instead they seem to use my default computer resolution settings. If I change my CreateWindow settings to use 800x600 the application wont run fullscreen and instead just uses a part of the entire screen. Any help is appreciated, Thanks in Advance...
Advertisement
non DirectX apps do not normally affect the resolution (I've never done this or seen it done ... a windows desktop app is suppsoed to live on the desktop in any size screen the user wants) ... but in directx apps ...

iDirectDraw->SetCooperativeLevel(hwnd,DDSCL_EXCLUSIVE|DDSCL_FULLSCREEN);
iDirectDraw->SetDisplayMode(800,600,16); // the 16 is color depth which is probably not the best default choice ... but ...

here's 1 link of many

http://www.mvps.org/user32/directxtutorial.html
The values returned inside DIMOUSESTATE2 are actually relative offsets in the devices local system. The values are all relative to the current sensitivity of the device itself, not your resolution. You need to scale this yourself appropriately (basically adding your own sensitivity), if it's too much then divide it, too little then multiply it. I don't know if DirectInput really has any way to read the current sensitivity of the device, though (it's a Windows settings AFAIK), so how much you want to scale it is up to you (trial and error to find a smooth value, or make it configurable). Keep in mind that different machines will have different sensitivity values.
Thanks a lot,

i'll look into it this afternoon. Just to clearify, there is no directinput function to retreive the mouse coordinates in absolute value?

Thanks again :P
AFAIK you can set the dinput device properties to get absolute coordinates instead of relative, but...

If you use the mouse for GUI-like things you're way better off to do that with the Win32 mouse messages. They'll take in account all the user settings which you'd have to do yourself.

Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>

I'm actually using it for in-game rotation and movement as well as for a in-game gui with some windows etc.

They annoying part is that the coords on wich my 2D images are renderd are really strange (All really small negative numbers I think), this is likely because of the projection settings etc.

This topic is closed to new replies.

Advertisement