Archived

This topic is now archived and is closed to further replies.

dapeos

Mouse Problems

Recommended Posts

My problem is that since I keep track of my mouses position like this: MouseState = mDInput.ReadMouse(); MouseXPos += MouseState.lX; MouseYPos += MouseState.lY; what can I set MouseXPos and MouseYPos to intially, right now I set them both to zero but since my cursor can be in different positions when the game is launched my menu items that use the mouse never line up. My game runs in both full screen and window mode which creates another problem. COULD I SET THE MOUSE POSITION TO (0,0), AND HOW? IF NOT HOW CAN I SLOVE THIS PROBLEM. Here is some more code showing what I am trying to do.
while(Ptr!=NULL){

	if(MouseXPos  >= Ptr-> location.x &&
		MouseXPos <=(Ptr-> location.x + Ptr->width) &&
		MouseYPos >= Ptr-> location.y && 
		MouseYPos <=(Ptr->location.y + Ptr->height))
		{
		Ptr->srcRect.left=200;
		Ptr->srcRect.right=400;
		}
	else{
		Ptr->srcRect.left=0;
		Ptr->srcRect.right=200;
		}
	
			
	Ptr=Ptr->Next;
	}
thank you for helping me -Dapeos

Share this post


Link to post
Share on other sites
One thing to note is that you should put the mouse events in a while loop until the queue is empty, or however that works. That helps to eliminate gay mouse handling issues.

As for your problem, I don''t understand what you meant by "but since my cursor can be in different positions
when the game is launched my menu items that use the mouse never line up".

I understand some of your woes regarding the window positioning, but if the mouse coords are relative, it should still work.. The only problems I''m thinking of occur when you use GetCursorPos .

But to set the mouse to 0,0, just init the mouse variables to 0,0.. Movement is relative, so it should be fine.. Just draw your cursor sprite on the same coords..

More info!

Share this post


Link to post
Share on other sites
Hope this clarifies
MouseXPos and MouseYPos are set to zero, but the mouse isn''t in the upperRight hand cornor of the client area. So where ever the mouse is when the application is run becomes the mouse origin and all movement is relative to that position. Since my check for collision
is specific points on the screen it doesn''t line up how can I fix this.
thanks again

Share this post


Link to post
Share on other sites
Okay, lol, thanks Oluseyi. So yah, make sure it's in relative mode. That way if MouseXPos is 0, and MouseYPos is 0, and you blit your mouse at those coords, and MouseState is given in relative format, then you will have no problems.
Here is DI mouse loading code from my current main project:


if(FAILED(dInput->CreateDevice(GUID_SysMouse, &dMouse, NULL)))
return false;

if(FAILED(dMouse->SetDataFormat(&c_dfDIMouse)))
return false;

if(FAILED(dMouse->SetCooperativeLevel(hWnd,DISCL_EXCLUSIVE | DISCL_FOREGROUND)))
return false;

if(NULL == (MouseEvent = CreateEvent(NULL, FALSE, FALSE, NULL)))
return false;

if(FAILED(dMouse->SetEventNotification(MouseEvent)))
return false;

DIPROPDWORD dipdw;
dipdw.diph.dwSize = sizeof(DIPROPDWORD);
dipdw.diph.dwHeaderSize = sizeof(DIPROPHEADER);
dipdw.diph.dwObj = 0;
dipdw.diph.dwHow = DIPH_DEVICE;
dipdw.dwData = MOUSE_SAMPLE_BUFFER_SIZE;

if(FAILED(dMouse->SetProperty(DIPROP_BUFFERSIZE, &dipdw.diph)))
return false;

if(dMouse)
dMouse->Acquire();


[edited by - n0ob on March 28, 2004 12:23:10 AM]

Share this post


Link to post
Share on other sites
Hey thanks for bearing with me the only difference I saw between your code and mine was:

DIPROPDWORD dipdw;
dipdw.diph.dwSize = sizeof(DIPROPDWORD);
dipdw.diph.dwHeaderSize = sizeof(DIPROPHEADER);
dipdw.diph.dwObj = 0;
dipdw.diph.dwHow = DIPH_DEVICE;
dipdw.dwData = MOUSE_SAMPLE_BUFFER_SIZE;

if(FAILED(dMouse->SetProperty(DIPROP_BUFFERSIZE, &dipdw.diph)))
return false;

not sure exactly what that does and what is "MOUSE_SAMPLE_BUFFER_SIZE;" my compiler doesn''t recognize it.
I would love to blit the mouse to the upperRightHand cornor, how is that done I didn''t see anyway in the sdk to do that.
thank you I promise I won''t ask anymore stupid questions at least not until tomorrow lol.
thanks

Share this post


Link to post
Share on other sites
I seen this post ... I''m not into DirectX but here goes my attempt:

Two approaches:

If you want to force the cursor to (0,0) of your client area (to match up with your mouse pos, you could use ClientToScreen to convert the (0,0) client coord to a screen coord and thus you can call SetCursorPos to go there.

Personally I don''t like the cursor jumping like that. What I do is use GetCursorPos to obtain the screen coord and then use ScreenToClient to convert to my client coord for the initial value. That is what I use instead of forcing the coord to (0,0).

These approaches work with windowed and fullscreen.

Share this post


Link to post
Share on other sites
I went with the second approach but GetCursorPos(lpPoint) is failing everytime when I call it.

LPPOINT lpPoint;
GetCursorPos(lpPoint);
ScreenToClient(g_hWnd,lpPoint);
MouseXPos=lpPoint->x;//right here is where it crashes

MouseYPos=lpPoint->y;

Do you know why?


[edited by - dapeos on March 29, 2004 1:27:38 AM]

Share this post


Link to post
Share on other sites
quote:
Original post by dapeos
I went with the second approach but GetCursorPos(lpPoint) is failing everytime when I call it... Do you know why?
Is your DI device cooperation level set to exclusive mode? If yes, Windows won''t be able to access the mouse via Win32.

Stick to fixing the problem in DI.

Share this post


Link to post
Share on other sites
POINT pt;
GetCursorPos(&pt);
ScreenToClient(g_hWnd,&pt);
MouseXPos=pt.x;
MouseYPos=pt.y;

A parameter that uses LPPOINT is a pointer to a POINT.

Added->

Oluseyi: I use OpenGL but my app can use DI as an option for setting exlusive mode and obtaining the mouse. I simply do the above just before I acquire the mouse and everything is fine. The key is that he asked "what can I set MouseXPos and MouseYPos to intially" and this method works for me (to obtain the initial value).

[edited by - JotDot on March 29, 2004 2:08:49 AM]

Share this post


Link to post
Share on other sites