Detect mouse movement after left click

Started by
1 comment, last by oenda 10 years, 11 months ago

Hello.This is my first post.I am developing a strategy game like AoE 2 with OpenGL.I need to calculate mouse move amount after left click.My codes so far:



bool mouseMove = false;

POINT firstMouse;

POINT lastMouse;

.
.
.
Render()
{

     float x =firstMouse.x;
     float y =firstMouse.y;


   if(mouse.buttonDown(Mouse::BUTTON_LEFT) && (mouseMove) )
	{

	glColor3f(1.0,0.0,0.0); 

	glLineWidth(2);

	float lastX = lastMouse.x;
	float lastY = lastMouse.y; 
	

	glBegin(GL_LINE_LOOP);
         glVertex2i(x,y);
	     glVertex2i(lastX ,y);
	     glVertex2i(lastX ,lastY);
	     glVertex2i(x,lastY);
	glEnd();

	glFlush();

	glColor3f(1.0,1.0,1.0); 

         }



}

.
.
.

WndProc(HWND hWnd, UINT uiMsg, WPARAM wParam, LPARAM lParam)
{

case WM_MOUSEMOVE:
		mouseMove = true;
             GetCursorPos(&lastMouse);
            break;
default:
		mouseMove = false;
           GetCursorPos(&firstMouse);
        break;

}

Thanks.

Advertisement

in your wndproc, catch the mouse button down event (not sure what its called in Windows but msdn should list all events), it should also give you the position as either wParam or lParam (so you shouldn't have to call GetCursorPos)

store the position when the button goes down. (The event is only sent once per click), then you can get the position either when the button is released or when the mouse moves and calculate the distance from there.

[size="1"]I don't suffer from insanity, I'm enjoying every minute of it.
The voices in my head may not be real, but they have some good ideas!

Thanks a lot smile.png It worked with a little change.I am sharing.Maybe, it requires to someone


LRESULT CALLBACK CWindow::WndProc(HWND hWnd, UINT uiMsg, WPARAM wParam, LPARAM lParam)
{

	case WM_LBUTTONDOWN:
		GetCursorPos(&lastMouse);
                 break;

	case WM_MOUSEMOVE:
		mouseMove = true;
		break;

	default:
		mouseMove = false;
		GetCursorPos(&firstMouse);
                break;

}

This topic is closed to new replies.

Advertisement